diff --git a/bytecode_optimizer/templates/ecmascript_codegen_intrinsics_gen.inc.erb b/bytecode_optimizer/templates/ecmascript_codegen_intrinsics_gen.inc.erb index f5a97af4464556b141e08457c5fb7f30b3a3f9f2..cd92f337d86d088de84dcf4003a23fa33cb3f936 100644 --- a/bytecode_optimizer/templates/ecmascript_codegen_intrinsics_gen.inc.erb +++ b/bytecode_optimizer/templates/ecmascript_codegen_intrinsics_gen.inc.erb @@ -28,9 +28,9 @@ % params_arr = inst.operands case compiler::RuntimeInterface::IntrinsicId::<%= intrinsic_name %>: { % if inst.acc.include?("in") - auto acc_src = inst->GetSrcReg(inst->GetInputsCount() - 2); - if (acc_src != compiler::ACC_REG_ID) { - DoLdaDyn(acc_src, enc->result_); + auto accSrc = inst->GetSrcReg(inst->GetInputsCount() - 2); + if (accSrc != compiler::ACC_REG_ID) { + DoLdaDyn(accSrc, enc->result_); } % end % params_str = "" @@ -47,19 +47,19 @@ % elsif param.id? % if inst.properties.include?("method_id") ASSERT(inst->HasImms() && inst->GetImms().size() > <%= imm_index %>); // NOLINT(readability-container-size-empty) - auto ir_id<%= id_index %> = static_cast(inst->GetImms()[<%= imm_index %>]); - auto bc_id<%= id_index %> = enc->ir_interface_->GetMethodIdByOffset(ir_id<%= id_index %>); -% params_str = params_str + "bc_id#{id_index}, " + auto irId<%= id_index %> = static_cast(inst->GetImms()[<%= imm_index %>]); + auto bcId<%= id_index %> = enc->irInterface_->GetMethodIdByOffset(irId<%= id_index %>); +% params_str = params_str + "bcId#{id_index}, " % elsif inst.properties.include?("string_id") ASSERT(inst->HasImms() && inst->GetImms().size() > <%= imm_index %>); // NOLINT(readability-container-size-empty) - auto ir_id<%= id_index %> = static_cast(inst->GetImms()[<%= imm_index %>]); - auto bc_id<%= id_index %> = enc->ir_interface_->GetStringIdByOffset(ir_id<%= id_index %>); -% params_str = params_str + "bc_id#{id_index}, " + auto irId<%= id_index %> = static_cast(inst->GetImms()[<%= imm_index %>]); + auto bcId<%= id_index %> = enc->irInterface_->GetStringIdByOffset(irId<%= id_index %>); +% params_str = params_str + "bcId#{id_index}, " % elsif inst.properties.include?("literalarray_id") ASSERT(inst->HasImms() && inst->GetImms().size() > <%= imm_index %>); // NOLINT(readability-container-size-empty) - auto ir_id<%= id_index %> = static_cast(inst->GetImms()[<%= imm_index %>]); - auto bc_id<%= id_index %> = std::to_string(ir_id<%= id_index %>); -% params_str = params_str + "bc_id#{id_index}, " + auto irId<%= id_index %> = static_cast(inst->GetImms()[<%= imm_index %>]); + auto bcId<%= id_index %> = std::to_string(irId<%= id_index %>); +% params_str = params_str + "bcId#{id_index}, " % end % id_index = id_index + 1 % imm_index = imm_index + 1 @@ -80,8 +80,8 @@ % end enc->result_.emplace_back(pandasm::Create_<%= inst.asm_token %>(<%= params_str %>)); % if inst.acc.include?("out") - auto acc_dst = inst->GetDstReg(); - if (acc_dst != compiler::ACC_REG_ID) { + auto accDst = inst->GetDstReg(); + if (accDst != compiler::ACC_REG_ID) { DoStaDyn(inst->GetDstReg(), enc->result_); } % end diff --git a/compiler/codegen_intrinsics_ecmascript.cpp b/compiler/codegen_intrinsics_ecmascript.cpp index b28e065de653664a8a37500316be5ff80ce30d97..399f89fd830e13f7785abf6cda709e44f10aa27b 100644 --- a/compiler/codegen_intrinsics_ecmascript.cpp +++ b/compiler/codegen_intrinsics_ecmascript.cpp @@ -28,17 +28,17 @@ static void LoadIFramePtr(Codegen *cg, Reg dst) MemRef(cg->ThreadReg(), cross_values::GetManagedThreadFrameOffset(cg->GetArch()))); } -static MemRef IFrameAccMemRef(Encoder *enc, Reg iframe_reg) +static MemRef IFrameAccMemRef(Encoder *enc, Reg iframeReg) { - return MemRef(iframe_reg, cross_values::GetFrameAccOffset(enc->GetArch())); + return MemRef(iframeReg, cross_values::GetFrameAccOffset(enc->GetArch())); } -MemRef AccMemRef(Encoder *enc, Reg thread, Reg acc_reg) +MemRef AccMemRef(Encoder *enc, Reg thread, Reg accReg) { - enc->EncodeAdd(acc_reg, thread, Imm(ManagedThread::GetFrameOffset())); - auto acc_ptr = MemRef(acc_reg); - enc->EncodeLdr(acc_reg, false, MemRef(acc_ptr)); - return MemRef(acc_reg, cross_values::GetFrameAccOffset(enc->GetArch())); + enc->EncodeAdd(accReg, thread, Imm(ManagedThread::GetFrameOffset())); + auto accPtr = MemRef(accReg); + enc->EncodeLdr(accReg, false, MemRef(accPtr)); + return MemRef(accReg, cross_values::GetFrameAccOffset(enc->GetArch())); } void Codegen::LdlexenvDyn([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src) @@ -46,28 +46,28 @@ void Codegen::LdlexenvDyn([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] GetEncoder()->EncodeLdr(dst, false, MemRef(src[0], cross_values::GetJsfunctionLexicalEnvOffset(GetArch()))); } -static void EncodeLoadParentLexEnv(Codegen *cg, IntrinsicInst *inst, uint32_t level_imm, Reg level_reg, Reg lex_env, - Reg lex_env_ptr) +static void EncodeLoadParentLexEnv(Codegen *cg, IntrinsicInst *inst, uint32_t levelImm, Reg levelReg, Reg lexEnv, + Reg lexEnvPtr) { auto *enc = cg->GetEncoder(); auto arch = enc->GetArch(); auto *runtime = cg->GetRuntime(); auto data = runtime->GetArrayDataOffset(arch); - auto elem_size = runtime->GetTaggedArrayElementSize(); - if (!inst->HasImms() || level_imm > 0U) { + auto elemSize = runtime->GetTaggedArrayElementSize(); + if (!inst->HasImms() || levelImm > 0U) { auto head = enc->CreateLabel(); auto exit = enc->CreateLabel(); ScopedTmpRegU32 counter(enc); if (inst->HasImms()) { - enc->EncodeMov(counter, Imm(level_imm)); + enc->EncodeMov(counter, Imm(levelImm)); } else { - enc->EncodeJump(exit, level_reg.As(INT32_TYPE), Condition::EQ); // fast path for level 0 - enc->EncodeMov(counter, level_reg.As(INT32_TYPE)); + enc->EncodeJump(exit, levelReg.As(INT32_TYPE), Condition::EQ); // fast path for level 0 + enc->EncodeMov(counter, levelReg.As(INT32_TYPE)); } enc->BindLabel(head); // get parent env - enc->EncodeLdr(lex_env, false, MemRef(lex_env_ptr, data + runtime->GetLexicalEnvParentEnvIndex() * elem_size)); + enc->EncodeLdr(lexEnv, false, MemRef(lexEnvPtr, data + runtime->GetLexicalEnvParentEnvIndex() * elemSize)); enc->EncodeSub(counter, counter, Imm(1U)); enc->EncodeJump(head, counter, Condition::NE); enc->BindLabel(exit); @@ -79,8 +79,8 @@ void Codegen::EncodeGetUnmappedArgs(IntrinsicInst *inst, [[maybe_unused]] Reg ds auto *enc = GetEncoder(); auto slot = GetRuntime()->GetNumMandatoryArgs(); auto offset = GetStackOffset(Location(LocationType::STACK_PARAMETER, slot)); - Reg param_1 = GetTarget().GetParamReg(1); - enc->EncodeAdd(param_1, SpReg(), Imm(offset)); + Reg param1 = GetTarget().GetParamReg(1); + enc->EncodeAdd(param1, SpReg(), Imm(offset)); CreateCallIntrinsic(inst); } @@ -94,31 +94,31 @@ void Codegen::LdLexVarDyn(IntrinsicInst *inst, Reg dst, SRCREGS src) auto *runtime = GetRuntime(); ScopedTmpRegU64 tmp(enc); - auto lex_env = tmp.GetReg().As(Codegen::ConvertDataType(DataType::ANY, arch)); - auto lex_env_ptr = tmp.GetReg().As(Codegen::ConvertDataType(DataType::POINTER, arch)); - ASSERT(lex_env.GetSize() >= lex_env_ptr.GetSize()); + auto lexEnv = tmp.GetReg().As(Codegen::ConvertDataType(DataType::ANY, arch)); + auto lexEnvPtr = tmp.GetReg().As(Codegen::ConvertDataType(DataType::POINTER, arch)); + ASSERT(lexEnv.GetSize() >= lexEnvPtr.GetSize()); ASSERT(GetGraph()->SupportManagedCode() == (inst->GetSaveState() == nullptr)); - std::size_t lex_env_index = GetGraph()->GetMode().IsInterpreter() ? 2 : 0; - enc->EncodeMov(tmp, src[lex_env_index]); + std::size_t lexEnvIndex = GetGraph()->GetMode().IsInterpreter() ? 2 : 0; + enc->EncodeMov(tmp, src[lexEnvIndex]); - EncodeLoadParentLexEnv(this, inst, inst->HasImms() ? inst->GetImm(0) : 0, src[0], lex_env, lex_env_ptr); + EncodeLoadParentLexEnv(this, inst, inst->HasImms() ? inst->GetImm(0) : 0, src[0], lexEnv, lexEnvPtr); auto data = runtime->GetArrayDataOffset(arch); - auto elem_size = runtime->GetTaggedArrayElementSize(); + auto elemSize = runtime->GetTaggedArrayElementSize(); auto start = runtime->GetLexicalEnvStartDataIndex(); constexpr size_t SLOT_INDEX = 1U; if (!GetGraph()->GetMode().IsInterpreter()) { - enc->EncodeLdr(dst, false, MemRef(lex_env_ptr, data + (start + inst->GetImms()[SLOT_INDEX]) * elem_size)); + enc->EncodeLdr(dst, false, MemRef(lexEnvPtr, data + (start + inst->GetImms()[SLOT_INDEX]) * elemSize)); } else { auto props = tmp.GetReg().As(Codegen::ConvertDataType(DataType::ANY, arch)); enc->EncodeLdr(props, false, - MemRef(lex_env_ptr, src[SLOT_INDEX].As(INT32_TYPE), elem_size, data + start * elem_size)); + MemRef(lexEnvPtr, src[SLOT_INDEX].As(INT32_TYPE), elemSize, data + start * elemSize)); // save to acc - ScopedTmpReg iframe_reg(enc, Codegen::ConvertDataType(DataType::POINTER, arch)); - LoadIFramePtr(this, iframe_reg); - enc->EncodeStr(props, IFrameAccMemRef(enc, iframe_reg)); + ScopedTmpReg iframeReg(enc, Codegen::ConvertDataType(DataType::POINTER, arch)); + LoadIFramePtr(this, iframeReg); + enc->EncodeStr(props, IFrameAccMemRef(enc, iframeReg)); } } @@ -132,26 +132,26 @@ void Codegen::StLexVarDyn(IntrinsicInst *inst, [[maybe_unused]] Reg dst, SRCREGS auto *runtime = GetRuntime(); ScopedTmpRegU64 tmp(enc); - auto lex_env = tmp.GetReg().As(Codegen::ConvertDataType(DataType::ANY, arch)); - auto lex_env_ptr = tmp.GetReg().As(Codegen::ConvertDataType(DataType::POINTER, arch)); - ASSERT(lex_env.GetSize() >= lex_env_ptr.GetSize()); + auto lexEnv = tmp.GetReg().As(Codegen::ConvertDataType(DataType::ANY, arch)); + auto lexEnvPtr = tmp.GetReg().As(Codegen::ConvertDataType(DataType::POINTER, arch)); + ASSERT(lexEnv.GetSize() >= lexEnvPtr.GetSize()); ASSERT(GetGraph()->SupportManagedCode() == (inst->GetSaveState() == nullptr)); - std::size_t lex_env_index = GetGraph()->GetMode().IsInterpreter() ? 3 : 1; - enc->EncodeMov(tmp, src[lex_env_index]); + std::size_t lexEnvIndex = GetGraph()->GetMode().IsInterpreter() ? 3 : 1; + enc->EncodeMov(tmp, src[lexEnvIndex]); - EncodeLoadParentLexEnv(this, inst, inst->HasImms() ? inst->GetImm(0) : 0, src[0], lex_env, lex_env_ptr); + EncodeLoadParentLexEnv(this, inst, inst->HasImms() ? inst->GetImm(0) : 0, src[0], lexEnv, lexEnvPtr); auto data = runtime->GetArrayDataOffset(arch); - auto elem_size = runtime->GetTaggedArrayElementSize(); + auto elemSize = runtime->GetTaggedArrayElementSize(); auto start = runtime->GetLexicalEnvStartDataIndex(); constexpr size_t SLOT_INDEX = 1U; - std::size_t acc_index = GetGraph()->GetMode().IsInterpreter() ? 2 : 0; + std::size_t accIndex = GetGraph()->GetMode().IsInterpreter() ? 2 : 0; if (!GetGraph()->GetMode().IsInterpreter()) { - enc->EncodeStr(src[acc_index], MemRef(lex_env_ptr, data + (start + inst->GetImms()[SLOT_INDEX]) * elem_size)); + enc->EncodeStr(src[accIndex], MemRef(lexEnvPtr, data + (start + inst->GetImms()[SLOT_INDEX]) * elemSize)); } else { - enc->EncodeStr(src[acc_index], - MemRef(lex_env_ptr, src[SLOT_INDEX].As(INT32_TYPE), elem_size, data + start * elem_size)); + enc->EncodeStr(src[accIndex], + MemRef(lexEnvPtr, src[SLOT_INDEX].As(INT32_TYPE), elemSize, data + start * elemSize)); } } @@ -170,44 +170,44 @@ void Codegen::StLexDyn(IntrinsicInst *inst, [[maybe_unused]] Reg dst, SRCREGS sr auto *runtime = GetRuntime(); ScopedTmpRegU64 tmp(enc); - auto lex_env = tmp.GetReg().As(Codegen::ConvertDataType(DataType::ANY, arch)); - auto lex_env_ptr = tmp.GetReg().As(Codegen::ConvertDataType(DataType::POINTER, arch)); - ASSERT(lex_env.GetSize() >= lex_env_ptr.GetSize()); + auto lexEnv = tmp.GetReg().As(Codegen::ConvertDataType(DataType::ANY, arch)); + auto lexEnvPtr = tmp.GetReg().As(Codegen::ConvertDataType(DataType::POINTER, arch)); + ASSERT(lexEnv.GetSize() >= lexEnvPtr.GetSize()); - std::size_t lex_env_index = GetGraph()->GetMode().IsInterpreter() ? 4 : 1; - enc->EncodeMov(tmp, src[lex_env_index]); + std::size_t lexEnvIndex = GetGraph()->GetMode().IsInterpreter() ? 4 : 1; + enc->EncodeMov(tmp, src[lexEnvIndex]); - EncodeLoadParentLexEnv(this, inst, inst->HasImms() ? inst->GetImm(1) : 0, src[1], lex_env, lex_env_ptr); + EncodeLoadParentLexEnv(this, inst, inst->HasImms() ? inst->GetImm(1) : 0, src[1], lexEnv, lexEnvPtr); auto data = runtime->GetArrayDataOffset(arch); - auto elem_size = runtime->GetTaggedArrayElementSize(); + auto elemSize = runtime->GetTaggedArrayElementSize(); auto start = runtime->GetLexicalEnvStartDataIndex(); constexpr size_t SLOT_INDEX = 1U; - auto mem_ref = MemRef(lex_env_ptr, data + (start + inst->GetImms()[SLOT_INDEX]) * elem_size); + auto memRef = MemRef(lexEnvPtr, data + (start + inst->GetImms()[SLOT_INDEX]) * elemSize); - ScopedTmpReg tmp_reg(enc, ConvertDataType(DataType::REFERENCE, arch)); - enc->EncodeLdr(tmp_reg, false, mem_ref); - auto slow_path = CreateSlowPath(inst, DeoptimizeType::HOLE); - enc->EncodeJump(slow_path->GetLabel(), tmp_reg, Imm(panda::coretypes::TaggedValue::VALUE_HOLE), Condition::EQ); + ScopedTmpReg tmpReg(enc, ConvertDataType(DataType::REFERENCE, arch)); + enc->EncodeLdr(tmpReg, false, memRef); + auto slowPath = CreateSlowPath(inst, DeoptimizeType::HOLE); + enc->EncodeJump(slowPath->GetLabel(), tmpReg, Imm(panda::coretypes::TaggedValue::VALUE_HOLE), Condition::EQ); - std::size_t acc_index = 0; - enc->EncodeStr(src[acc_index], mem_ref); + std::size_t accIndex = 0; + enc->EncodeStr(src[accIndex], memRef); } void Codegen::GetObjectClassTypeIntrinsic([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, SRCREGS src) { - ScopedTmpReg tmp_reg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); - Reg tmp_reg_ref = tmp_reg.GetReg().As(ConvertDataType(DataType::REFERENCE, GetArch())); + ScopedTmpReg tmpReg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); + Reg tmpRegRef = tmpReg.GetReg().As(ConvertDataType(DataType::REFERENCE, GetArch())); - GetEncoder()->EncodeLdr(tmp_reg_ref, false, MemRef(src[0], GetRuntime()->GetObjClassOffset(GetArch()))); - GetEncoder()->EncodeLdr(tmp_reg, false, MemRef(tmp_reg_ref, cross_values::GetJshclassBitfieldOffset(GetArch()))); - GetEncoder()->EncodeAnd(tmp_reg, tmp_reg, + GetEncoder()->EncodeLdr(tmpRegRef, false, MemRef(src[0], GetRuntime()->GetObjClassOffset(GetArch()))); + GetEncoder()->EncodeLdr(tmpReg, false, MemRef(tmpRegRef, cross_values::GetJshclassBitfieldOffset(GetArch()))); + GetEncoder()->EncodeAnd(tmpReg, tmpReg, Imm(static_cast(cross_values::GetJshclassBitfieldTypeMask(GetArch())))); - auto type_start_bit = cross_values::GetJshclassBitfieldTypeStartBit(GetArch()); - if (type_start_bit != 0) { - GetEncoder()->EncodeShr(tmp_reg, tmp_reg, Imm(type_start_bit)); + auto typeStartBit = cross_values::GetJshclassBitfieldTypeStartBit(GetArch()); + if (typeStartBit != 0) { + GetEncoder()->EncodeShr(tmpReg, tmpReg, Imm(typeStartBit)); } - GetEncoder()->EncodeMov(dst, tmp_reg); + GetEncoder()->EncodeMov(dst, tmpReg); } void Codegen::GetWeakReferent([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, @@ -219,18 +219,18 @@ void Codegen::GetWeakReferent([[maybe_unused]] IntrinsicInst *inst, [[maybe_unus void Codegen::CreateDynClassIsDictionaryElement([[maybe_unused]] IntrinsicInst *inst, Reg dst, SRCREGS src) { - ScopedTmpReg tmp_reg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); - GetEncoder()->EncodeLdr(tmp_reg, false, MemRef(src[0], cross_values::GetJshclassBitfieldOffset(GetArch()))); - GetEncoder()->EncodeShr(tmp_reg, tmp_reg, Imm(cross_values::GetJshclassBitfieldIsDictionaryStartBit(GetArch()))); - GetEncoder()->EncodeAnd(dst, tmp_reg, Imm(1U)); + ScopedTmpReg tmpReg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); + GetEncoder()->EncodeLdr(tmpReg, false, MemRef(src[0], cross_values::GetJshclassBitfieldOffset(GetArch()))); + GetEncoder()->EncodeShr(tmpReg, tmpReg, Imm(cross_values::GetJshclassBitfieldIsDictionaryStartBit(GetArch()))); + GetEncoder()->EncodeAnd(dst, tmpReg, Imm(1U)); } void Codegen::CreateDynClassIsExtensible([[maybe_unused]] IntrinsicInst *inst, Reg dst, SRCREGS src) { - ScopedTmpReg tmp_reg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); - GetEncoder()->EncodeLdr(tmp_reg, false, MemRef(src[0], cross_values::GetJshclassBitfieldOffset(GetArch()))); - GetEncoder()->EncodeShr(tmp_reg, tmp_reg, Imm(cross_values::GetJshclassBitfieldExtensibleStartBit(GetArch()))); - GetEncoder()->EncodeAnd(dst, tmp_reg, Imm(1U)); + ScopedTmpReg tmpReg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); + GetEncoder()->EncodeLdr(tmpReg, false, MemRef(src[0], cross_values::GetJshclassBitfieldOffset(GetArch()))); + GetEncoder()->EncodeShr(tmpReg, tmpReg, Imm(cross_values::GetJshclassBitfieldExtensibleStartBit(GetArch()))); + GetEncoder()->EncodeAnd(dst, tmpReg, Imm(1U)); } void Codegen::CreateDynObjectGetClass(IntrinsicInst *inst, Reg dst, SRCREGS src) @@ -244,10 +244,10 @@ void Codegen::CreateDynObjectGetClass(IntrinsicInst *inst, Reg dst, SRCREGS src) void Codegen::CreateDynObjectSetClass(IntrinsicInst *inst, [[maybe_unused]] Reg dst, SRCREGS src) { - ScopedTmpReg tmp_reg(GetEncoder(), ConvertDataType(DataType::REFERENCE, GetArch())); - GetEncoder()->EncodeMov(tmp_reg, src[1]); - GetEncoder()->EncodeAdd(tmp_reg, tmp_reg, Imm(cross_values::GetJshclassHclassOffset(GetArch()))); - GetEncoder()->EncodeStr(tmp_reg, MemRef(src[0], GetRuntime()->GetObjClassOffset(GetArch()))); + ScopedTmpReg tmpReg(GetEncoder(), ConvertDataType(DataType::REFERENCE, GetArch())); + GetEncoder()->EncodeMov(tmpReg, src[1]); + GetEncoder()->EncodeAdd(tmpReg, tmpReg, Imm(cross_values::GetJshclassHclassOffset(GetArch()))); + GetEncoder()->EncodeStr(tmpReg, MemRef(src[0], GetRuntime()->GetObjClassOffset(GetArch()))); if (inst->GetSaveState() != nullptr) { CreateStackMap(inst); } @@ -255,11 +255,11 @@ void Codegen::CreateDynObjectSetClass(IntrinsicInst *inst, [[maybe_unused]] Reg void Codegen::CreateDynClassNumberOfProps([[maybe_unused]] IntrinsicInst *inst, Reg dst, SRCREGS src) { - ScopedTmpReg tmp_reg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); - GetEncoder()->EncodeLdr(tmp_reg, false, MemRef(src[0], cross_values::GetJshclassBitfield1Offset(GetArch()))); - GetEncoder()->EncodeShr(tmp_reg, tmp_reg, + ScopedTmpReg tmpReg(GetEncoder(), ConvertDataType(DataType::UINT64, GetArch())); + GetEncoder()->EncodeLdr(tmpReg, false, MemRef(src[0], cross_values::GetJshclassBitfield1Offset(GetArch()))); + GetEncoder()->EncodeShr(tmpReg, tmpReg, Imm(cross_values::GetJshclassBitfield1NumberOfPropsBitsStartBit(GetArch()))); - GetEncoder()->EncodeAnd(dst, tmp_reg, Imm(cross_values::GetJshclassBitfield1NumberOfPropsBitsMask(GetArch()))); + GetEncoder()->EncodeAnd(dst, tmpReg, Imm(cross_values::GetJshclassBitfield1NumberOfPropsBitsMask(GetArch()))); } void Codegen::CreateDynClassGetHash([[maybe_unused]] IntrinsicInst *inst, Reg dst, SRCREGS src) @@ -290,22 +290,22 @@ void Codegen::CreateResolveAllocResult([[maybe_unused]] IntrinsicInst *inst, Reg void Codegen::CreateEcmaStringEquals([[maybe_unused]] IntrinsicInst *inst, Reg dst, SRCREGS src) { - auto entrypoint_id = GetRuntime()->IsCompressedStringsEnabled() ? EntrypointId::ECMA_STRING_EQUALS_COMPRESSED - : EntrypointId::ECMA_STRING_EQUALS; - CallFastPath(inst, entrypoint_id, dst, {}, src[0], src[1U]); + auto entrypointId = GetRuntime()->IsCompressedStringsEnabled() ? EntrypointId::ECMA_STRING_EQUALS_COMPRESSED + : EntrypointId::ECMA_STRING_EQUALS; + CallFastPath(inst, entrypointId, dst, {}, src[0], src[1U]); } void Codegen::CreateFastPathStrictEq([[maybe_unused]] IntrinsicInst *inst, Reg dst, SRCREGS src) { - auto entrypoint_id = EntrypointId::FAST_PATH_ECMA_STRICT_EQ; - CallFastPath(inst, entrypoint_id, dst, {}, src[0], src[1U]); + auto entrypointId = EntrypointId::FAST_PATH_ECMA_STRICT_EQ; + CallFastPath(inst, entrypointId, dst, {}, src[0], src[1U]); GetEncoder()->EncodeOr(dst, dst, Imm(panda::coretypes::TaggedValue::VALUE_FALSE)); } void Codegen::CreateFastPathStrictNotEq([[maybe_unused]] IntrinsicInst *inst, Reg dst, SRCREGS src) { - auto entrypoint_id = EntrypointId::FAST_PATH_ECMA_STRICT_EQ; - CallFastPath(inst, entrypoint_id, dst, {}, src[0], src[1U]); + auto entrypointId = EntrypointId::FAST_PATH_ECMA_STRICT_EQ; + CallFastPath(inst, entrypointId, dst, {}, src[0], src[1U]); GetEncoder()->EncodeXor(dst, dst, Imm(1)); GetEncoder()->EncodeOr(dst, dst, Imm(panda::coretypes::TaggedValue::VALUE_FALSE)); } diff --git a/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp b/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp index 7d6de0e9ec02d1a9fb1b498d4167df3f94480356..38bc9fffdd1a82c981dd80730688dc74bb1da120 100644 --- a/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp +++ b/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp @@ -21,14 +21,14 @@ namespace panda::compiler { bool Codegen::GenerateLoadObjectDynamic(Inst *inst) { - auto dst_reg = ConvertRegister(inst->GetDstReg(), inst->GetType()); - auto obj_reg = ConvertRegister(inst->GetSrcReg(0), inst->GetInputType(0)); - auto key_reg = ConvertRegister(inst->GetSrcReg(1U), inst->GetInputType(1U)); - auto this_func = ConvertRegister(inst->GetSrcReg(2U), inst->GetInputType(2U)); + auto dstReg = ConvertRegister(inst->GetDstReg(), inst->GetType()); + auto objReg = ConvertRegister(inst->GetSrcReg(0), inst->GetInputType(0)); + auto keyReg = ConvertRegister(inst->GetSrcReg(1U), inst->GetInputType(1U)); + auto thisFunc = ConvertRegister(inst->GetSrcReg(2U), inst->GetInputType(2U)); auto type = inst->CastToLoadObjectDynamic()->GetAccessType(); auto mode = inst->CastToLoadObjectDynamic()->GetAccessMode(); - auto use_ic = type == DynObjectAccessType::BY_NAME; + auto useIc = type == DynObjectAccessType::BY_NAME; EntrypointId id = EntrypointId::LOAD_OBJECT_DYNAMIC; @@ -40,13 +40,13 @@ bool Codegen::GenerateLoadObjectDynamic(Inst *inst) id = EntrypointId::LOAD_OBJECT_DYNAMIC_BY_NAME; } - if (use_ic) { - CallFastPath(inst, id, dst_reg, {}, obj_reg, key_reg, TypedImm(inst->GetPc())); + if (useIc) { + CallFastPath(inst, id, dstReg, {}, objReg, keyReg, TypedImm(inst->GetPc())); } else { if (type != DynObjectAccessType::BY_INDEX) { - CallFastPath(inst, id, dst_reg, {}, obj_reg, key_reg, this_func); + CallFastPath(inst, id, dstReg, {}, objReg, keyReg, thisFunc); } else { - CallFastPath(inst, id, dst_reg, {}, obj_reg, key_reg); + CallFastPath(inst, id, dstReg, {}, objReg, keyReg); } } @@ -55,15 +55,15 @@ bool Codegen::GenerateLoadObjectDynamic(Inst *inst) bool Codegen::GenerateStoreObjectDynamic(Inst *inst) { - auto dst_reg = ConvertRegister(inst->GetDstReg(), inst->GetType()); - auto obj_reg = ConvertRegister(inst->GetSrcReg(0), inst->GetInputType(0)); - auto key_reg = ConvertRegister(inst->GetSrcReg(1U), inst->GetInputType(1U)); - auto val_reg = ConvertRegister(inst->GetSrcReg(2U), inst->GetInputType(2U)); - auto this_func = ConvertRegister(inst->GetSrcReg(3U), inst->GetInputType(3U)); + auto dstReg = ConvertRegister(inst->GetDstReg(), inst->GetType()); + auto objReg = ConvertRegister(inst->GetSrcReg(0), inst->GetInputType(0)); + auto keyReg = ConvertRegister(inst->GetSrcReg(1U), inst->GetInputType(1U)); + auto valReg = ConvertRegister(inst->GetSrcReg(2U), inst->GetInputType(2U)); + auto thisFunc = ConvertRegister(inst->GetSrcReg(3U), inst->GetInputType(3U)); auto type = inst->CastToStoreObjectDynamic()->GetAccessType(); auto mode = inst->CastToStoreObjectDynamic()->GetAccessMode(); - auto use_ic = type == DynObjectAccessType::BY_NAME; + auto useIc = type == DynObjectAccessType::BY_NAME; EntrypointId id = EntrypointId::STORE_OBJECT_DYNAMIC; @@ -75,13 +75,13 @@ bool Codegen::GenerateStoreObjectDynamic(Inst *inst) id = EntrypointId::STORE_OBJECT_DYNAMIC_BY_NAME; } - if (use_ic) { - CallFastPath(inst, id, dst_reg, {}, obj_reg, key_reg, val_reg, TypedImm(inst->GetPc())); + if (useIc) { + CallFastPath(inst, id, dstReg, {}, objReg, keyReg, valReg, TypedImm(inst->GetPc())); } else { if (type != DynObjectAccessType::BY_INDEX) { - CallFastPath(inst, id, dst_reg, {}, obj_reg, key_reg, val_reg, this_func); + CallFastPath(inst, id, dstReg, {}, objReg, keyReg, valReg, thisFunc); } else { - CallFastPath(inst, id, dst_reg, {}, obj_reg, key_reg, val_reg); + CallFastPath(inst, id, dstReg, {}, objReg, keyReg, valReg); } } diff --git a/compiler/ecmascript_extensions/ecmascript_compiler_interface.h b/compiler/ecmascript_extensions/ecmascript_compiler_interface.h index c7b9cd48139ca5bc81293c42319db5f90b97b853..3c2f470095795b7e123bd535ce3b6500b005436f 100644 --- a/compiler/ecmascript_extensions/ecmascript_compiler_interface.h +++ b/compiler/ecmascript_extensions/ecmascript_compiler_interface.h @@ -40,28 +40,28 @@ virtual NewObjDynInfo GetNewObjDynInfo([[maybe_unused]] uintptr_t method) const } virtual bool GetProfileDataForNamedAccess( - [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t slot_id, + [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t slotId, [[maybe_unused]] ArenaVector *profile) { return false; } virtual bool GetProfileDataForNamedAccess( - [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t func, [[maybe_unused]] uintptr_t slot_id, + [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t func, [[maybe_unused]] uintptr_t slotId, [[maybe_unused]] ArenaVector *profile) { return false; } virtual bool GetProfileDataForValueAccess( - [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t slot_id, + [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t slotId, [[maybe_unused]] ArenaVector *profile) { return false; } virtual bool GetProfileDataForValueAccess( - [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t func, [[maybe_unused]] uintptr_t slot_id, + [[maybe_unused]] RuntimeInterface::MethodPtr m, [[maybe_unused]] uintptr_t func, [[maybe_unused]] uintptr_t slotId, [[maybe_unused]] ArenaVector *profile) { return false; @@ -102,13 +102,13 @@ struct GlobalVarInfo { }; virtual GlobalVarInfo GetGlobalVarInfo([[maybe_unused]] MethodPtr method, [[maybe_unused]] size_t id, - [[maybe_unused]] uintptr_t slot_id) const + [[maybe_unused]] uintptr_t slotId) const { return {GlobalVarInfo::Type::DEFAULT, 0}; } virtual GlobalVarInfo GetGlobalVarInfo([[maybe_unused]] MethodPtr method, [[maybe_unused]] uintptr_t func, - [[maybe_unused]] size_t id, [[maybe_unused]] uintptr_t slot_id) const + [[maybe_unused]] size_t id, [[maybe_unused]] uintptr_t slotId) const { return {GlobalVarInfo::Type::DEFAULT, 0}; } diff --git a/compiler/ecmascript_extensions/ecmascript_environment.h b/compiler/ecmascript_extensions/ecmascript_environment.h index 23b4429a04e1419e1ee514f1a336725f609b4ec3..0190b8268b689d698e430cc122c304cace01fcee 100644 --- a/compiler/ecmascript_extensions/ecmascript_environment.h +++ b/compiler/ecmascript_extensions/ecmascript_environment.h @@ -34,7 +34,7 @@ class JSHandle; class EcmascriptEnvironment { public: EcmascriptEnvironment(ObjectHeader *cp, ObjectHeader *le, ObjectHeader *tf) - : constant_pool_(cp), lexical_env_(le), this_func_(tf) + : constantPool_(cp), lexicalEnv_(le), thisFunc_(tf) { } @@ -45,47 +45,47 @@ public: static constexpr size_t GetConstantPoolOffset() { - return MEMBER_OFFSET(EcmascriptEnvironment, constant_pool_); + return MEMBER_OFFSET(EcmascriptEnvironment, constantPool_); } static constexpr size_t GetLexicalEnvOffset() { - return MEMBER_OFFSET(EcmascriptEnvironment, lexical_env_); + return MEMBER_OFFSET(EcmascriptEnvironment, lexicalEnv_); } static constexpr size_t GetThisFuncOffset() { - return MEMBER_OFFSET(EcmascriptEnvironment, this_func_); + return MEMBER_OFFSET(EcmascriptEnvironment, thisFunc_); } ObjectHeader *GetConstantPool() const { - return constant_pool_.GetHeapObject(); + return constantPool_.GetHeapObject(); } ObjectHeader *GetLexicalEnv() const { - return lexical_env_.GetHeapObject(); + return lexicalEnv_.GetHeapObject(); } void SetLexicalEnv(ObjectHeader *le) { - lexical_env_ = panda::coretypes::TaggedValue(le); + lexicalEnv_ = panda::coretypes::TaggedValue(le); } void SetConstantPool(ObjectHeader *cp) { - constant_pool_ = panda::coretypes::TaggedValue(cp); + constantPool_ = panda::coretypes::TaggedValue(cp); } ObjectHeader *GetThisFunc() const { - return this_func_.GetHeapObject(); + return thisFunc_.GetHeapObject(); } - void SetThisFunc(ObjectHeader *this_func) + void SetThisFunc(ObjectHeader *thisFunc) { - this_func_ = panda::coretypes::TaggedValue(this_func); + thisFunc_ = panda::coretypes::TaggedValue(thisFunc); } static constexpr size_t GetSize() @@ -94,9 +94,9 @@ public: } private: - panda::coretypes::TaggedValue constant_pool_; - panda::coretypes::TaggedValue lexical_env_; - panda::coretypes::TaggedValue this_func_; + panda::coretypes::TaggedValue constantPool_; + panda::coretypes::TaggedValue lexicalEnv_; + panda::coretypes::TaggedValue thisFunc_; }; } // namespace ecmascript diff --git a/compiler/ecmascript_extensions/ecmascript_irtoc_interface.h b/compiler/ecmascript_extensions/ecmascript_irtoc_interface.h index 14a415f1eb06aa1657164ab0484c5c77232e9f87..f26e8b568cf5823de874efc6f727f868bed7ea22 100644 --- a/compiler/ecmascript_extensions/ecmascript_irtoc_interface.h +++ b/compiler/ecmascript_extensions/ecmascript_irtoc_interface.h @@ -18,39 +18,39 @@ size_t GetGlobalConstStringOffsetForAnyType(compiler::AnyBaseType type, Arch arch) const override { - auto global_const_array_offset = + auto globalConstArrayOffset = cross_values::GetJsthreadGlobalConstantsOffset(arch) + cross_values::GetGlobalConstConstantsOffset(arch); switch (type) { case compiler::AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::UNDEFINED_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::UNDEFINED_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_STRING_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::STRING_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::STRING_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_INT_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_SYMBOL_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::SYMBOL_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::SYMBOL_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_CALLABLE_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::FUNCTION_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::FUNCTION_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::BOOLEAN_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::BOOLEAN_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_NULL_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_BIGINT_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::BIGINT_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::BIGINT_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); default: UNREACHABLE(); } diff --git a/compiler/inline_intrinsics_ecmascript.cpp b/compiler/inline_intrinsics_ecmascript.cpp index f9ac928e24775fed83cd9735037ea1f92329c8c3..ea41f3595b9882403541d9798ad5c70b4599858f 100644 --- a/compiler/inline_intrinsics_ecmascript.cpp +++ b/compiler/inline_intrinsics_ecmascript.cpp @@ -22,29 +22,29 @@ namespace panda::compiler { template -bool InlineLdConstant(IntrinsicInst *intrinsic, AnyBaseType any_type, T value) +bool InlineLdConstant(IntrinsicInst *intrinsic, AnyBaseType anyType, T value) { - auto current_block = intrinsic->GetBasicBlock(); - auto graph = current_block->GetGraph(); + auto currentBlock = intrinsic->GetBasicBlock(); + auto graph = currentBlock->GetGraph(); auto cnst = graph->FindOrCreateConstant(value); - auto cast_to_any_inst = graph->CreateInstCastValueToAnyType(intrinsic->GetPc(), any_type, cnst); - current_block->InsertAfter(cast_to_any_inst, intrinsic); + auto castToAnyInst = graph->CreateInstCastValueToAnyType(intrinsic->GetPc(), anyType, cnst); + currentBlock->InsertAfter(castToAnyInst, intrinsic); - intrinsic->ReplaceUsers(cast_to_any_inst); - current_block->RemoveInst(intrinsic); + intrinsic->ReplaceUsers(castToAnyInst); + currentBlock->RemoveInst(intrinsic); return true; } bool InlineLdConstant(IntrinsicInst *intrinsic, DataType::Any value) { - auto current_block = intrinsic->GetBasicBlock(); - auto graph = current_block->GetGraph(); + auto currentBlock = intrinsic->GetBasicBlock(); + auto graph = currentBlock->GetGraph(); auto cnst = graph->FindOrCreateConstant(value); intrinsic->ReplaceUsers(cnst); - current_block->RemoveInst(intrinsic); + currentBlock->RemoveInst(intrinsic); return true; } @@ -87,255 +87,254 @@ bool InlineIntrinsics::InlineLdNan(IntrinsicInst *intrinsic) bool InlineIntrinsics::InlineTypeOf(IntrinsicInst *intrinsic) { - auto any_type = intrinsic->GetInput(0).GetInst(); - if (any_type->GetOpcode() != Opcode::AnyTypeCheck) { + auto anyType = intrinsic->GetInput(0).GetInst(); + if (anyType->GetOpcode() != Opcode::AnyTypeCheck) { return false; } - auto type = any_type->CastToAnyTypeCheck()->GetAnyType(); + auto type = anyType->CastToAnyTypeCheck()->GetAnyType(); if (type == AnyBaseType::UNDEFINED_TYPE) { return false; } - auto any_name = GetGraph()->CreateInstGetAnyTypeName(intrinsic->GetPc(), type); - intrinsic->InsertAfter(any_name); - intrinsic->ReplaceUsers(any_name); + auto anyName = GetGraph()->CreateInstGetAnyTypeName(intrinsic->GetPc(), type); + intrinsic->InsertAfter(anyName); + intrinsic->ReplaceUsers(anyName); return true; } -void InlineIntrinsics::CreateCompareClass(uint32_t pc, Inst *get_cls_inst, RuntimeInterface::ClassPtr receiver, - BasicBlock *load_bb) +void InlineIntrinsics::CreateCompareClass(uint32_t pc, Inst *getClsInst, RuntimeInterface::ClassPtr receiver, + BasicBlock *loadBb) { - auto load_cls_inst = GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, receiver); - auto cmp_inst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, load_cls_inst, get_cls_inst, DataType::REFERENCE, - ConditionCode::CC_EQ); - auto if_inst = GetGraph()->CreateInstIfImm(DataType::BOOL, pc, cmp_inst, 0, DataType::BOOL, ConditionCode::CC_NE); + auto loadClsInst = GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, receiver); + auto cmpInst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, loadClsInst, getClsInst, DataType::REFERENCE, + ConditionCode::CC_EQ); + auto ifInst = GetGraph()->CreateInstIfImm(DataType::BOOL, pc, cmpInst, 0, DataType::BOOL, ConditionCode::CC_NE); // We insert LoadImmediate in Dominate blockm because VN can be applied - get_cls_inst->InsertAfter(load_cls_inst); - load_bb->AppendInst(cmp_inst); - load_bb->AppendInst(if_inst); + getClsInst->InsertAfter(loadClsInst); + loadBb->AppendInst(cmpInst); + loadBb->AppendInst(ifInst); } -Inst *InlineIntrinsics::CreateCompareClassWithDeopt(uint32_t pc, Inst *get_cls_inst, - RuntimeInterface::ClassPtr receiver, Inst *save_state) +Inst *InlineIntrinsics::CreateCompareClassWithDeopt(uint32_t pc, Inst *getClsInst, RuntimeInterface::ClassPtr receiver, + Inst *saveState) { - auto load_cls_inst = GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, receiver); - auto cmp_inst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, get_cls_inst, load_cls_inst, DataType::REFERENCE, - ConditionCode::CC_NE); - auto deopt_inst = - GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmp_inst, save_state, DeoptimizeType::INLINE_IC); - get_cls_inst->InsertAfter(deopt_inst); - get_cls_inst->InsertAfter(cmp_inst); - get_cls_inst->InsertAfter(load_cls_inst); - return deopt_inst; + auto loadClsInst = GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, receiver); + auto cmpInst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, getClsInst, loadClsInst, DataType::REFERENCE, + ConditionCode::CC_NE); + auto deoptInst = + GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmpInst, saveState, DeoptimizeType::INLINE_IC); + getClsInst->InsertAfter(deoptInst); + getClsInst->InsertAfter(cmpInst); + getClsInst->InsertAfter(loadClsInst); + return deoptInst; } -Inst *InsertLoadObject(Inst *input, uint32_t type_id, RuntimeInterface::MethodPtr method, uint32_t pc, - RuntimeInterface::FieldPtr field, ObjectType obj_type, Inst *insert_after, - DataType::Type data_type) +Inst *InsertLoadObject(Inst *input, uint32_t typeId, RuntimeInterface::MethodPtr method, uint32_t pc, + RuntimeInterface::FieldPtr field, ObjectType objType, Inst *insertAfter, DataType::Type dataType) { - auto load_object = - input->GetBasicBlock()->GetGraph()->CreateInstLoadObject(data_type, pc, input, type_id, method, field); - load_object->SetObjectType(obj_type); - insert_after->InsertAfter(load_object); - return load_object; + auto loadObject = + input->GetBasicBlock()->GetGraph()->CreateInstLoadObject(dataType, pc, input, typeId, method, field); + loadObject->SetObjectType(objType); + insertAfter->InsertAfter(loadObject); + return loadObject; } -void InsertCheckJSArrayLength(Inst *obj, Inst *index, Inst *insert_after, RuntimeInterface::MethodPtr method, +void InsertCheckJSArrayLength(Inst *obj, Inst *index, Inst *insertAfter, RuntimeInterface::MethodPtr method, uint32_t pc) { - auto curr_bb = insert_after->GetBasicBlock(); - auto graph = curr_bb->GetGraph(); + auto currBb = insertAfter->GetBasicBlock(); + auto graph = currBb->GetGraph(); // Insert Load Object length field for JsArray object auto length = InsertLoadObject(obj, TypeIdMixin::MEM_DYN_ARRAY_LENGTH_ID, method, pc, nullptr, - ObjectType::MEM_DYN_ARRAY_LENGTH, insert_after, DataType::INT32); + ObjectType::MEM_DYN_ARRAY_LENGTH, insertAfter, DataType::INT32); - auto cmp_inst = graph->CreateInstCompare(DataType::BOOL, pc, index, length, DataType::INT32, ConditionCode::CC_LT); - auto if_inst = graph->CreateInstIfImm(DataType::BOOL, pc, cmp_inst, 0, DataType::BOOL, ConditionCode::CC_NE); - length->InsertAfter(cmp_inst); - cmp_inst->InsertAfter(if_inst); + auto cmpInst = graph->CreateInstCompare(DataType::BOOL, pc, index, length, DataType::INT32, ConditionCode::CC_LT); + auto ifInst = graph->CreateInstIfImm(DataType::BOOL, pc, cmpInst, 0, DataType::BOOL, ConditionCode::CC_NE); + length->InsertAfter(cmpInst); + cmpInst->InsertAfter(ifInst); // Split block by call instruction - auto curr_cont_bb = curr_bb->SplitBlockAfterInstruction(if_inst, true); - auto store_bb = graph->CreateEmptyBlock(curr_bb); - curr_bb->GetLoop()->AppendBlock(store_bb); - curr_bb->AddSucc(store_bb); - store_bb->AddSucc(curr_cont_bb); + auto currContBb = currBb->SplitBlockAfterInstruction(ifInst, true); + auto storeBb = graph->CreateEmptyBlock(currBb); + currBb->GetLoop()->AppendBlock(storeBb); + currBb->AddSucc(storeBb); + storeBb->AddSucc(currContBb); // calculate new length auto add = graph->CreateInstAdd(DataType::INT32, pc, index, graph->FindOrCreateConstant(1)); // Store new length - auto store_length = graph->CreateInstStoreObject(DataType::INT32, pc, obj, add, - TypeIdMixin::MEM_DYN_ARRAY_LENGTH_ID, method, nullptr); - store_length->SetObjectType(ObjectType::MEM_DYN_ARRAY_LENGTH); - store_bb->AppendInst(add); - add->InsertAfter(store_length); + auto storeLength = graph->CreateInstStoreObject(DataType::INT32, pc, obj, add, TypeIdMixin::MEM_DYN_ARRAY_LENGTH_ID, + method, nullptr); + storeLength->SetObjectType(ObjectType::MEM_DYN_ARRAY_LENGTH); + storeBb->AppendInst(add); + add->InsertAfter(storeLength); } template -Inst *InsertMemFromFieldInlined(IntrinsicInst *intrinsic, Inst *obj_inst, Inst *insert_after, uint32_t offset) +Inst *InsertMemFromFieldInlined(IntrinsicInst *intrinsic, Inst *objInst, Inst *insertAfter, uint32_t offset) { - auto graph = obj_inst->GetBasicBlock()->GetGraph(); - auto save_state = intrinsic->GetSaveState(); - auto pc = obj_inst->GetPc(); + auto graph = objInst->GetBasicBlock()->GetGraph(); + auto saveState = intrinsic->GetSaveState(); + auto pc = objInst->GetPc(); if constexpr (IS_LOAD) { - auto load_object = InsertLoadObject(obj_inst, offset, save_state->GetMethod(), pc, nullptr, - ObjectType::MEM_DYN_INLINED, insert_after, DataType::ANY); - return load_object; + auto loadObject = InsertLoadObject(objInst, offset, saveState->GetMethod(), pc, nullptr, + ObjectType::MEM_DYN_INLINED, insertAfter, DataType::ANY); + return loadObject; } else { - auto store_object = graph->CreateInstStoreObject(DataType::ANY, pc, obj_inst, intrinsic->GetInput(2).GetInst(), - offset, save_state->GetMethod(), nullptr, false, true); - store_object->SetObjectType(ObjectType::MEM_DYN_INLINED); - insert_after->InsertAfter(store_object); + auto storeObject = graph->CreateInstStoreObject(DataType::ANY, pc, objInst, intrinsic->GetInput(2).GetInst(), + offset, saveState->GetMethod(), nullptr, false, true); + storeObject->SetObjectType(ObjectType::MEM_DYN_INLINED); + insertAfter->InsertAfter(storeObject); - return store_object; + return storeObject; } } -Inst *InsertBoundsCheck(Inst *array, Inst *index, Inst *save_state, uint32_t pc, Inst *insert_after) +Inst *InsertBoundsCheck(Inst *array, Inst *index, Inst *saveState, uint32_t pc, Inst *insertAfter) { auto graph = array->GetBasicBlock()->GetGraph(); - auto array_length = graph->CreateInstLenArray(DataType::INT32, pc, array); + auto arrayLength = graph->CreateInstLenArray(DataType::INT32, pc, array); // Create BoundCheck instruction - auto bounds_check = graph->CreateInstBoundsCheck(DataType::INT32, pc, array_length, index, save_state); - bounds_check->SetFlag(inst_flags::CAN_DEOPTIMIZE); - insert_after->InsertAfter(bounds_check); - insert_after->InsertAfter(array_length); + auto boundsCheck = graph->CreateInstBoundsCheck(DataType::INT32, pc, arrayLength, index, saveState); + boundsCheck->SetFlag(inst_flags::CAN_DEOPTIMIZE); + insertAfter->InsertAfter(boundsCheck); + insertAfter->InsertAfter(arrayLength); - return bounds_check; + return boundsCheck; } template -Inst *InsertMemFromField(IntrinsicInst *intrinsic, Inst *obj_inst, Inst *insert_after, uint32_t offset) +Inst *InsertMemFromField(IntrinsicInst *intrinsic, Inst *objInst, Inst *insertAfter, uint32_t offset) { - auto graph = obj_inst->GetBasicBlock()->GetGraph(); - auto save_state = intrinsic->GetSaveState(); - auto pc = obj_inst->GetPc(); - auto load_object = InsertLoadObject(obj_inst, TypeIdMixin::MEM_DYN_PROPS_ID, save_state->GetMethod(), pc, nullptr, - ObjectType::MEM_DYN_PROPS, insert_after, DataType::REFERENCE); - insert_after = load_object; + auto graph = objInst->GetBasicBlock()->GetGraph(); + auto saveState = intrinsic->GetSaveState(); + auto pc = objInst->GetPc(); + auto loadObject = InsertLoadObject(objInst, TypeIdMixin::MEM_DYN_PROPS_ID, saveState->GetMethod(), pc, nullptr, + ObjectType::MEM_DYN_PROPS, insertAfter, DataType::REFERENCE); + insertAfter = loadObject; Inst *index = graph->FindOrCreateConstant(offset); if constexpr (INSERT_BOUNDS_CHECK) { - auto bounds_check = InsertBoundsCheck(load_object, index, save_state, pc, insert_after); - insert_after = bounds_check; + auto boundsCheck = InsertBoundsCheck(loadObject, index, saveState, pc, insertAfter); + insertAfter = boundsCheck; - index = bounds_check; + index = boundsCheck; } Inst *array = nullptr; if constexpr (IS_LOAD) { - auto load_array = graph->CreateInstLoadArray(DataType::ANY, pc, load_object, index); - array = load_array; + auto loadArray = graph->CreateInstLoadArray(DataType::ANY, pc, loadObject, index); + array = loadArray; } else { - auto store_array = - graph->CreateInstStoreArray(DataType::ANY, pc, load_object, index, intrinsic->GetInput(2).GetInst(), true); - array = store_array; + auto storeArray = + graph->CreateInstStoreArray(DataType::ANY, pc, loadObject, index, intrinsic->GetInput(2).GetInst(), true); + array = storeArray; } - insert_after->InsertAfter(array); + insertAfter->InsertAfter(array); return array; } -Inst *InsertChangeClassInst(IntrinsicInst *intrinsic, Inst *obj_inst, Inst *insert_after, uintptr_t klass_addr) +Inst *InsertChangeClassInst(IntrinsicInst *intrinsic, Inst *objInst, Inst *insertAfter, uintptr_t klassAddr) { - auto graph = obj_inst->GetBasicBlock()->GetGraph(); - auto pc = obj_inst->GetPc(); - auto klass = reinterpret_cast(klass_addr); - auto load_cls_inst = graph->CreateInstLoadImmediate(DataType::REFERENCE, pc, klass); - auto store_class = - graph->CreateInstStoreObject(DataType::REFERENCE, pc, obj_inst, load_cls_inst, TypeIdMixin::MEM_DYN_CLASS_ID, + auto graph = objInst->GetBasicBlock()->GetGraph(); + auto pc = objInst->GetPc(); + auto klass = reinterpret_cast(klassAddr); + auto loadClsInst = graph->CreateInstLoadImmediate(DataType::REFERENCE, pc, klass); + auto storeClass = + graph->CreateInstStoreObject(DataType::REFERENCE, pc, objInst, loadClsInst, TypeIdMixin::MEM_DYN_CLASS_ID, intrinsic->GetSaveState()->GetMethod(), nullptr, false, true); - store_class->SetObjectType(ObjectType::MEM_DYN_CLASS); - insert_after->InsertAfter(store_class); - insert_after->InsertAfter(load_cls_inst); - return store_class; + storeClass->SetObjectType(ObjectType::MEM_DYN_CLASS); + insertAfter->InsertAfter(storeClass); + insertAfter->InsertAfter(loadClsInst); + return storeClass; } -Inst *InsertPrototypeCheckInst(IntrinsicInst *intrinsic, uintptr_t proto_mem, Inst **insert_after) +Inst *InsertPrototypeCheckInst(IntrinsicInst *intrinsic, uintptr_t protoMem, Inst **insertAfter) { auto graph = intrinsic->GetBasicBlock()->GetGraph(); - auto save_state = intrinsic->GetSaveState(); + auto saveState = intrinsic->GetSaveState(); auto pc = intrinsic->GetPc(); // Get Prototype handler - auto proto_handler = graph->CreateInstLoadObjFromConst(DataType::REFERENCE, pc, proto_mem); - (*insert_after)->InsertAfter(proto_handler); + auto protoHandler = graph->CreateInstLoadObjFromConst(DataType::REFERENCE, pc, protoMem); + (*insertAfter)->InsertAfter(protoHandler); // Get Prototype object - auto prototype = InsertLoadObject(proto_handler, TypeIdMixin::MEM_DYN_PROTO_HOLDER_ID, save_state->GetMethod(), pc, - nullptr, ObjectType::MEM_DYN_PROTO_HOLDER, proto_handler, DataType::REFERENCE); + auto prototype = InsertLoadObject(protoHandler, TypeIdMixin::MEM_DYN_PROTO_HOLDER_ID, saveState->GetMethod(), pc, + nullptr, ObjectType::MEM_DYN_PROTO_HOLDER, protoHandler, DataType::REFERENCE); // Get Prototype change marker - auto prototype_marker = - InsertLoadObject(proto_handler, TypeIdMixin::MEM_DYN_PROTO_CELL_ID, save_state->GetMethod(), pc, nullptr, + auto prototypeMarker = + InsertLoadObject(protoHandler, TypeIdMixin::MEM_DYN_PROTO_CELL_ID, saveState->GetMethod(), pc, nullptr, ObjectType::MEM_DYN_PROTO_CELL, prototype, DataType::REFERENCE); // Get change field from the marker - auto is_change = InsertLoadObject(prototype_marker, TypeIdMixin::MEM_DYN_CHANGE_FIELD_ID, save_state->GetMethod(), - pc, nullptr, ObjectType::MEM_DYN_CHANGE_FIELD, prototype_marker, DataType::BOOL); + auto isChange = InsertLoadObject(prototypeMarker, TypeIdMixin::MEM_DYN_CHANGE_FIELD_ID, saveState->GetMethod(), pc, + nullptr, ObjectType::MEM_DYN_CHANGE_FIELD, prototypeMarker, DataType::BOOL); - auto deopt_inst = - graph->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, is_change, save_state, DeoptimizeType::INLINE_IC); + auto deoptInst = + graph->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, isChange, saveState, DeoptimizeType::INLINE_IC); - is_change->InsertAfter(deopt_inst); + isChange->InsertAfter(deoptInst); - *insert_after = deopt_inst; + *insertAfter = deoptInst; return prototype; } template -Inst *InsertAccessInst(IntrinsicInst *intrinsic, Inst *obj_inst, Inst *insert_after, +Inst *InsertAccessInst(IntrinsicInst *intrinsic, Inst *objInst, Inst *insertAfter, RuntimeInterface::NamedAccessProfileData profile) { uint32_t offset = profile.offset; RuntimeInterface::NamedAccessProfileType type = profile.type; switch (type) { case RuntimeInterface::NamedAccessProfileType::FIELD_INLINED: - return InsertMemFromFieldInlined(intrinsic, obj_inst, insert_after, offset); + return InsertMemFromFieldInlined(intrinsic, objInst, insertAfter, offset); case RuntimeInterface::NamedAccessProfileType::FIELD: - return InsertMemFromField(intrinsic, obj_inst, insert_after, offset); + return InsertMemFromField(intrinsic, objInst, insertAfter, offset); case RuntimeInterface::NamedAccessProfileType::TRANSITION_INLINED: { ASSERT(!IS_LOAD); - auto store_class = InsertChangeClassInst(intrinsic, obj_inst, insert_after, profile.cached_value); - return InsertMemFromFieldInlined(intrinsic, obj_inst, store_class, offset); + auto storeClass = InsertChangeClassInst(intrinsic, objInst, insertAfter, profile.cachedValue); + return InsertMemFromFieldInlined(intrinsic, objInst, storeClass, offset); } case RuntimeInterface::NamedAccessProfileType::TRANSITION: { ASSERT(!IS_LOAD); - auto store = InsertMemFromField(intrinsic, obj_inst, insert_after, offset); - InsertChangeClassInst(intrinsic, obj_inst, store->GetPrev(), profile.cached_value); + auto store = InsertMemFromField(intrinsic, objInst, insertAfter, offset); + InsertChangeClassInst(intrinsic, objInst, store->GetPrev(), profile.cachedValue); return store; } case RuntimeInterface::NamedAccessProfileType::PROTOTYPE_INLINED: { - auto load_proto = InsertPrototypeCheckInst(intrinsic, profile.cached_value, &insert_after); - return InsertMemFromFieldInlined(intrinsic, load_proto, insert_after, offset); + auto loadProto = InsertPrototypeCheckInst(intrinsic, profile.cachedValue, &insertAfter); + return InsertMemFromFieldInlined(intrinsic, loadProto, insertAfter, offset); } case RuntimeInterface::NamedAccessProfileType::PROTOTYPE: { - auto load_proto = InsertPrototypeCheckInst(intrinsic, profile.cached_value, &insert_after); - return InsertMemFromField(intrinsic, load_proto, insert_after, offset); + auto loadProto = InsertPrototypeCheckInst(intrinsic, profile.cachedValue, &insertAfter); + return InsertMemFromField(intrinsic, loadProto, insertAfter, offset); } default: UNREACHABLE(); } } -void InsertDeoptimizeInst(uint32_t pc, SaveStateInst *ss, BasicBlock *load_bb) +void InsertDeoptimizeInst(uint32_t pc, SaveStateInst *ss, BasicBlock *loadBb) { - ASSERT(load_bb != nullptr); + ASSERT(loadBb != nullptr); // NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage) - auto graph = load_bb->GetGraph(); + auto graph = loadBb->GetGraph(); ASSERT(graph != nullptr); // If last class compare returns false we need to deoptimize the method. // So we construct instruction DeoptimizeIf and insert instead of IfImm inst. - auto if_inst = load_bb->GetLastInst(); - ASSERT(if_inst != nullptr && if_inst->GetOpcode() == Opcode::IfImm); - ASSERT(if_inst->CastToIfImm()->GetImm() == 0 && if_inst->CastToIfImm()->GetCc() == ConditionCode::CC_NE); + auto ifInst = loadBb->GetLastInst(); + ASSERT(ifInst != nullptr && ifInst->GetOpcode() == Opcode::IfImm); + ASSERT(ifInst->CastToIfImm()->GetImm() == 0 && ifInst->CastToIfImm()->GetCc() == ConditionCode::CC_NE); - auto compare_inst = if_inst->GetInput(0).GetInst()->CastToCompare(); - ASSERT(compare_inst != nullptr && compare_inst->GetCc() == ConditionCode::CC_EQ); - compare_inst->SetCc(ConditionCode::CC_NE); + auto compareInst = ifInst->GetInput(0).GetInst()->CastToCompare(); + ASSERT(compareInst != nullptr && compareInst->GetCc() == ConditionCode::CC_EQ); + compareInst->SetCc(ConditionCode::CC_NE); - auto deopt_inst = graph->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, compare_inst, ss, DeoptimizeType::INLINE_IC); + auto deoptInst = graph->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, compareInst, ss, DeoptimizeType::INLINE_IC); - load_bb->RemoveInst(if_inst); - load_bb->AppendInst(deopt_inst); + loadBb->RemoveInst(ifInst); + loadBb->AppendInst(deoptInst); } bool InlineIntrinsics::InlineLdObjByName(IntrinsicInst *intrinsic) @@ -362,172 +361,171 @@ bool InlineIntrinsics::GetICForMemNamedAccess(IntrinsicInst *intrinsic) { auto pc = intrinsic->GetPc(); auto runtime = GetGraph()->GetRuntime(); - auto save_state = intrinsic->GetSaveState(); - ASSERT(save_state != nullptr); - auto caller_inst = save_state->GetCallerInst(); - if (caller_inst != nullptr) { - ASSERT(caller_inst->IsInlined()); - auto func = caller_inst->GetFunctionObject(); + auto saveState = intrinsic->GetSaveState(); + ASSERT(saveState != nullptr); + auto callerInst = saveState->GetCallerInst(); + if (callerInst != nullptr) { + ASSERT(callerInst->IsInlined()); + auto func = callerInst->GetFunctionObject(); if (func != 0) { - return runtime->GetProfileDataForNamedAccess(GetGraph()->GetMethod(), func, pc, &named_access_profile_); + return runtime->GetProfileDataForNamedAccess(GetGraph()->GetMethod(), func, pc, &namedAccessProfile_); } - return runtime->GetProfileDataForNamedAccess(caller_inst->GetCallMethod(), pc, &named_access_profile_); + return runtime->GetProfileDataForNamedAccess(callerInst->GetCallMethod(), pc, &namedAccessProfile_); } - return runtime->GetProfileDataForNamedAccess(GetGraph()->GetMethod(), pc, &named_access_profile_); + return runtime->GetProfileDataForNamedAccess(GetGraph()->GetMethod(), pc, &namedAccessProfile_); } bool InlineIntrinsics::GetICForMemValueAccess(IntrinsicInst *intrinsic) { auto pc = intrinsic->GetPc(); auto runtime = GetGraph()->GetRuntime(); - auto save_state = intrinsic->GetSaveState(); - ASSERT(save_state != nullptr); - auto caller_inst = save_state->GetCallerInst(); - if (caller_inst != nullptr) { - ASSERT(caller_inst->IsInlined()); - auto func = caller_inst->GetFunctionObject(); + auto saveState = intrinsic->GetSaveState(); + ASSERT(saveState != nullptr); + auto callerInst = saveState->GetCallerInst(); + if (callerInst != nullptr) { + ASSERT(callerInst->IsInlined()); + auto func = callerInst->GetFunctionObject(); if (func != 0) { - return runtime->GetProfileDataForValueAccess(GetGraph()->GetMethod(), func, pc, &named_access_profile_); + return runtime->GetProfileDataForValueAccess(GetGraph()->GetMethod(), func, pc, &namedAccessProfile_); } - return runtime->GetProfileDataForValueAccess(caller_inst->GetCallMethod(), pc, &named_access_profile_); + return runtime->GetProfileDataForValueAccess(callerInst->GetCallMethod(), pc, &namedAccessProfile_); } - return runtime->GetProfileDataForValueAccess(GetGraph()->GetMethod(), pc, &named_access_profile_); + return runtime->GetProfileDataForValueAccess(GetGraph()->GetMethod(), pc, &namedAccessProfile_); } template Inst *InlineIntrinsics::InsertCheckAndCastInstructions(IntrinsicInst *intrinsic) { auto pc = intrinsic->GetPc(); - auto save_state = intrinsic->GetSaveState(); - auto obj_inst = intrinsic->GetInput(BY_NAME ? 1 : 0).GetInst(); + auto saveState = intrinsic->GetSaveState(); + auto objInst = intrinsic->GetInput(BY_NAME ? 1 : 0).GetInst(); - auto any_check = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, pc, obj_inst, save_state, - AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE); - intrinsic->InsertBefore(any_check); + auto anyCheck = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, pc, objInst, saveState, + AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE); + intrinsic->InsertBefore(anyCheck); - auto cast_value = GetGraph()->CreateInstCastAnyTypeValue(pc, any_check, AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE); + auto castValue = GetGraph()->CreateInstCastAnyTypeValue(pc, anyCheck, AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE); // NOLINTNEXTLINE(readability-magic-numbers) - cast_value->SetFlag(inst_flags::NO_HOIST); - any_check->InsertAfter(cast_value); + castValue->SetFlag(inst_flags::NO_HOIST); + anyCheck->InsertAfter(castValue); - return cast_value; + return castValue; } template -void InlineIntrinsics::InlineObjByNameMonomorphic(IntrinsicInst *intrinsic, Inst *get_cls_inst, Inst *obj_inst) +void InlineIntrinsics::InlineObjByNameMonomorphic(IntrinsicInst *intrinsic, Inst *getClsInst, Inst *objInst) { auto pc = intrinsic->GetPc(); - auto save_state = intrinsic->GetSaveState(); - auto prof = named_access_profile_[0]; - auto deopt = CreateCompareClassWithDeopt(pc, get_cls_inst, prof.klass, save_state); - Inst *obj = obj_inst; + auto saveState = intrinsic->GetSaveState(); + auto prof = namedAccessProfile_[0]; + auto deopt = CreateCompareClassWithDeopt(pc, getClsInst, prof.klass, saveState); + Inst *obj = objInst; if (prof.type == RuntimeInterface::NamedAccessProfileType::PROTOTYPE || prof.type == RuntimeInterface::NamedAccessProfileType::PROTOTYPE_INLINED) { - obj = get_cls_inst; + obj = getClsInst; } - [[maybe_unused]] auto load_inst = InsertAccessInst(intrinsic, obj, deopt, prof); + [[maybe_unused]] auto loadInst = InsertAccessInst(intrinsic, obj, deopt, prof); if constexpr (IS_LOAD) { - intrinsic->ReplaceUsers(load_inst); + intrinsic->ReplaceUsers(loadInst); } intrinsic->GetBasicBlock()->RemoveInst(intrinsic); } template -void InlineIntrinsics::InlineObjByNamePolymorphic(IntrinsicInst *intrinsic, Inst *get_cls_inst, Inst *obj_inst) +void InlineIntrinsics::InlineObjByNamePolymorphic(IntrinsicInst *intrinsic, Inst *getClsInst, Inst *objInst) { auto pc = intrinsic->GetPc(); - auto save_state = intrinsic->GetSaveState(); - PhiInst *phi_inst = nullptr; - BasicBlock *load_bb = nullptr; - BasicBlock *load_cont_bb = nullptr; - Inst *load_inst = intrinsic; - for (auto &prof : named_access_profile_) { - if (load_bb == nullptr) { + auto saveState = intrinsic->GetSaveState(); + PhiInst *phiInst = nullptr; + BasicBlock *loadBb = nullptr; + BasicBlock *loadContBb = nullptr; + Inst *loadInst = intrinsic; + for (auto &prof : namedAccessProfile_) { + if (loadBb == nullptr) { // Split block by call instruction - load_bb = load_inst->GetBasicBlock(); - load_cont_bb = load_bb->SplitBlockAfterInstruction(load_inst, false); + loadBb = loadInst->GetBasicBlock(); + loadContBb = loadBb->SplitBlockAfterInstruction(loadInst, false); if constexpr (IS_LOAD) { - phi_inst = GetGraph()->CreateInstPhi(load_inst->GetType(), load_inst->GetPc()); - phi_inst->ReserveInputs(named_access_profile_.size()); - load_cont_bb->AppendPhi(phi_inst); + phiInst = GetGraph()->CreateInstPhi(loadInst->GetType(), loadInst->GetPc()); + phiInst->ReserveInputs(namedAccessProfile_.size()); + loadContBb->AppendPhi(phiInst); } } else { - auto new_load_bb = GetGraph()->CreateEmptyBlock(load_bb); - load_bb->GetLoop()->AppendBlock(new_load_bb); - load_bb->AddSucc(new_load_bb); - load_bb = new_load_bb; + auto newLoadBb = GetGraph()->CreateEmptyBlock(loadBb); + loadBb->GetLoop()->AppendBlock(newLoadBb); + loadBb->AddSucc(newLoadBb); + loadBb = newLoadBb; } - CreateCompareClass(pc, get_cls_inst, prof.klass, load_bb); + CreateCompareClass(pc, getClsInst, prof.klass, loadBb); // Create load_inserting_block - auto load_inserting_block = GetGraph()->CreateEmptyBlock(load_bb); - load_bb->GetLoop()->AppendBlock(load_inserting_block); - load_bb->AddSucc(load_inserting_block); - auto last_ss = CopySaveState(GetGraph(), save_state); - load_inserting_block->PrependInst(last_ss); - Inst *obj = obj_inst; + auto loadInsertingBlock = GetGraph()->CreateEmptyBlock(loadBb); + loadBb->GetLoop()->AppendBlock(loadInsertingBlock); + loadBb->AddSucc(loadInsertingBlock); + auto lastSs = CopySaveState(GetGraph(), saveState); + loadInsertingBlock->PrependInst(lastSs); + Inst *obj = objInst; if (prof.type == RuntimeInterface::NamedAccessProfileType::PROTOTYPE || prof.type == RuntimeInterface::NamedAccessProfileType::PROTOTYPE_INLINED) { - obj = get_cls_inst; + obj = getClsInst; } - [[maybe_unused]] auto load = InsertAccessInst(intrinsic, obj, last_ss, prof); + [[maybe_unused]] auto load = InsertAccessInst(intrinsic, obj, lastSs, prof); if constexpr (IS_LOAD) { - phi_inst->AppendInput(load); + phiInst->AppendInput(load); } - load_inserting_block->AddSucc(load_cont_bb); + loadInsertingBlock->AddSucc(loadContBb); } - InsertDeoptimizeInst(pc, save_state, load_bb); + InsertDeoptimizeInst(pc, saveState, loadBb); if constexpr (IS_LOAD) { - intrinsic->ReplaceUsers(phi_inst); + intrinsic->ReplaceUsers(phiInst); } intrinsic->GetBasicBlock()->RemoveInst(intrinsic); } -void InsertCheckKeyInstructions(IntrinsicInst *intrinsic, uintptr_t key_mem) +void InsertCheckKeyInstructions(IntrinsicInst *intrinsic, uintptr_t keyMem) { auto graph = intrinsic->GetBasicBlock()->GetGraph(); auto pc = intrinsic->GetPc(); - auto save_state = intrinsic->GetSaveState(); - auto key_ic = graph->CreateInstLoadObjFromConst(DataType::ANY, pc, key_mem); - auto cmp_inst = graph->CreateInstCompare(DataType::BOOL, pc, key_ic, intrinsic->GetInput(1).GetInst(), - DataType::ANY, ConditionCode::CC_NE); - auto deopt_inst = - graph->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmp_inst, save_state, DeoptimizeType::INLINE_IC); - intrinsic->InsertBefore(key_ic); - intrinsic->InsertBefore(cmp_inst); - intrinsic->InsertBefore(deopt_inst); + auto saveState = intrinsic->GetSaveState(); + auto keyIc = graph->CreateInstLoadObjFromConst(DataType::ANY, pc, keyMem); + auto cmpInst = graph->CreateInstCompare(DataType::BOOL, pc, keyIc, intrinsic->GetInput(1).GetInst(), DataType::ANY, + ConditionCode::CC_NE); + auto deoptInst = + graph->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmpInst, saveState, DeoptimizeType::INLINE_IC); + intrinsic->InsertBefore(keyIc); + intrinsic->InsertBefore(cmpInst); + intrinsic->InsertBefore(deoptInst); } template void InlineIntrinsics::InlineObjByValueWithKey(IntrinsicInst *intrinsic) { auto pc = intrinsic->GetPc(); - auto save_state = intrinsic->GetSaveState(); - auto prof = named_access_profile_[0]; + auto saveState = intrinsic->GetSaveState(); + auto prof = namedAccessProfile_[0]; InsertCheckKeyInstructions(intrinsic, prof.key); - auto cast_value = InsertCheckAndCastInstructions(intrinsic); - auto get_cls_inst = - InsertLoadObject(cast_value, TypeIdMixin::MEM_DYN_CLASS_ID, intrinsic->GetSaveState()->GetMethod(), pc, nullptr, - ObjectType::MEM_DYN_CLASS, cast_value, DataType::REFERENCE); + auto castValue = InsertCheckAndCastInstructions(intrinsic); + auto getClsInst = InsertLoadObject(castValue, TypeIdMixin::MEM_DYN_CLASS_ID, intrinsic->GetSaveState()->GetMethod(), + pc, nullptr, ObjectType::MEM_DYN_CLASS, castValue, DataType::REFERENCE); - auto deopt = CreateCompareClassWithDeopt(pc, get_cls_inst, prof.klass, save_state); - Inst *obj = cast_value; + auto deopt = CreateCompareClassWithDeopt(pc, getClsInst, prof.klass, saveState); + Inst *obj = castValue; if (prof.type == RuntimeInterface::NamedAccessProfileType::PROTOTYPE || prof.type == RuntimeInterface::NamedAccessProfileType::PROTOTYPE_INLINED) { - obj = get_cls_inst; + obj = getClsInst; } - [[maybe_unused]] auto load_inst = InsertAccessInst(intrinsic, obj, deopt, prof); + [[maybe_unused]] auto loadInst = InsertAccessInst(intrinsic, obj, deopt, prof); if constexpr (IS_LOAD) { - intrinsic->ReplaceUsers(load_inst); + intrinsic->ReplaceUsers(loadInst); } intrinsic->GetBasicBlock()->RemoveInst(intrinsic); @@ -537,77 +535,76 @@ template void InlineIntrinsics::InlineObjByValueFromElements(IntrinsicInst *intrinsic) { auto pc = intrinsic->GetPc(); - auto save_state = intrinsic->GetSaveState(); + auto saveState = intrinsic->GetSaveState(); // Check that input is heap object - auto cast_value = InsertCheckAndCastInstructions(intrinsic); + auto castValue = InsertCheckAndCastInstructions(intrinsic); // Insert Load class for the object - auto get_cls_inst = InsertLoadObject(cast_value, TypeIdMixin::MEM_DYN_CLASS_ID, save_state->GetMethod(), pc, - nullptr, ObjectType::MEM_DYN_CLASS, cast_value, DataType::REFERENCE); + auto getClsInst = InsertLoadObject(castValue, TypeIdMixin::MEM_DYN_CLASS_ID, saveState->GetMethod(), pc, nullptr, + ObjectType::MEM_DYN_CLASS, castValue, DataType::REFERENCE); // check objects classes with first class from IC - auto load_cls_inst = GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, named_access_profile_[0].klass); - auto cmp_inst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, get_cls_inst, load_cls_inst, DataType::REFERENCE, - ConditionCode::CC_NE); - get_cls_inst->InsertAfter(load_cls_inst); - load_cls_inst->InsertAfter(cmp_inst); - Inst *deopt_input = cmp_inst; - if (named_access_profile_.size() == 2) { + auto loadClsInst = GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, namedAccessProfile_[0].klass); + auto cmpInst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, getClsInst, loadClsInst, DataType::REFERENCE, + ConditionCode::CC_NE); + getClsInst->InsertAfter(loadClsInst); + loadClsInst->InsertAfter(cmpInst); + Inst *deoptInput = cmpInst; + if (namedAccessProfile_.size() == 2) { // check objects classes with second class from IC - auto load_cls_inst_1 = - GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, named_access_profile_[1].klass); - auto cmp_inst_1 = GetGraph()->CreateInstCompare(DataType::BOOL, pc, get_cls_inst, load_cls_inst_1, - DataType::REFERENCE, ConditionCode::CC_NE); - auto and_inst = GetGraph()->CreateInstAnd(DataType::BOOL, pc, cmp_inst, cmp_inst_1); - deopt_input = and_inst; - cmp_inst->InsertAfter(load_cls_inst_1); - load_cls_inst_1->InsertAfter(cmp_inst_1); - cmp_inst_1->InsertAfter(and_inst); + auto loadClsInst1 = GetGraph()->CreateInstLoadImmediate(DataType::REFERENCE, pc, namedAccessProfile_[1].klass); + auto cmpInst1 = GetGraph()->CreateInstCompare(DataType::BOOL, pc, getClsInst, loadClsInst1, DataType::REFERENCE, + ConditionCode::CC_NE); + auto andInst = GetGraph()->CreateInstAnd(DataType::BOOL, pc, cmpInst, cmpInst1); + deoptInput = andInst; + cmpInst->InsertAfter(loadClsInst1); + loadClsInst1->InsertAfter(cmpInst1); + cmpInst1->InsertAfter(andInst); } // Insert deoptimize - auto deopt_inst = - GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, deopt_input, save_state, DeoptimizeType::INLINE_IC); - deopt_input->InsertAfter(deopt_inst); + auto deoptInst = + GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, deoptInput, saveState, DeoptimizeType::INLINE_IC); + deoptInput->InsertAfter(deoptInst); auto key = intrinsic->GetInput(1).GetInst(); - auto any_check = - GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, pc, key, save_state, AnyBaseType::ECMASCRIPT_INT_TYPE); - intrinsic->InsertBefore(any_check); + auto anyCheck = + GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, pc, key, saveState, AnyBaseType::ECMASCRIPT_INT_TYPE); + intrinsic->InsertBefore(anyCheck); - auto cast_value_int = GetGraph()->CreateInstCastAnyTypeValue(pc, any_check, AnyBaseType::ECMASCRIPT_INT_TYPE); + auto castValueInt = GetGraph()->CreateInstCastAnyTypeValue(pc, anyCheck, AnyBaseType::ECMASCRIPT_INT_TYPE); // NOLINTNEXTLINE(readability-magic-numbers) - cast_value_int->SetFlag(inst_flags::NO_HOIST); - any_check->InsertAfter(cast_value_int); + castValueInt->SetFlag(inst_flags::NO_HOIST); + anyCheck->InsertAfter(castValueInt); // Insert Load Object for Elements array - auto load_object = InsertLoadObject(cast_value, TypeIdMixin::MEM_DYN_ELEMENTS_ID, save_state->GetMethod(), pc, - nullptr, ObjectType::MEM_DYN_ELEMENTS, cast_value_int, DataType::REFERENCE); + auto loadObject = InsertLoadObject(castValue, TypeIdMixin::MEM_DYN_ELEMENTS_ID, saveState->GetMethod(), pc, nullptr, + ObjectType::MEM_DYN_ELEMENTS, castValueInt, DataType::REFERENCE); // Insert LenArray and BoundChecks - auto bounds_check = InsertBoundsCheck(load_object, cast_value_int, save_state, pc, load_object); + auto boundsCheck = InsertBoundsCheck(loadObject, castValueInt, saveState, pc, loadObject); if constexpr (IS_LOAD) { - auto load_array = GetGraph()->CreateInstLoadArray(DataType::ANY, pc, load_object, bounds_check); + auto loadArray = GetGraph()->CreateInstLoadArray(DataType::ANY, pc, loadObject, boundsCheck); - intrinsic->ReplaceUsers(load_array); - bounds_check->InsertAfter(load_array); - auto cmp_hole_inst = GetGraph()->CreateInstCompare( - DataType::BOOL, pc, load_array, + intrinsic->ReplaceUsers(loadArray); + boundsCheck->InsertAfter(loadArray); + auto cmpHoleInst = GetGraph()->CreateInstCompare( + DataType::BOOL, pc, loadArray, GetGraph()->FindOrCreateConstant(DataType::Any(panda::coretypes::TaggedValue::VALUE_HOLE)), DataType::ANY, ConditionCode::CC_EQ); - load_array->InsertAfter(cmp_hole_inst); + loadArray->InsertAfter(cmpHoleInst); - auto deopt_hole_inst = - GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmp_hole_inst, save_state, DeoptimizeType::HOLE); - cmp_hole_inst->InsertAfter(deopt_hole_inst); + auto deoptHoleInst = + GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmpHoleInst, saveState, DeoptimizeType::HOLE); + cmpHoleInst->InsertAfter(deoptHoleInst); } else { - auto store_array = GetGraph()->CreateInstStoreArray(DataType::ANY, pc, load_object, bounds_check, - intrinsic->GetInput(2).GetInst(), true); + auto storeArray = GetGraph()->CreateInstStoreArray(DataType::ANY, pc, loadObject, boundsCheck, + intrinsic->GetInput(2).GetInst(), true); - bounds_check->InsertAfter(store_array); - if (named_access_profile_[0].type == RuntimeInterface::NamedAccessProfileType::ARRAY_ELEMENT) { - InsertCheckJSArrayLength(cast_value, cast_value_int, bounds_check, save_state->GetMethod(), pc); + boundsCheck->InsertAfter(storeArray); + if (namedAccessProfile_[0].type == RuntimeInterface::NamedAccessProfileType::ARRAY_ELEMENT) { + InsertCheckJSArrayLength(castValue, castValueInt, boundsCheck, saveState->GetMethod(), pc); } } intrinsic->GetBasicBlock()->RemoveInst(intrinsic); @@ -623,10 +620,10 @@ bool InlineIntrinsics::InlineObjByValue(IntrinsicInst *intrinsic) if (!GetICForMemValueAccess(intrinsic)) { return false; } - ASSERT(!named_access_profile_.empty()); - if (named_access_profile_[0].key == 0) { + ASSERT(!namedAccessProfile_.empty()); + if (namedAccessProfile_[0].key == 0) { // we need to fix length for ARRAY_ELEMENT - if (named_access_profile_.size() == 2 && named_access_profile_[0].type != named_access_profile_[1].type) { + if (namedAccessProfile_.size() == 2 && namedAccessProfile_[0].type != namedAccessProfile_[1].type) { return false; } InlineObjByValueFromElements(intrinsic); @@ -648,33 +645,32 @@ bool InlineIntrinsics::InlineObjByName(IntrinsicInst *intrinsic) if (!GetICForMemNamedAccess(intrinsic)) { return false; } - ASSERT(!named_access_profile_.empty()); + ASSERT(!namedAccessProfile_.empty()); - auto cast_value = InsertCheckAndCastInstructions(intrinsic); - auto get_cls_inst = - InsertLoadObject(cast_value, TypeIdMixin::MEM_DYN_CLASS_ID, intrinsic->GetSaveState()->GetMethod(), pc, nullptr, - ObjectType::MEM_DYN_CLASS, cast_value, DataType::REFERENCE); + auto castValue = InsertCheckAndCastInstructions(intrinsic); + auto getClsInst = InsertLoadObject(castValue, TypeIdMixin::MEM_DYN_CLASS_ID, intrinsic->GetSaveState()->GetMethod(), + pc, nullptr, ObjectType::MEM_DYN_CLASS, castValue, DataType::REFERENCE); - if (named_access_profile_.size() == 1) { - InlineObjByNameMonomorphic(intrinsic, get_cls_inst, cast_value); + if (namedAccessProfile_.size() == 1) { + InlineObjByNameMonomorphic(intrinsic, getClsInst, castValue); return true; } - InlineObjByNamePolymorphic(intrinsic, get_cls_inst, cast_value); + InlineObjByNamePolymorphic(intrinsic, getClsInst, castValue); return true; } bool InlineIntrinsics::InlineResolveAllocResult(IntrinsicInst *intrinsic) { - auto ctor_res = intrinsic->GetInput(2U).GetInst(); - if (ctor_res->GetOpcode() != Opcode::CastValueToAnyType) { + auto ctorRes = intrinsic->GetInput(2U).GetInst(); + if (ctorRes->GetOpcode() != Opcode::CastValueToAnyType) { return false; } - if (ctor_res->CastToCastValueToAnyType()->GetAnyType() != AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE) { + if (ctorRes->CastToCastValueToAnyType()->GetAnyType() != AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE) { return false; } - auto alloc_inst = intrinsic->GetInput(1U).GetInst(); - intrinsic->ReplaceUsers(alloc_inst); + auto allocInst = intrinsic->GetInput(1U).GetInst(); + intrinsic->ReplaceUsers(allocInst); intrinsic->GetBasicBlock()->RemoveInst(intrinsic); return true; @@ -700,14 +696,14 @@ bool InlineIntrinsics::InlineStrictCompareDifferentTypes(IntrinsicInst *intrinsi auto input1 = intrinsic->GetInput(0).GetInst(); auto input2 = intrinsic->GetInput(0).GetInst(); - auto allowed_type1 = input1->GetOpcode() == Opcode::AnyTypeCheck - ? input1->CastToAnyTypeCheck()->GetAllowedInputType() - : profiling::AnyInputType::DEFAULT; - auto allowed_type2 = input2->GetOpcode() == Opcode::AnyTypeCheck - ? input1->CastToAnyTypeCheck()->GetAllowedInputType() - : profiling::AnyInputType::DEFAULT; - - if (IsAnyTypeCanBeSubtypeOf(SourceLanguage::ECMASCRIPT, type1, type2, allowed_type1, allowed_type2) == false) { + auto allowedType1 = input1->GetOpcode() == Opcode::AnyTypeCheck + ? input1->CastToAnyTypeCheck()->GetAllowedInputType() + : profiling::AnyInputType::DEFAULT; + auto allowedType2 = input2->GetOpcode() == Opcode::AnyTypeCheck + ? input1->CastToAnyTypeCheck()->GetAllowedInputType() + : profiling::AnyInputType::DEFAULT; + + if (IsAnyTypeCanBeSubtypeOf(SourceLanguage::ECMASCRIPT, type1, type2, allowedType1, allowedType2) == false) { auto result = intrinsic->GetIntrinsicId() == RuntimeInterface::IntrinsicId::INTRINSIC_STRICT_EQ_DYN ? 0U : 1U; return InlineLdConstant(intrinsic, AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE, result); } @@ -733,24 +729,24 @@ bool InlineIntrinsics::InlineCompareWithNull(IntrinsicInst *intrinsic, AnyBaseTy if (type1 == AnyBaseType::UNDEFINED_TYPE || type2 == AnyBaseType::UNDEFINED_TYPE) { return false; } - bool first_null = (type1 == AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE || type1 == AnyBaseType::ECMASCRIPT_NULL_TYPE); - bool second_null = (type2 == AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE || type2 == AnyBaseType::ECMASCRIPT_NULL_TYPE); - auto eq_result = intrinsic->GetIntrinsicId() == RuntimeInterface::IntrinsicId::INTRINSIC_EQ_DYN ? 1U : 0U; - if (first_null && second_null) { - return InlineLdConstant(intrinsic, AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE, eq_result); + bool firstNull = (type1 == AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE || type1 == AnyBaseType::ECMASCRIPT_NULL_TYPE); + bool secondNull = (type2 == AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE || type2 == AnyBaseType::ECMASCRIPT_NULL_TYPE); + auto eqResult = intrinsic->GetIntrinsicId() == RuntimeInterface::IntrinsicId::INTRINSIC_EQ_DYN ? 1U : 0U; + if (firstNull && secondNull) { + return InlineLdConstant(intrinsic, AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE, eqResult); } - Inst *other_input; - if (first_null) { - other_input = intrinsic->GetInput(1).GetInst(); - } else if (second_null) { - other_input = intrinsic->GetInput(0).GetInst(); + Inst *otherInput; + if (firstNull) { + otherInput = intrinsic->GetInput(1).GetInst(); + } else if (secondNull) { + otherInput = intrinsic->GetInput(0).GetInst(); } else { return false; } - if (other_input->GetOpcode() == Opcode::AnyTypeCheck && other_input->CastToAnyTypeCheck()->IsSpecialWasSeen()) { + if (otherInput->GetOpcode() == Opcode::AnyTypeCheck && otherInput->CastToAnyTypeCheck()->IsSpecialWasSeen()) { return false; } - return InlineLdConstant(intrinsic, AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE, 1 - eq_result); + return InlineLdConstant(intrinsic, AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE, 1 - eqResult); } bool InlineIntrinsics::InlineEqDyn(IntrinsicInst *intrinsic, AnyBaseType type1, AnyBaseType type2) @@ -765,57 +761,55 @@ bool InlineIntrinsics::InlineNotEqDyn(IntrinsicInst *intrinsic, AnyBaseType type bool InlineIntrinsics::InlineToNumber(IntrinsicInst *intrinsic, AnyBaseType type1) { - auto special_allowed = (GetAllowedTypeForInput(intrinsic, 0) & profiling::AnyInputType::SPECIAL) != 0; - return panda::compiler::IrtocInlineToNumber(intrinsic, type1, special_allowed); + auto specialAllowed = (GetAllowedTypeForInput(intrinsic, 0) & profiling::AnyInputType::SPECIAL) != 0; + return panda::compiler::IrtocInlineToNumber(intrinsic, type1, specialAllowed); } bool InlineIntrinsics::InlineLdLexDyn(IntrinsicInst *intrinsic) { - auto *save_state = intrinsic->GetSaveState(); - ASSERT(save_state != nullptr); + auto *saveState = intrinsic->GetSaveState(); + ASSERT(saveState != nullptr); // level, slot ASSERT(intrinsic->GetImms().size() == 2U); // Name, LexEnv, SaveState ASSERT(intrinsic->GetInputsCount() == 3U); - auto *load_lex_var = intrinsic; - load_lex_var->SetIntrinsicId(RuntimeInterface::IntrinsicId::INTRINSIC_LD_LEX_VAR_DYN); - AdjustFlags(RuntimeInterface::IntrinsicId::INTRINSIC_LD_LEX_VAR_DYN, load_lex_var); - ASSERT(load_lex_var->GetInput(2U).GetInst()->GetOpcode() == Opcode::SaveState); - load_lex_var->RemoveInput(2U); - load_lex_var->RemoveInput(0U); - load_lex_var->ClearFlag(inst_flags::REQUIRE_STATE); - InstAppender appender(load_lex_var->GetBasicBlock(), load_lex_var); + auto *loadLexVar = intrinsic; + loadLexVar->SetIntrinsicId(RuntimeInterface::IntrinsicId::INTRINSIC_LD_LEX_VAR_DYN); + AdjustFlags(RuntimeInterface::IntrinsicId::INTRINSIC_LD_LEX_VAR_DYN, loadLexVar); + ASSERT(loadLexVar->GetInput(2U).GetInst()->GetOpcode() == Opcode::SaveState); + loadLexVar->RemoveInput(2U); + loadLexVar->RemoveInput(0U); + loadLexVar->ClearFlag(inst_flags::REQUIRE_STATE); + InstAppender appender(loadLexVar->GetBasicBlock(), loadLexVar); auto pc = intrinsic->GetPc(); auto *hole = GetGraph()->FindOrCreateConstant(DataType::Any(panda::coretypes::TaggedValue::VALUE_HOLE)); auto *compare = - GetGraph()->CreateInstCompare(DataType::BOOL, pc, load_lex_var, hole, DataType::ANY, ConditionCode::CC_EQ); + GetGraph()->CreateInstCompare(DataType::BOOL, pc, loadLexVar, hole, DataType::ANY, ConditionCode::CC_EQ); appender.Append(compare); - auto *deopt_if = - GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, compare, save_state, DeoptimizeType::HOLE); - appender.Append(deopt_if); + auto *deoptIf = GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, compare, saveState, DeoptimizeType::HOLE); + appender.Append(deoptIf); - InlineLdLexVarDyn(load_lex_var); + InlineLdLexVarDyn(loadLexVar); return true; } -Inst *InlineIntrinsics::GetParentLexEnv(InstAppender *appender, Inst *current_lex_env, uint32_t level, uint32_t pc) +Inst *InlineIntrinsics::GetParentLexEnv(InstAppender *appender, Inst *currentLexEnv, uint32_t level, uint32_t pc) { auto *runtime = GetGraph()->GetRuntime(); for (; level > 0U; --level) { - auto *load_parent = - GetGraph()->CreateInstLoadArray(DataType::ANY, pc, current_lex_env, - GetGraph()->FindOrCreateConstant(runtime->GetLexicalEnvParentEnvIndex())); - appender->Append(load_parent); - - auto *parent_ref = GetGraph()->CreateInstCastAnyTypeValue(pc, load_parent, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); - parent_ref->SetFlag(inst_flags::NO_HOIST); - appender->Append(parent_ref); - current_lex_env = parent_ref; + auto *loadParent = GetGraph()->CreateInstLoadArray( + DataType::ANY, pc, currentLexEnv, GetGraph()->FindOrCreateConstant(runtime->GetLexicalEnvParentEnvIndex())); + appender->Append(loadParent); + + auto *parentRef = GetGraph()->CreateInstCastAnyTypeValue(pc, loadParent, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); + parentRef->SetFlag(inst_flags::NO_HOIST); + appender->Append(parentRef); + currentLexEnv = parentRef; } - return current_lex_env; + return currentLexEnv; } bool InlineIntrinsics::InlineStLexDyn(IntrinsicInst *intrinsic) @@ -831,44 +825,43 @@ bool InlineIntrinsics::InlineStLexDyn(IntrinsicInst *intrinsic) auto slot = intrinsic->GetImms()[1U]; - auto *store_acc_val = intrinsic->GetInput(1U).GetInst(); - auto *store_lex_env = intrinsic->GetInput(2U).GetInst(); + auto *storeAccVal = intrinsic->GetInput(1U).GetInst(); + auto *storeLexEnv = intrinsic->GetInput(2U).GetInst(); InstAppender appender(intrinsic->GetBasicBlock(), intrinsic); auto pc = intrinsic->GetPc(); - auto *env_ref = GetGraph()->CreateInstCastAnyTypeValue(pc, store_lex_env, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); - env_ref->SetFlag(inst_flags::NO_HOIST); - appender.Append(env_ref); + auto *envRef = GetGraph()->CreateInstCastAnyTypeValue(pc, storeLexEnv, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); + envRef->SetFlag(inst_flags::NO_HOIST); + appender.Append(envRef); - Inst *current_lex_env = env_ref; - current_lex_env = GetParentLexEnv(&appender, current_lex_env, level, pc); + Inst *currentLexEnv = envRef; + currentLexEnv = GetParentLexEnv(&appender, currentLexEnv, level, pc); auto start = GetGraph()->GetRuntime()->GetLexicalEnvStartDataIndex(); - auto elem_offset = start + slot; + auto elemOffset = start + slot; - auto save_state = intrinsic->GetSaveState(); - ASSERT(save_state != nullptr); + auto saveState = intrinsic->GetSaveState(); + ASSERT(saveState != nullptr); - auto *get_prop = GetGraph()->CreateInstLoadArray(DataType::ANY, pc, current_lex_env, - GetGraph()->FindOrCreateConstant(elem_offset)); - appender.Append(get_prop); + auto *getProp = + GetGraph()->CreateInstLoadArray(DataType::ANY, pc, currentLexEnv, GetGraph()->FindOrCreateConstant(elemOffset)); + appender.Append(getProp); auto *hole = GetGraph()->FindOrCreateConstant(DataType::Any(panda::coretypes::TaggedValue::VALUE_HOLE)); auto *compare = - GetGraph()->CreateInstCompare(DataType::BOOL, pc, get_prop, hole, DataType::ANY, ConditionCode::CC_EQ); + GetGraph()->CreateInstCompare(DataType::BOOL, pc, getProp, hole, DataType::ANY, ConditionCode::CC_EQ); appender.Append(compare); - auto *deopt_if = - GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, compare, save_state, DeoptimizeType::HOLE); - appender.Append(deopt_if); + auto *deoptIf = GetGraph()->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, compare, saveState, DeoptimizeType::HOLE); + appender.Append(deoptIf); - auto *store_lex_var = GetGraph()->CreateInstStoreArray( - DataType::ANY, pc, current_lex_env, GetGraph()->FindOrCreateConstant(elem_offset), store_acc_val, true); - appender.Append(store_lex_var); + auto *storeLexVar = GetGraph()->CreateInstStoreArray( + DataType::ANY, pc, currentLexEnv, GetGraph()->FindOrCreateConstant(elemOffset), storeAccVal, true); + appender.Append(storeLexVar); if (intrinsic->HasUsers()) { - intrinsic->ReplaceUsers(store_acc_val); + intrinsic->ReplaceUsers(storeAccVal); } intrinsic->GetBasicBlock()->RemoveInst(intrinsic); return true; @@ -883,25 +876,25 @@ bool InlineIntrinsics::InlineLdLexVarDyn(IntrinsicInst *intrinsic) auto slot = intrinsic->GetImms()[1U]; - auto *load_lex_env = intrinsic->GetInput(0U).GetInst(); + auto *loadLexEnv = intrinsic->GetInput(0U).GetInst(); InstAppender appender(intrinsic->GetBasicBlock(), intrinsic); auto pc = intrinsic->GetPc(); - auto *env_ref = GetGraph()->CreateInstCastAnyTypeValue(pc, load_lex_env, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); - env_ref->SetFlag(inst_flags::NO_HOIST); - appender.Append(env_ref); + auto *envRef = GetGraph()->CreateInstCastAnyTypeValue(pc, loadLexEnv, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); + envRef->SetFlag(inst_flags::NO_HOIST); + appender.Append(envRef); - Inst *current_lex_env = env_ref; - current_lex_env = GetParentLexEnv(&appender, current_lex_env, level, pc); + Inst *currentLexEnv = envRef; + currentLexEnv = GetParentLexEnv(&appender, currentLexEnv, level, pc); auto start = GetGraph()->GetRuntime()->GetLexicalEnvStartDataIndex(); - auto elem_offset = start + slot; - auto *load_lex_var = GetGraph()->CreateInstLoadArray(DataType::ANY, pc, current_lex_env, - GetGraph()->FindOrCreateConstant(elem_offset)); - appender.Append(load_lex_var); + auto elemOffset = start + slot; + auto *loadLexVar = + GetGraph()->CreateInstLoadArray(DataType::ANY, pc, currentLexEnv, GetGraph()->FindOrCreateConstant(elemOffset)); + appender.Append(loadLexVar); - intrinsic->ReplaceUsers(load_lex_var); + intrinsic->ReplaceUsers(loadLexVar); intrinsic->GetBasicBlock()->RemoveInst(intrinsic); return true; } @@ -909,9 +902,9 @@ bool InlineIntrinsics::InlineLdLexVarDyn(IntrinsicInst *intrinsic) bool InlineIntrinsics::InlineLdlexenvDyn([[maybe_unused]] IntrinsicInst *intrinsic) { auto pc = intrinsic->GetPc(); - auto load_lexical_env = GetGraph()->CreateInstLoadLexicalEnv(DataType::ANY, pc, intrinsic->GetInput(0).GetInst()); - intrinsic->InsertBefore(load_lexical_env); - intrinsic->ReplaceUsers(load_lexical_env); + auto loadLexicalEnv = GetGraph()->CreateInstLoadLexicalEnv(DataType::ANY, pc, intrinsic->GetInput(0).GetInst()); + intrinsic->InsertBefore(loadLexicalEnv); + intrinsic->ReplaceUsers(loadLexicalEnv); intrinsic->GetBasicBlock()->RemoveInst(intrinsic); return true; } @@ -925,28 +918,28 @@ bool InlineIntrinsics::InlineStLexVarDyn(IntrinsicInst *intrinsic) auto slot = intrinsic->GetImms()[1U]; - auto *store_acc_val = intrinsic->GetInput(0U).GetInst(); - auto *store_lex_env = intrinsic->GetInput(1U).GetInst(); + auto *storeAccVal = intrinsic->GetInput(0U).GetInst(); + auto *storeLexEnv = intrinsic->GetInput(1U).GetInst(); InstAppender appender(intrinsic->GetBasicBlock(), intrinsic); auto pc = intrinsic->GetPc(); - auto *env_ref = GetGraph()->CreateInstCastAnyTypeValue(pc, store_lex_env, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); - env_ref->SetFlag(inst_flags::NO_HOIST); - appender.Append(env_ref); + auto *envRef = GetGraph()->CreateInstCastAnyTypeValue(pc, storeLexEnv, AnyBaseType::ECMASCRIPT_ARRAY_TYPE); + envRef->SetFlag(inst_flags::NO_HOIST); + appender.Append(envRef); - Inst *current_lex_env = env_ref; - current_lex_env = GetParentLexEnv(&appender, current_lex_env, level, pc); + Inst *currentLexEnv = envRef; + currentLexEnv = GetParentLexEnv(&appender, currentLexEnv, level, pc); auto start = GetGraph()->GetRuntime()->GetLexicalEnvStartDataIndex(); - auto elem_offset = start + slot; + auto elemOffset = start + slot; - auto *store_lex_var = GetGraph()->CreateInstStoreArray( - DataType::ANY, pc, current_lex_env, GetGraph()->FindOrCreateConstant(elem_offset), store_acc_val, true); - appender.Append(store_lex_var); + auto *storeLexVar = GetGraph()->CreateInstStoreArray( + DataType::ANY, pc, currentLexEnv, GetGraph()->FindOrCreateConstant(elemOffset), storeAccVal, true); + appender.Append(storeLexVar); if (intrinsic->HasUsers()) { - intrinsic->ReplaceUsers(store_acc_val); + intrinsic->ReplaceUsers(storeAccVal); } intrinsic->GetBasicBlock()->RemoveInst(intrinsic); return true; @@ -957,17 +950,17 @@ bool InlineIntrinsics::InlinePopLexenvDyn(IntrinsicInst *intrinsic) InstAppender appender(intrinsic->GetBasicBlock(), intrinsic); auto pc = intrinsic->GetPc(); - auto *env_ref = GetGraph()->CreateInstCastAnyTypeValue(pc, intrinsic->GetInput(0).GetInst(), - AnyBaseType::ECMASCRIPT_ARRAY_TYPE); - env_ref->SetFlag(inst_flags::NO_HOIST); - appender.Append(env_ref); + auto *envRef = GetGraph()->CreateInstCastAnyTypeValue(pc, intrinsic->GetInput(0).GetInst(), + AnyBaseType::ECMASCRIPT_ARRAY_TYPE); + envRef->SetFlag(inst_flags::NO_HOIST); + appender.Append(envRef); - auto *load_parent = GetGraph()->CreateInstLoadArray( - DataType::ANY, pc, env_ref, + auto *loadParent = GetGraph()->CreateInstLoadArray( + DataType::ANY, pc, envRef, GetGraph()->FindOrCreateConstant(GetGraph()->GetRuntime()->GetLexicalEnvParentEnvIndex())); - appender.Append(load_parent); + appender.Append(loadParent); - intrinsic->ReplaceUsers(load_parent); + intrinsic->ReplaceUsers(loadParent); intrinsic->GetBasicBlock()->RemoveInst(intrinsic); return true; } @@ -979,36 +972,36 @@ bool InlineIntrinsics::InlineTryLdGlobalByName(IntrinsicInst *inst) } ASSERT(inst->GetSaveState() != nullptr); auto runtime = GetGraph()->GetRuntime(); - auto load_from_cp = inst->GetInput(0).GetInst(); - auto type_id = load_from_cp->CastToLoadFromConstantPool()->GetTypeId(); + auto loadFromCp = inst->GetInput(0).GetInst(); + auto typeId = loadFromCp->CastToLoadFromConstantPool()->GetTypeId(); auto pc = inst->GetPc(); - auto save_state = inst->GetSaveState(); - ASSERT(save_state != nullptr); - auto caller_inst = save_state->GetCallerInst(); - RuntimeInterface::GlobalVarInfo inline_info; - if (caller_inst != nullptr) { - ASSERT(caller_inst->IsInlined()); - auto func = caller_inst->GetFunctionObject(); + auto saveState = inst->GetSaveState(); + ASSERT(saveState != nullptr); + auto callerInst = saveState->GetCallerInst(); + RuntimeInterface::GlobalVarInfo inlineInfo; + if (callerInst != nullptr) { + ASSERT(callerInst->IsInlined()); + auto func = callerInst->GetFunctionObject(); if (func != 0) { - inline_info = runtime->GetGlobalVarInfo(GetGraph()->GetMethod(), func, type_id, pc); + inlineInfo = runtime->GetGlobalVarInfo(GetGraph()->GetMethod(), func, typeId, pc); } else { - inline_info = runtime->GetGlobalVarInfo(caller_inst->GetCallMethod(), type_id, pc); + inlineInfo = runtime->GetGlobalVarInfo(callerInst->GetCallMethod(), typeId, pc); } } else { - inline_info = runtime->GetGlobalVarInfo(GetGraph()->GetMethod(), type_id, pc); + inlineInfo = runtime->GetGlobalVarInfo(GetGraph()->GetMethod(), typeId, pc); } - switch (inline_info.type) { + switch (inlineInfo.type) { case RuntimeInterface::GlobalVarInfo::Type::CONSTANT: { - auto constant = GetGraph()->FindOrCreateConstant(DataType::Any(inline_info.value)); + auto constant = GetGraph()->FindOrCreateConstant(DataType::Any(inlineInfo.value)); inst->ReplaceUsers(constant); inst->GetBasicBlock()->RemoveInst(inst); return true; } case RuntimeInterface::GlobalVarInfo::Type::NON_CONFIGURABLE: - InlineTryLdGlobalField(inst, type_id, static_cast(inline_info.value)); + InlineTryLdGlobalField(inst, typeId, static_cast(inlineInfo.value)); return true; case RuntimeInterface::GlobalVarInfo::Type::FIELD: - InlineTryLdGlobalField(inst, type_id, static_cast(inline_info.value)); + InlineTryLdGlobalField(inst, typeId, static_cast(inlineInfo.value)); return true; default: return false; @@ -1016,28 +1009,28 @@ bool InlineIntrinsics::InlineTryLdGlobalByName(IntrinsicInst *inst) } template -void InlineIntrinsics::InlineTryLdGlobalField(IntrinsicInst *inst, uint32_t type_id, uintptr_t address) +void InlineIntrinsics::InlineTryLdGlobalField(IntrinsicInst *inst, uint32_t typeId, uintptr_t address) { auto pc = inst->GetPc(); - auto save_state = inst->GetSaveState(); + auto saveState = inst->GetSaveState(); - auto get_address = GetGraph()->CreateInstGetGlobalVarAddress(DataType::REFERENCE, pc, inst->GetInput(2).GetInst(), - save_state, type_id, GetGraph()->GetMethod(), address); - inst->InsertBefore(get_address); + auto getAddress = GetGraph()->CreateInstGetGlobalVarAddress(DataType::REFERENCE, pc, inst->GetInput(2).GetInst(), + saveState, typeId, GetGraph()->GetMethod(), address); + inst->InsertBefore(getAddress); - auto load_object = GetGraph()->CreateInstLoadObject(DataType::ANY, pc, get_address, TypeIdMixin::MEM_DYN_GLOBAL_ID, - GetGraph()->GetMethod(), nullptr); - load_object->SetObjectType(ObjectType::MEM_DYN_GLOBAL); - inst->InsertBefore(load_object); + auto loadObject = GetGraph()->CreateInstLoadObject(DataType::ANY, pc, getAddress, TypeIdMixin::MEM_DYN_GLOBAL_ID, + GetGraph()->GetMethod(), nullptr); + loadObject->SetObjectType(ObjectType::MEM_DYN_GLOBAL); + inst->InsertBefore(loadObject); if constexpr (NEED_GUARD) { - auto cmp = GetGraph()->CreateInstCompareAnyType(pc, load_object, AnyBaseType::ECMASCRIPT_HOLE_TYPE); - auto deopt = GetGraph()->CreateInstDeoptimizeIf(DataType::BOOL, pc, cmp, save_state, DeoptimizeType::INLINE_IC); + auto cmp = GetGraph()->CreateInstCompareAnyType(pc, loadObject, AnyBaseType::ECMASCRIPT_HOLE_TYPE); + auto deopt = GetGraph()->CreateInstDeoptimizeIf(DataType::BOOL, pc, cmp, saveState, DeoptimizeType::INLINE_IC); inst->InsertBefore(cmp); inst->InsertBefore(deopt); } - inst->ReplaceUsers(load_object); + inst->ReplaceUsers(loadObject); inst->GetBasicBlock()->RemoveInst(inst); } diff --git a/compiler/intrinsics_inline_ecmascript.inl.h b/compiler/intrinsics_inline_ecmascript.inl.h index 294a66fca674815f3869ff210b42d348c1abb5e3..1a5c95210cefabaffc98a2a4bce99fe773026901 100644 --- a/compiler/intrinsics_inline_ecmascript.inl.h +++ b/compiler/intrinsics_inline_ecmascript.inl.h @@ -50,18 +50,17 @@ template void InlineObjByValueFromElements(IntrinsicInst *intrinsic); template -void InlineObjByNameMonomorphic(IntrinsicInst *intrinsic, Inst *get_cls_inst, Inst *obj_inst); +void InlineObjByNameMonomorphic(IntrinsicInst *intrinsic, Inst *getClsInst, Inst *objInst); template -void InlineObjByNamePolymorphic(IntrinsicInst *intrinsic, Inst *get_cls_inst, Inst *obj_inst); +void InlineObjByNamePolymorphic(IntrinsicInst *intrinsic, Inst *getClsInst, Inst *objInst); bool GetICForMemNamedAccess(IntrinsicInst *intrinsic); bool GetICForMemValueAccess(IntrinsicInst *intrinsic); template Inst *InsertCheckAndCastInstructions(IntrinsicInst *intrinsic); -void CreateCompareClass(uint32_t pc, Inst *get_cls_inst, RuntimeInterface::ClassPtr receiver, BasicBlock *load_bb); -Inst *CreateCompareClassWithDeopt(uint32_t pc, Inst *get_cls_inst, RuntimeInterface::ClassPtr receiver, - Inst *save_state); +void CreateCompareClass(uint32_t pc, Inst *getClsInst, RuntimeInterface::ClassPtr receiver, BasicBlock *loadBb); +Inst *CreateCompareClassWithDeopt(uint32_t pc, Inst *getClsInst, RuntimeInterface::ClassPtr receiver, Inst *saveState); profiling::AnyInputType GetAllowedTypeForInput(IntrinsicInst *intrinsic, size_t index); bool InlineStrictCompareDifferentTypes(IntrinsicInst *intrinsic, AnyBaseType type1, AnyBaseType type2); @@ -71,7 +70,7 @@ bool InlineCompareWithNull(IntrinsicInst *intrinsic, AnyBaseType type1, AnyBaseT bool InlineEqDyn(IntrinsicInst *intrinsic, AnyBaseType type1, AnyBaseType type2); bool InlineNotEqDyn(IntrinsicInst *intrinsic, AnyBaseType type1, AnyBaseType type2); bool InlineToNumber(IntrinsicInst *intrinsic, AnyBaseType type1); -Inst *GetParentLexEnv(InstAppender *appender, Inst *current_lex_env, uint32_t level, uint32_t pc); +Inst *GetParentLexEnv(InstAppender *appender, Inst *currentLexEnv, uint32_t level, uint32_t pc); bool InlineLdLexDyn(IntrinsicInst *intrinsic); bool InlineStLexDyn(IntrinsicInst *intrinsic); bool InlineLdLexVarDyn(IntrinsicInst *intrinsic); @@ -81,6 +80,6 @@ bool InlinePopLexenvDyn(IntrinsicInst *intrinsic); bool InlineTryLdGlobalByName(IntrinsicInst *inst); template -void InlineTryLdGlobalField(IntrinsicInst *inst, uint32_t type_id, uintptr_t address); +void InlineTryLdGlobalField(IntrinsicInst *inst, uint32_t typeId, uintptr_t address); #endif // PLUGINS_ECMASCRIPT_COMPILER_INLINE_INTRINSICS_ECMASCRIPT_INL_H diff --git a/compiler/optimizer/code_generator/compiler_base_types.cpp b/compiler/optimizer/code_generator/compiler_base_types.cpp index f968d0900e48c700c20a8d1f98d9ec3db3f5b3f3..1899129713f2974586ece6b35af9e16f87ec125a 100644 --- a/compiler/optimizer/code_generator/compiler_base_types.cpp +++ b/compiler/optimizer/code_generator/compiler_base_types.cpp @@ -23,95 +23,95 @@ namespace panda::compiler { -static void IsHasTagMaskGen(Encoder *enc, Reg dst, Reg src, Imm val_tag, Imm val_mask, +static void IsHasTagMaskGen(Encoder *enc, Reg dst, Reg src, Imm valTag, Imm valMask, LabelHolder::LabelId id = LabelHolder::INVALID_LABEL) { - ScopedTmpReg reg_val_tag(enc, TypeInfo(TypeInfo::TypeId::INT64)); - auto dst_ext = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); + ScopedTmpReg regValTag(enc, TypeInfo(TypeInfo::TypeId::INT64)); + auto dstExt = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); - enc->EncodeMov(reg_val_tag, val_tag); - if (val_tag != val_mask) { - enc->EncodeAnd(dst_ext, src, val_mask); + enc->EncodeMov(regValTag, valTag); + if (valTag != valMask) { + enc->EncodeAnd(dstExt, src, valMask); } else { - enc->EncodeAnd(dst_ext, src, reg_val_tag); + enc->EncodeAnd(dstExt, src, regValTag); } if (id == LabelHolder::INVALID_LABEL) { - enc->EncodeCompare(dst, dst_ext, reg_val_tag, Condition::EQ); + enc->EncodeCompare(dst, dstExt, regValTag, Condition::EQ); } else { - enc->EncodeJump(id, dst_ext, reg_val_tag, Condition::NE); + enc->EncodeJump(id, dstExt, regValTag, Condition::NE); } } -static void CompareAnyTypeGenDouble(Encoder *enc, Reg dst, Reg src, profiling::AnyInputType allowed_input_type, - LabelHolder::LabelId not_number_label = LabelHolder::INVALID_LABEL, - LabelHolder::LabelId double_with_int_label = LabelHolder::INVALID_LABEL) +static void CompareAnyTypeGenDouble(Encoder *enc, Reg dst, Reg src, profiling::AnyInputType allowedInputType, + LabelHolder::LabelId notNumberLabel = LabelHolder::INVALID_LABEL, + LabelHolder::LabelId doubleWithIntLabel = LabelHolder::INVALID_LABEL) { static constexpr uint16_t CMP_VAL = static_cast(UINT16_MAX) >> 1U; // 0x7fff static constexpr uint8_t SHIFT_VAL = coretypes::TaggedValue::TAG_BITS_SHIFT + 1; - auto dst_ext = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); + auto dstExt = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); - auto jump = not_number_label != LabelHolder::INVALID_LABEL; - ASSERT(allowed_input_type == profiling::AnyInputType::DEFAULT || jump); - if (allowed_input_type == profiling::AnyInputType::SPECIAL_INT) { + auto jump = notNumberLabel != LabelHolder::INVALID_LABEL; + ASSERT(allowedInputType == profiling::AnyInputType::DEFAULT || jump); + if (allowedInputType == profiling::AnyInputType::SPECIAL_INT) { constexpr auto MIN_OBJECT = coretypes::TaggedValue::VALUE_UNDEFINED + 1; constexpr auto MIN_NUMBER = 1ULL << coretypes::TaggedValue::TAG_BITS_SHIFT; static_assert(coretypes::TaggedValue::VALUE_TRUE < MIN_OBJECT); static_assert(coretypes::TaggedValue::TAG_EXCEPTION >= MIN_OBJECT); - enc->EncodeSub(dst_ext, src, Imm(MIN_OBJECT)); - enc->EncodeJump(not_number_label, dst_ext, Imm(MIN_NUMBER - MIN_OBJECT), Condition::LO); + enc->EncodeSub(dstExt, src, Imm(MIN_OBJECT)); + enc->EncodeJump(notNumberLabel, dstExt, Imm(MIN_NUMBER - MIN_OBJECT), Condition::LO); return; } - if (allowed_input_type == profiling::AnyInputType::INTEGER) { - enc->EncodeShr(dst_ext, src, Imm(coretypes::TaggedValue::TAG_BITS_SHIFT)); - enc->EncodeJump(not_number_label, dst_ext, Imm(0), Condition::EQ); + if (allowedInputType == profiling::AnyInputType::INTEGER) { + enc->EncodeShr(dstExt, src, Imm(coretypes::TaggedValue::TAG_BITS_SHIFT)); + enc->EncodeJump(notNumberLabel, dstExt, Imm(0), Condition::EQ); return; } - LabelHolder::LabelId end_label = enc->CreateLabel(); - if (allowed_input_type == profiling::AnyInputType::SPECIAL) { - enc->EncodeJump(end_label, src, Imm(coretypes::TaggedValue::VALUE_UNDEFINED), Condition::EQ); + LabelHolder::LabelId endLabel = enc->CreateLabel(); + if (allowedInputType == profiling::AnyInputType::SPECIAL) { + enc->EncodeJump(endLabel, src, Imm(coretypes::TaggedValue::VALUE_UNDEFINED), Condition::EQ); } else { - ASSERT(allowed_input_type == profiling::AnyInputType::DEFAULT); + ASSERT(allowedInputType == profiling::AnyInputType::DEFAULT); } // (u16) tag + 0xffff is [0xffff for Object, 0xfffe for Int, other - Double] - enc->EncodeAdd(dst_ext, src, Imm(panda::coretypes::TaggedValue::TAG_MASK)); + enc->EncodeAdd(dstExt, src, Imm(panda::coretypes::TaggedValue::TAG_MASK)); // Examine tag and shift it by one -> 0x7fff for both Object and Int - enc->EncodeShr(dst_ext, dst_ext, Imm(SHIFT_VAL)); - ScopedTmpReg reg_cmp(enc, TypeInfo(TypeInfo::TypeId::INT64)); - enc->EncodeMov(reg_cmp, Imm(CMP_VAL)); + enc->EncodeShr(dstExt, dstExt, Imm(SHIFT_VAL)); + ScopedTmpReg regCmp(enc, TypeInfo(TypeInfo::TypeId::INT64)); + enc->EncodeMov(regCmp, Imm(CMP_VAL)); // check if not Object and not Int if (!jump) { - enc->EncodeCompare(dst, dst_ext, reg_cmp, Condition::LO); - } else if (double_with_int_label != LabelHolder::INVALID_LABEL) { - enc->EncodeJump(end_label, dst_ext, reg_cmp, Condition::LT); + enc->EncodeCompare(dst, dstExt, regCmp, Condition::LO); + } else if (doubleWithIntLabel != LabelHolder::INVALID_LABEL) { + enc->EncodeJump(endLabel, dstExt, regCmp, Condition::LT); auto bit = coretypes::TaggedValue::TAG_BITS_SIZE + coretypes::TaggedValue::TAG_BITS_SHIFT - 1; - enc->EncodeBitTestAndBranch(double_with_int_label, src, bit, true); - enc->EncodeJump(not_number_label); + enc->EncodeBitTestAndBranch(doubleWithIntLabel, src, bit, true); + enc->EncodeJump(notNumberLabel); } else { - enc->EncodeJump(not_number_label, dst_ext, reg_cmp, Condition::GE); + enc->EncodeJump(notNumberLabel, dstExt, regCmp, Condition::GE); } - enc->BindLabel(end_label); + enc->BindLabel(endLabel); } -static void CompareAnyTypeGenInt(Encoder *enc, Reg dst, Reg src, profiling::AnyInputType allowed_input_type, +static void CompareAnyTypeGenInt(Encoder *enc, Reg dst, Reg src, profiling::AnyInputType allowedInputType, LabelHolder::LabelId id = LabelHolder::INVALID_LABEL) { - if (allowed_input_type == profiling::AnyInputType::DEFAULT) { + if (allowedInputType == profiling::AnyInputType::DEFAULT) { IsHasTagMaskGen(enc, dst, src, Imm(panda::coretypes::TaggedValue::TAG_INT), Imm(panda::coretypes::TaggedValue::TAG_MASK), id); return; } - ASSERT(allowed_input_type == profiling::AnyInputType::SPECIAL); + ASSERT(allowedInputType == profiling::AnyInputType::SPECIAL); constexpr auto MIN_FAIL = coretypes::TaggedValue::VALUE_UNDEFINED; // accept values < VALUE_UNDEFINED or >= TAG_INT - auto dst_ext = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); - enc->EncodeSub(dst_ext, src, Imm(MIN_FAIL)); + auto dstExt = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); + enc->EncodeSub(dstExt, src, Imm(MIN_FAIL)); if (id == LabelHolder::INVALID_LABEL) { - ScopedTmpReg reg_cmp(enc, TypeInfo(TypeInfo::TypeId::INT64)); - enc->EncodeMov(reg_cmp, Imm(coretypes::TaggedValue::TAG_INT - MIN_FAIL)); - enc->EncodeCompare(dst_ext, dst_ext, reg_cmp, Condition::HS); + ScopedTmpReg regCmp(enc, TypeInfo(TypeInfo::TypeId::INT64)); + enc->EncodeMov(regCmp, Imm(coretypes::TaggedValue::TAG_INT - MIN_FAIL)); + enc->EncodeCompare(dstExt, dstExt, regCmp, Condition::HS); } else { - enc->EncodeJump(id, dst_ext, Imm(coretypes::TaggedValue::TAG_INT - MIN_FAIL), Condition::LO); + enc->EncodeJump(id, dstExt, Imm(coretypes::TaggedValue::TAG_INT - MIN_FAIL), Condition::LO); } } @@ -122,15 +122,15 @@ static void CompareAnyTypeGenBool(Encoder *enc, Reg dst, Reg src, LabelHolder::L static constexpr uint64_t BOOL_MASK = panda::coretypes::TaggedValue::VALUE_FALSE & panda::coretypes::TaggedValue::VALUE_TRUE; - ScopedTmpReg reg_cmp(enc, TypeInfo(TypeInfo::TypeId::INT64)); - auto dst_ext = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); + ScopedTmpReg regCmp(enc, TypeInfo(TypeInfo::TypeId::INT64)); + auto dstExt = dst.As(TypeInfo(TypeInfo::TypeId::INT64)); - enc->EncodeAnd(dst_ext, src, Imm(BOOL_DIFF_MASK)); - enc->EncodeMov(reg_cmp, Imm(BOOL_MASK)); + enc->EncodeAnd(dstExt, src, Imm(BOOL_DIFF_MASK)); + enc->EncodeMov(regCmp, Imm(BOOL_MASK)); if (id == LabelHolder::INVALID_LABEL) { - enc->EncodeCompare(dst, dst_ext, reg_cmp, Condition::EQ); + enc->EncodeCompare(dst, dstExt, regCmp, Condition::EQ); } else { - enc->EncodeJump(id, dst_ext, reg_cmp, Condition::NE); + enc->EncodeJump(id, dstExt, regCmp, Condition::NE); } } @@ -138,9 +138,9 @@ static void IsEqualToValGen(Encoder *enc, Reg dst, Reg src, Imm val, LabelHolder::LabelId id = LabelHolder::INVALID_LABEL) { if (id == LabelHolder::INVALID_LABEL) { - ScopedTmpReg reg_val(enc, TypeInfo(TypeInfo::TypeId::INT64)); - enc->EncodeMov(reg_val, val); - enc->EncodeCompare(dst, src, reg_val, Condition::EQ); + ScopedTmpReg regVal(enc, TypeInfo(TypeInfo::TypeId::INT64)); + enc->EncodeMov(regVal, val); + enc->EncodeCompare(dst, src, regVal, Condition::EQ); } else { enc->EncodeJump(id, src, val, Condition::NE); } @@ -149,11 +149,11 @@ static void IsEqualToValGen(Encoder *enc, Reg dst, Reg src, Imm val, // Jump out if !IsHeapObject() static void CheckAnyTypeGenObject(Encoder *enc, const Reg &src, LabelHolder::LabelId label) { - ScopedTmpReg tmp_reg(enc, TypeInfo(TypeInfo::TypeId::INT64)); + ScopedTmpReg tmpReg(enc, TypeInfo(TypeInfo::TypeId::INT64)); // IsObject() - enc->EncodeAnd(tmp_reg, src, Imm(panda::coretypes::TaggedValue::TAG_MASK)); - enc->EncodeJump(label, tmp_reg, Imm(panda::coretypes::TaggedValue::TAG_OBJECT), Condition::NE); + enc->EncodeAnd(tmpReg, src, Imm(panda::coretypes::TaggedValue::TAG_MASK)); + enc->EncodeJump(label, tmpReg, Imm(panda::coretypes::TaggedValue::TAG_OBJECT), Condition::NE); // !IsSpecial // It's enough to check that `src` > `TAG_SPECIAL_MASK`, as it's guaranteed that special values @@ -164,94 +164,94 @@ static void CheckAnyTypeGenObject(Encoder *enc, const Reg &src, LabelHolder::Lab // Jump out if (!IsHeapObject() or object.type, type) static void CheckAnyTypeGenObjectType(Codegen *codegen, Encoder *enc, const Reg &src, uint32_t type, - LabelHolder::LabelId label, Condition fail_cc = Condition::NE) + LabelHolder::LabelId label, Condition failCc = Condition::NE) { CheckAnyTypeGenObject(enc, src, label); auto arch = codegen->GetArch(); - ScopedTmpReg tmp_reg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); - - enc->EncodeLdr(tmp_reg, false, MemRef(src, codegen->GetRuntime()->GetObjClassOffset(arch))); - auto type_start_bit = cross_values::GetJshclassBitfieldTypeStartBit(arch); - auto bit_mask = static_cast(cross_values::GetJshclassBitfieldTypeMask(arch)); - enc->EncodeLdr(tmp_reg, false, MemRef(tmp_reg, cross_values::GetHclassDataOffset(arch))); - if (type_start_bit != 0) { - enc->EncodeShr(tmp_reg, tmp_reg, Imm(type_start_bit)); + ScopedTmpReg tmpReg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); + + enc->EncodeLdr(tmpReg, false, MemRef(src, codegen->GetRuntime()->GetObjClassOffset(arch))); + auto typeStartBit = cross_values::GetJshclassBitfieldTypeStartBit(arch); + auto bitMask = static_cast(cross_values::GetJshclassBitfieldTypeMask(arch)); + enc->EncodeLdr(tmpReg, false, MemRef(tmpReg, cross_values::GetHclassDataOffset(arch))); + if (typeStartBit != 0) { + enc->EncodeShr(tmpReg, tmpReg, Imm(typeStartBit)); } - enc->EncodeAnd(tmp_reg, tmp_reg, Imm(bit_mask)); - enc->EncodeJump(label, tmp_reg, Imm(type), fail_cc); + enc->EncodeAnd(tmpReg, tmpReg, Imm(bitMask)); + enc->EncodeJump(label, tmpReg, Imm(type), failCc); } // dst = IsHeapObject() static void CompareAnyTypeGenObject(Encoder *enc, const Reg &dst, const Reg &src) { - auto label_false = enc->CreateLabel(); + auto labelFalse = enc->CreateLabel(); enc->EncodeMov(dst, Imm(0)); - CheckAnyTypeGenObject(enc, src, label_false); + CheckAnyTypeGenObject(enc, src, labelFalse); enc->EncodeMov(dst, Imm(1U)); - enc->BindLabel(label_false); + enc->BindLabel(labelFalse); } static void CompareOrCheckAnyTypeCallable(Codegen *codegen, Encoder *enc, const Reg &dst, const Reg &src, LabelHolder::LabelId id = LabelHolder::INVALID_LABEL) { - auto label_false = enc->CreateLabel(); + auto labelFalse = enc->CreateLabel(); auto arch = codegen->GetArch(); - Reg res_reg = dst; - bool need_temp = (dst.GetId() == src.GetId()); - ScopedTmpRegLazy tmp_dst(enc); - if (need_temp) { - tmp_dst.AcquireIfInvalid(); - res_reg = tmp_dst.GetReg().As(codegen->ConvertDataType(DataType::ANY, arch)); + Reg resReg = dst; + bool needTemp = (dst.GetId() == src.GetId()); + ScopedTmpRegLazy tmpDst(enc); + if (needTemp) { + tmpDst.AcquireIfInvalid(); + resReg = tmpDst.GetReg().As(codegen->ConvertDataType(DataType::ANY, arch)); } if (id == LabelHolder::INVALID_LABEL) { - enc->EncodeMov(res_reg, Imm(0)); + enc->EncodeMov(resReg, Imm(0)); } - LabelHolder::LabelId label = (id == LabelHolder::INVALID_LABEL) ? label_false : id; + LabelHolder::LabelId label = (id == LabelHolder::INVALID_LABEL) ? labelFalse : id; CheckAnyTypeGenObject(enc, src, label); - ScopedTmpReg tmp_reg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); + ScopedTmpReg tmpReg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); - enc->EncodeLdr(tmp_reg, false, MemRef(src, codegen->GetRuntime()->GetObjClassOffset(arch))); - Reg tmp32_reg = tmp_reg.GetReg().As(TypeInfo(TypeInfo::TypeId::INT32)); - enc->EncodeLdr(tmp32_reg, false, MemRef(tmp_reg, codegen->GetRuntime()->GetBaseClassFlagsOffset(arch))); - auto is_callable_mask = codegen->GetRuntime()->GetCallableMask(); - enc->EncodeJumpTest(label, tmp32_reg, Imm(is_callable_mask), Condition::TST_EQ); + enc->EncodeLdr(tmpReg, false, MemRef(src, codegen->GetRuntime()->GetObjClassOffset(arch))); + Reg tmp32Reg = tmpReg.GetReg().As(TypeInfo(TypeInfo::TypeId::INT32)); + enc->EncodeLdr(tmp32Reg, false, MemRef(tmpReg, codegen->GetRuntime()->GetBaseClassFlagsOffset(arch))); + auto isCallableMask = codegen->GetRuntime()->GetCallableMask(); + enc->EncodeJumpTest(label, tmp32Reg, Imm(isCallableMask), Condition::TST_EQ); if (id == LabelHolder::INVALID_LABEL) { - enc->EncodeMov(res_reg, Imm(1U)); - enc->BindLabel(label_false); - if (need_temp) { - enc->EncodeMov(dst, res_reg); + enc->EncodeMov(resReg, Imm(1U)); + enc->BindLabel(labelFalse); + if (needTemp) { + enc->EncodeMov(dst, resReg); } } } // dst = (IsHeapObject() and ! object.type, type) static void CompareAnyTypeGenObjectType(Codegen *codegen, Encoder *enc, const Reg &dst, const Reg &src, uint32_t type, - Condition fail_cc = Condition::NE) + Condition failCc = Condition::NE) { - Reg res_reg = dst; + Reg resReg = dst; auto arch = codegen->GetArch(); - bool need_temp = (dst.GetId() == src.GetId()); - ScopedTmpRegLazy tmp_reg(enc); - if (need_temp) { - tmp_reg.AcquireIfInvalid(); - res_reg = tmp_reg.GetReg().As(codegen->ConvertDataType(DataType::ANY, arch)); + bool needTemp = (dst.GetId() == src.GetId()); + ScopedTmpRegLazy tmpReg(enc); + if (needTemp) { + tmpReg.AcquireIfInvalid(); + resReg = tmpReg.GetReg().As(codegen->ConvertDataType(DataType::ANY, arch)); } - auto label_false = enc->CreateLabel(); - enc->EncodeMov(res_reg, Imm(0)); - CheckAnyTypeGenObjectType(codegen, enc, src, type, label_false, fail_cc); - enc->EncodeMov(res_reg, Imm(1U)); - enc->BindLabel(label_false); - if (need_temp) { - enc->EncodeMov(dst, res_reg); + auto labelFalse = enc->CreateLabel(); + enc->EncodeMov(resReg, Imm(0)); + CheckAnyTypeGenObjectType(codegen, enc, src, type, labelFalse, failCc); + enc->EncodeMov(resReg, Imm(1U)); + enc->BindLabel(labelFalse); + if (needTemp) { + enc->EncodeMov(dst, resReg); } } -bool ecmascript::GetAnyTypeNameGen(const GetAnyTypeNameInst *inst, EncodeVisitor *enc_v) +bool ecmascript::GetAnyTypeNameGen(const GetAnyTypeNameInst *inst, EncodeVisitor *encV) { - Encoder *enc = enc_v->GetEncoder(); - Codegen *codegen = enc_v->GetCodegen(); + Encoder *enc = encV->GetEncoder(); + Codegen *codegen = encV->GetCodegen(); auto dst = codegen->ConvertRegister(inst->GetDstReg(), DataType::Type::ANY); auto graph = codegen->GetGraph(); @@ -261,13 +261,13 @@ bool ecmascript::GetAnyTypeNameGen(const GetAnyTypeNameInst *inst, EncodeVisitor return true; } -bool ecmascript::CompareAnyTypeGen(const CompareAnyTypeInst *cati, EncodeVisitor *enc_v) +bool ecmascript::CompareAnyTypeGen(const CompareAnyTypeInst *cati, EncodeVisitor *encV) { - auto *codegen = enc_v->GetCodegen(); - auto dst = enc_v->GetCodegen()->ConvertRegister(cati->GetDstReg(), DataType::Type::BOOL); - auto src = enc_v->GetCodegen()->ConvertRegister(cati->GetSrcReg(0), DataType::Type::INT64); + auto *codegen = encV->GetCodegen(); + auto dst = encV->GetCodegen()->ConvertRegister(cati->GetDstReg(), DataType::Type::BOOL); + auto src = encV->GetCodegen()->ConvertRegister(cati->GetSrcReg(0), DataType::Type::INT64); - Encoder *enc = enc_v->GetEncoder(); + Encoder *enc = encV->GetEncoder(); switch (cati->GetAnyType()) { case AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE: IsEqualToValGen(enc, dst, src, Imm(panda::coretypes::TaggedValue::VALUE_UNDEFINED)); @@ -333,14 +333,14 @@ bool ecmascript::CompareAnyTypeGen(const CompareAnyTypeInst *cati, EncodeVisitor } // NOLINTNEXTLINE(readability-function-size) -bool ecmascript::CastAnyTypeValueGen(const CastAnyTypeValueInst *cati, EncodeVisitor *enc_v) +bool ecmascript::CastAnyTypeValueGen(const CastAnyTypeValueInst *cati, EncodeVisitor *encV) { - auto dst_reg_type = cati->GetType(); - dst_reg_type = DataType::IsFloatType(dst_reg_type) ? DataType::FLOAT64 : dst_reg_type; - auto dst = enc_v->GetCodegen()->ConvertRegister(cati->GetDstReg(), dst_reg_type); - auto src = enc_v->GetCodegen()->ConvertRegister(cati->GetSrcReg(0), DataType::INT64); + auto dstRegType = cati->GetType(); + dstRegType = DataType::IsFloatType(dstRegType) ? DataType::FLOAT64 : dstRegType; + auto dst = encV->GetCodegen()->ConvertRegister(cati->GetDstReg(), dstRegType); + auto src = encV->GetCodegen()->ConvertRegister(cati->GetSrcReg(0), DataType::INT64); - auto *enc = enc_v->GetEncoder(); + auto *enc = encV->GetEncoder(); switch (cati->GetAnyType()) { case AnyBaseType::ECMASCRIPT_NULL_TYPE: case AnyBaseType::ECMASCRIPT_HOLE_TYPE: @@ -351,67 +351,67 @@ bool ecmascript::CastAnyTypeValueGen(const CastAnyTypeValueInst *cati, EncodeVis enc->EncodeAnd(dst, src, Imm(1)); return true; case AnyBaseType::ECMASCRIPT_INT_TYPE: { - if (DataType::GetTypeSize(dst_reg_type, RUNTIME_ARCH) > + if (DataType::GetTypeSize(dstRegType, RUNTIME_ARCH) > DataType::GetTypeSize(DataType::INT32, RUNTIME_ARCH)) { ASSERT(false && "sign-extension by dst type is not supported"); } - Reg res_reg = src; - ScopedTmpRegLazy tmp_dst(enc); + Reg resReg = src; + ScopedTmpRegLazy tmpDst(enc); if (cati->GetAllowedInputType() == profiling::AnyInputType::SPECIAL) { if (dst.GetId() == src.GetId()) { - tmp_dst.AcquireIfInvalid(); - res_reg = tmp_dst; + tmpDst.AcquireIfInvalid(); + resReg = tmpDst; } else { - res_reg = dst.As(INT64_TYPE); + resReg = dst.As(INT64_TYPE); } - enc->EncodeAShr(res_reg, src, Imm(BitNumbers() - 1)); - enc->EncodeOr(res_reg, res_reg, Imm(1)); + enc->EncodeAShr(resReg, src, Imm(BitNumbers() - 1)); + enc->EncodeOr(resReg, resReg, Imm(1)); // here res_reg contains 1 for special values and -1 for tagged ints - enc->EncodeAnd(res_reg, res_reg, src); + enc->EncodeAnd(resReg, resReg, src); } - ASSERT(res_reg.GetSize() == DOUBLE_WORD_SIZE); + ASSERT(resReg.GetSize() == DOUBLE_WORD_SIZE); ASSERT(!dst.IsFloat() && !src.IsFloat()); - enc->EncodeCast(dst, false, res_reg, false); + enc->EncodeCast(dst, false, resReg, false); return true; } case AnyBaseType::ECMASCRIPT_DOUBLE_TYPE: { ASSERT(dst.IsFloat()); - ScopedTmpReg reg_tmp(enc, TypeInfo(TypeInfo::INT64)); - auto end_label = enc->CreateLabel(); - auto return_label = enc->CreateLabel(); + ScopedTmpReg regTmp(enc, TypeInfo(TypeInfo::INT64)); + auto endLabel = enc->CreateLabel(); + auto returnLabel = enc->CreateLabel(); if ((cati->GetAllowedInputType() & profiling::AnyInputType::SPECIAL) != 0) { // We allow Hole value in AnyTypeCheck with SPECIAL flag, but assume it cannot be // CastValueToAnyType input, so it is cast to 0 instead of NaN here - SCOPED_DISASM_STR(enc_v->GetCodegen(), "Try cast from Undefined"); - enc->EncodeMov(reg_tmp, + SCOPED_DISASM_STR(encV->GetCodegen(), "Try cast from Undefined"); + enc->EncodeMov(regTmp, Imm(coretypes::ReinterpretDoubleToTaggedType(coretypes::TaggedValue::VALUE_NAN))); - enc->EncodeJump(return_label, src, Imm(coretypes::TaggedValue::VALUE_UNDEFINED), Condition::EQ); + enc->EncodeJump(returnLabel, src, Imm(coretypes::TaggedValue::VALUE_UNDEFINED), Condition::EQ); } if (cati->GetAllowedInputType() == profiling::AnyInputType::SPECIAL_INT) { - SCOPED_DISASM_STR(enc_v->GetCodegen(), "Try cast from Boolean or Null"); - auto int_double_label = enc->CreateLabel(); - enc->EncodeShr(reg_tmp, src, Imm(coretypes::TaggedValue::TAG_BITS_SHIFT)); - enc->EncodeJump(int_double_label, reg_tmp, Imm(0), Condition::NE); + SCOPED_DISASM_STR(encV->GetCodegen(), "Try cast from Boolean or Null"); + auto intDoubleLabel = enc->CreateLabel(); + enc->EncodeShr(regTmp, src, Imm(coretypes::TaggedValue::TAG_BITS_SHIFT)); + enc->EncodeJump(intDoubleLabel, regTmp, Imm(0), Condition::NE); enc->EncodeAnd(dst.As(INT32_TYPE), src, Imm(1)); enc->EncodeCast(dst.As(FLOAT64_TYPE), true, dst.As(INT32_TYPE), true); - enc->EncodeJump(end_label); - enc->BindLabel(int_double_label); + enc->EncodeJump(endLabel); + enc->BindLabel(intDoubleLabel); } if ((cati->GetAllowedInputType() & profiling::AnyInputType::INTEGER) != 0) { - SCOPED_DISASM_STR(enc_v->GetCodegen(), "Try cast from SMI"); - auto not_int_label = enc->CreateLabel(); - enc->EncodeShr(reg_tmp, src, Imm(coretypes::TaggedValue::TAG_BITS_SHIFT)); - enc->EncodeJump(not_int_label, reg_tmp, + SCOPED_DISASM_STR(encV->GetCodegen(), "Try cast from SMI"); + auto notIntLabel = enc->CreateLabel(); + enc->EncodeShr(regTmp, src, Imm(coretypes::TaggedValue::TAG_BITS_SHIFT)); + enc->EncodeJump(notIntLabel, regTmp, Imm(coretypes::TaggedValue::TAG_INT >> coretypes::TaggedValue::TAG_BITS_SHIFT), Condition::NE); enc->EncodeCast(dst.As(FLOAT64_TYPE), true, src.As(INT32_TYPE), true); - enc->EncodeJump(end_label); - enc->BindLabel(not_int_label); + enc->EncodeJump(endLabel); + enc->BindLabel(notIntLabel); } - enc->EncodeSub(reg_tmp, src, Imm(panda::coretypes::TaggedValue::DOUBLE_ENCODE_OFFSET)); - enc->BindLabel(return_label); - enc->EncodeMov(dst, reg_tmp); - enc->BindLabel(end_label); + enc->EncodeSub(regTmp, src, Imm(panda::coretypes::TaggedValue::DOUBLE_ENCODE_OFFSET)); + enc->BindLabel(returnLabel); + enc->EncodeMov(dst, regTmp); + enc->BindLabel(endLabel); return true; } case AnyBaseType::ECMASCRIPT_OBJECT_TYPE: @@ -435,14 +435,14 @@ bool ecmascript::CastAnyTypeValueGen(const CastAnyTypeValueInst *cati, EncodeVis return false; } -bool ecmascript::CastValueToAnyTypeGen(const CastValueToAnyTypeInst *cvai, EncodeVisitor *enc_v) +bool ecmascript::CastValueToAnyTypeGen(const CastValueToAnyTypeInst *cvai, EncodeVisitor *encV) { - auto src_reg_type = cvai->GetInputType(0); - src_reg_type = DataType::IsFloatType(src_reg_type) ? DataType::FLOAT64 : src_reg_type; - auto dst = enc_v->GetCodegen()->ConvertRegister(cvai->GetDstReg(), DataType::INT64); - auto src = enc_v->GetCodegen()->ConvertRegister(cvai->GetSrcReg(0), src_reg_type); + auto srcRegType = cvai->GetInputType(0); + srcRegType = DataType::IsFloatType(srcRegType) ? DataType::FLOAT64 : srcRegType; + auto dst = encV->GetCodegen()->ConvertRegister(cvai->GetDstReg(), DataType::INT64); + auto src = encV->GetCodegen()->ConvertRegister(cvai->GetSrcReg(0), srcRegType); - auto *enc = enc_v->GetEncoder(); + auto *enc = encV->GetEncoder(); switch (cvai->GetAnyType()) { case AnyBaseType::ECMASCRIPT_NULL_TYPE: enc->EncodeMov(dst, Imm(panda::coretypes::TaggedValue::VALUE_NULL)); @@ -457,8 +457,8 @@ bool ecmascript::CastValueToAnyTypeGen(const CastValueToAnyTypeInst *cvai, Encod enc->EncodeOr(dst, src, Imm(panda::coretypes::TaggedValue::VALUE_FALSE)); return true; case AnyBaseType::ECMASCRIPT_INT_TYPE: { - auto src_32 = enc_v->GetCodegen()->ConvertRegister(cvai->GetSrcReg(0), DataType::INT32); - enc->EncodeCast(dst, false, src_32, false); + auto src32 = encV->GetCodegen()->ConvertRegister(cvai->GetSrcReg(0), DataType::INT32); + enc->EncodeCast(dst, false, src32, false); enc->EncodeOr(dst, dst, Imm(panda::coretypes::TaggedValue::TAG_INT)); return true; } @@ -496,49 +496,48 @@ bool ecmascript::CastValueToAnyTypeGen(const CastValueToAnyTypeInst *cvai, Encod return false; } -bool ecmascript::ObjByIndexCheckGen(const FixedInputsInst2 *check_inst, EncodeVisitor *enc_v, LabelHolder::LabelId id) +bool ecmascript::ObjByIndexCheckGen(const FixedInputsInst2 *checkInst, EncodeVisitor *encV, LabelHolder::LabelId id) { - auto src = enc_v->GetCodegen()->ConvertRegister(check_inst->GetSrcReg(0), DataType::Type::INT64); - Encoder *enc = enc_v->GetEncoder(); - Codegen *codegen = enc_v->GetCodegen(); + auto src = encV->GetCodegen()->ConvertRegister(checkInst->GetSrcReg(0), DataType::Type::INT64); + Encoder *enc = encV->GetEncoder(); + Codegen *codegen = encV->GetCodegen(); // Check that the value is Heap Object CheckAnyTypeGenObject(enc, src, id); auto arch = codegen->GetArch(); - ScopedTmpReg property_reg(enc, codegen->ConvertDataType(DataType::INT64, arch)); - ScopedTmpReg tmp_reg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); - - enc->EncodeLdr(tmp_reg, false, MemRef(src, codegen->GetRuntime()->GetObjClassOffset(arch))); - enc->EncodeLdr(property_reg, false, MemRef(tmp_reg, cross_values::GetHclassDataOffset(arch))); - auto type_start_bit = cross_values::GetJshclassBitfieldTypeStartBit(arch); - if (type_start_bit != 0) { - enc->EncodeShr(property_reg, property_reg, Imm(type_start_bit)); + ScopedTmpReg propertyReg(enc, codegen->ConvertDataType(DataType::INT64, arch)); + ScopedTmpReg tmpReg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); + + enc->EncodeLdr(tmpReg, false, MemRef(src, codegen->GetRuntime()->GetObjClassOffset(arch))); + enc->EncodeLdr(propertyReg, false, MemRef(tmpReg, cross_values::GetHclassDataOffset(arch))); + auto typeStartBit = cross_values::GetJshclassBitfieldTypeStartBit(arch); + if (typeStartBit != 0) { + enc->EncodeShr(propertyReg, propertyReg, Imm(typeStartBit)); } // Check that te object isn't special - enc->EncodeAnd(tmp_reg, property_reg, Imm(static_cast(cross_values::GetJshclassBitfieldTypeMask(arch)))); - enc->EncodeJump(id, tmp_reg, Imm(cross_values::GetJstypeJsArray(codegen->GetArch())), Condition::GT); - auto bit_offset = static_cast(cross_values::GetJshclassBitfieldIsDictionaryStartBit(codegen->GetArch())); + enc->EncodeAnd(tmpReg, propertyReg, Imm(static_cast(cross_values::GetJshclassBitfieldTypeMask(arch)))); + enc->EncodeJump(id, tmpReg, Imm(cross_values::GetJstypeJsArray(codegen->GetArch())), Condition::GT); + auto bitOffset = static_cast(cross_values::GetJshclassBitfieldIsDictionaryStartBit(codegen->GetArch())); // Check that the object isn't dictionary - enc->EncodeJumpTest(id, tmp_reg, Imm(1U << bit_offset), Condition::TST_NE); + enc->EncodeJumpTest(id, tmpReg, Imm(1U << bitOffset), Condition::TST_NE); return true; } -static bool AnyTypeCheckGenCustomDeoptimization(Encoder *enc, Codegen *codegen, AnyTypeCheckInst *check_inst, Reg src) +static bool AnyTypeCheckGenCustomDeoptimization(Encoder *enc, Codegen *codegen, AnyTypeCheckInst *checkInst, Reg src) { - ScopedTmpReg tmp_reg(enc, TypeInfo(TypeInfo::TypeId::INT64)); - switch (check_inst->GetAnyType()) { + ScopedTmpReg tmpReg(enc, TypeInfo(TypeInfo::TypeId::INT64)); + switch (checkInst->GetAnyType()) { case AnyBaseType::ECMASCRIPT_INT_TYPE: { - auto id = - codegen->CreateSlowPath(check_inst, DeoptimizeType::NOT_SMALL_INT)->GetLabel(); - CompareAnyTypeGenInt(enc, tmp_reg, src, check_inst->GetAllowedInputType(), id); + auto id = codegen->CreateSlowPath(checkInst, DeoptimizeType::NOT_SMALL_INT)->GetLabel(); + CompareAnyTypeGenInt(enc, tmpReg, src, checkInst->GetAllowedInputType(), id); return true; } case AnyBaseType::ECMASCRIPT_DOUBLE_TYPE: { - auto not_number = - codegen->CreateSlowPath(check_inst, DeoptimizeType::NOT_NUMBER)->GetLabel(); - auto double_with_int = - codegen->CreateSlowPath(check_inst, DeoptimizeType::DOUBLE_WITH_INT)->GetLabel(); - CompareAnyTypeGenDouble(enc, tmp_reg, src, check_inst->GetAllowedInputType(), not_number, double_with_int); + auto notNumber = + codegen->CreateSlowPath(checkInst, DeoptimizeType::NOT_NUMBER)->GetLabel(); + auto doubleWithInt = + codegen->CreateSlowPath(checkInst, DeoptimizeType::DOUBLE_WITH_INT)->GetLabel(); + CompareAnyTypeGenDouble(enc, tmpReg, src, checkInst->GetAllowedInputType(), notNumber, doubleWithInt); return true; } default: @@ -546,47 +545,47 @@ static bool AnyTypeCheckGenCustomDeoptimization(Encoder *enc, Codegen *codegen, } } -bool ecmascript::AnyTypeCheckGen(AnyTypeCheckInst *check_inst, EncodeVisitor *enc_v) +bool ecmascript::AnyTypeCheckGen(AnyTypeCheckInst *checkInst, EncodeVisitor *encV) { - auto src = enc_v->GetCodegen()->ConvertRegister(check_inst->GetSrcReg(0), DataType::Type::INT64); - Encoder *enc = enc_v->GetEncoder(); - Codegen *codegen = enc_v->GetCodegen(); + auto src = encV->GetCodegen()->ConvertRegister(checkInst->GetSrcReg(0), DataType::Type::INT64); + Encoder *enc = encV->GetEncoder(); + Codegen *codegen = encV->GetCodegen(); auto graph = codegen->GetGraph(); - auto custom_deoptimize = graph->IsAotMode() || graph->GetRuntime()->GetMethodProfile(graph->GetMethod(), true) != - profiling::INVALID_PROFILE; + auto customDeoptimize = graph->IsAotMode() || graph->GetRuntime()->GetMethodProfile(graph->GetMethod(), true) != + profiling::INVALID_PROFILE; // avoid excessive recompilations for methods which were created while "eval" because such methods are not profiled // in current implementation - if (custom_deoptimize && AnyTypeCheckGenCustomDeoptimization(enc, codegen, check_inst, src)) { + if (customDeoptimize && AnyTypeCheckGenCustomDeoptimization(enc, codegen, checkInst, src)) { return true; } - ScopedTmpReg tmp_reg(enc, TypeInfo(TypeInfo::TypeId::INT64)); + ScopedTmpReg tmpReg(enc, TypeInfo(TypeInfo::TypeId::INT64)); - auto id = codegen->CreateSlowPath(check_inst, DeoptimizeType::ANY_TYPE_CHECK)->GetLabel(); - switch (check_inst->GetAnyType()) { + auto id = codegen->CreateSlowPath(checkInst, DeoptimizeType::ANY_TYPE_CHECK)->GetLabel(); + switch (checkInst->GetAnyType()) { case AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE: - IsEqualToValGen(enc, tmp_reg, src, Imm(panda::coretypes::TaggedValue::VALUE_UNDEFINED), id); + IsEqualToValGen(enc, tmpReg, src, Imm(panda::coretypes::TaggedValue::VALUE_UNDEFINED), id); return true; case AnyBaseType::ECMASCRIPT_INT_TYPE: { - CompareAnyTypeGenInt(enc, tmp_reg, src, check_inst->GetAllowedInputType(), id); + CompareAnyTypeGenInt(enc, tmpReg, src, checkInst->GetAllowedInputType(), id); return true; } case AnyBaseType::ECMASCRIPT_OBJECT_TYPE: - IsHasTagMaskGen(enc, tmp_reg, src, Imm(panda::coretypes::TaggedValue::TAG_OBJECT), + IsHasTagMaskGen(enc, tmpReg, src, Imm(panda::coretypes::TaggedValue::TAG_OBJECT), Imm(panda::coretypes::TaggedValue::TAG_MASK), id); return true; case AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE: CheckAnyTypeGenObject(enc, src, id); return true; case AnyBaseType::ECMASCRIPT_DOUBLE_TYPE: - CompareAnyTypeGenDouble(enc, tmp_reg, src, check_inst->GetAllowedInputType(), id); + CompareAnyTypeGenDouble(enc, tmpReg, src, checkInst->GetAllowedInputType(), id); return true; case AnyBaseType::ECMASCRIPT_STRING_TYPE: CheckAnyTypeGenObjectType(codegen, enc, src, cross_values::GetJstypeString(codegen->GetArch()), id); return true; case AnyBaseType::ECMASCRIPT_SYMBOL_TYPE: - CompareAnyTypeGenObjectType(codegen, enc, tmp_reg, src, cross_values::GetJstypeSymbol(codegen->GetArch())); + CompareAnyTypeGenObjectType(codegen, enc, tmpReg, src, cross_values::GetJstypeSymbol(codegen->GetArch())); return true; case AnyBaseType::ECMASCRIPT_BIGINT_TYPE: CheckAnyTypeGenObjectType(codegen, enc, src, cross_values::GetJstypeBigint(codegen->GetArch()), id); @@ -607,14 +606,14 @@ bool ecmascript::AnyTypeCheckGen(AnyTypeCheckInst *check_inst, EncodeVisitor *en Condition::LE); return true; case AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE: { - CompareAnyTypeGenBool(enc, tmp_reg, src, id); + CompareAnyTypeGenBool(enc, tmpReg, src, id); return true; } case AnyBaseType::ECMASCRIPT_NULL_TYPE: - IsEqualToValGen(enc, tmp_reg, src, Imm(panda::coretypes::TaggedValue::VALUE_NULL), id); + IsEqualToValGen(enc, tmpReg, src, Imm(panda::coretypes::TaggedValue::VALUE_NULL), id); return true; case AnyBaseType::ECMASCRIPT_HOLE_TYPE: - IsEqualToValGen(enc, tmp_reg, src, Imm(panda::coretypes::TaggedValue::VALUE_HOLE), id); + IsEqualToValGen(enc, tmpReg, src, Imm(panda::coretypes::TaggedValue::VALUE_HOLE), id); return true; case AnyBaseType::ECMASCRIPT_FUNCTION_TYPE: CheckAnyTypeGenObjectType(codegen, enc, src, cross_values::GetJstypeJsFunction(codegen->GetArch()), id); @@ -629,9 +628,9 @@ bool ecmascript::AnyTypeCheckGen(AnyTypeCheckInst *check_inst, EncodeVisitor *en return false; } -bool ecmascript::LoadConstantPoolGen(const Inst *inst, EncodeVisitor *enc_v) +bool ecmascript::LoadConstantPoolGen(const Inst *inst, EncodeVisitor *encV) { - auto *codegen = enc_v->GetCodegen(); + auto *codegen = encV->GetCodegen(); auto src = codegen->ConvertRegister(inst->GetSrcReg(0), inst->GetType()); auto dst = codegen->ConvertRegister(inst->GetDstReg(), inst->GetType()); codegen->GetEncoder()->EncodeLdr(dst, false, @@ -639,9 +638,9 @@ bool ecmascript::LoadConstantPoolGen(const Inst *inst, EncodeVisitor *enc_v) return true; } -bool ecmascript::LoadLexicalEnvGen(const Inst *inst, EncodeVisitor *enc_v) +bool ecmascript::LoadLexicalEnvGen(const Inst *inst, EncodeVisitor *encV) { - auto *codegen = enc_v->GetCodegen(); + auto *codegen = encV->GetCodegen(); auto src = codegen->ConvertRegister(inst->GetSrcReg(0), inst->GetType()); auto dst = codegen->ConvertRegister(inst->GetDstReg(), inst->GetType()); codegen->GetEncoder()->EncodeLdr(dst, false, @@ -649,27 +648,26 @@ bool ecmascript::LoadLexicalEnvGen(const Inst *inst, EncodeVisitor *enc_v) return true; } -bool ecmascript::HclassCheckGen(HclassCheckInst *check_inst, EncodeVisitor *enc_v) +bool ecmascript::HclassCheckGen(HclassCheckInst *checkInst, EncodeVisitor *encV) { - auto enc = enc_v->GetEncoder(); - auto codegen = enc_v->GetCodegen(); + auto enc = encV->GetEncoder(); + auto codegen = encV->GetCodegen(); auto arch = codegen->GetArch(); - auto src = codegen->ConvertRegister(check_inst->GetSrcReg(0), DataType::Type::REFERENCE); - auto exit_label = - codegen->CreateSlowPath(check_inst, DeoptimizeType::ANY_TYPE_CHECK)->GetLabel(); + auto src = codegen->ConvertRegister(checkInst->GetSrcReg(0), DataType::Type::REFERENCE); + auto exitLabel = codegen->CreateSlowPath(checkInst, DeoptimizeType::ANY_TYPE_CHECK)->GetLabel(); - ScopedTmpReg tmp_reg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); - auto bit_mask = codegen->GetRuntime()->GetHClassBitfieldTypeMask(arch); + ScopedTmpReg tmpReg(enc, codegen->ConvertDataType(DataType::REFERENCE, arch)); + auto bitMask = codegen->GetRuntime()->GetHClassBitfieldTypeMask(arch); auto type = codegen->GetRuntime()->GetJstypeJsFunction(arch); - if (check_inst->GetCheckIsFunction()) { - enc->EncodeAnd(tmp_reg, src, Imm(bit_mask)); - enc->EncodeJump(exit_label, tmp_reg, Imm(type), Condition::NE); + if (checkInst->GetCheckIsFunction()) { + enc->EncodeAnd(tmpReg, src, Imm(bitMask)); + enc->EncodeJump(exitLabel, tmpReg, Imm(type), Condition::NE); } - if (check_inst->GetCheckFunctionIsNotClassConstructor()) { - auto constructor_start_bit = codegen->GetRuntime()->GetJshclassBitfieldClassConstructorStartBit(arch); - enc->EncodeBitTestAndBranch(exit_label, src, constructor_start_bit, true); + if (checkInst->GetCheckFunctionIsNotClassConstructor()) { + auto constructorStartBit = codegen->GetRuntime()->GetJshclassBitfieldClassConstructorStartBit(arch); + enc->EncodeBitTestAndBranch(exitLabel, src, constructorStartBit, true); } return true; diff --git a/compiler/optimizer/code_generator/compiler_base_types.h b/compiler/optimizer/code_generator/compiler_base_types.h index b8382536c9b32acfc6645ac8251a4ec52b63fb9f..79a4503ff8d836629dcf10d9623d4fcce566fdc7 100644 --- a/compiler/optimizer/code_generator/compiler_base_types.h +++ b/compiler/optimizer/code_generator/compiler_base_types.h @@ -32,16 +32,16 @@ class HclassCheckInst; namespace ecmascript { -bool CompareAnyTypeGen(const CompareAnyTypeInst *cati, EncodeVisitor *enc_v); -bool CastAnyTypeValueGen(const CastAnyTypeValueInst *cati, EncodeVisitor *enc_v); -bool CastValueToAnyTypeGen(const CastValueToAnyTypeInst *cvai, EncodeVisitor *enc_v); -bool AnyTypeCheckGen(AnyTypeCheckInst *check_inst, EncodeVisitor *enc_v); -bool ObjByIndexCheckGen(const FixedInputsInst2 *check_inst, EncodeVisitor *enc_v, LabelHolder::LabelId id); -bool DynamicCallCheckGen(FixedInputsInst2 *check_inst, EncodeVisitor *enc_v); -bool LoadConstantPoolGen(const Inst *inst, EncodeVisitor *enc_v); -bool LoadLexicalEnvGen(const Inst *inst, EncodeVisitor *enc_v); -bool GetAnyTypeNameGen(const GetAnyTypeNameInst *inst, EncodeVisitor *enc_v); -bool HclassCheckGen(HclassCheckInst *check_inst, EncodeVisitor *enc_v); +bool CompareAnyTypeGen(const CompareAnyTypeInst *cati, EncodeVisitor *encV); +bool CastAnyTypeValueGen(const CastAnyTypeValueInst *cati, EncodeVisitor *encV); +bool CastValueToAnyTypeGen(const CastValueToAnyTypeInst *cvai, EncodeVisitor *encV); +bool AnyTypeCheckGen(AnyTypeCheckInst *checkInst, EncodeVisitor *encV); +bool ObjByIndexCheckGen(const FixedInputsInst2 *checkInst, EncodeVisitor *encV, LabelHolder::LabelId id); +bool DynamicCallCheckGen(FixedInputsInst2 *checkInst, EncodeVisitor *encV); +bool LoadConstantPoolGen(const Inst *inst, EncodeVisitor *encV); +bool LoadLexicalEnvGen(const Inst *inst, EncodeVisitor *encV); +bool GetAnyTypeNameGen(const GetAnyTypeNameInst *inst, EncodeVisitor *encV); +bool HclassCheckGen(HclassCheckInst *checkInst, EncodeVisitor *encV); bool IsDynHeapObject(AnyBaseType type); } // namespace ecmascript diff --git a/compiler/optimizer/ecma_pipeline.cpp b/compiler/optimizer/ecma_pipeline.cpp index fb539f85dc65ba0b6c960494bb1e2d0baa277597..897c022aadd6031d598ea8ccc57029b9d17d8168 100644 --- a/compiler/optimizer/ecma_pipeline.cpp +++ b/compiler/optimizer/ecma_pipeline.cpp @@ -78,7 +78,7 @@ bool EcmaPipeline::RunOptimizations() graph->RunPass(); graph->RunPass(false); graph->RunPass(); - graph->RunPass(OPTIONS.GetCompilerLicmHoistLimit()); + graph->RunPass(g_options.GetCompilerLicmHoistLimit()); graph->RunPass(); graph->RunPass(); graph->RunPass(); @@ -94,7 +94,7 @@ bool EcmaPipeline::RunOptimizations() graph->RunPass(); } graph->RunPass(); - graph->RunPass(OPTIONS.GetCompilerLoopUnrollInstLimit(), OPTIONS.GetCompilerLoopUnrollFactor()); + graph->RunPass(g_options.GetCompilerLoopUnrollInstLimit(), g_options.GetCompilerLoopUnrollFactor()); graph->RunPass(); if (graph->RunPass()) { graph->RunPass(); @@ -114,8 +114,8 @@ bool EcmaPipeline::RunOptimizations() graph->RunPass(); graph->RunPass(false); graph->RunPass(); - graph->RunPass(OPTIONS.IsCompilerMemoryCoalescingAligned()); - graph->RunPass(OPTIONS.GetCompilerIfConversionLimit()); + graph->RunPass(g_options.IsCompilerMemoryCoalescingAligned()); + graph->RunPass(g_options.GetCompilerIfConversionLimit()); graph->RunPass(); // Perform MoveConstants after Scheduler because Scheduler can rearrange constants // and cause spillfill in reg alloc diff --git a/compiler/optimizer/ir/dyn_datatype.h b/compiler/optimizer/ir/dyn_datatype.h index 245ac16f9eb62e55079a0723eeb54d6233ab538b..3bc21d0848c3812ce7d9f85bf84469890114f078 100644 --- a/compiler/optimizer/ir/dyn_datatype.h +++ b/compiler/optimizer/ir/dyn_datatype.h @@ -59,7 +59,7 @@ static inline panda::compiler::AnyBaseType GetAnyBigintType() // For two types (at least one of which is int or double) inclusion relation on // masks returned by this function is eqivalent to this relation on types -static inline uint8_t GetPossibleTypeMask(panda::compiler::AnyBaseType type, profiling::AnyInputType allowed_types) +static inline uint8_t GetPossibleTypeMask(panda::compiler::AnyBaseType type, profiling::AnyInputType allowedTypes) { enum Type : uint8_t { NONE = 0, @@ -83,18 +83,18 @@ static inline uint8_t GetPossibleTypeMask(panda::compiler::AnyBaseType type, pro case panda::compiler::AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE: return Type::UNDEFINED; case panda::compiler::AnyBaseType::ECMASCRIPT_INT_TYPE: - if ((allowed_types & profiling::AnyInputType::SPECIAL) != 0) { + if ((allowedTypes & profiling::AnyInputType::SPECIAL) != 0) { return Type::SPECIAL_INT; } return Type::INTEGER; case panda::compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE: - if ((allowed_types & profiling::AnyInputType::INTEGER) != 0) { - if ((allowed_types & profiling::AnyInputType::SPECIAL) != 0) { + if ((allowedTypes & profiling::AnyInputType::INTEGER) != 0) { + if ((allowedTypes & profiling::AnyInputType::SPECIAL) != 0) { return Type::SPECIAL_NUMBER; } return Type::NUMBER; } - if ((allowed_types & profiling::AnyInputType::SPECIAL) != 0) { + if ((allowedTypes & profiling::AnyInputType::SPECIAL) != 0) { return Type::SPECIAL_DOUBLE; } return Type::DOUBLE; @@ -103,16 +103,16 @@ static inline uint8_t GetPossibleTypeMask(panda::compiler::AnyBaseType type, pro } } -static inline std::optional IsAnyTypeCanBeSubtypeOf(panda::compiler::AnyBaseType super_type, +static inline std::optional IsAnyTypeCanBeSubtypeOf(panda::compiler::AnyBaseType superType, panda::compiler::AnyBaseType type, - [[maybe_unused]] profiling::AnyInputType super_allowed_types, - [[maybe_unused]] profiling::AnyInputType allowed_types) + [[maybe_unused]] profiling::AnyInputType superAllowedTypes, + [[maybe_unused]] profiling::AnyInputType allowedTypes) { - if (super_type == type) { - return (super_allowed_types & allowed_types) == allowed_types ? std::optional {true} : std::nullopt; + if (superType == type) { + return (superAllowedTypes & allowedTypes) == allowedTypes ? std::optional {true} : std::nullopt; } - switch (super_type) { + switch (superType) { case panda::compiler::AnyBaseType::ECMASCRIPT_OBJECT_TYPE: switch (type) { case panda::compiler::AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE: @@ -195,16 +195,16 @@ static inline std::optional IsAnyTypeCanBeSubtypeOf(panda::compiler::AnyBa if (type == panda::compiler::AnyBaseType::UNDEFINED_TYPE) { return std::nullopt; } - if (super_type == panda::compiler::AnyBaseType::ECMASCRIPT_INT_TYPE || - super_type == panda::compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE || + if (superType == panda::compiler::AnyBaseType::ECMASCRIPT_INT_TYPE || + superType == panda::compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE || type == panda::compiler::AnyBaseType::ECMASCRIPT_INT_TYPE || type == panda::compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE) { - auto possible_mask_super = GetPossibleTypeMask(super_type, super_allowed_types); - auto possible_mask = GetPossibleTypeMask(type, allowed_types); - if ((possible_mask_super & possible_mask) == possible_mask) { + auto possibleMaskSuper = GetPossibleTypeMask(superType, superAllowedTypes); + auto possibleMask = GetPossibleTypeMask(type, allowedTypes); + if ((possibleMaskSuper & possibleMask) == possibleMask) { return true; } - if ((possible_mask_super & possible_mask) != 0) { + if ((possibleMaskSuper & possibleMask) != 0) { return std::nullopt; } } diff --git a/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp b/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp index 414828ad3bee5ddcf61cc3b1c7716708cfc89b62..9184c165ce72e2f87b10a9c01d5c7cf702ef4abc 100644 --- a/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp +++ b/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp @@ -24,93 +24,93 @@ #include "optimizer/ir_builder/pbc_iterator.h" namespace panda::compiler { -void InstBuilder::FinalizeEcmaFnCall(SaveStateInst *save_state, CallInst *call_inst) +void InstBuilder::FinalizeEcmaFnCall(SaveStateInst *saveState, CallInst *callInst) { - call_inst->AppendInput(save_state); - call_inst->AddInputType(DataType::NO_TYPE); - AddInstruction(call_inst); - UpdateDefinitionAcc(call_inst); + callInst->AppendInput(saveState); + callInst->AddInputType(DataType::NO_TYPE); + AddInstruction(callInst); + UpdateDefinitionAcc(callInst); } // NOLINTNEXTLINE(misc-definitions-in-headers) -void InstBuilder::BuildEcmaFnCall(const BytecodeInstruction *bc_inst, bool is_range, bool call_this, uint64_t num_args) +void InstBuilder::BuildEcmaFnCall(const BytecodeInstruction *bcInst, bool isRange, bool callThis, uint64_t numArgs) { - auto bc_pc = GetPc(bc_inst->GetAddress()); - auto save_state = CreateSaveState(Opcode::SaveState, bc_pc); - AddInstruction(save_state); + auto bcPc = GetPc(bcInst->GetAddress()); + auto saveState = CreateSaveState(Opcode::SaveState, bcPc); + AddInstruction(saveState); Inst *callee {}; - switch (bc_inst->GetOpcode()) { + switch (bcInst->GetOpcode()) { case BytecodeInstruction::Opcode::ECMA_CALL0DYN_PREF_NONE_PROF16: { callee = GetDefinitionAcc(); break; } default: { - callee = GetDefinition(bc_inst->GetVReg(0)); + callee = GetDefinition(bcInst->GetVReg(0)); break; } } // Check callee is heap object - auto type_check = BuildAnyTypeCheckInst(bc_pc, callee, save_state, AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE); - callee = type_check; + auto typeCheck = BuildAnyTypeCheckInst(bcPc, callee, saveState, AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE); + callee = typeCheck; { // Load class (it is movable object in js) - auto load_class = GetGraph()->CreateInstLoadObject( - DataType::REFERENCE, bc_pc, callee, TypeIdMixin::MEM_DYN_CLASS_ID, GetGraph()->GetMethod(), nullptr); - load_class->SetObjectType(ObjectType::MEM_DYN_CLASS); - AddInstruction(load_class); + auto loadClass = GetGraph()->CreateInstLoadObject( + DataType::REFERENCE, bcPc, callee, TypeIdMixin::MEM_DYN_CLASS_ID, GetGraph()->GetMethod(), nullptr); + loadClass->SetObjectType(ObjectType::MEM_DYN_CLASS); + AddInstruction(loadClass); // Load Jshclass - auto load_hclass = GetGraph()->CreateInstLoadObject( - DataType::REFERENCE, bc_pc, load_class, TypeIdMixin::MEM_DYN_HCLASS_ID, GetGraph()->GetMethod(), nullptr); - load_hclass->SetObjectType(ObjectType::MEM_DYN_HCLASS); - AddInstruction(load_hclass); - - auto hclass_check = GetGraph()->CreateInstHclassCheck(DataType::NO_TYPE, bc_pc, load_hclass, save_state); - hclass_check->SetCheckIsFunction(true); - hclass_check->SetCheckFunctionIsNotClassConstructor(true); - AddInstruction(hclass_check); + auto loadHclass = GetGraph()->CreateInstLoadObject( + DataType::REFERENCE, bcPc, loadClass, TypeIdMixin::MEM_DYN_HCLASS_ID, GetGraph()->GetMethod(), nullptr); + loadHclass->SetObjectType(ObjectType::MEM_DYN_HCLASS); + AddInstruction(loadHclass); + + auto hclassCheck = GetGraph()->CreateInstHclassCheck(DataType::NO_TYPE, bcPc, loadHclass, saveState); + hclassCheck->SetCheckIsFunction(true); + hclassCheck->SetCheckFunctionIsNotClassConstructor(true); + AddInstruction(hclassCheck); } - auto call_inst = GetGraph()->CreateInstCallDynamic(DataType::ANY, bc_pc); - call_inst->SetCanNativeException(true); + auto callInst = GetGraph()->CreateInstCallDynamic(DataType::ANY, bcPc); + callInst->SetCanNativeException(true); // func, new_target, this?, args..., ss - uint64_t args_count = 2U + (call_this ? 0 : 1) + (is_range ? bc_inst->GetImm64() : num_args) + 1U; - call_inst->ReserveInputs(args_count); - call_inst->AllocateInputTypes(GetGraph()->GetAllocator(), args_count); + uint64_t argsCount = 2U + (callThis ? 0 : 1) + (isRange ? bcInst->GetImm64() : numArgs) + 1U; + callInst->ReserveInputs(argsCount); + callInst->AllocateInputTypes(GetGraph()->GetAllocator(), argsCount); // Append func, new_target, this - call_inst->AppendInput(callee); - call_inst->AddInputType(DataType::ANY); - call_inst->AppendInput(FindOrCreateAnyConstant(DataType::Any(coretypes::TaggedValue::VALUE_UNDEFINED))); - call_inst->AddInputType(DataType::ANY); - - if (!call_this) { // Assume strict mode - call_inst->AppendInput(FindOrCreateAnyConstant(DataType::Any(coretypes::TaggedValue::VALUE_UNDEFINED))); - call_inst->AddInputType(DataType::ANY); + callInst->AppendInput(callee); + callInst->AddInputType(DataType::ANY); + callInst->AppendInput(FindOrCreateAnyConstant(DataType::Any(coretypes::TaggedValue::VALUE_UNDEFINED))); + callInst->AddInputType(DataType::ANY); + + if (!callThis) { // Assume strict mode + callInst->AppendInput(FindOrCreateAnyConstant(DataType::Any(coretypes::TaggedValue::VALUE_UNDEFINED))); + callInst->AddInputType(DataType::ANY); } else { - num_args++; + numArgs++; } - switch (bc_inst->GetOpcode()) { + switch (bcInst->GetOpcode()) { case BytecodeInstruction::Opcode::ECMA_CALL0DYN_PREF_NONE_PROF16: { - FinalizeEcmaFnCall(save_state, call_inst); + FinalizeEcmaFnCall(saveState, callInst); return; } case BytecodeInstruction::Opcode::ECMA_CALLIRANGEDYN_PREF_IMM16_V8_PROF16: case BytecodeInstruction::Opcode::ECMA_CALLITHISRANGEDYN_PREF_IMM16_V8_PROF16: { - auto range_start = bc_inst->GetVReg(0) + 1; - auto range_size = bc_inst->GetImm64(); + auto rangeStart = bcInst->GetVReg(0) + 1; + auto rangeSize = bcInst->GetImm64(); - for (int64_t i = 0; i < range_size; ++i) { - call_inst->AppendInput(GetDefinition(range_start + i)); - call_inst->AddInputType(DataType::ANY); + for (int64_t i = 0; i < rangeSize; ++i) { + callInst->AppendInput(GetDefinition(rangeStart + i)); + callInst->AddInputType(DataType::ANY); } - FinalizeEcmaFnCall(save_state, call_inst); + FinalizeEcmaFnCall(saveState, callInst); return; } default: { @@ -118,54 +118,54 @@ void InstBuilder::BuildEcmaFnCall(const BytecodeInstruction *bc_inst, bool is_ra } } - for (uint64_t i = 1; i < num_args; ++i) { - call_inst->AppendInput(GetDefinition(bc_inst->GetVReg(i))); - call_inst->AddInputType(DataType::ANY); + for (uint64_t i = 1; i < numArgs; ++i) { + callInst->AppendInput(GetDefinition(bcInst->GetVReg(i))); + callInst->AddInputType(DataType::ANY); } - call_inst->AppendInput(GetDefinitionAcc()); - call_inst->AddInputType(DataType::ANY); + callInst->AppendInput(GetDefinitionAcc()); + callInst->AddInputType(DataType::ANY); - FinalizeEcmaFnCall(save_state, call_inst); + FinalizeEcmaFnCall(saveState, callInst); } -void InstBuilder::BuildEcmaNewobjdynrange(const BytecodeInstruction *bc_inst) +void InstBuilder::BuildEcmaNewobjdynrange(const BytecodeInstruction *bcInst) { auto graph = GetGraph(); - auto bc_pc = GetPc(bc_inst->GetAddress()); - auto start_reg = bc_inst->GetVReg(0); + auto bcPc = GetPc(bcInst->GetAddress()); + auto startReg = bcInst->GetVReg(0); - auto inst = graph->CreateInstIntrinsic(DataType::ANY, bc_pc, + auto inst = graph->CreateInstIntrinsic(DataType::ANY, bcPc, RuntimeInterface::IntrinsicId::INTRINSIC_NEWOBJ_DYNRANGE_HANDLED); AdjustFlags(inst->GetIntrinsicId(), inst); inst->SetFlag(inst_flags::CAN_THROW); - auto save_state = CreateSaveState(Opcode::SaveState, bc_pc); - AddInstruction(save_state); + auto saveState = CreateSaveState(Opcode::SaveState, bcPc); + AddInstruction(saveState); uint32_t constexpr FIXED_INPUTS = 2U; - auto args_count = bc_inst->GetImm64(); - inst->ReserveInputs(args_count + FIXED_INPUTS); - inst->AllocateInputTypes(graph->GetAllocator(), args_count + FIXED_INPUTS); + auto argsCount = bcInst->GetImm64(); + inst->ReserveInputs(argsCount + FIXED_INPUTS); + inst->AllocateInputTypes(graph->GetAllocator(), argsCount + FIXED_INPUTS); - inst->AppendInput(FindOrCreateConstant(args_count - 2)); + inst->AppendInput(FindOrCreateConstant(argsCount - 2)); inst->AddInputType(DataType::UINT16); - for (int64_t i = 0; i < args_count; ++i) { - inst->AppendInput(GetDefinition(start_reg + i)); + for (int64_t i = 0; i < argsCount; ++i) { + inst->AppendInput(GetDefinition(startReg + i)); inst->AddInputType(DataType::ANY); } - inst->AppendInput(save_state); + inst->AppendInput(saveState); inst->AddInputType(DataType::NO_TYPE); inst->SetFlag(inst_flags::ACC_WRITE); AddInstruction(inst); UpdateDefinitionAcc(inst); } -void InstBuilder::BuildEcmaGetunmappedargs(const BytecodeInstruction *bc_inst) +void InstBuilder::BuildEcmaGetunmappedargs(const BytecodeInstruction *bcInst) { // NOTE(pishin) support for inlined graph - if (caller_inst_ != nullptr) { + if (callerInst_ != nullptr) { failed_ = true; return; } @@ -185,33 +185,33 @@ void InstBuilder::BuildEcmaGetunmappedargs(const BytecodeInstruction *bc_inst) failed_ = true; return; } - auto curr_inst = bb->GetLastInst(); - while (curr_inst != nullptr) { - if (curr_inst->IsSaveState()) { + auto currInst = bb->GetLastInst(); + while (currInst != nullptr) { + if (currInst->IsSaveState()) { failed_ = true; return; } - curr_inst = curr_inst->GetPrev(); + currInst = currInst->GetPrev(); } - auto bc_pc = GetPc(bc_inst->GetAddress()); + auto bcPc = GetPc(bcInst->GetAddress()); auto inst = - graph->CreateInstIntrinsic(DataType::ANY, bc_pc, RuntimeInterface::IntrinsicId::INTRINSIC_GET_UNMAPPED_ARGS); + graph->CreateInstIntrinsic(DataType::ANY, bcPc, RuntimeInterface::IntrinsicId::INTRINSIC_GET_UNMAPPED_ARGS); AdjustFlags(inst->GetIntrinsicId(), inst); inst->SetFlag(inst_flags::CAN_THROW); - auto save_state = CreateSaveState(Opcode::SaveState, bc_pc); - AddInstruction(save_state); + auto saveState = CreateSaveState(Opcode::SaveState, bcPc); + AddInstruction(saveState); // first input is actual num args, second save state uint32_t constexpr FIXED_INPUTS = 2U; inst->ReserveInputs(FIXED_INPUTS); inst->AllocateInputTypes(graph->GetAllocator(), FIXED_INPUTS); - auto num_args_inst = graph->FindParameter(ParameterInst::DYNAMIC_NUM_ARGS); - ASSERT(num_args_inst != nullptr); - inst->AppendInput(num_args_inst); + auto numArgsInst = graph->FindParameter(ParameterInst::DYNAMIC_NUM_ARGS); + ASSERT(numArgsInst != nullptr); + inst->AppendInput(numArgsInst); inst->AddInputType(DataType::UINT32); - inst->AppendInput(save_state); + inst->AppendInput(saveState); inst->AddInputType(DataType::NO_TYPE); inst->SetFlag(inst_flags::ACC_WRITE); AddInstruction(inst); @@ -225,105 +225,105 @@ void InstBuilder::BuildEcmaGetunmappedargs(const BytecodeInstruction *bc_inst) namespace panda::compiler { template -void InstBuilder::BuildStGlobalVar(const BytecodeInstruction *bc_inst, size_t type_id) +void InstBuilder::BuildStGlobalVar(const BytecodeInstruction *bcInst, size_t typeId) { - auto pc = GetPc(bc_inst->GetAddress()); - auto save_state = CreateSaveState(Opcode::SaveState, pc); - auto get_address = graph_->CreateInstGetGlobalVarAddress(DataType::REFERENCE, pc, GetEnvDefinition(CONST_POOL_IDX), - save_state, type_id, GetGraph()->GetMethod(), 0); + auto pc = GetPc(bcInst->GetAddress()); + auto saveState = CreateSaveState(Opcode::SaveState, pc); + auto getAddress = graph_->CreateInstGetGlobalVarAddress(DataType::REFERENCE, pc, GetEnvDefinition(CONST_POOL_IDX), + saveState, typeId, GetGraph()->GetMethod(), 0); - auto store_object = - graph_->CreateInstStoreObject(DataType::ANY, pc, get_address, nullptr, TypeIdMixin::MEM_DYN_GLOBAL_ID, + auto storeObject = + graph_->CreateInstStoreObject(DataType::ANY, pc, getAddress, nullptr, TypeIdMixin::MEM_DYN_GLOBAL_ID, GetGraph()->GetMethod(), nullptr, false, true); - store_object->SetObjectType(ObjectType::MEM_DYN_GLOBAL); - Inst *store_val = nullptr; + storeObject->SetObjectType(ObjectType::MEM_DYN_GLOBAL); + Inst *storeVal = nullptr; if constexpr (IS_ACC_READ) { - store_val = GetDefinitionAcc(); + storeVal = GetDefinitionAcc(); } else { - store_val = GetDefinition(bc_inst->GetVReg(0)); + storeVal = GetDefinition(bcInst->GetVReg(0)); } - store_object->SetInput(1, store_val); - AddInstruction(save_state); - AddInstruction(get_address); - AddInstruction(store_object); + storeObject->SetInput(1, storeVal); + AddInstruction(saveState); + AddInstruction(getAddress); + AddInstruction(storeObject); } template -void InstBuilder::BuildLdGlobalVar(const BytecodeInstruction *bc_inst, size_t type_id) +void InstBuilder::BuildLdGlobalVar(const BytecodeInstruction *bcInst, size_t typeId) { - auto pc = GetPc(bc_inst->GetAddress()); - auto save_state = CreateSaveState(Opcode::SaveState, pc); - auto get_address = graph_->CreateInstGetGlobalVarAddress(DataType::REFERENCE, pc, GetEnvDefinition(CONST_POOL_IDX), - save_state, type_id, GetGraph()->GetMethod(), 0); - - auto load_object = graph_->CreateInstLoadObject(DataType::ANY, pc, get_address, TypeIdMixin::MEM_DYN_GLOBAL_ID, - GetGraph()->GetMethod(), nullptr); - load_object->SetObjectType(ObjectType::MEM_DYN_GLOBAL); - AddInstruction(save_state); - AddInstruction(get_address); - AddInstruction(load_object); + auto pc = GetPc(bcInst->GetAddress()); + auto saveState = CreateSaveState(Opcode::SaveState, pc); + auto getAddress = graph_->CreateInstGetGlobalVarAddress(DataType::REFERENCE, pc, GetEnvDefinition(CONST_POOL_IDX), + saveState, typeId, GetGraph()->GetMethod(), 0); + + auto loadObject = graph_->CreateInstLoadObject(DataType::ANY, pc, getAddress, TypeIdMixin::MEM_DYN_GLOBAL_ID, + GetGraph()->GetMethod(), nullptr); + loadObject->SetObjectType(ObjectType::MEM_DYN_GLOBAL); + AddInstruction(saveState); + AddInstruction(getAddress); + AddInstruction(loadObject); if constexpr (IS_ACC_WRITE) { - UpdateDefinitionAcc(load_object); + UpdateDefinitionAcc(loadObject); } else { - UpdateDefinition(bc_inst->GetVReg(0), load_object); + UpdateDefinition(bcInst->GetVReg(0), loadObject); } } -void InstBuilder::BuildStObjByIndex(const BytecodeInstruction *bc_inst, uint64_t imm) +void InstBuilder::BuildStObjByIndex(const BytecodeInstruction *bcInst, uint64_t imm) { - auto pc = GetPc(bc_inst->GetAddress()); - if (GetRuntime()->CanInlineLdStObjByIndex(bc_inst, pc, method_profile_)) { - BuildLdStObjByIndex(bc_inst, GetDefinition(bc_inst->GetVReg(0)), imm, GetDefinitionAcc()); + auto pc = GetPc(bcInst->GetAddress()); + if (GetRuntime()->CanInlineLdStObjByIndex(bcInst, pc, methodProfile_)) { + BuildLdStObjByIndex(bcInst, GetDefinition(bcInst->GetVReg(0)), imm, GetDefinitionAcc()); } else { - BuildEcma(bc_inst); + BuildEcma(bcInst); } } -void InstBuilder::BuildLdObjByIndex(const BytecodeInstruction *bc_inst, uint64_t imm) +void InstBuilder::BuildLdObjByIndex(const BytecodeInstruction *bcInst, uint64_t imm) { - auto pc = GetPc(bc_inst->GetAddress()); - if (GetRuntime()->CanInlineLdStObjByIndex(bc_inst, pc, method_profile_)) { - BuildLdStObjByIndex(bc_inst, GetDefinitionAcc(), imm, nullptr); + auto pc = GetPc(bcInst->GetAddress()); + if (GetRuntime()->CanInlineLdStObjByIndex(bcInst, pc, methodProfile_)) { + BuildLdStObjByIndex(bcInst, GetDefinitionAcc(), imm, nullptr); } else { - BuildEcma(bc_inst); + BuildEcma(bcInst); } } -void InstBuilder::BuildLdStObjByIndex(const BytecodeInstruction *bc_inst, Inst *obj_inst, uint64_t imm, Inst *store_def) +void InstBuilder::BuildLdStObjByIndex(const BytecodeInstruction *bcInst, Inst *objInst, uint64_t imm, Inst *storeDef) { - auto pc = GetPc(bc_inst->GetAddress()); - auto check_obj = graph_->CreateInstObjByIndexCheck(DataType::ANY, pc, obj_inst, nullptr); + auto pc = GetPc(bcInst->GetAddress()); + auto checkObj = graph_->CreateInstObjByIndexCheck(DataType::ANY, pc, objInst, nullptr); - auto load_object = graph_->CreateInstLoadObject(DataType::REFERENCE, pc, check_obj, - TypeIdMixin::MEM_DYN_ELEMENTS_ID, GetGraph()->GetMethod(), nullptr); - load_object->SetObjectType(ObjectType::MEM_DYN_ELEMENTS); + auto loadObject = graph_->CreateInstLoadObject(DataType::REFERENCE, pc, checkObj, TypeIdMixin::MEM_DYN_ELEMENTS_ID, + GetGraph()->GetMethod(), nullptr); + loadObject->SetObjectType(ObjectType::MEM_DYN_ELEMENTS); - Inst *save_state = nullptr; - Inst *null_check = nullptr; - Inst *array_length = nullptr; - Inst *bounds_check = nullptr; - BuildChecksBeforeArray(pc, load_object, &save_state, &null_check, &array_length, &bounds_check, false); - ASSERT(save_state != nullptr && null_check == load_object && array_length != nullptr && bounds_check != nullptr); + Inst *saveState = nullptr; + Inst *nullCheck = nullptr; + Inst *arrayLength = nullptr; + Inst *boundsCheck = nullptr; + BuildChecksBeforeArray(pc, loadObject, &saveState, &nullCheck, &arrayLength, &boundsCheck, false); + ASSERT(saveState != nullptr && nullCheck == loadObject && arrayLength != nullptr && boundsCheck != nullptr); - check_obj->SetInput(1, save_state); + checkObj->SetInput(1, saveState); // Create instruction - auto inst = graph_->CreateInstLoadArray(DataType::ANY, pc, null_check, bounds_check); - bounds_check->SetInput(1, FindOrCreateConstant(imm)); - bounds_check->SetFlag(inst_flags::CAN_DEOPTIMIZE); + auto inst = graph_->CreateInstLoadArray(DataType::ANY, pc, nullCheck, boundsCheck); + boundsCheck->SetInput(1, FindOrCreateConstant(imm)); + boundsCheck->SetFlag(inst_flags::CAN_DEOPTIMIZE); - auto cmp_inst = graph_->CreateInstCompare( + auto cmpInst = graph_->CreateInstCompare( DataType::BOOL, pc, inst, graph_->FindOrCreateConstant(DataType::Any(panda::coretypes::TaggedValue::VALUE_HOLE)), DataType::ANY, ConditionCode::CC_EQ); - auto deopt_inst = graph_->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmp_inst, save_state, DeoptimizeType::HOLE); + auto deoptInst = graph_->CreateInstDeoptimizeIf(DataType::NO_TYPE, pc, cmpInst, saveState, DeoptimizeType::HOLE); - AddInstruction(save_state, check_obj, load_object, array_length, bounds_check, inst, cmp_inst, deopt_inst); + AddInstruction(saveState, checkObj, loadObject, arrayLength, boundsCheck, inst, cmpInst, deoptInst); - if (store_def != nullptr) { - auto store = graph_->CreateInstStoreArray(DataType::ANY, pc, load_object, bounds_check, store_def, true); + if (storeDef != nullptr) { + auto store = graph_->CreateInstStoreArray(DataType::ANY, pc, loadObject, boundsCheck, storeDef, true); AddInstruction(store); } else { UpdateDefinitionAcc(inst); diff --git a/compiler/optimizer/ir_builder/ecmascript_inst_builder.h b/compiler/optimizer/ir_builder/ecmascript_inst_builder.h index a3739bb776f0c7a3ae5be1846d85365026998354..bc93499050b9828b907fa99dcf6005aba9353fa3 100644 --- a/compiler/optimizer/ir_builder/ecmascript_inst_builder.h +++ b/compiler/optimizer/ir_builder/ecmascript_inst_builder.h @@ -16,23 +16,23 @@ #ifndef PLUGINS_ECMASCRIPT_COMPILER_OPTIMIZER_IR_BUILDER_ECMASCRIPT_INST_BUILDER_H #define PLUGINS_ECMASCRIPT_COMPILER_OPTIMIZER_IR_BUILDER_ECMASCRIPT_INST_BUILDER_H -void BuildEcma([[maybe_unused]] const BytecodeInstruction *bc_inst); +void BuildEcma([[maybe_unused]] const BytecodeInstruction *bcInst); template -void BuildEcmaAsIntrinsics([[maybe_unused]] const BytecodeInstruction *bc_inst); -void BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction *bc_inst); +void BuildEcmaAsIntrinsics([[maybe_unused]] const BytecodeInstruction *bcInst); +void BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction *bcInst); template -void BuildStGlobalVar(const BytecodeInstruction *bc_inst, size_t type_id); +void BuildStGlobalVar(const BytecodeInstruction *bcInst, size_t typeId); template -void BuildLdGlobalVar(const BytecodeInstruction *bc_inst, size_t type_id); +void BuildLdGlobalVar(const BytecodeInstruction *bcInst, size_t typeId); -void BuildStObjByIndex(const BytecodeInstruction *bc_inst, uint64_t imm); -void BuildLdObjByIndex(const BytecodeInstruction *bc_inst, uint64_t imm); +void BuildStObjByIndex(const BytecodeInstruction *bcInst, uint64_t imm); +void BuildLdObjByIndex(const BytecodeInstruction *bcInst, uint64_t imm); -void BuildLdStObjByIndex(const BytecodeInstruction *bc_inst, Inst *obj_inst, uint64_t imm, Inst *store_def); -void BuildEcmaFnCall(const BytecodeInstruction *bc_inst, bool is_range, bool call_this, uint64_t num_args = 0); -void FinalizeEcmaFnCall(SaveStateInst *save_state, CallInst *call_inst); +void BuildLdStObjByIndex(const BytecodeInstruction *bcInst, Inst *objInst, uint64_t imm, Inst *storeDef); +void BuildEcmaFnCall(const BytecodeInstruction *bcInst, bool isRange, bool callThis, uint64_t numArgs = 0); +void FinalizeEcmaFnCall(SaveStateInst *saveState, CallInst *callInst); -void BuildEcmaNewobjdynrange(const BytecodeInstruction *bc_inst); -void BuildEcmaGetunmappedargs(const BytecodeInstruction *bc_inst); +void BuildEcmaNewobjdynrange(const BytecodeInstruction *bcInst); +void BuildEcmaGetunmappedargs(const BytecodeInstruction *bcInst); #endif // PLUGINS_ECMASCRIPT_COMPILER_OPTIMIZER_IR_BUILDER_ECMASCRIPT_INST_BUILDER_H diff --git a/compiler/optimizer/optimizations/ecma_inlining.cpp b/compiler/optimizer/optimizations/ecma_inlining.cpp index 1f892fc78657d1acededd4048b346706fb39c363..3ce6cfa0a56dae95dd14ec9155fd77b7b032ea42 100644 --- a/compiler/optimizer/optimizations/ecma_inlining.cpp +++ b/compiler/optimizer/optimizations/ecma_inlining.cpp @@ -25,11 +25,11 @@ namespace panda::compiler::ecmascript { -EcmaInlining::EcmaInlining(Graph *graph, uint32_t instructions_count, uint32_t inline_depth, uint32_t methods_inlined) - : Inlining(graph, instructions_count, inline_depth, methods_inlined), - js_functions_(graph->GetLocalAllocator()->Adapter()) +EcmaInlining::EcmaInlining(Graph *graph, uint32_t instructionsCount, uint32_t inlineDepth, uint32_t methodsInlined) + : Inlining(graph, instructionsCount, inlineDepth, methodsInlined), + jsFunctions_(graph->GetLocalAllocator()->Adapter()) { - instructions_limit_ = OPTIONS.GetCompilerEcmaInliningMaxInsts(); + instructionsLimit_ = g_options.GetCompilerEcmaInliningMaxInsts(); } void EcmaInlining::RunOptimizations() const @@ -52,15 +52,15 @@ bool EcmaInlining::IsInstSuitableForInline(Inst *inst) const return inst->GetOpcode() == Opcode::CallDynamic; } -bool EcmaInlining::ResolveTargets(CallInst *call_inst) +bool EcmaInlining::ResolveTargets(CallInst *callInst) { - ASSERT(js_functions_.empty()); + ASSERT(jsFunctions_.empty()); auto runtime = GetGraph()->GetRuntime(); auto kind = - runtime->GetCallProfile(GetGraph()->GetMethod(), call_inst->GetPc(), &js_functions_, GetGraph()->IsAotMode()); + runtime->GetCallProfile(GetGraph()->GetMethod(), callInst->GetPc(), &jsFunctions_, GetGraph()->IsAotMode()); if (kind == profiling::CallKind::MEGAMORPHIC || kind == profiling::CallKind::UNKNOWN) { LOG_INLINING(DEBUG) << "Call have " << CallKindToString(kind) << " type"; - EVENT_INLINE(runtime->GetMethodFullName(GetGraph()->GetMethod()), "-", call_inst->GetId(), + EVENT_INLINE(runtime->GetMethodFullName(GetGraph()->GetMethod()), "-", callInst->GetId(), events::InlineKind::DYNAMIC_POLYMORPHIC, kind == profiling::CallKind::MEGAMORPHIC ? events::InlineResult::FAIL_MEGAMORPHIC : events::InlineResult::FAIL_RESOLVE); @@ -69,12 +69,12 @@ bool EcmaInlining::ResolveTargets(CallInst *call_inst) return true; } -bool EcmaInlining::IsInstSuitableForEcmaStaticInlining(Inst *define_func) const +bool EcmaInlining::IsInstSuitableForEcmaStaticInlining(Inst *defineFunc) const { - if (define_func->GetOpcode() != Opcode::Intrinsic) { + if (defineFunc->GetOpcode() != Opcode::Intrinsic) { return false; } - switch (define_func->CastToIntrinsic()->GetIntrinsicId()) { + switch (defineFunc->CastToIntrinsic()->GetIntrinsicId()) { case RuntimeInterface::IntrinsicId::INTRINSIC_DEFINEFUNC_DYN: case RuntimeInterface::IntrinsicId::INTRINSIC_DEFINE_NC_FUNC_DYN: case RuntimeInterface::IntrinsicId::INTRINSIC_DEFINE_METHOD: @@ -84,148 +84,147 @@ bool EcmaInlining::IsInstSuitableForEcmaStaticInlining(Inst *define_func) const } } -RuntimeInterface::MethodPtr EcmaInlining::TryResolveTargetStatic(CallInst *call_inst) const +RuntimeInterface::MethodPtr EcmaInlining::TryResolveTargetStatic(CallInst *callInst) const { - auto define_func = call_inst->GetDataFlowInput(0); - if (IsInstSuitableForEcmaStaticInlining(define_func)) { - auto load_from_cp = define_func->CastToIntrinsic()->GetInput(0).GetInst()->CastToLoadFromConstantPool(); + auto defineFunc = callInst->GetDataFlowInput(0); + if (IsInstSuitableForEcmaStaticInlining(defineFunc)) { + auto loadFromCp = defineFunc->CastToIntrinsic()->GetInput(0).GetInst()->CastToLoadFromConstantPool(); return GetGraph()->GetRuntime()->GetMethodByIdAndSaveJsFunction(GetGraph()->GetMethod(), - load_from_cp->GetTypeId()); + loadFromCp->GetTypeId()); } return nullptr; } -bool EcmaInlining::CheckMethod(CallInst *call_inst, InlineContext *ctx) +bool EcmaInlining::CheckMethod(CallInst *callInst, InlineContext *ctx) { - if (!CheckMethodCanBeInlined(call_inst, ctx)) { + if (!CheckMethodCanBeInlined(callInst, ctx)) { return false; } - if (!CheckBytecode(call_inst, *ctx, nullptr)) { + if (!CheckBytecode(callInst, *ctx, nullptr)) { return false; } return true; } -Graph *EcmaInlining::BuildGraph(InlineContext *ctx, CallInst *call_inst, CallInst *new_call_inst) +Graph *EcmaInlining::BuildGraph(InlineContext *ctx, CallInst *callInst, CallInst *newCallInst) { - auto graph_inl = GetGraph()->CreateChildGraph(ctx->method); + auto graphInl = GetGraph()->CreateChildGraph(ctx->method); // Propagate instruction id counter to inlined graph, thereby avoid instructions id duplication - graph_inl->SetCurrentInstructionId(GetGraph()->GetCurrentInstructionId()); - graph_inl->SetMaxInliningDepth(depth_); + graphInl->SetCurrentInstructionId(GetGraph()->GetCurrentInstructionId()); + graphInl->SetMaxInliningDepth(depth_); auto stats = GetGraph()->GetPassManager()->GetStatistics(); - auto saved_pbc_inst_num = stats->GetPbcInstNum(); - if (!TryBuildGraph(*ctx, graph_inl, call_inst, new_call_inst)) { - stats->SetPbcInstNum(saved_pbc_inst_num); + auto savedPbcInstNum = stats->GetPbcInstNum(); + if (!TryBuildGraph(*ctx, graphInl, callInst, newCallInst)) { + stats->SetPbcInstNum(savedPbcInstNum); return nullptr; } // Run basic optimizations - graph_inl->RunPass(); - graph_inl->RunPass(false); - if (graph_inl->RunPass()) { - graph_inl->RunPass(); - graph_inl->RunPass(); + graphInl->RunPass(); + graphInl->RunPass(false); + if (graphInl->RunPass()) { + graphInl->RunPass(); + graphInl->RunPass(); } // Don't inline if we reach the limit of instructions and method is big enough. - auto inlined_insts_count = CalculateInstructionsCount(graph_inl); - if (!CheckInstructionLimit(call_inst, ctx, inlined_insts_count)) { - stats->SetPbcInstNum(saved_pbc_inst_num); + auto inlinedInstsCount = CalculateInstructionsCount(graphInl); + if (!CheckInstructionLimit(callInst, ctx, inlinedInstsCount)) { + stats->SetPbcInstNum(savedPbcInstNum); [[maybe_unused]] auto runtime = GetGraph()->GetRuntime(); EVENT_INLINE(runtime->GetMethodFullName(GetGraph()->GetMethod()), runtime->GetMethodFullName(ctx->method), - call_inst->GetId(), events::InlineKind::DYNAMIC_MONOMORPHIC, events::InlineResult::LIMIT); + callInst->GetId(), events::InlineKind::DYNAMIC_MONOMORPHIC, events::InlineResult::LIMIT); LOG_INLINING(DEBUG) << "Reach the limit of instructions and method is big enough."; return nullptr; } - if ((depth_ + 1) < OPTIONS.GetCompilerInliningMaxDepth()) { - graph_inl->RunPass(instructions_count_ + inlined_insts_count, depth_ + 1, methods_inlined_ + 1); + if ((depth_ + 1) < g_options.GetCompilerInliningMaxDepth()) { + graphInl->RunPass(instructionsCount_ + inlinedInstsCount, depth_ + 1, methodsInlined_ + 1); } - instructions_count_ += CalculateInstructionsCount(graph_inl); - GetGraph()->SetMaxMarkerIdx(graph_inl->GetCurrentMarkerIdx()); - GetGraph()->SetCurrentInstructionId(graph_inl->GetCurrentInstructionId()); - GetGraph()->SetMaxInliningDepth(graph_inl->GetMaxInliningDepth() + 1); - return graph_inl; + instructionsCount_ += CalculateInstructionsCount(graphInl); + GetGraph()->SetMaxMarkerIdx(graphInl->GetCurrentMarkerIdx()); + GetGraph()->SetCurrentInstructionId(graphInl->GetCurrentInstructionId()); + GetGraph()->SetMaxInliningDepth(graphInl->GetMaxInliningDepth() + 1); + return graphInl; } -void EcmaInlining::BuildGuard(CallInst *call_inst, RuntimeInterface::MethodPtr method_ptr) +void EcmaInlining::BuildGuard(CallInst *callInst, RuntimeInterface::MethodPtr methodPtr) { - auto graph = call_inst->GetBasicBlock()->GetGraph(); - auto method_cnst = graph->CreateInstLoadImmediate(DataType::POINTER, call_inst->GetPc(), method_ptr, - LoadImmediateInst::ObjectType::METHOD); - auto load_method = - graph->CreateInstLoadObject(DataType::POINTER, call_inst->GetPc(), call_inst->GetInput(0).GetInst(), - TypeIdMixin::MEM_DYN_METHOD_ID, nullptr, nullptr); - load_method->SetObjectType(ObjectType::MEM_DYN_METHOD); - auto cmp_inst = graph->CreateInstCompare(DataType::BOOL, call_inst->GetPc(), load_method, method_cnst, - DataType::POINTER, ConditionCode::CC_NE); - auto deopt_inst = graph->CreateInstDeoptimizeIf(DataType::BOOL, call_inst->GetPc(), cmp_inst, - call_inst->GetSaveState(), DeoptimizeType::INLINE_DYN); - call_inst->InsertBefore(method_cnst); - call_inst->InsertBefore(load_method); - call_inst->InsertBefore(cmp_inst); - call_inst->InsertBefore(deopt_inst); + auto graph = callInst->GetBasicBlock()->GetGraph(); + auto methodCnst = graph->CreateInstLoadImmediate(DataType::POINTER, callInst->GetPc(), methodPtr, + LoadImmediateInst::ObjectType::METHOD); + auto loadMethod = graph->CreateInstLoadObject(DataType::POINTER, callInst->GetPc(), callInst->GetInput(0).GetInst(), + TypeIdMixin::MEM_DYN_METHOD_ID, nullptr, nullptr); + loadMethod->SetObjectType(ObjectType::MEM_DYN_METHOD); + auto cmpInst = graph->CreateInstCompare(DataType::BOOL, callInst->GetPc(), loadMethod, methodCnst, + DataType::POINTER, ConditionCode::CC_NE); + auto deoptInst = graph->CreateInstDeoptimizeIf(DataType::BOOL, callInst->GetPc(), cmpInst, callInst->GetSaveState(), + DeoptimizeType::INLINE_DYN); + callInst->InsertBefore(methodCnst); + callInst->InsertBefore(loadMethod); + callInst->InsertBefore(cmpInst); + callInst->InsertBefore(deoptInst); } -void EcmaInlining::InsertGraph(CallInst *call_inst, const InlineContext &ctx, Graph *graph_inl) +void EcmaInlining::InsertGraph(CallInst *callInst, const InlineContext &ctx, Graph *graphInl) { if (!IsStaticInlining()) { - BuildGuard(call_inst, ctx.method); + BuildGuard(callInst, ctx.method); } - auto call_bb = call_inst->GetBasicBlock(); - auto call_cont_bb = call_bb->SplitBlockAfterInstruction(call_inst, false); + auto callBb = callInst->GetBasicBlock(); + auto callContBb = callBb->SplitBlockAfterInstruction(callInst, false); - UpdateParameterDataflow(graph_inl, call_inst); - UpdateDataflow(graph_inl, call_inst, call_cont_bb); - MoveConstants(graph_inl); - UpdateControlflow(graph_inl, call_bb, call_cont_bb); + UpdateParameterDataflow(graphInl, callInst); + UpdateDataflow(graphInl, callInst, callContBb); + MoveConstants(graphInl); + UpdateControlflow(graphInl, callBb, callContBb); - if (call_cont_bb->GetPredsBlocks().empty()) { + if (callContBb->GetPredsBlocks().empty()) { GetGraph()->RemoveUnreachableBlocks(); } else { - return_blocks_.push_back(call_cont_bb); + returnBlocks_.push_back(callContBb); } - bool need_barriers = GetGraph()->GetRuntime()->IsMemoryBarrierRequired(ctx.method); - ProcessCallReturnInstructions(call_inst, call_cont_bb, true, need_barriers); + bool needBarriers = GetGraph()->GetRuntime()->IsMemoryBarrierRequired(ctx.method); + ProcessCallReturnInstructions(callInst, callContBb, true, needBarriers); - call_inst->SetCallMethod(ctx.method); - call_inst->SetCallMethodId(GetGraph()->GetRuntime()->GetMethodId(ctx.method)); + callInst->SetCallMethod(ctx.method); + callInst->SetCallMethodId(GetGraph()->GetRuntime()->GetMethodId(ctx.method)); if (!IsStaticInlining()) { - call_inst->SetFunctionObject(js_functions_[0]); + callInst->SetFunctionObject(jsFunctions_[0]); } } -bool EcmaInlining::DoEcmaMonomorphicInilning(CallInst *call_inst, InlineContext &ctx) +bool EcmaInlining::DoEcmaMonomorphicInilning(CallInst *callInst, InlineContext &ctx) { - ASSERT(js_functions_.size() <= 1U); + ASSERT(jsFunctions_.size() <= 1U); LOG_INLINING(DEBUG) << "Try inline monomorphic" << (IsStaticInlining() ? "(static)" : "") << " CallDynamic:"; - LOG_INLINING(DEBUG) << " instruction: " << *call_inst; + LOG_INLINING(DEBUG) << " instruction: " << *callInst; LOG_INLINING(DEBUG) << "Method: " << GetGraph()->GetRuntime()->GetMethodFullName(ctx.method, true); - if (OPTIONS.IsCompilerEcmaInlineBuiltins() && CheckInlinableBuiltin(call_inst, ctx.method)) { + if (g_options.IsCompilerEcmaInlineBuiltins() && CheckInlinableBuiltin(callInst, ctx.method)) { // Actual inlining will happen during InlineIntrinsics: return false; } - if (!CheckMethod(call_inst, &ctx)) { + if (!CheckMethod(callInst, &ctx)) { LOG_INLINING(DEBUG) << "Unsuitable bytecode"; return false; } // Build graph for current target and run EcmaInlining recursively - auto graph_inl = BuildGraph(&ctx, call_inst); - if (graph_inl == nullptr) { + auto graphInl = BuildGraph(&ctx, callInst); + if (graphInl == nullptr) { return false; } - InsertGraph(call_inst, ctx, graph_inl); + InsertGraph(callInst, ctx, graphInl); GetGraph()->GetPassManager()->GetStatistics()->AddInlinedMethods(1); - methods_inlined_++; + methodsInlined_++; EVENT_INLINE(GetGraph()->GetRuntime()->GetMethodFullName(GetGraph()->GetMethod()), - GetGraph()->GetRuntime()->GetMethodFullName(ctx.method), call_inst->GetId(), + GetGraph()->GetRuntime()->GetMethodFullName(ctx.method), callInst->GetId(), IsStaticInlining() ? events::InlineKind::STATIC : events::InlineKind::DYNAMIC_MONOMORPHIC, events::InlineResult::SUCCESS); LOG_INLINING(DEBUG) << "Successfully monomorophic " << (IsStaticInlining() ? "(static)" : "") @@ -233,165 +232,164 @@ bool EcmaInlining::DoEcmaMonomorphicInilning(CallInst *call_inst, InlineContext return true; } -void EcmaInlining::CreateCompareFunctions(CallInst *call_inst, RuntimeInterface::MethodPtr method_ptr, - BasicBlock *call_bb) +void EcmaInlining::CreateCompareFunctions(CallInst *callInst, RuntimeInterface::MethodPtr methodPtr, BasicBlock *callBb) { - auto method_cnst = GetGraph()->CreateInstLoadImmediate(DataType::POINTER, call_inst->GetPc(), method_ptr, - LoadImmediateInst::ObjectType::METHOD); - auto load_method = - GetGraph()->CreateInstLoadObject(DataType::POINTER, call_inst->GetPc(), call_inst->GetInput(0).GetInst(), + auto methodCnst = GetGraph()->CreateInstLoadImmediate(DataType::POINTER, callInst->GetPc(), methodPtr, + LoadImmediateInst::ObjectType::METHOD); + auto loadMethod = + GetGraph()->CreateInstLoadObject(DataType::POINTER, callInst->GetPc(), callInst->GetInput(0).GetInst(), TypeIdMixin::MEM_DYN_METHOD_ID, nullptr, nullptr); - load_method->SetObjectType(ObjectType::MEM_DYN_METHOD); - auto cmp_inst = GetGraph()->CreateInstCompare(DataType::BOOL, call_inst->GetPc(), load_method, method_cnst, - DataType::POINTER, ConditionCode::CC_EQ); - auto if_inst = GetGraph()->CreateInstIfImm(DataType::BOOL, call_inst->GetPc(), cmp_inst, 0, DataType::BOOL, - ConditionCode::CC_NE); - call_bb->AppendInst(method_cnst); - call_bb->AppendInst(load_method); - call_bb->AppendInst(cmp_inst); - call_bb->AppendInst(if_inst); + loadMethod->SetObjectType(ObjectType::MEM_DYN_METHOD); + auto cmpInst = GetGraph()->CreateInstCompare(DataType::BOOL, callInst->GetPc(), loadMethod, methodCnst, + DataType::POINTER, ConditionCode::CC_EQ); + auto ifInst = GetGraph()->CreateInstIfImm(DataType::BOOL, callInst->GetPc(), cmpInst, 0, DataType::BOOL, + ConditionCode::CC_NE); + callBb->AppendInst(methodCnst); + callBb->AppendInst(loadMethod); + callBb->AppendInst(cmpInst); + callBb->AppendInst(ifInst); } -bool EcmaInlining::DoEcmaPolymorphicInilning(CallInst *call_inst) +bool EcmaInlining::DoEcmaPolymorphicInilning(CallInst *callInst) { - ASSERT(js_functions_.size() > 1U); - ASSERT(js_functions_.size() <= profiling::MAX_FUNC_NUMBER); - LOG_INLINING(DEBUG) << "Try inline polymorphic call(" << js_functions_.size() << " receivers):"; - LOG_INLINING(DEBUG) << " instruction: " << *call_inst; - - bool has_unreachable_blocks = false; - PhiInst *phi_inst = nullptr; - BasicBlock *call_bb = nullptr; - BasicBlock *call_cont_bb = nullptr; + ASSERT(jsFunctions_.size() > 1U); + ASSERT(jsFunctions_.size() <= profiling::MAX_FUNC_NUMBER); + LOG_INLINING(DEBUG) << "Try inline polymorphic call(" << jsFunctions_.size() << " receivers):"; + LOG_INLINING(DEBUG) << " instruction: " << *callInst; + + bool hasUnreachableBlocks = false; + PhiInst *phiInst = nullptr; + BasicBlock *callBb = nullptr; + BasicBlock *callContBb = nullptr; auto runtime = GetGraph()->GetRuntime(); - auto inlined_methods = methods_inlined_; - for (uintptr_t func : js_functions_) { + auto inlinedMethods = methodsInlined_; + for (uintptr_t func : jsFunctions_) { InlineContext ctx {runtime->GetMethodFromFunction(func)}; LOG_INLINING(DEBUG) << "Method: " << GetGraph()->GetRuntime()->GetMethodFullName(ctx.method, true); - if (!CheckMethod(call_inst, &ctx)) { + if (!CheckMethod(callInst, &ctx)) { continue; } - CallInst *new_call_inst = call_inst->Clone(GetGraph())->CastToCallDynamic(); - new_call_inst->SetCallMethodId(runtime->GetMethodId(ctx.method)); - new_call_inst->SetCallMethod(ctx.method); + CallInst *newCallInst = callInst->Clone(GetGraph())->CastToCallDynamic(); + newCallInst->SetCallMethodId(runtime->GetMethodId(ctx.method)); + newCallInst->SetCallMethod(ctx.method); // Build graph for current target and run EcmaInlining recursively - auto graph_inl = BuildGraph(&ctx, call_inst, new_call_inst); - if (graph_inl == nullptr) { + auto graphInl = BuildGraph(&ctx, callInst, newCallInst); + if (graphInl == nullptr) { continue; } - if (call_bb == nullptr) { + if (callBb == nullptr) { // Split block by call instruction - call_bb = call_inst->GetBasicBlock(); - call_cont_bb = call_bb->SplitBlockAfterInstruction(call_inst, false); - if (call_inst->GetType() != DataType::VOID) { - phi_inst = GetGraph()->CreateInstPhi(call_inst->GetType(), call_inst->GetPc()); - phi_inst->ReserveInputs(js_functions_.size() << 1U); - call_cont_bb->AppendPhi(phi_inst); + callBb = callInst->GetBasicBlock(); + callContBb = callBb->SplitBlockAfterInstruction(callInst, false); + if (callInst->GetType() != DataType::VOID) { + phiInst = GetGraph()->CreateInstPhi(callInst->GetType(), callInst->GetPc()); + phiInst->ReserveInputs(jsFunctions_.size() << 1U); + callContBb->AppendPhi(phiInst); } } else { - auto new_call_bb = GetGraph()->CreateEmptyBlock(call_bb); - call_bb->GetLoop()->AppendBlock(new_call_bb); - call_bb->AddSucc(new_call_bb); - call_bb = new_call_bb; + auto newCallBb = GetGraph()->CreateEmptyBlock(callBb); + callBb->GetLoop()->AppendBlock(newCallBb); + callBb->AddSucc(newCallBb); + callBb = newCallBb; } - CreateCompareFunctions(call_inst, ctx.method, call_bb); + CreateCompareFunctions(callInst, ctx.method, callBb); // Create call_inlined_block - auto call_inlined_block = GetGraph()->CreateEmptyBlock(call_bb); - call_bb->GetLoop()->AppendBlock(call_inlined_block); - call_bb->AddSucc(call_inlined_block); + auto callInlinedBlock = GetGraph()->CreateEmptyBlock(callBb); + callBb->GetLoop()->AppendBlock(callInlinedBlock); + callBb->AddSucc(callInlinedBlock); // Insert Call.inlined in call_inlined_block - new_call_inst->AppendInput(call_inst->GetObjectInst()); - new_call_inst->AppendInput(call_inst->GetSaveState()); - new_call_inst->SetInlined(true); - new_call_inst->SetFlag(inst_flags::NO_DST); - new_call_inst->SetFunctionObject(func); - call_inlined_block->PrependInst(new_call_inst); + newCallInst->AppendInput(callInst->GetObjectInst()); + newCallInst->AppendInput(callInst->GetSaveState()); + newCallInst->SetInlined(true); + newCallInst->SetFlag(inst_flags::NO_DST); + newCallInst->SetFunctionObject(func); + callInlinedBlock->PrependInst(newCallInst); // Create return_inlined_block and inster PHI for non void functions - auto return_inlined_block = GetGraph()->CreateEmptyBlock(call_bb); - call_bb->GetLoop()->AppendBlock(return_inlined_block); - PhiInst *local_phi_inst = nullptr; - if (call_inst->GetType() != DataType::VOID) { - local_phi_inst = GetGraph()->CreateInstPhi(call_inst->GetType(), call_inst->GetPc()); - local_phi_inst->ReserveInputs(js_functions_.size()); - return_inlined_block->AppendPhi(local_phi_inst); + auto returnInlinedBlock = GetGraph()->CreateEmptyBlock(callBb); + callBb->GetLoop()->AppendBlock(returnInlinedBlock); + PhiInst *localPhiInst = nullptr; + if (callInst->GetType() != DataType::VOID) { + localPhiInst = GetGraph()->CreateInstPhi(callInst->GetType(), callInst->GetPc()); + localPhiInst->ReserveInputs(jsFunctions_.size()); + returnInlinedBlock->AppendPhi(localPhiInst); } // Inlined graph between call_inlined_block and return_inlined_block - UpdateParameterDataflow(graph_inl, call_inst); - UpdateDataflow(graph_inl, call_inst, local_phi_inst, phi_inst); - MoveConstants(graph_inl); - UpdateControlflow(graph_inl, call_inlined_block, return_inlined_block); - if (!return_inlined_block->GetPredsBlocks().empty()) { - auto inlined_return = GetGraph()->CreateInstReturnInlined(DataType::VOID, INVALID_PC); - return_inlined_block->PrependInst(inlined_return); - inlined_return->SetInput(0, new_call_inst->GetSaveState()); - if (call_inst->GetType() != DataType::VOID) { - ASSERT(phi_inst); + UpdateParameterDataflow(graphInl, callInst); + UpdateDataflow(graphInl, callInst, localPhiInst, phiInst); + MoveConstants(graphInl); + UpdateControlflow(graphInl, callInlinedBlock, returnInlinedBlock); + if (!returnInlinedBlock->GetPredsBlocks().empty()) { + auto inlinedReturn = GetGraph()->CreateInstReturnInlined(DataType::VOID, INVALID_PC); + returnInlinedBlock->PrependInst(inlinedReturn); + inlinedReturn->SetInput(0, newCallInst->GetSaveState()); + if (callInst->GetType() != DataType::VOID) { + ASSERT(phiInst); // clang-tidy think that phi_inst can be nullptr - phi_inst->AppendInput(local_phi_inst); // NOLINT + phiInst->AppendInput(localPhiInst); // NOLINT } - return_inlined_block->AddSucc(call_cont_bb); + returnInlinedBlock->AddSucc(callContBb); } else { // We need remove return_inlined_block if inlined graph doesn't have Return inst(only Throw or Deoptimize) - has_unreachable_blocks = true; + hasUnreachableBlocks = true; } GetGraph()->GetPassManager()->GetStatistics()->AddInlinedMethods(1); EVENT_INLINE(runtime->GetMethodFullName(GetGraph()->GetMethod()), runtime->GetMethodFullName(ctx.method), - call_inst->GetId(), events::InlineKind::DYNAMIC_POLYMORPHIC, events::InlineResult::SUCCESS); + callInst->GetId(), events::InlineKind::DYNAMIC_POLYMORPHIC, events::InlineResult::SUCCESS); LOG_INLINING(DEBUG) << "Successfully polymorphic inlined: " << GetMethodFullName(GetGraph(), ctx.method); - methods_inlined_++; + methodsInlined_++; } - if (call_bb == nullptr) { + if (callBb == nullptr) { // Nothing was inlined return false; } - if (call_cont_bb->GetPredsBlocks().empty() || has_unreachable_blocks) { + if (callContBb->GetPredsBlocks().empty() || hasUnreachableBlocks) { GetGraph()->RemoveUnreachableBlocks(); } - if (methods_inlined_ - inlined_methods == js_functions_.size()) { - InsertDeoptimizeInst(call_inst, call_bb, DeoptimizeType::INLINE_DYN); + if (methodsInlined_ - inlinedMethods == jsFunctions_.size()) { + InsertDeoptimizeInst(callInst, callBb, DeoptimizeType::INLINE_DYN); } else { - InsertCallInst(call_inst, call_bb, call_cont_bb, phi_inst); + InsertCallInst(callInst, callBb, callContBb, phiInst); } - if (call_inst->GetType() != DataType::VOID) { - call_inst->ReplaceUsers(phi_inst); + if (callInst->GetType() != DataType::VOID) { + callInst->ReplaceUsers(phiInst); } - ProcessCallReturnInstructions(call_inst, call_cont_bb, true); - call_inst->GetBasicBlock()->RemoveInst(call_inst); + ProcessCallReturnInstructions(callInst, callContBb, true); + callInst->GetBasicBlock()->RemoveInst(callInst); return true; } -bool EcmaInlining::TryInline(CallInst *call_inst) +bool EcmaInlining::TryInline(CallInst *callInst) { - js_functions_.clear(); - auto method = TryResolveTargetStatic(call_inst); + jsFunctions_.clear(); + auto method = TryResolveTargetStatic(callInst); if (method != nullptr) { InlineContext ctx {method}; - return DoEcmaMonomorphicInilning(call_inst, ctx); + return DoEcmaMonomorphicInilning(callInst, ctx); } - if (!ResolveTargets(call_inst)) { - LOG_INLINING(DEBUG) << "Target methods were not found for CallDynaimc(id = " << call_inst->GetId() << ")"; + if (!ResolveTargets(callInst)) { + LOG_INLINING(DEBUG) << "Target methods were not found for CallDynaimc(id = " << callInst->GetId() << ")"; return false; } - ASSERT(!js_functions_.empty()); + ASSERT(!jsFunctions_.empty()); if (IsMonomorphicInlining()) { - InlineContext ctx {GetGraph()->GetRuntime()->GetMethodFromFunction(js_functions_[0])}; - return DoEcmaMonomorphicInilning(call_inst, ctx); + InlineContext ctx {GetGraph()->GetRuntime()->GetMethodFromFunction(jsFunctions_[0])}; + return DoEcmaMonomorphicInilning(callInst, ctx); } - return DoEcmaPolymorphicInilning(call_inst); + return DoEcmaPolymorphicInilning(callInst); } -bool EcmaInlining::CheckInlinableBuiltin(CallInst *call_inst, RuntimeInterface::MethodPtr method) +bool EcmaInlining::CheckInlinableBuiltin(CallInst *callInst, RuntimeInterface::MethodPtr method) { if (GetGraph()->GetRuntime()->IsInlinableNativeMethod(method)) { - call_inst->SetCallMethod(method); - ASSERT(!js_functions_.empty()); + callInst->SetCallMethod(method); + ASSERT(!jsFunctions_.empty()); return true; } return false; diff --git a/compiler/optimizer/optimizations/ecma_inlining.h b/compiler/optimizer/optimizations/ecma_inlining.h index a2e1a34bb27525b05cbf76f493df5715bca3cbe5..676323f90a20dfa57d24006c3133107845f30855 100644 --- a/compiler/optimizer/optimizations/ecma_inlining.h +++ b/compiler/optimizer/optimizations/ecma_inlining.h @@ -25,45 +25,45 @@ class EcmaInlining : public Inlining { public: using Inlining::Inlining; - explicit EcmaInlining(Graph *graph, uint32_t instructions_count, uint32_t inline_depth, uint32_t methods_inlined); + explicit EcmaInlining(Graph *graph, uint32_t instructionsCount, uint32_t inlineDepth, uint32_t methodsInlined); explicit EcmaInlining(Graph *graph) : EcmaInlining(graph, 0, 0, 0) {}; NO_MOVE_SEMANTIC(EcmaInlining); NO_COPY_SEMANTIC(EcmaInlining); ~EcmaInlining() override = default; - static void BuildGuard(CallInst *call_inst, RuntimeInterface::MethodPtr method_ptr); + static void BuildGuard(CallInst *callInst, RuntimeInterface::MethodPtr methodPtr); private: void RunOptimizations() const override; bool IsInstSuitableForInline(Inst *inst) const override; bool SkipBlock(const BasicBlock *block) const override; - bool TryInline(CallInst *call_inst) override; - bool DoEcmaMonomorphicInilning(CallInst *call_inst, InlineContext &ctx); - bool DoEcmaPolymorphicInilning(CallInst *call_inst); - bool ResolveTargets(CallInst *call_inst); - RuntimeInterface::MethodPtr TryResolveTargetStatic(CallInst *call_inst) const; - bool IsInstSuitableForEcmaStaticInlining(Inst *define_func) const; - bool CheckCallKind(CallInst *call_inst); - bool CheckMethod(CallInst *call_inst, InlineContext *ctx); - Graph *BuildGraph(InlineContext *ctx, CallInst *call_inst, CallInst *new_call_inst = nullptr); - void CreateCompareFunctions(CallInst *call_inst, RuntimeInterface::MethodPtr method_ptr, BasicBlock *call_bb); - void InsertGraph(CallInst *call_inst, const InlineContext &ctx, Graph *graph_inl); + bool TryInline(CallInst *callInst) override; + bool DoEcmaMonomorphicInilning(CallInst *callInst, InlineContext &ctx); + bool DoEcmaPolymorphicInilning(CallInst *callInst); + bool ResolveTargets(CallInst *callInst); + RuntimeInterface::MethodPtr TryResolveTargetStatic(CallInst *callInst) const; + bool IsInstSuitableForEcmaStaticInlining(Inst *defineFunc) const; + bool CheckCallKind(CallInst *callInst); + bool CheckMethod(CallInst *callInst, InlineContext *ctx); + Graph *BuildGraph(InlineContext *ctx, CallInst *callInst, CallInst *newCallInst = nullptr); + void CreateCompareFunctions(CallInst *callInst, RuntimeInterface::MethodPtr methodPtr, BasicBlock *callBb); + void InsertGraph(CallInst *callInst, const InlineContext &ctx, Graph *graphInl); bool IsStaticInlining() const { - return js_functions_.empty(); + return jsFunctions_.empty(); } - bool CheckInlinableBuiltin(CallInst *call_inst, RuntimeInterface::MethodPtr native_method); + bool CheckInlinableBuiltin(CallInst *callInst, RuntimeInterface::MethodPtr nativeMethod); bool IsMonomorphicInlining() const { - return js_functions_.size() == 1U; + return jsFunctions_.size() == 1U; } private: // This vector contains pointers to element in EcmaCallProfilingTable // This element contains pointer to js function - ArenaVector js_functions_; + ArenaVector jsFunctions_; }; } // namespace panda::compiler::ecmascript diff --git a/compiler/optimizer/optimizations/inline_call_intrinsics.cpp b/compiler/optimizer/optimizations/inline_call_intrinsics.cpp index b8b2e6a3a97fc87b74bdb45969a04567ff793ef7..c7926299add7b0779de96060cef90701d10c9b7a 100644 --- a/compiler/optimizer/optimizations/inline_call_intrinsics.cpp +++ b/compiler/optimizer/optimizations/inline_call_intrinsics.cpp @@ -34,8 +34,8 @@ bool InlineCallIntrinsics::RunImpl() if (!inst->IsIntrinsic()) { continue; } - auto intrin_inst = inst->CastToIntrinsic(); - success |= Expand(intrin_inst); + auto intrinInst = inst->CastToIntrinsic(); + success |= Expand(intrinInst); } } return success; @@ -55,90 +55,89 @@ bool InlineCallIntrinsics::Expand(IntrinsicInst *inst) Inst *InlineCallIntrinsics::CreateAllocDynObjIntrinsic(Inst *ctor, SaveStateInst *ss, uint32_t pc) { - auto alloc_obj = + auto allocObj = GetGraph()->CreateInstIntrinsic(DataType::ANY, pc, RuntimeInterface::IntrinsicId::INTRINSIC_ALLOC_DYN_OBJECT); - alloc_obj->SetInputs(GetGraph()->GetAllocator(), {{ctor, DataType::ANY}, {ss, DataType::NO_TYPE}}); - return alloc_obj; + allocObj->SetInputs(GetGraph()->GetAllocator(), {{ctor, DataType::ANY}, {ss, DataType::NO_TYPE}}); + return allocObj; } -Inst *InlineCallIntrinsics::NewObjCreateConstructorCall(Inst *orig_call, Inst *alloc_obj, SaveStateInst *ss, - uint32_t pc) +Inst *InlineCallIntrinsics::NewObjCreateConstructorCall(Inst *origCall, Inst *allocObj, SaveStateInst *ss, uint32_t pc) { - auto call_ctor = GetGraph()->CreateInstCallDynamic(DataType::ANY, pc); - call_ctor->ReserveInputs(orig_call->GetInputsCount() + 1); - call_ctor->AllocateInputTypes(GetGraph()->GetAllocator(), orig_call->GetInputsCount() + 1); - call_ctor->AppendInputs({{orig_call->GetInput(1).GetInst(), DataType::ANY}, - {orig_call->GetInput(2).GetInst(), DataType::ANY}, - {alloc_obj, DataType::ANY}}); - for (size_t i = 3; i < orig_call->GetInputsCount() - 1; ++i) { - call_ctor->AppendInputAndType(orig_call->GetInput(i).GetInst(), orig_call->GetInputType(i)); + auto callCtor = GetGraph()->CreateInstCallDynamic(DataType::ANY, pc); + callCtor->ReserveInputs(origCall->GetInputsCount() + 1); + callCtor->AllocateInputTypes(GetGraph()->GetAllocator(), origCall->GetInputsCount() + 1); + callCtor->AppendInputs({{origCall->GetInput(1).GetInst(), DataType::ANY}, + {origCall->GetInput(2).GetInst(), DataType::ANY}, + {allocObj, DataType::ANY}}); + for (size_t i = 3; i < origCall->GetInputsCount() - 1; ++i) { + callCtor->AppendInputAndType(origCall->GetInput(i).GetInst(), origCall->GetInputType(i)); } - call_ctor->AppendInputAndType(ss, DataType::NO_TYPE); - return call_ctor; + callCtor->AppendInputAndType(ss, DataType::NO_TYPE); + return callCtor; } -void InlineCallIntrinsics::NewObjFillCurrBlock(InstAppender *appender, Inst *alloc_obj, uint32_t pc) +void InlineCallIntrinsics::NewObjFillCurrBlock(InstAppender *appender, Inst *allocObj, uint32_t pc) { - auto cmp = GetGraph()->CreateInstCompareAnyType(pc, alloc_obj, AnyBaseType::ECMASCRIPT_NULL_TYPE); + auto cmp = GetGraph()->CreateInstCompareAnyType(pc, allocObj, AnyBaseType::ECMASCRIPT_NULL_TYPE); // if alloc returned null -> jump into a slow path auto ifimm = GetGraph()->CreateInstIfImm(DataType::BOOL, pc, cmp, 0, DataType::BOOL, ConditionCode::CC_NE); appender->Append({cmp, ifimm}); } -void InlineCallIntrinsics::NewObjFillSlowPathBlock(InstAppender *appender, Inst *orig_alloc) +void InlineCallIntrinsics::NewObjFillSlowPathBlock(InstAppender *appender, Inst *origAlloc) { - auto curr_block = orig_alloc->GetBasicBlock(); - auto ss = orig_alloc->CastToIntrinsic()->GetSaveState(); - auto ss_copy = static_cast(ss->Clone(GetGraph())); - for (size_t input_idx = 0; input_idx < ss->GetInputsCount(); ++input_idx) { - ss_copy->AppendInput(ss->GetInput(input_idx)); - ss_copy->SetVirtualRegister(input_idx, ss->GetVirtualRegister(input_idx)); + auto currBlock = origAlloc->GetBasicBlock(); + auto ss = origAlloc->CastToIntrinsic()->GetSaveState(); + auto ssCopy = static_cast(ss->Clone(GetGraph())); + for (size_t inputIdx = 0; inputIdx < ss->GetInputsCount(); ++inputIdx) { + ssCopy->AppendInput(ss->GetInput(inputIdx)); + ssCopy->SetVirtualRegister(inputIdx, ss->GetVirtualRegister(inputIdx)); } - orig_alloc->SetSaveState(ss_copy); + origAlloc->SetSaveState(ssCopy); // move original intrinsic and its SaveState into a slow path - curr_block->EraseInst(orig_alloc, true); - appender->Append({ss_copy, orig_alloc}); + currBlock->EraseInst(origAlloc, true); + appender->Append({ssCopy, origAlloc}); } -Inst *InlineCallIntrinsics::NewObjFillCallConstructorBlock(InstAppender *appender, Inst *orig_alloc, Inst *alloc_obj, +Inst *InlineCallIntrinsics::NewObjFillCallConstructorBlock(InstAppender *appender, Inst *origAlloc, Inst *allocObj, uint32_t pc) { - auto ss = orig_alloc->GetSaveState(); - auto ss_copy = static_cast(ss->Clone(GetGraph())); - for (size_t input_idx = 0; input_idx < ss->GetInputsCount(); ++input_idx) { - ss_copy->AppendInput(ss->GetInput(input_idx)); - ss_copy->SetVirtualRegister(input_idx, ss->GetVirtualRegister(input_idx)); + auto ss = origAlloc->GetSaveState(); + auto ssCopy = static_cast(ss->Clone(GetGraph())); + for (size_t inputIdx = 0; inputIdx < ss->GetInputsCount(); ++inputIdx) { + ssCopy->AppendInput(ss->GetInput(inputIdx)); + ssCopy->SetVirtualRegister(inputIdx, ss->GetVirtualRegister(inputIdx)); } - ss_copy->AppendBridge(alloc_obj); - auto call_ctor = NewObjCreateConstructorCall(orig_alloc, alloc_obj, ss_copy, pc); + ssCopy->AppendBridge(allocObj); + auto callCtor = NewObjCreateConstructorCall(origAlloc, allocObj, ssCopy, pc); - appender->Append({ss_copy, call_ctor}); + appender->Append({ssCopy, callCtor}); - return call_ctor; + return callCtor; } -Inst *InlineCallIntrinsics::NewObjResolveCtorResult(InstAppender *appender, Inst *orig_alloc, Inst *alloc_obj, - Inst *call_ctor, uint32_t pc) +Inst *InlineCallIntrinsics::NewObjResolveCtorResult(InstAppender *appender, Inst *origAlloc, Inst *allocObj, + Inst *callCtor, uint32_t pc) { - auto ss = call_ctor->GetSaveState(); - auto ss_copy_2 = static_cast(ss->Clone(GetGraph())); - for (size_t input_idx = 0; input_idx < ss->GetInputsCount(); ++input_idx) { - ss_copy_2->AppendInput(ss->GetInput(input_idx)); - ss_copy_2->SetVirtualRegister(input_idx, ss->GetVirtualRegister(input_idx)); + auto ss = callCtor->GetSaveState(); + auto ssCopy2 = static_cast(ss->Clone(GetGraph())); + for (size_t inputIdx = 0; inputIdx < ss->GetInputsCount(); ++inputIdx) { + ssCopy2->AppendInput(ss->GetInput(inputIdx)); + ssCopy2->SetVirtualRegister(inputIdx, ss->GetVirtualRegister(inputIdx)); } - ss_copy_2->AppendBridge(call_ctor); + ssCopy2->AppendBridge(callCtor); - auto resolve_result = GetGraph()->CreateInstIntrinsic( - DataType::ANY, pc, RuntimeInterface::IntrinsicId::INTRINSIC_RESOLVE_ALLOC_RESULT); - resolve_result->SetInputs(GetGraph()->GetAllocator(), {{orig_alloc->GetInput(1).GetInst(), DataType::ANY}, - {alloc_obj, DataType::ANY}, - {call_ctor, DataType::ANY}, - {ss_copy_2, DataType::NO_TYPE}}); - resolve_result->SetInlined(true); + auto resolveResult = GetGraph()->CreateInstIntrinsic(DataType::ANY, pc, + RuntimeInterface::IntrinsicId::INTRINSIC_RESOLVE_ALLOC_RESULT); + resolveResult->SetInputs(GetGraph()->GetAllocator(), {{origAlloc->GetInput(1).GetInst(), DataType::ANY}, + {allocObj, DataType::ANY}, + {callCtor, DataType::ANY}, + {ssCopy2, DataType::NO_TYPE}}); + resolveResult->SetInlined(true); - appender->Append({ss_copy_2, resolve_result}); + appender->Append({ssCopy2, resolveResult}); - return resolve_result; + return resolveResult; } /* @@ -168,35 +167,35 @@ Inst *InlineCallIntrinsics::NewObjResolveCtorResult(InstAppender *appender, Inst */ bool InlineCallIntrinsics::ExpandNewObjDynRange(IntrinsicInst *inst) { - Inst *ctor_inst = inst->GetInput(1).GetInst(); - Inst *new_target_inst = inst->GetInput(2).GetInst(); + Inst *ctorInst = inst->GetInput(1).GetInst(); + Inst *newTargetInst = inst->GetInput(2).GetInst(); - if (ctor_inst != new_target_inst) { + if (ctorInst != newTargetInst) { return false; } auto runtime = GetGraph()->GetRuntime(); auto kind = panda::profiling::CallKind::UNKNOWN; - if (OPTIONS.IsCompilerEcmaNewobjProfiling()) { + if (g_options.IsCompilerEcmaNewobjProfiling()) { functions_.clear(); kind = runtime->GetCallProfile(GetGraph()->GetMethod(), inst->GetPc(), &functions_, GetGraph()->IsAotMode()); } - RuntimeInterface::NewObjDynInfo expansion_info {RuntimeInterface::NewObjDynInfo::AllocatorType::DEFAULT, - RuntimeInterface::NewObjDynInfo::ResolverType::RESOLVE}; + RuntimeInterface::NewObjDynInfo expansionInfo {RuntimeInterface::NewObjDynInfo::AllocatorType::DEFAULT, + RuntimeInterface::NewObjDynInfo::ResolverType::RESOLVE}; if (kind == panda::profiling::CallKind::MONOMORPHIC) { - expansion_info = runtime->GetNewObjDynInfo(functions_.front()); + expansionInfo = runtime->GetNewObjDynInfo(functions_.front()); } - switch (expansion_info.allocation) { + switch (expansionInfo.allocation) { // allocation always require slow path, so it doesn't make sense to expand the intrinsic case RuntimeInterface::NewObjDynInfo::AllocatorType::SLOW_PATH: - assert(expansion_info.resolution == RuntimeInterface::NewObjDynInfo::ResolverType::RESOLVE); + assert(expansionInfo.resolution == RuntimeInterface::NewObjDynInfo::ResolverType::RESOLVE); return false; // emit simplified fast path, but only for monomorphic call sites case RuntimeInterface::NewObjDynInfo::AllocatorType::UNDEFINED: case RuntimeInterface::NewObjDynInfo::AllocatorType::ALLOC_OBJ: if (kind == panda::profiling::CallKind::MONOMORPHIC) { - ExpandNewObjDynFastPath(inst, expansion_info, functions_.front()); + ExpandNewObjDynFastPath(inst, expansionInfo, functions_.front()); return true; } else { ExpandNewObjDynDefault(inst); @@ -212,35 +211,35 @@ bool InlineCallIntrinsics::ExpandNewObjDynRange(IntrinsicInst *inst) void InlineCallIntrinsics::ExpandNewObjDynDefault(Inst *inst) { - auto curr_block = inst->GetBasicBlock(); - auto succ_block = curr_block->SplitBlockAfterInstruction(inst, false); + auto currBlock = inst->GetBasicBlock(); + auto succBlock = currBlock->SplitBlockAfterInstruction(inst, false); auto pc = inst->GetPc(); - auto slow_path_block = GetGraph()->CreateEmptyBlock(curr_block); - auto call_ctor_block = GetGraph()->CreateEmptyBlock(curr_block); + auto slowPathBlock = GetGraph()->CreateEmptyBlock(currBlock); + auto callCtorBlock = GetGraph()->CreateEmptyBlock(currBlock); - InstAppender curr_block_appender {curr_block}; - auto alloc_obj = CreateAllocDynObjIntrinsic(inst->GetInput(1).GetInst(), inst->GetSaveState(), pc); - curr_block_appender.Append({alloc_obj}); - NewObjFillCurrBlock(&curr_block_appender, alloc_obj, pc); + InstAppender currBlockAppender {currBlock}; + auto allocObj = CreateAllocDynObjIntrinsic(inst->GetInput(1).GetInst(), inst->GetSaveState(), pc); + currBlockAppender.Append({allocObj}); + NewObjFillCurrBlock(&currBlockAppender, allocObj, pc); - InstAppender slow_path_block_appender {slow_path_block}; - NewObjFillSlowPathBlock(&slow_path_block_appender, inst); + InstAppender slowPathBlockAppender {slowPathBlock}; + NewObjFillSlowPathBlock(&slowPathBlockAppender, inst); - InstAppender call_ctor_block_appender {call_ctor_block}; - auto ctor = NewObjFillCallConstructorBlock(&call_ctor_block_appender, inst, alloc_obj, pc); - auto ctor_res = NewObjResolveCtorResult(&call_ctor_block_appender, inst, alloc_obj, ctor, pc); + InstAppender callCtorBlockAppender {callCtorBlock}; + auto ctor = NewObjFillCallConstructorBlock(&callCtorBlockAppender, inst, allocObj, pc); + auto ctorRes = NewObjResolveCtorResult(&callCtorBlockAppender, inst, allocObj, ctor, pc); - curr_block->AddSucc(slow_path_block); - curr_block->AddSucc(call_ctor_block); - slow_path_block->AddSucc(succ_block); - call_ctor_block->AddSucc(succ_block); + currBlock->AddSucc(slowPathBlock); + currBlock->AddSucc(callCtorBlock); + slowPathBlock->AddSucc(succBlock); + callCtorBlock->AddSucc(succBlock); auto phi = GetGraph()->CreateInstPhi(DataType::ANY, pc); inst->ReplaceUsers(phi); phi->AppendInput(inst); - phi->AppendInput(ctor_res); - succ_block->AppendPhi(phi); + phi->AppendInput(ctorRes); + succBlock->AppendPhi(phi); GetGraph()->InvalidateAnalysis(); GetGraph()->InvalidateAnalysis(); @@ -249,48 +248,48 @@ void InlineCallIntrinsics::ExpandNewObjDynDefault(Inst *inst) void InlineCallIntrinsics::ExpandNewObjDynFastPath(Inst *inst, RuntimeInterface::NewObjDynInfo info, uintptr_t target) { - auto curr_block = inst->GetBasicBlock(); + auto currBlock = inst->GetBasicBlock(); auto pc = inst->GetPc(); BuildGuard(inst, target); - Inst *alloc_obj; - InstAppender appender {curr_block, inst}; + Inst *allocObj; + InstAppender appender {currBlock, inst}; if (info.allocation == RuntimeInterface::NewObjDynInfo::AllocatorType::ALLOC_OBJ) { - alloc_obj = CreateAllocDynObjIntrinsic(inst->GetInput(1).GetInst(), inst->GetSaveState(), pc); - appender.Append({alloc_obj}); + allocObj = CreateAllocDynObjIntrinsic(inst->GetInput(1).GetInst(), inst->GetSaveState(), pc); + appender.Append({allocObj}); } else { ASSERT(info.allocation == RuntimeInterface::NewObjDynInfo::AllocatorType::UNDEFINED); - alloc_obj = GetGraph()->FindOrCreateConstant(DataType::Any(panda::coretypes::TaggedValue::VALUE_UNDEFINED)); + allocObj = GetGraph()->FindOrCreateConstant(DataType::Any(panda::coretypes::TaggedValue::VALUE_UNDEFINED)); } - auto ctor_res = NewObjFillCallConstructorBlock(&appender, inst, alloc_obj, pc); + auto ctorRes = NewObjFillCallConstructorBlock(&appender, inst, allocObj, pc); - Inst *res = ctor_res; + Inst *res = ctorRes; - bool need_resolver = info.resolution == RuntimeInterface::NewObjDynInfo::ResolverType::RESOLVE; - if (need_resolver) { - res = NewObjResolveCtorResult(&appender, inst, alloc_obj, ctor_res, pc); + bool needResolver = info.resolution == RuntimeInterface::NewObjDynInfo::ResolverType::RESOLVE; + if (needResolver) { + res = NewObjResolveCtorResult(&appender, inst, allocObj, ctorRes, pc); } inst->ReplaceUsers(res); - curr_block->RemoveInst(inst); + currBlock->RemoveInst(inst); } void InlineCallIntrinsics::BuildGuard(Inst *inst, uintptr_t target) { auto pc = inst->GetPc(); - auto load_function = GetGraph()->CreateInstFunctionImmediate(DataType::ANY, pc, target); - auto cmp_inst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, load_function, inst->GetInput(1).GetInst(), - DataType::ANY, ConditionCode::CC_NE); - auto deopt_inst = GetGraph()->CreateInstDeoptimizeIf(DataType::BOOL, pc, cmp_inst, inst->GetSaveState(), - DeoptimizeType::INLINE_DYN); - - auto save_state = inst->GetSaveState(); - ASSERT(save_state); - save_state->InsertBefore(load_function); - save_state->AppendBridge(load_function); - inst->InsertBefore(cmp_inst); - inst->InsertBefore(deopt_inst); + auto loadFunction = GetGraph()->CreateInstFunctionImmediate(DataType::ANY, pc, target); + auto cmpInst = GetGraph()->CreateInstCompare(DataType::BOOL, pc, loadFunction, inst->GetInput(1).GetInst(), + DataType::ANY, ConditionCode::CC_NE); + auto deoptInst = GetGraph()->CreateInstDeoptimizeIf(DataType::BOOL, pc, cmpInst, inst->GetSaveState(), + DeoptimizeType::INLINE_DYN); + + auto saveState = inst->GetSaveState(); + ASSERT(saveState); + saveState->InsertBefore(loadFunction); + saveState->AppendBridge(loadFunction); + inst->InsertBefore(cmpInst); + inst->InsertBefore(deoptInst); } } // namespace panda::compiler diff --git a/compiler/optimizer/optimizations/inline_call_intrinsics.h b/compiler/optimizer/optimizations/inline_call_intrinsics.h index 3fca9203b62044cb2ca4d0b6a1bb002a09f33369..a7acb343a64d8c07e28484d4b8ea6dd66364b98d 100644 --- a/compiler/optimizer/optimizations/inline_call_intrinsics.h +++ b/compiler/optimizer/optimizations/inline_call_intrinsics.h @@ -40,7 +40,7 @@ public: bool IsEnable() const override { - return OPTIONS.IsCompilerEcmaInlineCallIntrinsics(); + return g_options.IsCompilerEcmaInlineCallIntrinsics(); } private: @@ -49,12 +49,11 @@ private: void ExpandNewObjDynDefault(Inst *inst); void ExpandNewObjDynFastPath(Inst *inst, RuntimeInterface::NewObjDynInfo info, uintptr_t target); Inst *CreateAllocDynObjIntrinsic(Inst *ctor, SaveStateInst *ss, uint32_t pc); - Inst *NewObjCreateConstructorCall(Inst *orig_call, Inst *alloc_obj, SaveStateInst *ss, uint32_t pc); - Inst *NewObjFillCallConstructorBlock(InstAppender *appender, Inst *orig_alloc, Inst *alloc_obj, uint32_t pc); - void NewObjFillSlowPathBlock(InstAppender *appender, Inst *orig_alloc); - void NewObjFillCurrBlock(InstAppender *appender, Inst *alloc_obj, uint32_t pc); - Inst *NewObjResolveCtorResult(InstAppender *appender, Inst *orig_alloc, Inst *alloc_obj, Inst *call_ctor, - uint32_t pc); + Inst *NewObjCreateConstructorCall(Inst *origCall, Inst *allocObj, SaveStateInst *ss, uint32_t pc); + Inst *NewObjFillCallConstructorBlock(InstAppender *appender, Inst *origAlloc, Inst *allocObj, uint32_t pc); + void NewObjFillSlowPathBlock(InstAppender *appender, Inst *origAlloc); + void NewObjFillCurrBlock(InstAppender *appender, Inst *allocObj, uint32_t pc); + Inst *NewObjResolveCtorResult(InstAppender *appender, Inst *origAlloc, Inst *allocObj, Inst *callCtor, uint32_t pc); void BuildGuard(Inst *inst, uintptr_t target); ArenaVector functions_; diff --git a/compiler/templates/ecmascript_inst_builder_gen.cpp.erb b/compiler/templates/ecmascript_inst_builder_gen.cpp.erb index 4f714b069144462f01f9a97e6a1b95fa64a140cc..af1ee9ebce66335315915d6972da8986fce4829c 100644 --- a/compiler/templates/ecmascript_inst_builder_gen.cpp.erb +++ b/compiler/templates/ecmascript_inst_builder_gen.cpp.erb @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,31 +35,31 @@ namespace panda::compiler { // InstBuilder::BuildEcma selects proper strategy and calls relevant builder. // NOLINTNEXTLINE(readability-function-size) -void InstBuilder::BuildEcma([[maybe_unused]] const BytecodeInstruction* bc_inst) +void InstBuilder::BuildEcma([[maybe_unused]] const BytecodeInstruction* bcInst) { #ifdef ENABLE_BYTECODE_OPT - switch (bc_inst->GetOpcode()) { + switch (bcInst->GetOpcode()) { % Panda::instructions.select{|b| b.namespace == "ecmascript"}.each do |inst| case BytecodeInstruction::Opcode::<%= inst.opcode.upcase %>: { % if inst.compilable? && inst.inlinable? // +compilable, +inlinable: ecma.* -> intrinsics for BCO, inline IRtoC otherwise: if (GetGraph()->IsBytecodeOptimizer()) { - BuildEcmaAsIntrinsics(bc_inst); + BuildEcmaAsIntrinsics(bcInst); } else { - if (OPTIONS.IsCompilerInlineFullIntrinsics()) { - BuildEcmaFromIrtoc(bc_inst); + if (g_options.IsCompilerInlineFullIntrinsics()) { + BuildEcmaFromIrtoc(bcInst); } else { - BuildEcmaAsIntrinsics(bc_inst); + BuildEcmaAsIntrinsics(bcInst); } } % elsif inst.compilable? // +compilable, -inlinable: ecma.* -> intrinsics for all scenarios: - BuildEcmaAsIntrinsics(bc_inst); + BuildEcmaAsIntrinsics(bcInst); % else % abort "isa.yaml inconsistency: #{inst.opcode.upcase} is not compilable, but inlinable" if inst.inlinable? // -compilable, -inlinable: ecma.* -> intrinsics for BCO, fail IR builder otherwise: if (GetGraph()->IsBytecodeOptimizer()) { - BuildEcmaAsIntrinsics(bc_inst); + BuildEcmaAsIntrinsics(bcInst); } else { failed_ = true; } @@ -69,7 +69,7 @@ void InstBuilder::BuildEcma([[maybe_unused]] const BytecodeInstruction* bc_inst) % end default: { failed_ = true; - LOG(ERROR, COMPILER) << "Unknown ecma.* opcode: " << static_cast(bc_inst->GetOpcode()); + LOG(ERROR, COMPILER) << "Unknown ecma.* opcode: " << static_cast(bcInst->GetOpcode()); return; } } @@ -77,9 +77,9 @@ void InstBuilder::BuildEcma([[maybe_unused]] const BytecodeInstruction* bc_inst) } template -void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // NOLINT(readability-function-size) +void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bcInst) // NOLINT(readability-function-size) { - switch (bc_inst->GetOpcode()) { + switch (bcInst->GetOpcode()) { % Panda::instructions.select{|b| b.namespace == "ecmascript"}.each do |inst| % opc = inst.opcode.upcase % name = opc.split('_')[1] @@ -88,8 +88,8 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N % ret_type = acc_write ? "compiler::DataType::ANY" : "compiler::DataType::VOID" % iname = inst.intrinsic_name ? inst.intrinsic_name : opc case BytecodeInstruction::Opcode::<%= opc %>: { - auto intrinsic_id = <%= "compiler::RuntimeInterface::IntrinsicId::" + iname %>; - auto inst = GetGraph()->CreateInstIntrinsic(<%= ret_type %>, GetPc(bc_inst->GetAddress()), intrinsic_id); + auto intrinsicId = <%= "compiler::RuntimeInterface::IntrinsicId::" + iname %>; + auto inst = GetGraph()->CreateInstIntrinsic(<%= ret_type %>, GetPc(bcInst->GetAddress()), intrinsicId); % if inst.throwing? inst->SetFlag(inst_flags::CAN_THROW); % end @@ -99,7 +99,7 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N % end % has_profile = inst.profiled? % if has_profile - [[maybe_unused]] auto profile = GetRuntime()->GetBytecodeProfile(method_profile_, bc_inst->GetAddress(), inst->GetPc()); + [[maybe_unused]] auto profile = GetRuntime()->GetBytecodeProfile(methodProfile_, bcInst->GetAddress(), inst->GetPc()); % end % params_arr = inst.operands % format = "BytecodeInstruction::Format::" + inst.format.pretty.upcase @@ -127,63 +127,63 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N % num_inputs = num_inputs + 1 % end % if is_range_call - size_t args_count = <%= num_inputs %>U + static_cast(bc_inst->GetImm<<%= format %>, 0>()); + size_t argsCount = <%= num_inputs %>U + static_cast(bcInst->GetImm<<%= format %>, 0>()); % else - size_t args_count {<%= num_inputs %>U}; + size_t argsCount {<%= num_inputs %>U}; % end if (!inst->RequireState()) { - --args_count; + --argsCount; } % if need_newtarget if (GetGraph()->IsBytecodeOptimizer()) { - --args_count; + --argsCount; } % end % if use_ic % num_inputs = num_inputs + 1 if (!GetGraph()->IsBytecodeOptimizer()) { - args_count++; // Instruction supports IC: +1 input for IC slot index + argsCount++; // Instruction supports IC: +1 input for IC slot index } % end - inst->ReserveInputs(args_count); - inst->AllocateInputTypes(GetGraph()->GetAllocator(), args_count); + inst->ReserveInputs(argsCount); + inst->AllocateInputTypes(GetGraph()->GetAllocator(), argsCount); inst->SetInlined(true); % imm_index = 0 % vreg_index = 0 % id16_index = 0 % id32_index = 0 - auto inst_save_state = CreateSaveState(Opcode::SaveState, GetPc(bc_inst->GetAddress())); + auto instSaveState = CreateSaveState(Opcode::SaveState, GetPc(bcInst->GetAddress())); % if num_ids > 0 % abort "Too many ids in inputs: #{opc}" if num_ids > 1 - LoadFromPoolDynamic *load_from_pool = nullptr; + LoadFromPoolDynamic *loadFromPool = nullptr; if (!GetGraph()->IsBytecodeOptimizer()) { - load_from_pool = graph_->CreateInstLoadFromConstantPool(DataType::ANY, inst->GetPc()); - load_from_pool->SetInput(0, GetEnvDefinition(CONST_POOL_IDX)); - inst_save_state->AppendBridge(load_from_pool); - AddInstruction(load_from_pool); - inst->AppendInput(load_from_pool); + loadFromPool = graph_->CreateInstLoadFromConstantPool(DataType::ANY, inst->GetPc()); + loadFromPool->SetInput(0, GetEnvDefinition(CONST_POOL_IDX)); + instSaveState->AppendBridge(loadFromPool); + AddInstruction(loadFromPool); + inst->AppendInput(loadFromPool); inst->AddInputType(DataType::ANY); inst->SetHasIdInput(); } % end - AddInstruction(inst_save_state); + AddInstruction(instSaveState); % params_arr.each_with_index do |param, input_index| % if param.imm? - auto imm<%= imm_index %> = static_cast(bc_inst->GetImm<<%= format %>, <%= imm_index %>>()); + auto imm<%= imm_index %> = static_cast(bcInst->GetImm<<%= format %>, <%= imm_index %>>()); inst->AddImm(GetGraph()->GetAllocator(), imm<%= imm_index %>); % imm_index = imm_index + 1 % elsif param.reg? { - auto input = GetDefinition(bc_inst->GetVReg<<%= format %>, <%= vreg_index %>>()); + auto input = GetDefinition(bcInst->GetVReg<<%= format %>, <%= vreg_index %>>()); % if has_profile && (inst.profile.properties.include?('operand_types_1') || inst.profile.properties.include?('operand_types_2')) // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (WITH_SPECULATIVE) { - profiling::AnyInputType allowed_input_type {}; - bool is_type_profiled = false; - auto operand_type = GetRuntime()->GetProfilingAnyType(profile, bc_inst, <%= input_index %>, &allowed_input_type, &is_type_profiled); - input = BuildAnyTypeCheckInst(GetPc(bc_inst->GetAddress()), input, inst_save_state, operand_type, is_type_profiled, allowed_input_type); - if (OPTIONS.IsCompilerEcmaReplaceIntrinsicsToDeopt() && !is_type_profiled) { + profiling::AnyInputType allowedInputType {}; + bool isTypeProfiled = false; + auto operandType = GetRuntime()->GetProfilingAnyType(profile, bcInst, <%= input_index %>, &allowedInputType, &isTypeProfiled); + input = BuildAnyTypeCheckInst(GetPc(bcInst->GetAddress()), input, instSaveState, operandType, isTypeProfiled, allowedInputType); + if (g_options.IsCompilerEcmaReplaceIntrinsicsToDeopt() && !isTypeProfiled) { inst->SetReplaceOnDeoptimize(); } } @@ -195,28 +195,28 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N % elsif param.id? % abort "Id is not the first input: #{opc}" if input_index > 0 % if inst.properties.include?("method_id") - auto m_idx<%= id16_index %> = bc_inst->template GetId<<%= format %>>().AsRawValue(); + auto mIdx<%= id16_index %> = bcInst->template GetId<<%= format %>>().AsRawValue(); if (GetGraph()->IsBytecodeOptimizer()) { - m_idx<%= id16_index %> = GetRuntime()->ResolveMethodIndex(GetGraph()->GetMethod(), m_idx<%= id16_index %>); - inst->AddImm(GetGraph()->GetAllocator(), m_idx<%= id16_index %>); + mIdx<%= id16_index %> = GetRuntime()->ResolveMethodIndex(GetGraph()->GetMethod(), mIdx<%= id16_index %>); + inst->AddImm(GetGraph()->GetAllocator(), mIdx<%= id16_index %>); } else { - load_from_pool->SetTypeId(m_idx<%= id16_index %>); + loadFromPool->SetTypeId(mIdx<%= id16_index %>); } % id16_index = id16_index + 1 % elsif inst.properties.include?("literalarray_id") - auto literalarray_id<%= id16_index %> = bc_inst->template GetId<<%= format %>>().AsIndex(); + auto literalarrayId<%= id16_index %> = bcInst->template GetId<<%= format %>>().AsIndex(); if (GetGraph()->IsBytecodeOptimizer()) { - inst->AddImm(GetGraph()->GetAllocator(), literalarray_id<%= id16_index %>); + inst->AddImm(GetGraph()->GetAllocator(), literalarrayId<%= id16_index %>); } else { - load_from_pool->SetTypeId(literalarray_id<%= id16_index %>); + loadFromPool->SetTypeId(literalarrayId<%= id16_index %>); } % id16_index = id16_index + 1 % elsif inst.properties.include?("string_id") - auto string_id<%= id32_index %> = bc_inst->template GetId<<%= format %>>().AsFileId().GetOffset(); + auto stringId<%= id32_index %> = bcInst->template GetId<<%= format %>>().AsFileId().GetOffset(); if (GetGraph()->IsBytecodeOptimizer()) { - inst->AddImm(GetGraph()->GetAllocator(), string_id<%= id32_index %>); + inst->AddImm(GetGraph()->GetAllocator(), stringId<%= id32_index %>); } else { - load_from_pool->SetTypeId(string_id<%= id32_index %>); + loadFromPool->SetTypeId(stringId<%= id32_index %>); } % id32_index = id32_index + 1 % end @@ -227,7 +227,7 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N auto input = GetDefinition(GetGraph()->GetRuntime()->GetMethodRegistersCount(GetMethod()) + 1); // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (WITH_SPECULATIVE) { - input = BuildAnyTypeCheckInst(GetPc(bc_inst->GetAddress()), input, inst_save_state); + input = BuildAnyTypeCheckInst(GetPc(bcInst->GetAddress()), input, instSaveState); } inst->AppendInput(input); inst->AddInputType(DataType::ANY); @@ -236,12 +236,12 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N % if is_range_call % range_reg_idx = name == "CREATEOBJECTWITHEXCLUDEDKEYS" ? 1 : 0 % num_actual_vregs = range_should_exclude_last ? "imm0" : "imm0 + 1" - size_t start_reg = bc_inst->GetVReg<<%= format %>, <%= range_reg_idx %>>(); + size_t startReg = bcInst->GetVReg<<%= format %>, <%= range_reg_idx %>>(); for (uint32_t i = 1; i < <%= num_actual_vregs %>; ++i) { - auto input = GetDefinition(start_reg + i); + auto input = GetDefinition(startReg + i); // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (WITH_SPECULATIVE) { - input = BuildAnyTypeCheckInst(GetPc(bc_inst->GetAddress()), input, inst_save_state); + input = BuildAnyTypeCheckInst(GetPc(bcInst->GetAddress()), input, instSaveState); } inst->AppendInput(input); inst->AddInputType(DataType::ANY); @@ -254,12 +254,12 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (WITH_SPECULATIVE) { - profiling::AnyInputType allowed_input_type {}; - bool is_type_profiled = false; + profiling::AnyInputType allowedInputType {}; + bool isTypeProfiled = false; % idx = inst.profile.properties.include?('operand_types_2') ? 1 : 0 - auto operand_type = GetRuntime()->GetProfilingAnyType(profile, bc_inst, <%= idx %>, &allowed_input_type, &is_type_profiled); - input = BuildAnyTypeCheckInst(GetPc(bc_inst->GetAddress()), input, inst_save_state, operand_type, is_type_profiled, allowed_input_type); - if (OPTIONS.IsCompilerEcmaReplaceIntrinsicsToDeopt() && !is_type_profiled) { + auto operandType = GetRuntime()->GetProfilingAnyType(profile, bcInst, <%= idx %>, &allowedInputType, &isTypeProfiled); + input = BuildAnyTypeCheckInst(GetPc(bcInst->GetAddress()), input, instSaveState, operandType, isTypeProfiled, allowedInputType); + if (g_options.IsCompilerEcmaReplaceIntrinsicsToDeopt() && !isTypeProfiled) { inst->SetReplaceOnDeoptimize(); } } @@ -271,14 +271,14 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N % end % if use_ic if (!GetGraph()->IsBytecodeOptimizer()) { - inst->AppendInput(FindOrCreate32BitConstant(GetPc(bc_inst->GetAddress()))); + inst->AppendInput(FindOrCreate32BitConstant(GetPc(bcInst->GetAddress()))); inst->AddInputType(DataType::UINT16); } % end % if use_this_func if (!GetGraph()->IsBytecodeOptimizer()) { - inst->AppendInput(GetDefinition(vregs_and_args_count_ + 1 + THIS_FUNC_IDX)); + inst->AppendInput(GetDefinition(vregsAndArgsCount_ + 1 + THIS_FUNC_IDX)); inst->AddInputType(DataType::ANY); } % end @@ -297,7 +297,7 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N } % end if (inst->RequireState()) { - inst->AppendInput(inst_save_state); + inst->AppendInput(instSaveState); inst->AddInputType(DataType::NO_TYPE); } % if write_lex_env @@ -316,17 +316,17 @@ void InstBuilder::BuildEcmaAsIntrinsics(const BytecodeInstruction* bc_inst) // N % end default: failed_ = true; - LOG(ERROR,COMPILER) << "unknown Ecma opcode!" << static_cast(bc_inst->GetOpcode()); + LOG(ERROR,COMPILER) << "unknown Ecma opcode!" << static_cast(bcInst->GetOpcode()); return; } } // NOLINTNEXTLINE(readability-function-size) -void InstBuilder::BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction* bc_inst) +void InstBuilder::BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction* bcInst) { #ifdef ENABLE_BYTECODE_OPT ASSERT(!GetGraph()->IsBytecodeOptimizer()); // Not applicable for optimizing bytecode - switch (bc_inst->GetOpcode()) { + switch (bcInst->GetOpcode()) { % Panda::instructions.select{|b| b.namespace == "ecmascript"}.each do |inst| % format = "BytecodeInstruction::Format::" + inst.format.pretty.upcase % vreg_index = 0 @@ -347,22 +347,22 @@ void InstBuilder::BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction* case BytecodeInstruction::Opcode::<%= inst.opcode.upcase %>: { % inst.operands.each do |param| % if param.reg? - auto vreg<%= vreg_index %> = GetDefinition(bc_inst->GetVReg<<%= format %>, <%= vreg_index %>>()); + auto vreg<%= vreg_index %> = GetDefinition(bcInst->GetVReg<<%= format %>, <%= vreg_index %>>()); % inputs.push("vreg#{vreg_index}") % vreg_index = vreg_index + 1 % elsif param.imm? - auto imm<%= imm_index %>_payload = static_cast(bc_inst->GetImm<<%= format %>, <%= imm_index %>>()); - auto imm<%= imm_index %> = GetGraph()->FindOrCreateConstant(imm<%= imm_index %>_payload); + auto imm<%= imm_index %>Payload = static_cast(bcInst->GetImm<<%= format %>, <%= imm_index %>>()); + auto imm<%= imm_index %> = GetGraph()->FindOrCreateConstant(imm<%= imm_index %>Payload); % inputs.push("imm#{imm_index}") % imm_index = imm_index + 1 % elsif param.id? - auto id<%= id_index %>_payload = static_cast(bc_inst->template GetId<<%= format %>>().AsIndex()); - auto load_from_pool = graph_->CreateInstLoadFromConstantPool(DataType::ANY, GetPc(bc_inst->GetAddress())); - load_from_pool->SetInput(0, GetEnvDefinition(CONST_POOL_IDX)); - load_from_pool->SetTypeId(id<%= id_index %>_payload); - additional_def_ = load_from_pool; - AddInstruction(load_from_pool); -% inputs.push("load_from_pool") + auto id<%= id_index %>Payload = static_cast(bcInst->template GetId<<%= format %>>().AsIndex()); + auto loadFromPool = graph_->CreateInstLoadFromConstantPool(DataType::ANY, GetPc(bcInst->GetAddress())); + loadFromPool->SetInput(0, GetEnvDefinition(CONST_POOL_IDX)); + loadFromPool->SetTypeId(id<%= id_index %>Payload); + additionalDef_ = loadFromPool; + AddInstruction(loadFromPool); +% inputs.push("loadFromPool") % id_index = id_index + 1 % elsif param.prof? % # Just skip profile id @@ -375,7 +375,7 @@ void InstBuilder::BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction* % inputs.push('acc') % end % if inst.properties.include?('use_ic') -% inputs.push('GetGraph()->FindOrCreateConstant(GetPc(bc_inst->GetAddress()))') +% inputs.push('GetGraph()->FindOrCreateConstant(GetPc(bcInst->GetAddress()))') % end % if inst.properties.include?('func') % inputs.push('GetEnvDefinition(THIS_FUNC_IDX)') @@ -388,9 +388,9 @@ void InstBuilder::BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction* % end % builder = 'Build' + inst.opcode.split('_')[0..1].map do |_| _.capitalize end.join() - [[maybe_unused]] auto inst = <%= builder %>(GetGraph(), this, ¤t_bb_, <%= inputs.empty? ? '' : inputs.join(', ') + ', ' %>GetPc(bc_inst->GetAddress()), visited_block_marker_); + [[maybe_unused]] auto inst = <%= builder %>(GetGraph(), this, ¤tBb_, <%= inputs.empty? ? '' : inputs.join(', ') + ', ' %>GetPc(bcInst->GetAddress()), visitedBlockMarker_); % if id_index > 0 - additional_def_ = nullptr; + additionalDef_ = nullptr; % end % if inst.acc.include?('out') UpdateDefinitionAcc(inst); @@ -401,7 +401,7 @@ void InstBuilder::BuildEcmaFromIrtoc([[maybe_unused]] const BytecodeInstruction* % end default: { failed_ = true; - LOG(ERROR, COMPILER) << "Unknown ecma.* opcode: " << static_cast(bc_inst->GetOpcode()); + LOG(ERROR, COMPILER) << "Unknown ecma.* opcode: " << static_cast(bcInst->GetOpcode()); return; } } diff --git a/runtime/accessor_data.h b/runtime/accessor_data.h index 0f52782f9ecdbeb090324a9f77b4f1f3703e5e4a..3194539e45896e57077698afeefe2dc59856eeb6 100644 --- a/runtime/accessor_data.h +++ b/runtime/accessor_data.h @@ -48,17 +48,17 @@ public: { ASSERT(GetGetter().IsJSNativePointer()); JSNativePointer *getter = JSNativePointer::Cast(GetGetter().GetTaggedObject()); - auto get_func = reinterpret_cast(getter->GetExternalPointer()); - return get_func(thread, obj); + auto getFunc = reinterpret_cast(getter->GetExternalPointer()); + return getFunc(thread, obj); } bool CallInternalSet(JSThread *thread, const JSHandle &obj, const JSHandle &value, - bool may_throw = false) const + bool mayThrow = false) const { ASSERT(GetSetter().IsJSNativePointer()); JSNativePointer *setter = JSNativePointer::Cast(GetSetter().GetTaggedObject()); - auto set_func = reinterpret_cast(setter->GetExternalPointer()); - return set_func(thread, obj, value, may_throw); + auto setFunc = reinterpret_cast(setter->GetExternalPointer()); + return setFunc(thread, obj, value, mayThrow); } ACCESSORS_BASE(Record) diff --git a/runtime/asm_defines/asm_defines.def b/runtime/asm_defines/asm_defines.def index 18eca2de37927a80e31e8fefb9c9f86049c1ff7c..dac24aa4666c6ff2448552fc5cfeb91495ec1fc0 100644 --- a/runtime/asm_defines/asm_defines.def +++ b/runtime/asm_defines/asm_defines.def @@ -13,6 +13,7 @@ * limitations under the License. */ +// NOLINTBEGIN(readability-identifier-naming) DEFINE_VALUE(ECMASCRIPT_ENVIRONMENT_SIZE, panda::ecmascript::EcmascriptEnvironment::GetSize()) DEFINE_VALUE(ECMASCRIPT_ENVIRONMENT_CONSTANT_POOL_OFFSET, panda::ecmascript::EcmascriptEnvironment::GetConstantPoolOffset()) DEFINE_VALUE(ECMASCRIPT_ENVIRONMENT_LEXICAL_ENV_OFFSET, panda::ecmascript::EcmascriptEnvironment::GetLexicalEnvOffset()) @@ -133,4 +134,5 @@ DEFINE_VALUE(TAGGED_TYPE_SIZE, panda::ecmascript::JSTaggedValue::TaggedTypeSize( DEFINE_VALUE(ECMA_VM_GLOBAL_ENV_OFFSET, panda::ecmascript::EcmaVM::GetGlobalEnvOffset()) DEFINE_VALUE(GLOBAL_ENV_HEADER_SIZE, panda::ecmascript::GlobalEnv::HEADER_SIZE) DEFINE_VALUE(GLOBAL_ENV_EMPTY_ARRAY_INDEX, panda::ecmascript::GlobalEnv::EMPTY_ARRAY_OBJECT_INDEX) -DEFINE_VALUE(GLOBAL_CONST_CONSTANTS_OFFSET, panda::ecmascript::GlobalEnvConstants::GetConstantsOffset()) \ No newline at end of file +DEFINE_VALUE(GLOBAL_CONST_CONSTANTS_OFFSET, panda::ecmascript::GlobalEnvConstants::GetConstantsOffset()) +// NOLINTEND(readability-identifier-naming) diff --git a/runtime/base/array_helper.cpp b/runtime/base/array_helper.cpp index a583093f2ef80c7c27f483784bd43a6a7d7c04a8..a7a795d8194b0c0dc37f02f85a04cbeb11d8eb1c 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 = ecma_vm->GetGlobalEnv(); - JSHandle is_concatspr_key = env->GetIsConcatSpreadableSymbol(); - JSHandle spreadable = JSTaggedValue::GetProperty(thread, obj, is_concatspr_key).GetValue(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + JSHandle isConcatsprKey = env->GetIsConcatSpreadableSymbol(); + JSHandle spreadable = JSTaggedValue::GetProperty(thread, obj, isConcatsprKey).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 &callbackfn_handle, - const JSHandle &value_x, const JSHandle &value_y) +int32_t ArrayHelper::SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, + const JSHandle &valueX, const JSHandle &valueY) { // 1. If x and y are both undefined, return +0. - if (value_x->IsHole()) { - if (value_y->IsHole()) { + if (valueX->IsHole()) { + if (valueY->IsHole()) { return 0; } return 1; } - if (value_y->IsHole()) { + if (valueY->IsHole()) { return -1; } - if (value_x->IsUndefined()) { - if (value_y->IsUndefined()) { + if (valueX->IsUndefined()) { + if (valueY->IsUndefined()) { return 0; } // 2. If x is undefined, return 1. return 1; } // 3. If y is undefined, return -1. - if (value_y->IsUndefined()) { + if (valueY->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 (!callbackfn_handle->IsUndefined()) { - JSHandle this_arg_handle(thread, JSTaggedValue::Undefined()); + if (!callbackfnHandle->IsUndefined()) { + JSHandle thisArgHandle(thread, JSTaggedValue::Undefined()); - 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(); + 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(); } RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSHandle test_result(thread, call_result); - JSTaggedNumber v = JSTaggedValue::ToNumber(thread, test_result); + JSHandle testResult(thread, callResult); + JSTaggedNumber v = JSTaggedValue::ToNumber(thread, testResult); 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 x_value_handle(JSTaggedValue::ToString(thread, value_x)); + JSHandle xValueHandle(JSTaggedValue::ToString(thread, valueX)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSHandle y_value_handle(JSTaggedValue::ToString(thread, value_y)); + JSHandle yValueHandle(JSTaggedValue::ToString(thread, valueY)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - ComparisonResult compare_result = JSTaggedValue::Compare(thread, x_value_handle, y_value_handle); - return compare_result == ComparisonResult::GREAT ? 1 : 0; + ComparisonResult compareResult = JSTaggedValue::Compare(thread, xValueHandle, yValueHandle); + return compareResult == ComparisonResult::GREAT ? 1 : 0; } -double ArrayHelper::GetLength(JSThread *thread, const JSHandle &this_handle) +double ArrayHelper::GetLength(JSThread *thread, const JSHandle &thisHandle) { - if (this_handle->IsJSArray()) { - return JSArray::Cast(this_handle->GetTaggedObject())->GetArrayLength(); + if (thisHandle->IsJSArray()) { + return JSArray::Cast(thisHandle->GetTaggedObject())->GetArrayLength(); } - if (this_handle->IsTypedArray()) { - return TypedArrayHelper::GetArrayLength(thread, JSHandle::Cast(this_handle)); + if (thisHandle->IsTypedArray()) { + return TypedArrayHelper::GetArrayLength(thread, JSHandle::Cast(thisHandle)); } - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle len_result = JSTaggedValue::GetProperty(thread, this_handle, length_key).GetValue(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lenResult = JSTaggedValue::GetProperty(thread, thisHandle, lengthKey).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSTaggedNumber len = JSTaggedValue::ToLength(thread, len_result); + JSTaggedNumber len = JSTaggedValue::ToLength(thread, lenResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); return len.GetNumber(); } -double ArrayHelper::GetArrayLength(JSThread *thread, const JSHandle &this_handle) +double ArrayHelper::GetArrayLength(JSThread *thread, const JSHandle &thisHandle) { - if (this_handle->IsJSArray()) { - return JSArray::Cast(this_handle->GetTaggedObject())->GetArrayLength(); + if (thisHandle->IsJSArray()) { + return JSArray::Cast(thisHandle->GetTaggedObject())->GetArrayLength(); } - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle len_result = JSTaggedValue::GetProperty(thread, this_handle, length_key).GetValue(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lenResult = JSTaggedValue::GetProperty(thread, thisHandle, lengthKey).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSTaggedNumber len = JSTaggedValue::ToLength(thread, len_result); + JSTaggedNumber len = JSTaggedValue::ToLength(thread, lenResult); 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 d5bfbcd6bf3c273105c4bcdab9ac12f46f5ed095..2adc95fdcefdfc9e380bc21c9d6134425576a853 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 &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); + 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); }; } // namespace panda::ecmascript::base diff --git a/runtime/base/error_helper.cpp b/runtime/base/error_helper.cpp index 662cc7d53b4392cefa6bf000c53e8ca6a016ee95..696eddc7f85e6762b3d3939b611a7f20ce89d420 100644 --- a/runtime/base/error_helper.cpp +++ b/runtime/base/error_helper.cpp @@ -29,34 +29,34 @@ namespace panda::ecmascript::base { using panda::tooling::ecmascript::PtJSExtractor; -JSTaggedValue ErrorHelper::ErrorCommonToString(EcmaRuntimeCallInfo *argv, const ErrorType &error_type) +JSTaggedValue ErrorHelper::ErrorCommonToString(EcmaRuntimeCallInfo *argv, const ErrorType &errorType) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. // 2. If Type(O) is not Object, throw a TypeError exception - JSHandle this_value = builtins_common::GetThis(argv); - if (!this_value->IsECMAObject()) { + JSHandle thisValue = builtins_common::GetThis(argv); + if (!thisValue->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "ErrorToString:not an object", JSTaggedValue::Exception()); } // 3. Let name be Get(O, "name"). // 4. ReturnIfAbrupt(name). - auto global_const = thread->GlobalConstants(); - JSHandle handle_name = global_const->GetHandledNameString(); - JSHandle name = JSObject::GetProperty(thread, this_value, handle_name).GetValue(); + auto globalConst = thread->GlobalConstants(); + JSHandle handleName = globalConst->GetHandledNameString(); + JSHandle name = JSObject::GetProperty(thread, thisValue, handleName).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If name is undefined, let name be "Error"; otherwise let name be ToString(name). // 6. ReturnIfAbrupt(name). - name = ErrorHelper::GetErrorName(thread, name, error_type); + name = ErrorHelper::GetErrorName(thread, name, errorType); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let msg be Get(O, "message"). // 8. ReturnIfAbrupt(msg). - JSHandle handle_msg = global_const->GetHandledMessageString(); - JSHandle msg = JSObject::GetProperty(thread, this_value, handle_msg).GetValue(); + JSHandle handleMsg = globalConst->GetHandledMessageString(); + JSHandle msg = JSObject::GetProperty(thread, thisValue, handleMsg).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,56 +81,56 @@ 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 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); + JSHandle jsHandleName = JSHandle::Cast(name); + JSHandle jsHandleMsg = JSHandle::Cast(msg); + JSHandle handleNameSpace = factory->ConcatFromString(jsHandleName, space); + JSHandle result = factory->ConcatFromString(handleNameSpace, jsHandleMsg); return result.GetTaggedValue(); } JSHandle ErrorHelper::GetErrorName(JSThread *thread, const JSHandle &name, - const ErrorType &error_type) + const ErrorType &errorType) { - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); if (name->IsUndefined()) { - switch (error_type) { + switch (errorType) { case ErrorType::RANGE_ERROR: - return global_const->GetHandledRangeErrorString(); + return globalConst->GetHandledRangeErrorString(); case ErrorType::EVAL_ERROR: - return global_const->GetHandledEvalErrorString(); + return globalConst->GetHandledEvalErrorString(); case ErrorType::REFERENCE_ERROR: - return global_const->GetHandledReferenceErrorString(); + return globalConst->GetHandledReferenceErrorString(); case ErrorType::TYPE_ERROR: - return global_const->GetHandledTypeErrorString(); + return globalConst->GetHandledTypeErrorString(); case ErrorType::URI_ERROR: - return global_const->GetHandledURIErrorString(); + return globalConst->GetHandledURIErrorString(); case ErrorType::SYNTAX_ERROR: - return global_const->GetHandledSyntaxErrorString(); + return globalConst->GetHandledSyntaxErrorString(); default: - return global_const->GetHandledErrorString(); + return globalConst->GetHandledErrorString(); } } return JSHandle::Cast(JSTaggedValue::ToString(thread, name)); } JSTaggedValue ErrorHelper::ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, - [[maybe_unused]] const ErrorType &error_type) + [[maybe_unused]] const ErrorType &errorType) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. - auto ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle ctor = builtins_common::GetConstructor(argv); - JSMutableHandle new_target(builtins_common::GetNewTarget(argv)); - if (new_target->IsUndefined()) { - new_target.Update(ctor.GetTaggedValue()); + JSMutableHandle newTarget(builtins_common::GetNewTarget(argv)); + if (newTarget->IsUndefined()) { + newTarget.Update(ctor.GetTaggedValue()); } JSHandle message = builtins_common::GetCallArg(argv, 0); // 2. Let O be OrdinaryCreateFromConstructor(new_target, "%ErrorPrototype%", «[[ErrorData]]»). - JSHandle native_instance_obj = factory->NewJSObjectByConstructor(JSHandle(ctor), new_target); + JSHandle nativeInstanceObj = factory->NewJSObjectByConstructor(JSHandle(ctor), newTarget); // 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 global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); if (!message->IsUndefined()) { - JSHandle handle_str = JSTaggedValue::ToString(thread, message); - LOG(DEBUG, ECMASCRIPT) << "Ark throw error: " << utf::Mutf8AsCString(handle_str->GetDataUtf8()); + JSHandle handleStr = JSTaggedValue::ToString(thread, message); + LOG(DEBUG, ECMASCRIPT) << "Ark throw error: " << utf::Mutf8AsCString(handleStr->GetDataUtf8()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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); + JSHandle msgKey = globalConst->GetHandledMessageString(); + PropertyDescriptor msgDesc(thread, JSHandle::Cast(handleStr), true, false, true); + [[maybe_unused]] bool status = JSObject::DefineOwnProperty(thread, nativeInstanceObj, msgKey, msgDesc); ASSERT_PRINT(status, "return result exception!"); } - 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); + 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); ASSERT_PRINT(status, "return result exception!"); // 5. Return O. - return native_instance_obj.GetTaggedValue(); + return nativeInstanceObj.GetTaggedValue(); } PandaString ErrorHelper::DecodeFunctionName(const PandaString &name) @@ -181,7 +181,7 @@ JSHandle ErrorHelper::BuildEcmaStackTrace(JSThread *thread) PandaString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread) { - auto ecma_vm = thread->GetEcmaVM(); + auto ecmaVm = 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 *debug_extractor = ecma_vm->GetDebugInfoExtractor(method->GetPandaFile()); - const PandaString &source_file = debug_extractor->GetSourceFile(method->GetFileId()); - if (source_file.empty()) { + PtJSExtractor *debugExtractor = ecmaVm->GetDebugInfoExtractor(method->GetPandaFile()); + const PandaString &sourceFile = debugExtractor->GetSourceFile(method->GetFileId()); + if (sourceFile.empty()) { data.push_back('?'); } else { - data += source_file; + data += sourceFile; } data.push_back(':'); // line number and column number - auto callback_func = [&data](size_t line, size_t column) -> bool { + auto callbackFunc = [&data](size_t line, size_t column) -> bool { data += ToPandaString(line + 1); data.push_back(':'); data += ToPandaString(column + 1); return true; }; - if (!debug_extractor->MatchWithOffset(callback_func, method->GetFileId(), stack.GetBytecodePc())) { + if (!debugExtractor->MatchWithOffset(callbackFunc, method->GetFileId(), stack.GetBytecodePc())) { data.push_back('?'); } data.push_back(')'); diff --git a/runtime/base/error_helper.h b/runtime/base/error_helper.h index b410d2e4c230a2715b127903459aa93dbdac524f..2c4d2b245c09187eaa65a3aecf445ce2fa84ce55 100644 --- a/runtime/base/error_helper.h +++ b/runtime/base/error_helper.h @@ -27,9 +27,9 @@ constexpr char INTRINSIC_METHOD_NAME[] = "Intrinsic method"; // NOLINT (moder class ErrorHelper { public: - static JSTaggedValue ErrorCommonToString(EcmaRuntimeCallInfo *argv, const ErrorType &error_type); + static JSTaggedValue ErrorCommonToString(EcmaRuntimeCallInfo *argv, const ErrorType &errorType); - static JSTaggedValue ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, const ErrorType &error_type); + static JSTaggedValue ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, const ErrorType &errorType); static PandaString BuildNativeEcmaStackTrace(JSThread *thread); @@ -38,7 +38,7 @@ private: static JSHandle BuildEcmaStackTrace(JSThread *thread); static JSHandle GetErrorName(JSThread *thread, const JSHandle &name, - const ErrorType &error_type); + const ErrorType &errorType); }; } // namespace panda::ecmascript::base diff --git a/runtime/base/json_parser.cpp b/runtime/base/json_parser.cpp index 579d89b847fd7587305647c17f81244d1142c724..914bbb82dcfce1aeea6b0b2f4a7163b2448a0fc1 100644 --- a/runtime/base/json_parser.cpp +++ b/runtime/base/json_parser.cpp @@ -20,44 +20,44 @@ JSHandle Internalize::InternalizeJsonProperty(JSThread *thread, c const JSHandle &name, const JSHandle &receiver) { - JSHandle obj_handle(holder); - JSHandle val = JSTaggedValue::GetProperty(thread, obj_handle, name).GetValue(); - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle objHandle(holder); + JSHandle val = JSTaggedValue::GetProperty(thread, objHandle, name).GetValue(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); if (val->IsECMAObject()) { JSHandle obj = JSTaggedValue::ToObject(thread, val); - bool is_array = val->IsArray(thread); - if (is_array) { - JSHandle len_result = JSTaggedValue::GetProperty(thread, val, length_key).GetValue(); + bool isArray = val->IsArray(thread); + if (isArray) { + JSHandle lenResult = JSTaggedValue::GetProperty(thread, val, lengthKey).GetValue(); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - JSTaggedNumber len_number = JSTaggedValue::ToLength(thread, len_result); + JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread, lenResult); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - uint32_t length = len_number.ToUint32(); - JSMutableHandle key_unknow(thread, JSTaggedValue::Undefined()); - JSMutableHandle key_name(thread, JSTaggedValue::Undefined()); + uint32_t length = lenNumber.ToUint32(); + JSMutableHandle keyUnknow(thread, JSTaggedValue::Undefined()); + JSMutableHandle keyName(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; i++) { // Let prop be ! ToString((I)). - key_unknow.Update(JSTaggedValue(i)); - key_name.Update(JSTaggedValue::ToString(thread, key_unknow).GetTaggedValue()); - RecurseAndApply(thread, obj, key_name, receiver); + keyUnknow.Update(JSTaggedValue(i)); + keyName.Update(JSTaggedValue::ToString(thread, keyUnknow).GetTaggedValue()); + RecurseAndApply(thread, obj, keyName, receiver); } } else { // Let keys be ? EnumerableOwnPropertyNames(val, key). - JSHandle owner_names(JSObject::EnumerableOwnNames(thread, obj)); + JSHandle ownerNames(JSObject::EnumerableOwnNames(thread, obj)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - 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); + 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); } } } // Return ? Call(receiver, holder, « name, val »). - auto info = NewRuntimeCallInfo(thread, receiver, obj_handle, JSTaggedValue::Undefined(), 2); + auto info = NewRuntimeCallInfo(thread, receiver, objHandle, JSTaggedValue::Undefined(), 2); info->SetCallArgs(name, val); 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 change_result = false; + bool changeResult = false; // If newElement is undefined, then Perform ? val.[[Delete]](P). if (value->IsUndefined()) { - change_result = JSObject::DeleteProperty(thread, holder, name); + changeResult = JSObject::DeleteProperty(thread, holder, name); } else { // Perform ? CreateDataProperty(val, P, newElement) - change_result = JSObject::CreateDataProperty(thread, holder, name, value); + changeResult = JSObject::CreateDataProperty(thread, holder, name, value); } - return change_result; + return changeResult; } } // namespace panda::ecmascript::base diff --git a/runtime/base/json_parser.h b/runtime/base/json_parser.h index 713da40f79d401f7422c4bf061cb85679b816539..dd4fc6080f548c0da9768e79fc2352609d58cf2c 100644 --- a/runtime/base/json_parser.h +++ b/runtime/base/json_parser.h @@ -77,7 +77,7 @@ public: JSHandle ParseUtf8(EcmaString *str) { ASSERT(str != nullptr); - is_ascii_string_ = true; + isAsciiString_ = true; uint32_t len = str->GetUtf8Length(); PandaVector buf(len); str->CopyDataUtf8(buf.data(), len); @@ -125,15 +125,15 @@ private: JSTaggedValue ParseNumber() { if (IN_OBJ_OR_ARR) { - bool is_fast = true; - bool is_number = ReadNumberRange(is_fast); - if (!is_number) { + bool isFast = true; + bool isNumber = ReadNumberRange(isFast); + if (!isNumber) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } - if (is_fast) { - std::string str_num(current_, end_ + 1); + if (isFast) { + std::string strNum(current_, end_ + 1); current_ = end_; - auto d = std::stod(str_num); + auto d = std::stod(strNum); if (static_cast(d) == d) { return JSTaggedValue(static_cast(d)); } @@ -142,45 +142,45 @@ private: } Text current = current_; - bool has_exponent = false; + bool hasExponent = false; if (*current_ == '-') { if (UNLIKELY(current_++ == end_)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } } if (*current_ == '0') { - if (!CheckZeroBeginNumber(has_exponent)) { + if (!CheckZeroBeginNumber(hasExponent)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } } else if (*current_ >= '1' && *current_ <= '9') { - if (!CheckNonZeroBeginNumber(has_exponent)) { + if (!CheckNonZeroBeginNumber(hasExponent)) { 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 str_num(current, end_ + 1); + std::string strNum(current, end_ + 1); current_ = end_; - return JSTaggedValue(std::stod(str_num)); + return JSTaggedValue(std::stod(strNum)); } - bool ReadJsonStringRange(bool &is_fast_string, bool &is_ascii) + bool ReadJsonStringRange(bool &isFastString, bool &isAscii) { current_++; - if (is_ascii_string_) { - return ReadAsciiStringRange(is_fast_string); + if (isAsciiString_) { + return ReadAsciiStringRange(isFastString); } - return ReadStringRange(is_fast_string, is_ascii); + return ReadStringRange(isFastString, isAscii); } - bool IsFastParseJsonString(bool &is_fast_string, bool &is_ascii) + bool IsFastParseJsonString(bool &isFastString, bool &isAscii) { current_++; - if (is_ascii_string_) { - return IsFastParseString(is_fast_string, is_ascii); + if (isAsciiString_) { + return IsFastParseString(isFastString, isAscii); } - return IsFastParseAsciiString(is_fast_string); + return IsFastParseAsciiString(isFastString); } bool ParseBackslash(PandaString &res) @@ -219,9 +219,9 @@ private: if (UNLIKELY(!ConvertStringUnicode(vec))) { return false; } - std::u16string u16_str; - u16_str.assign(vec.begin(), vec.end()); - res += base::StringHelper::U16stringToString(u16_str); + std::u16string u16Str; + u16Str.assign(vec.begin(), vec.end()); + res += base::StringHelper::U16stringToString(u16Str); break; } default: @@ -236,8 +236,8 @@ private: PandaString res; while (current_ <= end_) { if (*current_ == '\\') { - bool is_legal_char = ParseBackslash(res); - if (!is_legal_char) { + bool isLegalChar = ParseBackslash(res); + if (!isLegalChar) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected string in JSON", JSTaggedValue::Exception()); } } else { @@ -252,16 +252,16 @@ private: template JSTaggedValue ParseString() { - bool is_fast_string = true; - bool is_ascii = true; - bool is_legal = true; + bool isFastString = true; + bool isAscii = true; + bool isLegal = true; if (IN_OBJOR_ARR) { - is_legal = ReadJsonStringRange(is_fast_string, is_ascii); - if (!is_legal) { + isLegal = ReadJsonStringRange(isFastString, isAscii); + if (!isLegal) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected end Text in JSON", JSTaggedValue::Exception()); } - if (is_fast_string) { - if (is_ascii) { + if (isFastString) { + if (isAscii) { PandaString value(current_, end_); current_ = end_; return factory_ @@ -280,12 +280,12 @@ private: if (*end_ != '"' || current_ == end_) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected end Text in JSON", JSTaggedValue::Exception()); } - is_legal = IsFastParseJsonString(is_fast_string, is_ascii); - if (!is_legal) { + isLegal = IsFastParseJsonString(isFastString, isAscii); + if (!isLegal) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected end Text in JSON", JSTaggedValue::Exception()); } - if (LIKELY(is_fast_string)) { - if (is_ascii) { + if (LIKELY(isFastString)) { + if (isAscii) { PandaString value(current_, end_); return factory_ ->NewFromUtf8LiteralUnCheck(reinterpret_cast(value.c_str()), value.length(), @@ -310,7 +310,7 @@ private: } current_++; - [[maybe_unused]] EcmaHandleScope handle_scope(thread_); + [[maybe_unused]] EcmaHandleScope handleScope(thread_); JSHandle arr = factory_->NewJSArray(); if (*current_ == ']') { return arr.GetTaggedValue(); @@ -342,7 +342,7 @@ private: THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Object in JSON", JSTaggedValue::Exception()); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread_); + [[maybe_unused]] EcmaHandleScope handleScope(thread_); JSHandle proto = env_->GetObjectFunction(); JSHandle result = factory_->NewJSObjectByConstructor(JSHandle(proto), proto); current_++; @@ -350,12 +350,12 @@ private: return result.GetTaggedValue(); } - JSMutableHandle key_handle(thread_, JSTaggedValue::Undefined()); + JSMutableHandle keyHandle(thread_, JSTaggedValue::Undefined()); JSMutableHandle value(thread_, JSTaggedValue::Undefined()); while (current_ <= range_) { SkipStartWhiteSpace(); if (*current_ == '"') { - key_handle.Update(ParseString()); + keyHandle.Update(ParseString()); } else { if (*current_ == '}' && (IN_OBJOR_ARR || current_ == range_)) { return result.GetTaggedValue(); @@ -369,7 +369,7 @@ private: THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Object in JSON", JSTaggedValue::Exception()); } value.Update(ParseJSONText()); - FastRuntimeStub::SetPropertyByValue(thread_, JSHandle(result), key_handle, value); + FastRuntimeStub::SetPropertyByValue(thread_, JSHandle(result), keyHandle, value); GetNextNonSpaceChar(); if (*current_ == ',') { current_++; @@ -443,17 +443,17 @@ private: } } - JSTaggedValue ParseLiteral(const PandaString &str, Tokens literal_token) + JSTaggedValue ParseLiteral(const PandaString &str, Tokens literalToken) { - uint32_t str_len = str.size() - 1; - uint32_t remaining_length = range_ - current_; - if (UNLIKELY(remaining_length < str_len)) { + uint32_t strLen = str.size() - 1; + uint32_t remainingLength = range_ - current_; + if (UNLIKELY(remainingLength < strLen)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Text in JSON", JSTaggedValue::Exception()); } - bool is_match = MatchText(str, str_len); - if (LIKELY(is_match)) { - switch (literal_token) { + bool isMatch = MatchText(str, strLen); + if (LIKELY(isMatch)) { + switch (literalToken) { case Tokens::LITERAL_TRUE: return JSTaggedValue::True(); case Tokens::LITERAL_FALSE: @@ -467,31 +467,31 @@ private: THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Text in JSON", JSTaggedValue::Exception()); } - bool MatchText(const PandaString &str, uint32_t match_len) + bool MatchText(const PandaString &str, uint32_t matchLen) { const char *text = str.c_str(); uint32_t pos = 1; - while (pos <= match_len) { + while (pos <= matchLen) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (current_[pos] != text[pos]) { return false; } pos++; } - current_ += match_len; + current_ += matchLen; return true; } - bool ReadNumberRange(bool &is_fast) + bool ReadNumberRange(bool &isFast) { Text current = current_; if (*current == '0') { - is_fast = false; + isFast = false; current++; } else if (*current == '-') { current++; if (*current == '0') { - is_fast = false; + isFast = false; current++; } } @@ -502,7 +502,7 @@ private: continue; } if (IsNumberSignalCharacter(*current)) { - is_fast = false; + isFast = false; current++; continue; } @@ -550,7 +550,7 @@ private: return false; } - bool IsDecimalsLegal(bool &has_exponent) + bool IsDecimalsLegal(bool &hasExponent) { if (current_ == end_ && !IsNumberCharacter(*++current_)) { return false; @@ -562,14 +562,14 @@ private: continue; } if (*current_ == 'e' || *current_ == 'E') { - if (has_exponent || current_ == end_) { + if (hasExponent || current_ == end_) { return false; } current_++; if (!IsExponentNumber()) { return false; } - has_exponent = true; + hasExponent = true; } else { return false; } @@ -577,9 +577,9 @@ private: return true; } - bool IsExponentLegal(bool &has_exponent) + bool IsExponentLegal(bool &hasExponent) { - if (has_exponent || current_ == end_) { + if (hasExponent || current_ == end_) { return false; } current_++; @@ -595,7 +595,7 @@ private: return true; } - bool ReadStringRange(bool &is_fast, bool &is_ascii) + bool ReadStringRange(bool &isFast, bool &isAscii) { T c = 0; Text current = current_; @@ -610,9 +610,9 @@ private: if (*(current + 1) == '"') { current++; } - is_fast = false; + isFast = false; } - if (!IsLegalAsciiCharacter(c, is_ascii)) { + if (!IsLegalAsciiCharacter(c, isAscii)) { return false; } current++; @@ -620,7 +620,7 @@ private: return false; } - bool ReadAsciiStringRange(bool &is_fast) + bool ReadAsciiStringRange(bool &isFast) { T c = 0; Text current = current_; @@ -635,7 +635,7 @@ private: if (*(current + 1) == '"') { current++; } - is_fast = false; + isFast = false; } else if (UNLIKELY(c < CODE_SPACE)) { return false; } @@ -644,22 +644,22 @@ private: return false; } - bool IsFastParseString(bool &is_fast, bool &is_ascii) + bool IsFastParseString(bool &isFast, bool &isAscii) { Text current = current_; while (current != end_) { - if (!IsLegalAsciiCharacter(*current, is_ascii)) { + if (!IsLegalAsciiCharacter(*current, isAscii)) { return false; } if (*current == '\\') { - is_fast = false; + isFast = false; } current++; } return true; } - bool IsFastParseAsciiString(bool &is_fast) + bool IsFastParseAsciiString(bool &isFast) { Text current = current_; while (current != end_) { @@ -667,7 +667,7 @@ private: return false; } if (*current == '\\') { - is_fast = false; + isFast = false; } current++; } @@ -676,8 +676,8 @@ private: bool ConvertStringUnicode(PandaVector &vec) { - uint32_t remaining_length = end_ - current_; - if (remaining_length < UNICODE_DIGIT_LENGTH) { + uint32_t remainingLength = end_ - current_; + if (remainingLength < UNICODE_DIGIT_LENGTH) { return false; } uint16_t res = 0; @@ -708,15 +708,15 @@ private: return true; } - bool CheckZeroBeginNumber(bool &has_exponent) + bool CheckZeroBeginNumber(bool &hasExponent) { if (current_++ != end_) { if (*current_ == '.') { - if (!IsDecimalsLegal(has_exponent)) { + if (!IsDecimalsLegal(hasExponent)) { return false; } } else if (*current_ == 'e' || *current_ == 'E') { - if (!IsExponentLegal(has_exponent)) { + if (!IsExponentLegal(hasExponent)) { return false; } } else { @@ -726,7 +726,7 @@ private: return true; } - bool CheckNonZeroBeginNumber(bool &has_exponent) + bool CheckNonZeroBeginNumber(bool &hasExponent) { while (current_ != end_) { current_++; @@ -734,11 +734,11 @@ private: continue; } if (*current_ == '.') { - if (!IsDecimalsLegal(has_exponent)) { + if (!IsDecimalsLegal(hasExponent)) { return false; } } else if (*current_ == 'e' || *current_ == 'E') { - if (!IsExponentLegal(has_exponent)) { + if (!IsExponentLegal(hasExponent)) { return false; } } else { @@ -748,16 +748,16 @@ private: return true; } - bool IsLegalAsciiCharacter(T c, bool &is_ascii) + bool IsLegalAsciiCharacter(T c, bool &isAscii) { if (c <= ASCII_END) { return c >= CODE_SPACE; } - is_ascii = false; + isAscii = false; return true; } - bool is_ascii_string_ {false}; + bool isAsciiString_ {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 46a33102efbfa3627ce081e026acd5e670f37802..ade4cd4e4eecd530075ca1ac8e0e38d810de6a4a 100644 --- a/runtime/base/json_stringifier.cpp +++ b/runtime/base/json_stringifier.cpp @@ -58,8 +58,8 @@ PandaString JsonStringifier::ValueToQuotedString(const PandaString &str) PandaString product; const char *value = str.c_str(); // fast mode - bool is_fast = IsFastValueToQuotedString(value); - if (is_fast) { + bool isFast = IsFastValueToQuotedString(value); + if (isFast) { product += "\""; product += str; product += "\""; @@ -140,14 +140,14 @@ JSHandle JsonStringifier::Stringify(const JSHandle const JSHandle &gap) { factory_ = thread_->GetEcmaVM()->GetFactory(); - handle_value_.Update(JSTaggedValue::Undefined()); - handle_key_.Update(JSTaggedValue::Undefined()); + handleValue_.Update(JSTaggedValue::Undefined()); + handleKey_.Update(JSTaggedValue::Undefined()); // Let isArray be IsArray(replacer). - bool is_array = replacer->IsArray(thread_); + bool isArray = replacer->IsArray(thread_); // ReturnIfAbrupt(isArray). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); // If isArray is true, then - if (is_array) { + if (isArray) { uint32_t len; if (replacer->IsJSArray()) { // FastPath @@ -155,16 +155,16 @@ JSHandle JsonStringifier::Stringify(const JSHandle len = arr->GetArrayLength(); } else { // Let len be ToLength(Get(replacer, "length")). - JSHandle length_key = thread_->GlobalConstants()->GetHandledLengthString(); - JSHandle len_result = JSTaggedValue::GetProperty(thread_, replacer, length_key).GetValue(); + JSHandle lengthKey = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lenResult = JSTaggedValue::GetProperty(thread_, replacer, lengthKey).GetValue(); // ReturnIfAbrupt(len). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); - JSTaggedNumber len_number = JSTaggedValue::ToLength(thread_, len_result); + JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread_, lenResult); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); - len = len_number.ToUint32(); + len = lenNumber.ToUint32(); } if (len > 0) { - JSMutableHandle prop_handle(thread_, JSTaggedValue::Undefined()); + JSMutableHandle propHandle(thread_, JSTaggedValue::Undefined()); // Repeat while k JsonStringifier::Stringify(const JSHandle * i. Append item to the end of PropertyList. * h. Let k be k+1. */ - prop_handle.Update(prop); + propHandle.Update(prop); if (prop.IsNumber() || prop.IsString()) { - AddDeduplicateProp(prop_handle); + AddDeduplicateProp(propHandle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); } else if (prop.IsJSPrimitiveRef()) { JSTaggedValue primitive = JSPrimitiveRef::Cast(prop.GetTaggedObject())->GetValue(); if (primitive.IsNumber() || primitive.IsString()) { - AddDeduplicateProp(prop_handle); + AddDeduplicateProp(propHandle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); } } @@ -233,10 +233,10 @@ JSHandle JsonStringifier::Stringify(const JSHandle return JSHandle(thread_, JSTaggedValue::Exception()); } - JSTaggedValue serialize_value = GetSerializeValue(JSHandle::Cast(wrapper), key, value, replacer); + JSTaggedValue serializeValue = GetSerializeValue(JSHandle::Cast(wrapper), key, value, replacer); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); - handle_value_.Update(serialize_value); - JSTaggedValue result = SerializeJSONProperty(handle_value_, replacer); + handleValue_.Update(serializeValue); + JSTaggedValue result = SerializeJSONProperty(handleValue_, replacer); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); if (!result.IsUndefined()) { return JSHandle( @@ -247,25 +247,25 @@ JSHandle JsonStringifier::Stringify(const JSHandle void JsonStringifier::AddDeduplicateProp(const JSHandle &property) { - uint32_t prop_len = prop_list_.size(); - for (uint32_t i = 0; i < prop_len; i++) { - if (JSTaggedValue::SameValue(prop_list_[i], property)) { + uint32_t propLen = propList_.size(); + for (uint32_t i = 0; i < propLen; i++) { + if (JSTaggedValue::SameValue(propList_[i], property)) { return; } } - JSHandle prim_string = JSTaggedValue::ToString(thread_, property); + JSHandle primString = JSTaggedValue::ToString(thread_, property); RETURN_IF_ABRUPT_COMPLETION(thread_); - JSHandle add_val(thread_, *prim_string); - prop_list_.emplace_back(add_val); + JSHandle addVal(thread_, *primString); + propList_.emplace_back(addVal); } bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap) { - double num_value = gap.GetNumber(); - int num = static_cast(num_value); + double numValue = gap.GetNumber(); + int num = static_cast(numValue); if (num > 0) { - int gap_length = std::min(num, GAP_MAX_LEN); - for (int i = 0; i < gap_length; i++) { + int gapLength = std::min(num, GAP_MAX_LEN); + for (int i = 0; i < gapLength; i++) { gap_ += " "; } gap_.append("\0"); @@ -273,13 +273,13 @@ bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap) return true; } -bool JsonStringifier::CalculateStringGap(const JSHandle &prim_string) +bool JsonStringifier::CalculateStringGap(const JSHandle &primString) { - 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); + 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); gap_ += str; gap_.append("\0"); } @@ -291,65 +291,65 @@ JSTaggedValue JsonStringifier::GetSerializeValue(const JSHandle & const JSHandle &value, const JSHandle &replacer) { - JSTaggedValue tag_value = value.GetTaggedValue(); + JSTaggedValue tagValue = value.GetTaggedValue(); // If Type(value) is Object, then if (value->IsECMAObject()) { // a. Let toJSON be Get(value, "toJSON"). - JSHandle to_json = thread_->GlobalConstants()->GetHandledToJsonString(); - JSHandle to_json_fun(thread_, FastRuntimeStub::FastGetPropertyByValue(thread_, value, to_json)); + JSHandle toJson = thread_->GlobalConstants()->GetHandledToJsonString(); + JSHandle toJsonFun(thread_, FastRuntimeStub::FastGetPropertyByValue(thread_, value, toJson)); // b. ReturnIfAbrupt(toJSON). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); // Reread tagValue because GC may move it in FastRuntimeStub::FastGetPropertyByValue - tag_value = value.GetTaggedValue(); + tagValue = value.GetTaggedValue(); // c. If IsCallable(toJSON) is true - if (UNLIKELY(to_json_fun->IsCallable())) { + if (UNLIKELY(toJsonFun->IsCallable())) { // Let value be Call(toJSON, value, «key»). - auto info = NewRuntimeCallInfo(thread_, to_json_fun, value, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread_, toJsonFun, value, JSTaggedValue::Undefined(), 1); info->SetCallArgs(key); - tag_value = JSFunction::Call(info.Get()); + tagValue = JSFunction::Call(info.Get()); // ii. ReturnIfAbrupt(value). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } } if (UNLIKELY(replacer->IsCallable())) { - handle_value_.Update(tag_value); + handleValue_.Update(tagValue); // a. Let value be Call(ReplacerFunction, holder, «key, value»). auto info = NewRuntimeCallInfo(thread_, replacer, object, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(key, handle_value_); - tag_value = JSFunction::Call(info.Get()); // 2: two args + info->SetCallArgs(key, handleValue_); + tagValue = JSFunction::Call(info.Get()); // 2: two args // b. ReturnIfAbrupt(value). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } - return tag_value; + return tagValue; } JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle &value, const JSHandle &replacer) { - JSTaggedValue tag_value = value.GetTaggedValue(); - if (!tag_value.IsHeapObject()) { - TaggedType type = tag_value.GetRawData(); + JSTaggedValue tagValue = value.GetTaggedValue(); + if (!tagValue.IsHeapObject()) { + TaggedType type = tagValue.GetRawData(); switch (type) { // If value is false, return "false". case JSTaggedValue::VALUE_FALSE: result_ += "false"; - return tag_value; + return tagValue; // If value is true, return "true". case JSTaggedValue::VALUE_TRUE: result_ += "true"; - return tag_value; + return tagValue; // If value is null, return "null". case JSTaggedValue::VALUE_NULL: result_ += "null"; - return tag_value; + return tagValue; default: // If Type(value) is Number, then - if (tag_value.IsNumber()) { + if (tagValue.IsNumber()) { // a. If value is finite, return ToString(value). - if (std::isfinite(tag_value.GetNumber())) { - result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, tag_value)); + if (std::isfinite(tagValue.GetNumber())) { + result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, tagValue)); } else { // b. Else, return "null". result_ += "null"; @@ -357,41 +357,41 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandleGetClass()->GetObjectType(); - JSHandle val_handle(thread_, tag_value); - switch (js_type) { + JSType jsType = tagValue.GetTaggedObject()->GetClass()->GetObjectType(); + JSHandle valHandle(thread_, tagValue); + switch (jsType) { case JSType::JS_ARRAY: { - SerializeJSArray(val_handle, replacer); + SerializeJSArray(valHandle, replacer); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); - return val_handle.GetTaggedValue(); + return valHandle.GetTaggedValue(); } // If Type(value) is String, return QuoteJSONString(value). case JSType::STRING: { - PandaString str = ConvertToPandaString(*JSHandle(val_handle)); + PandaString str = ConvertToPandaString(*JSHandle(valHandle)); str = ValueToQuotedString(str); result_ += str; - return val_handle.GetTaggedValue(); + return valHandle.GetTaggedValue(); } case JSType::JS_PRIMITIVE_REF: { - SerilaizePrimitiveRef(val_handle); - return val_handle.GetTaggedValue(); + SerilaizePrimitiveRef(valHandle); + return valHandle.GetTaggedValue(); } case JSType::SYMBOL: return JSTaggedValue::Undefined(); default: { - if (!val_handle->IsCallable()) { - if (UNLIKELY(val_handle->IsJSProxy())) { - SerializeJSProxy(val_handle, replacer); + if (!valHandle->IsCallable()) { + if (UNLIKELY(valHandle->IsJSProxy())) { + SerializeJSProxy(valHandle, replacer); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } else { - SerializeJSONObject(val_handle, replacer); + SerializeJSONObject(valHandle, replacer); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } - return val_handle.GetTaggedValue(); + return valHandle.GetTaggedValue(); } } } @@ -399,17 +399,17 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle &key, bool has_content) +void JsonStringifier::SerializeObjectKey(const JSHandle &key, bool hasContent) { - PandaString step_begin; - PandaString step_end; - if (has_content) { + PandaString stepBegin; + PandaString stepEnd; + if (hasContent) { result_ += ","; } if (!gap_.empty()) { - step_begin += "\n"; - step_begin += indent_; - step_end += " "; + stepBegin += "\n"; + stepBegin += indent_; + stepEnd += " "; } PandaString str; if (key->IsString()) { @@ -419,18 +419,18 @@ void JsonStringifier::SerializeObjectKey(const JSHandle &key, boo } else { str = ConvertToPandaString(*JSTaggedValue::ToString(thread_, key)); } - result_ += step_begin; + result_ += stepBegin; str = ValueToQuotedString(str); result_ += str; result_ += ":"; - result_ += step_end; + result_ += stepEnd; } bool JsonStringifier::PushValue(const JSHandle &value) { - uint32_t this_len = stack_.size(); + uint32_t thisLen = stack_.size(); - for (uint32_t i = 0; i < this_len; i++) { + for (uint32_t i = 0; i < thisLen; i++) { bool equal = JSTaggedValue::SameValue(stack_[i].GetTaggedValue(), value.GetTaggedValue()); if (equal) { return true; @@ -448,8 +448,8 @@ void JsonStringifier::PopValue() bool JsonStringifier::SerializeJSONObject(const JSHandle &value, const JSHandle &replacer) { - bool is_contain = PushValue(value); - if (is_contain) { + bool isContain = PushValue(value); + if (isContain) { THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value", true); } @@ -457,42 +457,42 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, indent_ += gap_; result_ += "{"; - bool has_content = false; + bool hasContent = false; JSHandle obj(value); if (!replacer->IsArray(thread_)) { - 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); + uint32_t numOfKeys = obj->GetNumberOfKeys(); + uint32_t numOfElements = obj->GetNumberOfElements(); + if (numOfElements > 0) { + hasContent = JsonStringifier::SerializeElements(obj, replacer, hasContent); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } - if (num_of_keys > 0) { - has_content = JsonStringifier::SerializeKeys(obj, replacer, has_content); + if (numOfKeys > 0) { + hasContent = JsonStringifier::SerializeKeys(obj, replacer, hasContent); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } else { - 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); + 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); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - if (UNLIKELY(serialize_value.IsUndefined() || serialize_value.IsSymbol() || - (serialize_value.IsECMAObject() && serialize_value.IsCallable()))) { + if (UNLIKELY(serializeValue.IsUndefined() || serializeValue.IsSymbol() || + (serializeValue.IsECMAObject() && serializeValue.IsCallable()))) { continue; } - handle_value_.Update(serialize_value); - SerializeObjectKey(prop_list_[i], has_content); - JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); + handleValue_.Update(serializeValue); + SerializeObjectKey(propList_[i], hasContent); + JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (!res.IsUndefined()) { - has_content = true; + hasContent = true; } } } - if (has_content && gap_.length() != 0) { + if (hasContent && gap_.length() != 0) { result_ += "\n"; result_ += stepback; } @@ -504,39 +504,39 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, bool JsonStringifier::SerializeJSProxy(const JSHandle &object, const JSHandle &replacer) { - bool is_contain = PushValue(object); - if (is_contain) { + bool isContain = PushValue(object); + if (isContain) { THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value", true); } PandaString stepback = indent_; - PandaString step_begin; + PandaString stepBegin; indent_ += gap_; if (!gap_.empty()) { - step_begin += "\n"; - step_begin += indent_; + stepBegin += "\n"; + stepBegin += indent_; } result_ += "["; JSHandle proxy(object); - JSHandle length_key = thread_->GlobalConstants()->GetHandledLengthString(); - JSHandle lengh_handle = JSProxy::GetProperty(thread_, proxy, length_key).GetValue(); + JSHandle lengthKey = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lenghHandle = JSProxy::GetProperty(thread_, proxy, lengthKey).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - JSTaggedNumber len_number = JSTaggedValue::ToLength(thread_, lengh_handle); + JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread_, lenghHandle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - uint32_t length = len_number.ToUint32(); + uint32_t length = lenNumber.ToUint32(); for (uint32_t i = 0; i < length; i++) { - handle_key_.Update(JSTaggedValue(i)); - JSHandle val_handle = JSProxy::GetProperty(thread_, proxy, handle_key_).GetValue(); + handleKey_.Update(JSTaggedValue(i)); + JSHandle valHandle = JSProxy::GetProperty(thread_, proxy, handleKey_).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (i > 0) { result_ += ","; } - result_ += step_begin; - JSTaggedValue serialize_value = GetSerializeValue(object, handle_key_, val_handle, replacer); + result_ += stepBegin; + JSTaggedValue serializeValue = GetSerializeValue(object, handleKey_, valHandle, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - handle_value_.Update(serialize_value); - JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); + handleValue_.Update(serializeValue); + JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (res.IsUndefined()) { result_ += "null"; @@ -556,39 +556,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 is_contain = PushValue(value); - if (is_contain) { + bool isContain = PushValue(value); + if (isContain) { THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value", true); } PandaString stepback = indent_; - PandaString step_begin; + PandaString stepBegin; indent_ += gap_; if (!gap_.empty()) { - step_begin += "\n"; - step_begin += indent_; + stepBegin += "\n"; + stepBegin += indent_; } result_ += "["; - JSHandle js_arr(value); - uint32_t len = js_arr->GetArrayLength(); + JSHandle jsArr(value); + uint32_t len = jsArr->GetArrayLength(); if (len > 0) { for (uint32_t i = 0; i < len; i++) { - 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); + JSTaggedValue tagVal = FastRuntimeStub::FastGetPropertyByIndex(thread_, value.GetTaggedValue(), i); + if (UNLIKELY(tagVal.IsAccessor())) { + tagVal = JSObject::CallGetter(thread_, AccessorData::Cast(tagVal.GetTaggedObject()), value); } - handle_value_.Update(tag_val); - handle_key_.Update(JSTaggedNumber(i).ToString(thread_).GetTaggedValue()); + handleValue_.Update(tagVal); + handleKey_.Update(JSTaggedNumber(i).ToString(thread_).GetTaggedValue()); if (i > 0) { result_ += ","; } - result_ += step_begin; - JSTaggedValue serialize_value = GetSerializeValue(value, handle_key_, handle_value_, replacer); + result_ += stepBegin; + JSTaggedValue serializeValue = GetSerializeValue(value, handleKey_, handleValue_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - handle_value_.Update(serialize_value); - JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); + handleValue_.Update(serializeValue); + JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (res.IsUndefined()) { result_ += "null"; @@ -607,20 +607,20 @@ bool JsonStringifier::SerializeJSArray(const JSHandle &value, con return true; } -void JsonStringifier::SerilaizePrimitiveRef(const JSHandle &primitive_ref) +void JsonStringifier::SerilaizePrimitiveRef(const JSHandle &primitiveRef) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(primitive_ref.GetTaggedValue().GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(primitiveRef.GetTaggedValue().GetTaggedObject())->GetValue(); if (primitive.IsString()) { - auto pri_str = JSTaggedValue::ToString(thread_, primitive_ref); + auto priStr = JSTaggedValue::ToString(thread_, primitiveRef); RETURN_IF_ABRUPT_COMPLETION(thread_); - PandaString str = ConvertToPandaString(*pri_str); + PandaString str = ConvertToPandaString(*priStr); str = ValueToQuotedString(str); result_ += str; } else if (primitive.IsNumber()) { - auto pri_num = JSTaggedValue::ToNumber(thread_, primitive_ref); + auto priNum = JSTaggedValue::ToNumber(thread_, primitiveRef); RETURN_IF_ABRUPT_COMPLETION(thread_); - if (std::isfinite(pri_num.GetNumber())) { - result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, pri_num)); + if (std::isfinite(priNum.GetNumber())) { + result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, priNum)); } else { result_ += "null"; } @@ -630,63 +630,63 @@ void JsonStringifier::SerilaizePrimitiveRef(const JSHandle &primi } bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSHandle &replacer, - bool has_content) + bool 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); + 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); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } } else { - 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); + JSHandle numberDic(elementsArr); + PandaVector> sortArr; + int size = numberDic->Size(); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = numberDic->GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = number_dic->GetAttributes(hash_index); + PropertyAttributes attr = numberDic->GetAttributes(hashIndex); if (attr.IsEnumerable()) { - auto number_key = JSTaggedValue(static_cast(key.GetInt())); - sort_arr.emplace_back(JSHandle(thread_, number_key)); + auto numberKey = JSTaggedValue(static_cast(key.GetInt())); + sortArr.emplace_back(JSHandle(thread_, numberKey)); } } } - 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); + 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); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } - return has_content; + return hasContent; } bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandle &replacer, - bool has_content) + bool hasContent) { - JSHandle own_keys = JSTaggedValue::GetOwnPropertyKeys(thread_, JSHandle(obj)); + JSHandle ownKeys = JSTaggedValue::GetOwnPropertyKeys(thread_, JSHandle(obj)); - uint32_t length = own_keys->GetLength(); + uint32_t length = ownKeys->GetLength(); for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = own_keys->Get(thread_, i); + JSTaggedValue key = ownKeys->Get(thread_, i); if (!key.IsString()) { continue; } - handle_key_.Update(key); + handleKey_.Update(key); TaggedArray *properties = TaggedArray::Cast(obj->GetProperties().GetHeapObject()); PropertyAttributes attr; - uint32_t index_or_entry = 0; - JSTaggedValue value = FastRuntimeStub::FindOwnProperty(thread_, *obj, properties, key, &attr, &index_or_entry); + uint32_t indexOrEntry = 0; + JSTaggedValue value = FastRuntimeStub::FindOwnProperty(thread_, *obj, properties, key, &attr, &indexOrEntry); if (!value.IsHole()) { if (!attr.IsEnumerable()) { continue; @@ -699,30 +699,29 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl } else { value = JSTaggedValue::Undefined(); } - handle_value_.Update(value); - has_content = JsonStringifier::AppendJsonString(obj, replacer, has_content); + handleValue_.Update(value); + hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } - return has_content; + return hasContent; } bool JsonStringifier::AppendJsonString(const JSHandle &obj, const JSHandle &replacer, - bool has_content) + bool hasContent) { - JSTaggedValue serialize_value = - GetSerializeValue(JSHandle(obj), handle_key_, handle_value_, replacer); + JSTaggedValue serializeValue = GetSerializeValue(JSHandle(obj), handleKey_, handleValue_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - if (UNLIKELY(serialize_value.IsUndefined() || serialize_value.IsSymbol() || - (serialize_value.IsECMAObject() && serialize_value.IsCallable()))) { - return has_content; + if (UNLIKELY(serializeValue.IsUndefined() || serializeValue.IsSymbol() || + (serializeValue.IsECMAObject() && serializeValue.IsCallable()))) { + return hasContent; } - handle_value_.Update(serialize_value); - SerializeObjectKey(handle_key_, has_content); - JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); + handleValue_.Update(serializeValue); + SerializeObjectKey(handleKey_, hasContent); + JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (!res.IsUndefined()) { return true; } - return has_content; + return hasContent; } } // namespace panda::ecmascript::base diff --git a/runtime/base/json_stringifier.h b/runtime/base/json_stringifier.h index b0b712dd434c19a18b4257f1d2929748f67feb0e..d66abd7a0b7e8882cc83313921ae78a4b660ba77 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), - handle_key_(thread, JSTaggedValue::Undefined()), - handle_value_(thread, JSTaggedValue::Undefined()) + handleKey_(thread, JSTaggedValue::Undefined()), + handleValue_(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 has_content); + void SerializeObjectKey(const JSHandle &key, bool hasContent); 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 &primitive_ref); + void SerilaizePrimitiveRef(const JSHandle &primitiveRef); bool PushValue(const JSHandle &value); @@ -63,10 +63,10 @@ private: bool CalculateNumberGap(JSTaggedValue gap); - 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); + 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); 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> prop_list_; - JSMutableHandle handle_key_; - JSMutableHandle handle_value_; + PandaVector> propList_; + JSMutableHandle handleKey_; + JSMutableHandle handleValue_; }; } // 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 44bd4283209f5b4529683f8fc70883f2f528a997..e367dd8bc8f5e1caff473f2b2e9a95b38f3ee1a7 100644 --- a/runtime/base/number_helper.cpp +++ b/runtime/base/number_helper.cpp @@ -72,10 +72,10 @@ bool NumberHelper::GotoNonspace(uint8_t **ptr, const uint8_t *end) size_t size = 1; if (c > INT8_MAX) { size = 0; - uint16_t utf8_bit = INT8_MAX + 1; // equal 0b1000'0000 - while (utf8_bit > 0 && (c & utf8_bit) == utf8_bit) { + uint16_t utf8Bit = INT8_MAX + 1; // equal 0b1000'0000 + while (utf8Bit > 0 && (c & utf8Bit) == utf8Bit) { ++size; - utf8_bit >>= 1UL; + utf8Bit >>= 1UL; } if (utf::ConvertRegionUtf8ToUtf16(*ptr, &c, end - *ptr, 1, 0) <= 0) { return true; @@ -108,20 +108,20 @@ JSTaggedValue NumberHelper::DoubleToString(JSThread *thread, double number, int number = -number; } - double number_integer = std::floor(number); - double number_fraction = number - number_integer; + double numberInteger = std::floor(number); + double numberFraction = number - numberInteger; auto value = bit_cast(number); value += 1; double delta = HALF * (bit_cast(value) - number); PandaString result; - if (number_fraction != 0 && number_fraction >= delta) { + if (numberFraction != 0 && numberFraction >= delta) { result += "."; - result += DecimalsToString(&number_integer, number_fraction, radix, delta); + result += DecimalsToString(&numberInteger, numberFraction, radix, delta); } - result = IntegerToString(number_integer, radix) + result; + result = IntegerToString(numberInteger, radix) + result; if (negative) { result = "-" + result; @@ -173,12 +173,12 @@ JSTaggedValue NumberHelper::DoubleToPrecision(JSThread *thread, double number, i return DoubleToFixed(thread, number, digit - 1); } PandaStringStream ss; - 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)) { - return DoubleToFixed(thread, number, std::abs(radix_digit)); + double positiveNumber = number > 0 ? number : -number; + int logDigit = std::floor(log10(positiveNumber)); + int radixDigit = digit - logDigit - 1; + const int maxExponentDigit = 6; + if ((logDigit >= 0 && radixDigit >= 0) || (logDigit < 0 && radixDigit <= maxExponentDigit)) { + return DoubleToFixed(thread, number, std::abs(radixDigit)); } return DoubleToExponential(thread, number, digit - 1); } @@ -186,76 +186,76 @@ JSTaggedValue NumberHelper::DoubleToPrecision(JSThread *thread, double number, i JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const uint8_t *end, int radix) { auto p = const_cast(start); - JSTaggedValue nan_result = builtins_common::GetTaggedDouble(NAN_VALUE); + JSTaggedValue nanResult = builtins_common::GetTaggedDouble(NAN_VALUE); // 1. skip space and line terminal if (!NumberHelper::GotoNonspace(&p, end)) { - return nan_result; + return nanResult; } // 2. sign bit bool negative = false; if (*p == '-') { negative = true; - RETURN_IF_CONVERSION_END(++p, end, nan_result); + RETURN_IF_CONVERSION_END(++p, end, nanResult); } else if (*p == '+') { - RETURN_IF_CONVERSION_END(++p, end, nan_result); + RETURN_IF_CONVERSION_END(++p, end, nanResult); } // 3. 0x or 0X - bool strip_prefix = true; + bool stripPrefix = true; // 4. If R  0, then // a. If R < 2 or R > 36, return NaN. // b. If R  16, let strip_prefix be false. if (radix != 0) { if (radix < MIN_RADIX || radix > MAX_RADIX) { - return nan_result; + return nanResult; } if (radix != HEXADECIMAL) { - strip_prefix = false; + stripPrefix = false; } } else { radix = DECIMAL; } int size = 0; - if (strip_prefix) { + if (stripPrefix) { if (*p == '0') { size++; if (++p != end && (*p == 'x' || *p == 'X')) { - RETURN_IF_CONVERSION_END(++p, end, nan_result); + RETURN_IF_CONVERSION_END(++p, end, nanResult); radix = HEXADECIMAL; } } } double result = 0; - bool is_done = false; + bool isDone = 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 maxMultiper = 0xffffffffU / 36; uint32_t m = multiplier * radix; - if (m > max_multiper) { + if (m > maxMultiper) { break; } - int current_bit = ToDigit(*p); - if (current_bit >= radix) { - is_done = true; + int currentBit = ToDigit(*p); + if (currentBit >= radix) { + isDone = true; break; } size++; - part = part * radix + current_bit; + part = part * radix + currentBit; multiplier = m; } result = result * multiplier + part; - if (is_done) { + if (isDone) { break; } } while (p != end); if (size == 0) { - return nan_result; + return nanResult; } if (negative) { @@ -287,7 +287,7 @@ PandaString NumberHelper::IntegerToString(double number, int radix) return result; } -PandaString NumberHelper::DecimalsToString(double *number_integer, double fraction, int radix, double delta) +PandaString NumberHelper::DecimalsToString(double *numberInteger, double fraction, int radix, double delta) { PandaString result; while (fraction >= delta) { @@ -297,17 +297,17 @@ PandaString NumberHelper::DecimalsToString(double *number_integer, double fracti fraction -= integer; result += CHARS[integer]; if (fraction > HALF && fraction + delta > 1) { - size_t fraction_end = result.size() - 1; - result[fraction_end] = Carry(*result.rbegin(), radix); - for (; fraction_end > 0; fraction_end--) { - if (result[fraction_end] == '0') { - result[fraction_end - 1] = Carry(result[fraction_end - 1], radix); + size_t fractionEnd = result.size() - 1; + result[fractionEnd] = Carry(*result.rbegin(), radix); + for (; fractionEnd > 0; fractionEnd--) { + if (result[fractionEnd] == '0') { + result[fractionEnd - 1] = Carry(result[fractionEnd - 1], radix); } else { break; } } - if (fraction_end == 0) { - (*number_integer)++; + if (fractionEnd == 0) { + (*numberInteger)++; } break; } @@ -326,22 +326,22 @@ PandaString NumberHelper::IntToString(int number) return ToPandaString(number); } -JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle str_val) +JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle strVal) { Span str; - auto str_obj = static_cast(str_val->GetTaggedObject()); - size_t str_len = str_obj->GetLength(); - if (str_len == 0) { + auto strObj = static_cast(strVal->GetTaggedObject()); + size_t strLen = strObj->GetLength(); + if (strLen == 0) { return BigInt::Int32ToBigInt(thread, 0).GetTaggedValue(); } - if (UNLIKELY(str_obj->IsUtf16())) { + if (UNLIKELY(strObj->IsUtf16())) { PandaVector buf; - size_t len = utf::Utf16ToUtf8Size(str_obj->GetDataUtf16(), str_len) - 1; + size_t len = utf::Utf16ToUtf8Size(strObj->GetDataUtf16(), strLen) - 1; buf.reserve(len); - len = utf::ConvertRegionUtf16ToUtf8(str_obj->GetDataUtf16(), buf.data(), str_len, len, 0); + len = utf::ConvertRegionUtf16ToUtf8(strObj->GetDataUtf16(), buf.data(), strLen, len, 0); str = Span(buf.data(), len); } else { - str = Span(str_obj->GetDataUtf8(), str_len); + str = Span(strObj->GetDataUtf8(), strLen); } auto p = const_cast(str.begin()); auto end = str.end(); @@ -389,7 +389,7 @@ JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle= radix) { - if (p_start != p && !NumberHelper::GotoNonspace(&p, end)) { + if (pStart != 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 &buf_tmp, int size) + std::array &bufTmp, int size) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - [[maybe_unused]] int result1 = snprintf_s(buf_tmp.data(), size, size - 1, "%+.*e", digits - 1, d); + [[maybe_unused]] int result1 = snprintf_s(bufTmp.data(), size, size - 1, "%+.*e", digits - 1, d); ASSERT(result1 != -1); // mantissa - buf[0] = buf_tmp[1]; + buf[0] = bufTmp[1]; if (digits > 1) { [[maybe_unused]] int result2 = - memcpy_s(buf.data() + 1, digits, buf_tmp.data() + 2, digits); // 2 means add the point char to buf + memcpy_s(buf.data() + 1, digits, bufTmp.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(buf_tmp.data() + digits + 2 + static_cast(digits > 1), nullptr, BASE) + + decpt = strtol(bufTmp.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 buf_tmp = {0}; + std::array bufTmp = {0}; // find the minimum amount of digits - 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) { + 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) { // no need to keep the trailing zeros while (digits >= 2 && buf[digits] == '0') { // 2 means ignore the integer and point digits--; } - max_digits = digits; + maxDigits = digits; } else { - min_digits = digits + 1; + minDigits = digits + 1; } } - digits = max_digits; - GetBase(d, digits, decpt, buf, buf_tmp, buf_tmp.size()); + digits = maxDigits; + GetBase(d, digits, decpt, buf, bufTmp, bufTmp.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 ignore_trailing = (flags & IGNORE_TRAILING) != 0; + bool ignoreTrailing = (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 (!ignore_trailing && NumberHelper::GotoNonspace(&p, end)) { + if (!ignoreTrailing && NumberHelper::GotoNonspace(&p, end)) { return NAN_VALUE; } return sign == Sign::NEG ? -POSITIVE_INFINITY : POSITIVE_INFINITY; } // 4. get number radix - bool leading_zero = false; - bool prefix_radix = false; + bool leadingZero = false; + bool prefixRadix = 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 ignore_trailing ? SignedZero(sign) : NAN_VALUE; + return ignoreTrailing ? SignedZero(sign) : NAN_VALUE; } RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); if (sign != Sign::NONE) { return NAN_VALUE; } - prefix_radix = true; + prefixRadix = true; radix = HEXADECIMAL; } else if (*p == 'o' || *p == 'O') { if ((flags & ALLOW_OCTAL) == 0) { - return ignore_trailing ? SignedZero(sign) : NAN_VALUE; + return ignoreTrailing ? SignedZero(sign) : NAN_VALUE; } RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); if (sign != Sign::NONE) { return NAN_VALUE; } - prefix_radix = true; + prefixRadix = true; radix = OCTAL; } else if (*p == 'b' || *p == 'B') { if ((flags & ALLOW_BINARY) == 0) { - return ignore_trailing ? SignedZero(sign) : NAN_VALUE; + return ignoreTrailing ? SignedZero(sign) : NAN_VALUE; } RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); if (sign != Sign::NONE) { return NAN_VALUE; } - prefix_radix = true; + prefixRadix = true; radix = BINARY; } else { - leading_zero = true; + leadingZero = true; } } if (radix == 0) { radix = DECIMAL; } - auto p_start = p; + auto pStart = p; // 5. skip leading '0' while (*p == '0') { RETURN_IF_CONVERSION_END(++p, end, SignedZero(sign)); - leading_zero = true; + leadingZero = true; } // 6. parse to number - uint64_t int_number = 0; - uint64_t number_max = (UINT64_MAX - (radix - 1)) / radix; + uint64_t intNumber = 0; + uint64_t numberMax = (UINT64_MAX - (radix - 1)) / radix; int digits = 0; int exponent = 0; do { uint8_t c = ToDigit(*p); if (c >= radix) { - if (!prefix_radix || ignore_trailing || (p_start != p && !NumberHelper::GotoNonspace(&p, end))) { + if (!prefixRadix || ignoreTrailing || (pStart != p && !NumberHelper::GotoNonspace(&p, end))) { break; } // "0b" "0x1.2" "0b1e2" ... return NAN_VALUE; } ++digits; - if (int_number < number_max) { - int_number = int_number * radix + c; + if (intNumber < numberMax) { + intNumber = intNumber * radix + c; } else { ++exponent; } } while (++p != end); - auto number = static_cast(int_number); + auto number = static_cast(intNumber); 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 && !leading_zero) || (p != end && !ignore_trailing && NumberHelper::GotoNonspace(&p, end))) { + if ((digits == 0 && !leadingZero) || (p != end && !ignoreTrailing && 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 && !leading_zero) { + if (digits == 0 && !leadingZero) { // no digits there, like ".", "sss", or ".e1" return NAN_VALUE; } - auto p_end = p; + auto pEnd = p; // 9. parse 'e/E' with '+/-' - char exponent_sign = '+'; - int additional_exponent = 0; + char exponentSign = '+'; + int additionalExponent = 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 == '-') { - exponent_sign = static_cast(*p); + exponentSign = static_cast(*p); RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); } uint8_t digit; while ((digit = ToDigit(*p)) < radix) { - if (additional_exponent > MAX_EXPONENT / radix) { - additional_exponent = MAX_EXPONENT; + if (additionalExponent > MAX_EXPONENT / radix) { + additionalExponent = MAX_EXPONENT; } else { - additional_exponent = additional_exponent * radix + digit; + additionalExponent = additionalExponent * radix + digit; } if (++p == end) { break; } } } - exponent += (exponent_sign == '-' ? -additional_exponent : additional_exponent); - if (!ignore_trailing && NumberHelper::GotoNonspace(&p, end)) { + exponent += (exponentSign == '-' ? -additionalExponent : additionalExponent); + if (!ignoreTrailing && 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 = p_start; i < p_end; ++i) { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + for (uint8_t *i = pStart; i < pEnd; ++i) { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (*i != static_cast('.')) { buffer += *i; } @@ -752,28 +752,28 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui static double PowHelper(uint64_t number, int16_t exponent, uint8_t radix) { - const double log_2_radix {std::log2(radix)}; + const double log2Radix {std::log2(radix)}; - double exp_rem = log_2_radix * exponent; - int exp_i = (int)exp_rem; - exp_rem = exp_rem - exp_i; + double expRem = log2Radix * exponent; + int expI = (int)expRem; + expRem = expRem - expI; // NOLINTNEXTLINE(readability-magic-numbers) - JSDoubleOperator u((double)number * std::pow(2.0, exp_rem)); + JSDoubleOperator u((double)number * std::pow(2.0, expRem)); - exp_i = u.GetExponent() + exp_i; - if (((exp_i & ~base::DOUBLE_EXPONENT_MASK) != 0) || exp_i == 0) { // NOLINT(hicpp-signed-bitwise) - if (exp_i > 0) { + expI = u.GetExponent() + expI; + if (((expI & ~base::DOUBLE_EXPONENT_MASK) != 0) || expI == 0) { // NOLINT(hicpp-signed-bitwise) + if (expI > 0) { return std::numeric_limits::infinity(); } - if (exp_i < -static_cast(base::DOUBLE_SIGNIFICAND_SIZE)) { + if (expI < -static_cast(base::DOUBLE_SIGNIFICAND_SIZE)) { return -std::numeric_limits::infinity(); } u.SetExponent(0); // NOLINTNEXTLINE(hicpp-signed-bitwise) - u.SetSignificand((u.GetSignificand() | base::DOUBLE_HIDDEN_BIT) >> (1 - exp_i)); + u.SetSignificand((u.GetSignificand() | base::DOUBLE_HIDDEN_BIT) >> (1 - expI)); } else { - u.SetExponent(exp_i); + u.SetExponent(expI); } return u.GetDouble(); @@ -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 number_max = (UINT64_MAX - (radix - 1)) / radix; + uint64_t numberMax = (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 < number_max) { + if (number < numberMax) { number = number * radix + digit; } else { ++exponent; diff --git a/runtime/base/number_helper.h b/runtime/base/number_helper.h index 3db41e4e42ebeb55e547adfbfcff0432d1cd8b28..1912bb37e448116b673fd04d01c61bba1b8a5dbf 100644 --- a/runtime/base/number_helper.h +++ b/runtime/base/number_helper.h @@ -93,13 +93,13 @@ 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 str_val); + static JSTaggedValue StringToBigInt(JSThread *thread, JSHandle strVal); private: static char Carry(char current, int radix); static double Strtod(const char *str, int exponent, uint8_t radix); static PandaString IntegerToString(double number, int radix); - static PandaString DecimalsToString(double *number_integer, double fraction, int radix, double delta); + static PandaString DecimalsToString(double *numberInteger, double fraction, int radix, double delta); static bool IsNonspace(uint16_t c); static bool GotoNonspace(uint8_t **ptr, const uint8_t *end); }; diff --git a/runtime/base/object_helper.cpp b/runtime/base/object_helper.cpp index 0949c1681cf70592a6202f4d70b4efc6f0db7c97..1ea087a1e73dbca938fcbbd0ab41aa4842f3a50e 100644 --- a/runtime/base/object_helper.cpp +++ b/runtime/base/object_helper.cpp @@ -27,13 +27,13 @@ JSTaggedValue ObjectHelper::CreateDataPropertyOnObject(EcmaRuntimeCallInfo *argv // 4. Let propertyKey be ? ToPropertyKey(key). JSHandle key = builtins_common::GetCallArg(argv, 0); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle property_key = JSTaggedValue::ToPropertyKey(thread, key); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle propertyKey = JSTaggedValue::ToPropertyKey(thread, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Perform ! CreateDataPropertyOrThrow(O, propertyKey, value). JSHandle value = builtins_common::GetCallArg(argv, 1); - JSObject::CreateDataPropertyOrThrow(thread, JSTaggedValue::ToObject(thread, object), property_key, value); + JSObject::CreateDataPropertyOrThrow(thread, JSTaggedValue::ToObject(thread, object), propertyKey, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Return undefined. @@ -52,8 +52,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 key_index(thread, JSTaggedValue(0)); - JSHandle value_index(thread, JSTaggedValue(1)); + JSHandle keyIndex(thread, JSTaggedValue(0)); + JSHandle valueIndex(thread, JSTaggedValue(1)); JSHandle next = JSIterator::IteratorStep(thread, iter); JSMutableHandle status(thread, JSTaggedValue::Undefined()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); @@ -62,29 +62,29 @@ JSTaggedValue ObjectHelper::AddEntriesFromIterable(JSThread *thread, const JSHan // ReturnIfAbrupt(next). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // Let nextValue be IteratorValue(next). - JSHandle next_value(JSIterator::IteratorValue(thread, next)); + JSHandle nextValue(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // If Type(nextItem) is not Object - if (!next_value->IsECMAObject()) { - JSHandle type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); + if (!nextValue->IsECMAObject()) { + JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); JSHandle record( - factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(type_error))); + factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(typeError))); JSTaggedValue ret = JSIterator::IteratorClose(thread, iter, record).GetTaggedValue(); if (LIKELY(!thread->HasPendingException())) { - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, type_error.GetTaggedValue(), ret); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, typeError.GetTaggedValue(), ret); }; return ret; } // Let k be Get(nextItem, "0"). - JSHandle key = JSObject::GetProperty(thread, next_value, key_index).GetValue(); + JSHandle key = JSObject::GetProperty(thread, nextValue, keyIndex).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, next_value, value_index).GetValue(); + JSHandle value = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); // If v is an abrupt completion, return IteratorClose(iter, v). if (UNLIKELY(thread->HasPendingException())) { return JSIterator::IteratorCloseAndReturn(thread, iter, value); diff --git a/runtime/base/string_helper.cpp b/runtime/base/string_helper.cpp index ebf3873c4e94b681707b167da776345589d93a8c..9017eecaf0f86b3382730be2372dd6775962e044 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 bit_set; + std::bitset bitSet; for (size_t i = 0; i < length; ++i) { char idx = *array; - if (bit_set.test(idx)) { + if (bitSet.test(idx)) { return true; } - bit_set.set(idx); + bitSet.set(idx); array++; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } } else { @@ -42,33 +42,32 @@ bool StringHelper::CheckDuplicate(EcmaString *string) return false; } -EcmaString *StringHelper::Repeat(JSThread *thread, const std::u16string &this_str, int32_t repeat_len, - bool can_be_compress) +EcmaString *StringHelper::Repeat(JSThread *thread, const std::u16string &thisStr, int32_t repeatLen, bool canBeCompress) { ecmascript::ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - if (repeat_len == 0) { + if (repeatLen == 0) { return *factory->GetEmptyString(); // Create empty EcmaString. } - std::u16string tmp_str = this_str; - for (int32_t i = 1; i < repeat_len; i++) { - tmp_str.append(this_str); + std::u16string tmpStr = thisStr; + for (int32_t i = 1; i < repeatLen; i++) { + tmpStr.append(thisStr); } - const char16_t *const_char16_t_data = tmp_str.data(); - auto *char16_t_data = const_cast(const_char16_t_data); - auto *uint16_t_data = reinterpret_cast(char16_t_data); - int32_t length = tmp_str.size(); - return *factory->NewFromUtf16UnCheck(uint16_t_data, length, can_be_compress); + const char16_t *constChar16TData = tmpStr.data(); + auto *char16TData = const_cast(constChar16TData); + auto *uint16TData = reinterpret_cast(char16TData); + int32_t length = tmpStr.size(); + return *factory->NewFromUtf16UnCheck(uint16TData, length, canBeCompress); } -EcmaString *StringHelper::Trim(JSThread *thread, const std::u16string &this_str, TrimKind kind) +EcmaString *StringHelper::Trim(JSThread *thread, const std::u16string &thisStr, TrimKind kind) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ecmascript::ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string tmp_str = this_str; - if (tmp_str.empty()) { + std::u16string tmpStr = thisStr; + if (tmpStr.empty()) { return *factory->GetEmptyString(); } - std::string str = U16stringToString(tmp_str); + std::string str = U16stringToString(tmpStr); std::wstring wstr = StringToWstring(str); std::wregex r; if (kind == TrimKind::TRIM_START) { @@ -92,20 +91,20 @@ EcmaString *StringHelper::Trim(JSThread *thread, const std::u16string &this_str, } wstr = regex_replace(wstr, r, L""); str = WstringToString(wstr); - tmp_str = StringToU16string(str); - const char16_t *const_char16_t_data = tmp_str.data(); - auto *char16_t_data = const_cast(const_char16_t_data); - auto *uint16_t_data = reinterpret_cast(char16_t_data); - int32_t length = tmp_str.size(); - return *factory->NewFromUtf16(uint16_t_data, length); + tmpStr = StringToU16string(str); + const char16_t *constChar16TData = tmpStr.data(); + auto *char16TData = const_cast(constChar16TData); + auto *uint16TData = reinterpret_cast(char16TData); + int32_t length = tmpStr.size(); + return *factory->NewFromUtf16(uint16TData, length); } // ES2021 22.1.3.15.1 StringPad ( O, max_length, fill_string, placement ) panda::ecmascript::JSTaggedValue StringHelper::StringPad(JSThread *thread, JSHandle obj, - JSHandle max_length, - JSHandle fill_string, PadPlacement placement) + JSHandle maxLength, + JSHandle fillString, PadPlacement placement) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Assert: placement is start or end. ASSERT(placement == PadPlacement::START || placement == PadPlacement::END); @@ -114,14 +113,14 @@ panda::ecmascript::JSTaggedValue StringHelper::StringPad(JSThread *thread, JSHan RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let string_length be the length of S. - size_t string_length = string->GetLength(); + size_t stringLength = string->GetLength(); // 3. Let int_max_length be ? ToLength(max_length). - size_t int_max_length = JSTaggedValue::ToLength(thread, max_length).ToUint32(); + size_t intMaxLength = JSTaggedValue::ToLength(thread, maxLength).ToUint32(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If int_max_length ≤ string_length, return S. - if (int_max_length <= string_length) { + if (intMaxLength <= stringLength) { return string.GetTaggedValue(); } @@ -129,37 +128,37 @@ panda::ecmascript::JSTaggedValue StringHelper::StringPad(JSThread *thread, JSHan // 7. Else, let filler be ? ToString(fill_string). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle filler; - if (fill_string->IsUndefined()) { + if (fillString->IsUndefined()) { filler = factory->NewFromString(" "); } else { - filler = JSTaggedValue::ToString(thread, fill_string); + filler = JSTaggedValue::ToString(thread, fillString); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 8. If filler is the empty String, return S. - size_t filler_length = filler->GetLength(); - if (filler_length == 0) { + size_t fillerLength = filler->GetLength(); + if (fillerLength == 0) { return string.GetTaggedValue(); } // 9. Let fill_len be int_max_length - string_length. - uint32_t fill_len = int_max_length - string_length; + uint32_t fillLen = intMaxLength - stringLength; // 10. Let truncated_string_filler be the String value consisting of repeated concatenations of filler truncated to // length fill_len. - 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 % filler_length]; + std::string truncatedString; + std::string fillerString = ToStdString(filler.GetObject()); + for (size_t i = 0; i < fillLen; i++) { + truncatedString += fillerString[i % fillerLength]; } - JSHandle truncated_string_filler = factory->NewFromStdString(truncated_string); + JSHandle truncatedStringFiller = factory->NewFromStdString(truncatedString); // 11. If placement is start, return the string-concatenation of truncated_string_filler and S. if (placement == PadPlacement::START) { - return factory->ConcatFromString(truncated_string_filler, string).GetTaggedValue(); + return factory->ConcatFromString(truncatedStringFiller, string).GetTaggedValue(); } // 12. Else, return the string-concatenation of S and truncated_string_filler. - return factory->ConcatFromString(string, truncated_string_filler).GetTaggedValue(); + return factory->ConcatFromString(string, truncatedStringFiller).GetTaggedValue(); } } // namespace panda::ecmascript::base diff --git a/runtime/base/string_helper.h b/runtime/base/string_helper.h index e611189b3f870d11d94797fb82a1ba8e04f9cbe6..7626406db633fc982dcc613f42b503d046642588 100644 --- a/runtime/base/string_helper.h +++ b/runtime/base/string_helper.h @@ -65,15 +65,15 @@ public: return (index != PandaString::npos); } - static inline PandaString RepalceAll(PandaString str, const PandaString &old_value, const PandaString &new_value) + static inline PandaString RepalceAll(PandaString str, const PandaString &oldValue, const PandaString &newValue) { - if (old_value.empty() || old_value == new_value) { + if (oldValue.empty() || oldValue == newValue) { return str; } PandaString::size_type pos(0); - while ((pos = str.find(old_value, pos)) != PandaString::npos) { - str.replace(pos, old_value.length(), new_value); - pos += new_value.length(); + while ((pos = str.find(oldValue, pos)) != PandaString::npos) { + str.replace(pos, oldValue.length(), newValue); + pos += newValue.length(); } return str; } @@ -84,24 +84,24 @@ public: ConvertToPandaString(string.GetObject(), start, length, StringConvertedUsage::LOGICOPERATION)); } - static inline std::u16string Utf16ToU16String(const uint16_t *utf16_data, uint32_t data_len) + static inline std::u16string Utf16ToU16String(const uint16_t *utf16Data, uint32_t dataLen) { - auto *char16t_data = reinterpret_cast(utf16_data); - std::u16string u16str(char16t_data, data_len); + auto *char16tData = reinterpret_cast(utf16Data); + std::u16string u16str(char16tData, dataLen); return u16str; } - static inline std::string Utf8ToString(const uint8_t *utf8_data, uint32_t data_len) + static inline std::string Utf8ToString(const uint8_t *utf8Data, uint32_t dataLen) { - auto *char_data = reinterpret_cast(utf8_data); - std::string str(char_data, data_len); + auto *charData = reinterpret_cast(utf8Data); + std::string str(charData, dataLen); return str; } - static inline std::u16string Utf8ToU16String(const uint8_t *utf8_data, uint32_t data_len) + static inline std::u16string Utf8ToU16String(const uint8_t *utf8Data, uint32_t dataLen) { - auto *char_data = reinterpret_cast(utf8_data); - std::string str(char_data, data_len); + auto *charData = reinterpret_cast(utf8Data); + std::string str(charData, dataLen); std::u16string u16str = std::wstring_convert, char16_t> {}.from_bytes(str); return u16str; } @@ -126,31 +126,31 @@ public: return std::wstring_convert, char16_t> {}.from_bytes(str); } - static inline size_t Find(const std::string &this_str, const std::string &search_str, int32_t pos) + static inline size_t Find(const std::string &thisStr, const std::string &searchStr, int32_t pos) { - size_t idx = this_str.find(search_str, pos); + size_t idx = thisStr.find(searchStr, pos); return idx; } - static inline size_t Find(const std::u16string &this_str, const std::u16string &search_str, int32_t pos) + static inline size_t Find(const std::u16string &thisStr, const std::u16string &searchStr, int32_t pos) { - size_t idx = this_str.find(search_str, pos); + size_t idx = thisStr.find(searchStr, pos); return idx; } - static inline size_t RFind(const std::u16string &this_str, const std::u16string &search_str, int32_t pos) + static inline size_t RFind(const std::u16string &thisStr, const std::u16string &searchStr, int32_t pos) { - size_t idx = this_str.rfind(search_str, pos); + size_t idx = thisStr.rfind(searchStr, pos); return idx; } static inline EcmaString *ToUpper(JSThread *thread, const std::u16string &str) { ecmascript::ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string tmp_str = str; - const char16_t *const_char16t_data = tmp_str.data(); - icu::UnicodeString u_string(const_char16t_data); - icu::UnicodeString up = u_string.toUpper(); + std::u16string tmpStr = str; + const char16_t *constChar16tData = tmpStr.data(); + icu::UnicodeString uString(constChar16tData); + icu::UnicodeString up = uString.toUpper(); std::string res; up.toUTF8String(res); return *factory->NewFromStdString(res); @@ -159,32 +159,31 @@ public: static inline EcmaString *ToLower(JSThread *thread, const std::u16string &str) { ecmascript::ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string tmp_str = str; - const char16_t *const_char16t_data = tmp_str.data(); - icu::UnicodeString u_string(const_char16t_data); - icu::UnicodeString low = u_string.toLower(); + std::u16string tmpStr = str; + const char16_t *constChar16tData = tmpStr.data(); + icu::UnicodeString uString(constChar16tData); + icu::UnicodeString low = uString.toLower(); std::string res; low.toUTF8String(res); return *factory->NewFromStdString(res); } - static inline size_t FindFromU16ToUpper(const std::u16string &this_str, uint16_t *u16_data) + static inline size_t FindFromU16ToUpper(const std::u16string &thisStr, uint16_t *u16Data) { - std::u16string tmp_str = Utf16ToU16String(u16_data, 1); - const char16_t *const_char16t_data = tmp_str.data(); - icu::UnicodeString u_string(const_char16t_data); - icu::UnicodeString up = u_string.toUpper(); + std::u16string tmpStr = Utf16ToU16String(u16Data, 1); + const char16_t *constChar16tData = tmpStr.data(); + icu::UnicodeString uString(constChar16tData); + icu::UnicodeString up = uString.toUpper(); std::string res; up.toUTF8String(res); - std::u16string search_str = StringToU16string(res); - size_t idx = Find(this_str, search_str, 0); + std::u16string searchStr = StringToU16string(res); + size_t idx = Find(thisStr, searchStr, 0); return idx; } - static EcmaString *Repeat(JSThread *thread, const std::u16string &this_str, int32_t repeat_len, - bool can_be_compress); + static EcmaString *Repeat(JSThread *thread, const std::u16string &thisStr, int32_t repeatLen, bool canBeCompress); - static int UnicodeFromUtf8(const uint8_t *p, int max_len, const uint8_t **pp) + static int UnicodeFromUtf8(const uint8_t *p, int maxLen, const uint8_t **pp) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) int c = *p++; @@ -208,7 +207,7 @@ public: return INVALID_UNICODE_FROM_UTF8; } /* check that we have enough characters */ - if (l > (max_len - 1)) { + if (l > (maxLen - 1)) { return INVALID_UNICODE_FROM_UTF8; } return FromUtf8(c, l, p, pp); @@ -235,16 +234,16 @@ public: return c; } - static EcmaString *Trim(JSThread *thread, const std::u16string &this_str, TrimKind kind); + static EcmaString *Trim(JSThread *thread, const std::u16string &thisStr, TrimKind kind); static panda::ecmascript::JSTaggedValue StringPad(JSThread *thread, JSHandle obj, - JSHandle max_length, - JSHandle fill_string, PadPlacement placement); + JSHandle maxLength, + JSHandle fillString, PadPlacement placement); static inline std::u16string Append(const std::u16string &str1, const std::u16string &str2) { - std::u16string tmp_str = str1; - return tmp_str.append(str2); + std::u16string tmpStr = str1; + return tmpStr.append(str2); } static inline uint32_t Utf8ToU32String(const std::vector &data) @@ -255,12 +254,12 @@ public: return *u32data; } - static inline std::string Utf32ToString(uint32_t u32_data) + static inline std::string Utf32ToString(uint32_t u32Data) { - UChar32 char_data = u32_data; - icu::UnicodeString u_string(char_data); + UChar32 charData = u32Data; + icu::UnicodeString uString(charData); std::string res; - u_string.toUTF8String(res); + uString.toUTF8String(res); return res; } }; diff --git a/runtime/base/typed_array_helper-inl.h b/runtime/base/typed_array_helper-inl.h index 93d175b45316245a843a063384305fe041bc94ca..a557addfc3510dc853399637a6ce97695ba77505 100644 --- a/runtime/base/typed_array_helper-inl.h +++ b/runtime/base/typed_array_helper-inl.h @@ -82,37 +82,37 @@ int32_t TypedArrayHelper::GetElementSize(const JSHandle &obj) } } -DataViewType TypedArrayHelper::GetTypeFromName(JSThread *thread, const JSHandle &type_name) +DataViewType TypedArrayHelper::GetTypeFromName(JSThread *thread, const JSHandle &typeName) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt8ArrayString())) { + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt8ArrayString())) { return DataViewType::INT8; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ArrayString())) { return DataViewType::UINT8; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ClampedArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ClampedArrayString())) { return DataViewType::UINT8_CLAMPED; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt16ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt16ArrayString())) { return DataViewType::INT16; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint16ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint16ArrayString())) { return DataViewType::UINT16; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt32ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt32ArrayString())) { return DataViewType::INT32; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint32ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint32ArrayString())) { return DataViewType::UINT32; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat32ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat32ArrayString())) { return DataViewType::FLOAT32; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat64ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat64ArrayString())) { return DataViewType::FLOAT64; } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledBigInt64ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledBigInt64ArrayString())) { return DataViewType::BIGINT64; } return DataViewType::BIGUINT64; @@ -148,63 +148,62 @@ JSHandle TypedArrayHelper::GetConstructor(JSThread *thread, const } } -JSHandle TypedArrayHelper::GetConstructorFromName(JSThread *thread, - const JSHandle &type_name) +JSHandle TypedArrayHelper::GetConstructorFromName(JSThread *thread, const JSHandle &typeName) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - auto global_const = thread->GlobalConstants(); - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt8ArrayString())) { + auto globalConst = thread->GlobalConstants(); + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt8ArrayString())) { return JSHandle(env->GetInt8ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ArrayString())) { return JSHandle(env->GetUint8ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ClampedArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ClampedArrayString())) { return JSHandle(env->GetUint8ClampedArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt16ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt16ArrayString())) { return JSHandle(env->GetInt16ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint16ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint16ArrayString())) { return JSHandle(env->GetUint16ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt32ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt32ArrayString())) { return JSHandle(env->GetInt32ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint32ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint32ArrayString())) { return JSHandle(env->GetUint32ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat32ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat32ArrayString())) { return JSHandle(env->GetFloat32ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat64ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat64ArrayString())) { return JSHandle(env->GetFloat64ArrayFunction()); } - if (JSTaggedValue::SameValue(type_name, global_const->GetHandledBigInt64ArrayString())) { + if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledBigInt64ArrayString())) { return JSHandle(env->GetBigInt64ArrayFunction()); } return JSHandle(env->GetBigUint64ArrayFunction()); } -int32_t TypedArrayHelper::GetSizeFromName(JSThread *thread, const JSHandle &type_name) +int32_t TypedArrayHelper::GetSizeFromName(JSThread *thread, const JSHandle &typeName) { - 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; + 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; } else { - element_size = ElementSize::EIGHT; + elementSize = ElementSize::EIGHT; } - return element_size; + return elementSize; } 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 af1864c4682ab614eed353e80c62ffc9b9e25196..90bc7e6278c40bff4b77e7b21e54e6040049a38b 100644 --- a/runtime/base/typed_array_helper.cpp +++ b/runtime/base/typed_array_helper.cpp @@ -35,43 +35,43 @@ namespace panda::ecmascript::base { // es11 22.2.4 The TypedArray Constructors JSTaggedValue TypedArrayHelper::TypedArrayConstructor(EcmaRuntimeCallInfo *argv, - const JSHandle &constructor_name) + const JSHandle &constructorName) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle new_target = builtins_common::GetNewTarget(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle newTarget = builtins_common::GetNewTarget(argv); // 2. If NewTarget is undefined, throw a TypeError exception. - if (new_target->IsUndefined()) { + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "The NewTarget is undefined.", JSTaggedValue::Exception()); } // 3. Let constructorName be the String value of the Constructor Name value specified in Table 61 for this // TypedArray constructor. // 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, "%TypedArray.prototype%"). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle first_arg = builtins_common::GetCallArg(argv, 0); - if (!first_arg->IsECMAObject()) { + JSHandle firstArg = builtins_common::GetCallArg(argv, 0); + if (!firstArg->IsECMAObject()) { // es11 22.2.4.1 TypedArray ( ) - double element_length = 0; + double elementLength = 0; // es11 22.2.4.2 TypedArray ( length ) - if (!first_arg->IsUndefined()) { - JSTaggedNumber index = JSTaggedValue::ToIndex(thread, first_arg); + if (!firstArg->IsUndefined()) { + JSTaggedNumber index = JSTaggedValue::ToIndex(thread, firstArg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - element_length = index.GetNumber(); + elementLength = index.GetNumber(); } JSHandle obj = - TypedArrayHelper::AllocateTypedArray(factory, ecma_vm, constructor_name, new_target, element_length); + TypedArrayHelper::AllocateTypedArray(factory, ecmaVm, constructorName, newTarget, elementLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return obj.GetTaggedValue(); } - JSHandle obj = TypedArrayHelper::AllocateTypedArray(factory, ecma_vm, constructor_name, new_target); + JSHandle obj = TypedArrayHelper::AllocateTypedArray(factory, ecmaVm, constructorName, newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (first_arg->IsTypedArray()) { - return TypedArrayHelper::CreateFromTypedArray(argv, obj, constructor_name); + if (firstArg->IsTypedArray()) { + return TypedArrayHelper::CreateFromTypedArray(argv, obj, constructorName); } - if (first_arg->IsArrayBuffer()) { - return TypedArrayHelper::CreateFromArrayBuffer(argv, obj, constructor_name); + if (firstArg->IsArrayBuffer()) { + return TypedArrayHelper::CreateFromArrayBuffer(argv, obj, constructorName); } return TypedArrayHelper::CreateFromOrdinaryObject(argv, obj); } @@ -81,36 +81,36 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - JSHandle object_arg = builtins_common::GetCallArg(argv, 0); - JSHandle object(object_arg); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + JSHandle objectArg = builtins_common::GetCallArg(argv, 0); + JSHandle object(objectArg); // 5. Let usingIterator be ? GetMethod(object, @@iterator). - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSHandle using_iterator = - JSObject::GetMethod(thread, JSHandle::Cast(object), iterator_symbol); + JSHandle iteratorSymbol = env->GetIteratorSymbol(); + JSHandle usingIterator = + JSObject::GetMethod(thread, JSHandle::Cast(object), iteratorSymbol); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. If usingIterator is not undefined, then - if (!using_iterator->IsUndefined()) { + if (!usingIterator->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, object_arg, using_iterator); + JSHandle iterator = JSIterator::GetIterator(thread, objectArg, usingIterator); 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 next_value = JSIterator::IteratorValue(thread, next); - vec.push_back(next_value); + JSHandle nextValue = JSIterator::IteratorValue(thread, next); + vec.push_back(nextValue); } } int32_t len = vec.size(); - TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecma_vm, obj, len); + TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, obj, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. Let k be 0. // e. Repeat, while k < len @@ -118,13 +118,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 t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - 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); + tKey.Update(JSTaggedValue(k)); + JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); + JSHandle kValue = vec[k]; + JSTaggedValue::SetProperty(thread, JSHandle::Cast(obj), kKey, kValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } @@ -136,13 +136,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 length_key = thread->GlobalConstants()->GetHandledLengthString(); - JSTaggedNumber len_temp = - JSTaggedValue::ToLength(thread, JSObject::GetProperty(thread, object_arg, length_key).GetValue()); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSTaggedNumber lenTemp = + JSTaggedValue::ToLength(thread, JSObject::GetProperty(thread, objectArg, lengthKey).GetValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double len = len_temp.GetNumber(); + double len = lenTemp.GetNumber(); // 10. Perform ? AllocateTypedArrayBuffer(O, len). - TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecma_vm, obj, len); + TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, obj, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Let k be 0. // 12. Repeat, while k < len @@ -150,14 +150,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 t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - t_key.Update(JSTaggedValue(k)); - JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); - JSHandle k_value = JSObject::GetProperty(thread, object_arg, k_key).GetValue(); + tKey.Update(JSTaggedValue(k)); + JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); + JSHandle kValue = JSObject::GetProperty(thread, objectArg, kKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(obj), k_key, k_value, true); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(obj), kKey, kValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } @@ -167,79 +167,79 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar // es11 22.2.4.3 TypedArray ( typedArray ) JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, const JSHandle &obj, - const JSHandle &constructor_name) + const JSHandle &constructorName) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 5. Let srcArray be typedArray. - JSHandle src_array = builtins_common::GetCallArg(argv, 0); - JSHandle src_obj(src_array); + JSHandle srcArray = builtins_common::GetCallArg(argv, 0); + JSHandle srcObj(srcArray); // 6. Let srcData be srcArray.[[ViewedArrayBuffer]]. - JSHandle src_data(thread, JSTypedArray::Cast(*src_obj)->GetViewedArrayBuffer()); + JSHandle srcData(thread, JSTypedArray::Cast(*srcObj)->GetViewedArrayBuffer()); // 7. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (builtins::array_buffer::IsDetachedBuffer(src_data.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(srcData.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 element_type = TypedArrayHelper::GetTypeFromName(thread, constructor_name); + DataViewType elementType = TypedArrayHelper::GetTypeFromName(thread, constructorName); // 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 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); + 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); // 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 src_byte_offset = TypedArrayHelper::GetByteOffset(thread, src_obj); - double element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); - double byte_length = element_size * element_length; + double srcByteOffset = TypedArrayHelper::GetByteOffset(thread, srcObj); + double elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); + double byteLength = elementSize * elementLength; // 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 (element_type == src_type) { - data.Update(builtins::array_buffer::CloneArrayBuffer(thread, src_data, src_byte_offset, - global_const->GetHandledUndefined())); + if (elementType == srcType) { + data.Update(builtins::array_buffer::CloneArrayBuffer(thread, srcData, srcByteOffset, + globalConst->GetHandledUndefined())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { // 19. Else, // a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). - JSHandle buffer_constructor = - JSObject::SpeciesConstructor(thread, JSHandle(src_data), env->GetArrayBufferFunction()); + JSHandle bufferConstructor = + JSObject::SpeciesConstructor(thread, JSHandle(srcData), env->GetArrayBufferFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - data.Update(builtins::array_buffer::AllocateArrayBuffer(thread, buffer_constructor, byte_length)); + data.Update(builtins::array_buffer::AllocateArrayBuffer(thread, bufferConstructor, byteLength)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (builtins::array_buffer::IsDetachedBuffer(src_data.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(srcData.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 src_byte_index = src_byte_offset; - int32_t target_byte_index = 0; + int32_t srcByteIndex = srcByteOffset; + int32_t targetByteIndex = 0; // f. Let count be elementLength. // g. Repeat, while count > 0 JSMutableHandle value(thread, JSTaggedValue::Undefined()); - for (int32_t count = element_length; count > 0; count--) { + for (int32_t count = elementLength; count > 0; count--) { // i. Let value be GetValueFromBuffer(srcData, srcByteIndex, srcType, true, Unordered). - JSTaggedValue tagged_data = - builtins::array_buffer::GetValueFromBuffer(thread, src_data, src_byte_index, src_type, true); - value.Update(tagged_data); + JSTaggedValue taggedData = + builtins::array_buffer::GetValueFromBuffer(thread, srcData, srcByteIndex, srcType, true); + value.Update(taggedData); // ii. Perform SetValueInBuffer(data, targetByteIndex, elementType, value, true, Unordered). - builtins::array_buffer::SetValueInBuffer(thread, data, target_byte_index, element_type, value, true); + builtins::array_buffer::SetValueInBuffer(thread, data, targetByteIndex, elementType, value, true); // iii. Set srcByteIndex to srcByteIndex + srcElementSize. // iv. Set targetByteIndex to targetByteIndex + elementSize. // v. Set count to count - 1. - src_byte_index = src_byte_index + src_element_size; - target_byte_index = target_byte_index + element_size; + srcByteIndex = srcByteIndex + srcElementSize; + targetByteIndex = targetByteIndex + elementSize; } } // 19. Set O’s [[ViewedArrayBuffer]] internal slot to data. @@ -247,40 +247,40 @@ 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(byte_length)); + JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(byteLength)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(0)); - JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(element_length)); + JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(elementLength)); // 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 &constructor_name) + const JSHandle &constructorName) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 5. Let elementSize be the Element Size value specified in Table 61 for constructorName. // 6. Let offset be ? ToIndex(byteOffset). - int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); - JSHandle byte_offset = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber index = JSTaggedValue::ToIndex(thread, byte_offset); + int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); + JSHandle byteOffset = builtins_common::GetCallArg(argv, 1); + JSTaggedNumber index = JSTaggedValue::ToIndex(thread, byteOffset); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto offset = static_cast(index.GetNumber()); // 7. If offset modulo elementSize ≠ 0, throw a RangeError exception. - if (offset % element_size != 0) { + if (offset % elementSize != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The offset cannot be an integral multiple of elementSize.", JSTaggedValue::Exception()); } // 8. If length is not undefined, then // a. Let new_length be ? ToIndex(length). JSHandle length = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); - int32_t new_length = 0; + int32_t newLength = 0; if (!length->IsUndefined()) { index = JSTaggedValue::ToIndex(thread, length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - new_length = static_cast(index.GetNumber()); + newLength = static_cast(index.GetNumber()); } // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. JSHandle buffer = builtins_common::GetCallArg(argv, 0); @@ -288,29 +288,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 new_length_num = + JSTaggedNumber newLengthNum = JSTaggedNumber::FromIntOrDouble(thread, JSHandle(buffer)->GetArrayBufferByteLength()); - int32_t buffer_byte_length = new_length_num.ToInt32(); + int32_t bufferByteLength = newLengthNum.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 new_byte_length; + int32_t newByteLength; if (length->IsUndefined()) { - if (buffer_byte_length % element_size != 0) { + if (bufferByteLength % elementSize != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The bufferByteLength cannot be an integral multiple of elementSize.", JSTaggedValue::Exception()); } - new_byte_length = buffer_byte_length - offset; - if (new_byte_length < 0) { + newByteLength = bufferByteLength - offset; + if (newByteLength < 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. - new_byte_length = new_length * element_size; - if (offset + new_byte_length > buffer_byte_length) { + newByteLength = newLength * elementSize; + if (offset + newByteLength > bufferByteLength) { THROW_RANGE_ERROR_AND_RETURN(thread, "The newByteLength is out of range.", JSTaggedValue::Exception()); } } @@ -319,43 +319,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(new_byte_length)); + JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(newByteLength)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(offset)); - JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(new_byte_length / element_size)); + JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(newByteLength / elementSize)); // 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 *ecma_vm, - const JSHandle &constructor_name, - const JSHandle &new_target) +JSHandle TypedArrayHelper::AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, + const JSHandle &constructorName, + const JSHandle &newTarget) { - JSThread *thread = ecma_vm->GetJSThread(); + JSThread *thread = ecmaVm->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 typed_array_func = TypedArrayHelper::GetConstructorFromName(thread, constructor_name); - JSHandle obj = factory->NewJSObjectByConstructor(typed_array_func, new_target); + JSHandle typedArrayFunc = TypedArrayHelper::GetConstructorFromName(thread, constructorName); + JSHandle obj = factory->NewJSObjectByConstructor(typedArrayFunc, newTarget); 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 *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); + JSTypedArray *jsTypedArray = JSTypedArray::Cast(*obj); + if (JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigInt64ArrayString()) || + JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigUint64ArrayString())) { + jsTypedArray->SetContentType(ContentType::BIG_INT); } else { - js_typed_array->SetContentType(ContentType::NUMBER); + jsTypedArray->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, constructor_name); + JSTypedArray::Cast(*obj)->SetTypedArrayName(thread, constructorName); JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(0)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(0)); JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(0)); @@ -364,34 +364,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 *ecma_vm, - const JSHandle &constructor_name, - const JSHandle &new_target, double length) +JSHandle TypedArrayHelper::AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, + const JSHandle &constructorName, + const JSHandle &newTarget, double length) { - JSThread *thread = ecma_vm->GetJSThread(); + JSThread *thread = ecmaVm->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 typed_array_func = TypedArrayHelper::GetConstructorFromName(thread, constructor_name); - JSHandle obj = factory->NewJSObjectByConstructor(typed_array_func, new_target); + JSHandle typedArrayFunc = TypedArrayHelper::GetConstructorFromName(thread, constructorName); + JSHandle obj = factory->NewJSObjectByConstructor(typedArrayFunc, newTarget); 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, constructor_name); + JSTypedArray::Cast(*obj)->SetTypedArrayName(thread, constructorName); // 7. If length is not present, then // 8. Else, // a. Perform ? AllocateTypedArrayBuffer(obj, length). - TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecma_vm, obj, length); + TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, 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 *ecma_vm, +JSHandle TypedArrayHelper::AllocateTypedArrayBuffer(JSThread *thread, EcmaVM *ecmaVm, const JSHandle &obj, double length) { - JSHandle env = ecma_vm->GetGlobalEnv(); + JSHandle env = ecmaVm->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. @@ -402,28 +402,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 constructor_name(thread, JSTypedArray::Cast(*obj)->GetTypedArrayName()); + JSHandle constructorName(thread, JSTypedArray::Cast(*obj)->GetTypedArrayName()); // 5. Let elementSize be the Element Size value specified in Table 61 for constructorName. - int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); + int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); // 6. Let byteLength be elementSize × length. - double byte_length = element_size * length; + double byteLength = elementSize * length; // 7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). JSHandle constructor = env->GetArrayBufferFunction(); - JSTaggedValue data = builtins::array_buffer::AllocateArrayBuffer(thread, constructor, byte_length); + JSTaggedValue data = builtins::array_buffer::AllocateArrayBuffer(thread, constructor, byteLength); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, exception); - 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); + JSTypedArray *jsTypedArray = JSTypedArray::Cast(*obj); + if (JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigInt64ArrayString()) || + JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigUint64ArrayString())) { + jsTypedArray->SetContentType(ContentType::BIG_INT); } else { - js_typed_array->SetContentType(ContentType::NUMBER); + jsTypedArray->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(byte_length)); + JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(byteLength)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(0)); JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(length)); // 12. Return O. @@ -439,13 +439,12 @@ 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 default_constructor = - TypedArrayHelper::GetConstructor(thread, JSHandle(obj)); + JSHandle defaultConstructor = TypedArrayHelper::GetConstructor(thread, JSHandle(obj)); // 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). - JSHandle this_constructor = JSObject::SpeciesConstructor(thread, obj, default_constructor); + JSHandle thisConstructor = JSObject::SpeciesConstructor(thread, obj, defaultConstructor); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); // 4. Let result be ? TypedArrayCreate(constructor, argumentList). - return TypedArrayHelper::TypedArrayCreate(thread, this_constructor, argc, argv); + return TypedArrayHelper::TypedArrayCreate(thread, thisConstructor, argc, argv); } // es11 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) @@ -458,21 +457,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 tagged_array = JSFunction::Construct(info.Get()); + JSTaggedValue taggedArray = JSFunction::Construct(info.Get()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); - if (!tagged_array.IsECMAObject()) { + if (!taggedArray.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the Typedarray.", JSHandle(thread, JSTaggedValue::Exception())); } - JSHandle tagged_array_handle(thread, tagged_array); + JSHandle taggedArrayHandle(thread, taggedArray); // 2. Perform ? ValidateTypedArray(newTypedArray). - TypedArrayHelper::ValidateTypedArray(thread, tagged_array_handle); + TypedArrayHelper::ValidateTypedArray(thread, taggedArrayHandle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); - JSHandle new_typed_array(tagged_array_handle); + JSHandle newTypedArray(taggedArrayHandle); // 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, new_typed_array) < + if (TypedArrayHelper::GetArrayLength(thread, newTypedArray) < // 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.", @@ -480,7 +479,7 @@ JSHandle TypedArrayHelper::TypedArrayCreate(JSThread *thread, const JS } } // 4. Return newTypedArray. - return new_typed_array; + return newTypedArray; } // es11 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) @@ -502,32 +501,31 @@ JSTaggedValue TypedArrayHelper::ValidateTypedArray(JSThread *thread, const JSHan return buffer; } -int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandle &callbackfn_handle, - const JSHandle &buffer, const JSHandle &first_value, - const JSHandle &second_value) +int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, + const JSHandle &buffer, const JSHandle &firstValue, + const JSHandle &secondValue) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Assert: Both Type(x) and Type(y) is Number. - ASSERT((first_value->IsNumber() && second_value->IsNumber()) || - (first_value->IsBigInt() && second_value->IsBigInt())); + ASSERT((firstValue->IsNumber() && secondValue->IsNumber()) || (firstValue->IsBigInt() && secondValue->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 (!callbackfn_handle->IsUndefined()) { - JSHandle this_arg_handle = global_const->GetHandledUndefined(); + if (!callbackfnHandle->IsUndefined()) { + JSHandle thisArgHandle = globalConst->GetHandledUndefined(); - 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 + auto info = NewRuntimeCallInfo(thread, callbackfnHandle, thisArgHandle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(firstValue, secondValue); + JSTaggedValue callResult = JSFunction::Call(info.Get()); // 2: two args RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); if (builtins::array_buffer::IsDetachedBuffer(buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The buffer is detached buffer.", 0); } - JSHandle test_result(thread, call_result); - JSTaggedNumber v = JSTaggedValue::ToNumber(thread, test_result); + JSHandle testResult(thread, callResult); + JSTaggedNumber v = JSTaggedValue::ToNumber(thread, testResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); double value = v.GetNumber(); if (std::isnan(value)) { @@ -536,39 +534,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 (compare_result == ComparisonResult::LESS) { + if (compareResult == ComparisonResult::LESS) { return -1; } - if (compare_result == ComparisonResult::GREAT) { + if (compareResult == ComparisonResult::GREAT) { return 1; } - 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)) { + 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)) { return -1; } - if (JSTaggedNumber::SameValue(x_number, p_zero) && JSTaggedNumber::SameValue(y_number, e_zero)) { + if (JSTaggedNumber::SameValue(xNumber, pZero) && JSTaggedNumber::SameValue(yNumber, eZero)) { return 1; } return +0; diff --git a/runtime/base/typed_array_helper.h b/runtime/base/typed_array_helper.h index 97db463db390921c38f0eb77ac82f15fef538e21..bd5336ac827132824c90f059b45e307030da3ab7 100644 --- a/runtime/base/typed_array_helper.h +++ b/runtime/base/typed_array_helper.h @@ -27,13 +27,13 @@ enum ElementSize : uint8_t { ONE = 1, TWO = 2, FOUR = 4, EIGHT = 8 }; class TypedArrayHelper { public: static JSTaggedValue TypedArrayConstructor(EcmaRuntimeCallInfo *argv, - 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 *ecma_vm, - const JSHandle &constructor_name, - const JSHandle &new_target, double length); + const JSHandle &constructorName); + static JSHandle AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, + const JSHandle &constructorName, + const JSHandle &newTarget); + static JSHandle AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, + const JSHandle &constructorName, + const JSHandle &newTarget, 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 &type_name); + inline static DataViewType GetTypeFromName(JSThread *thread, const JSHandle &typeName); inline static JSHandle GetConstructor(JSThread *thread, const JSHandle &obj); inline static JSHandle GetConstructorFromName(JSThread *thread, - const JSHandle &type_name); - inline static int32_t GetSizeFromName(JSThread *thread, const JSHandle &type_name); + const JSHandle &typeName); + inline static int32_t GetSizeFromName(JSThread *thread, const JSHandle &typeName); 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 &callbackfn_handle, - const JSHandle &buffer, const JSHandle &first_value, - const JSHandle &second_value); + static int32_t SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, + const JSHandle &buffer, const JSHandle &firstValue, + const JSHandle &secondValue); private: static JSTaggedValue CreateFromOrdinaryObject(EcmaRuntimeCallInfo *argv, const JSHandle &obj); static JSTaggedValue CreateFromTypedArray(EcmaRuntimeCallInfo *argv, const JSHandle &obj, - const JSHandle &constructor_name); + const JSHandle &constructorName); static JSTaggedValue CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, const JSHandle &obj, - const JSHandle &constructor_name); - static JSHandle AllocateTypedArrayBuffer(JSThread *thread, EcmaVM *ecma_vm, const JSHandle &obj, + const JSHandle &constructorName); + static JSHandle AllocateTypedArrayBuffer(JSThread *thread, EcmaVM *ecmaVm, const JSHandle &obj, double length); }; } // namespace panda::ecmascript::base diff --git a/runtime/bridge/ecma_bridge_helpers.cpp b/runtime/bridge/ecma_bridge_helpers.cpp index 210e3fb92ef216690517b76978b47c447a13ad4f..2baacd622fc4980490c75f7849cd9c03a6fb50ba 100644 --- a/runtime/bridge/ecma_bridge_helpers.cpp +++ b/runtime/bridge/ecma_bridge_helpers.cpp @@ -6,10 +6,10 @@ #include "plugins/ecmascript/compiler/ecmascript_extensions/thread_environment_api.h" namespace panda::ecmascript { -extern "C" uint64_t EcmaResolveSecondArgument(uint64_t function_tagged_value) +extern "C" uint64_t EcmaResolveSecondArgument(uint64_t functionTaggedValue) { - JSTaggedValue js_func(function_tagged_value); - if (js_func.IsJSFunction() && !JSFunction::Cast(js_func.GetHeapObject())->IsStrict()) { + JSTaggedValue jsFunc(functionTaggedValue); + if (jsFunc.IsJSFunction() && !JSFunction::Cast(jsFunc.GetHeapObject())->IsStrict()) { return JSThread::GetCurrentRaw()->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject().GetRawData(); } return JSTaggedValue::Undefined().GetRawData(); diff --git a/runtime/builtins.cpp b/runtime/builtins.cpp index 6433fcd4315d400fe54b39658056f87218f82002..2b408c73dfa77cf80616bf137158c985ebefbd15 100644 --- a/runtime/builtins.cpp +++ b/runtime/builtins.cpp @@ -67,159 +67,158 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) vm_ = thread->GetEcmaVM(); factory_ = vm_->GetFactory(); [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle null_handle(thread, JSTaggedValue::Null()); + JSHandle nullHandle(thread, JSTaggedValue::Null()); // Object.prototype[dynclass] - JSHandle obj_prototype_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, null_handle); + JSHandle objPrototypeDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, nullHandle); // Object.prototype - JSHandle obj_func_prototype = factory_->NewJSObject(obj_prototype_dynclass); - JSHandle obj_func_prototype_val(obj_func_prototype); + JSHandle objFuncPrototype = factory_->NewJSObject(objPrototypeDynclass); + JSHandle objFuncPrototypeVal(objFuncPrototype); // Object.prototype_or_dynclass - JSHandle obj_func_dynclass = - factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); + JSHandle objFuncDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); // GLobalObject.prototype_or_dynclass - 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); + JSHandle globalObjFuncDynclass = factory_->CreateDynClass(JSType::JS_GLOBAL_OBJECT, 0); + globalObjFuncDynclass->SetPrototype(thread_, objFuncPrototypeVal.GetTaggedValue()); + globalObjFuncDynclass->SetIsDictionaryMode(true); // Function.prototype_or_dynclass - JSHandle empty_func_dynclass( - factory_->CreateDynClass(JSType::JS_FUNCTION, obj_func_prototype_val, HClass::IS_CALLABLE)); - empty_func_dynclass->SetExtensible(true); + JSHandle emptyFuncDynclass( + factory_->CreateDynClass(JSType::JS_FUNCTION, objFuncPrototypeVal, HClass::IS_CALLABLE)); + emptyFuncDynclass->SetExtensible(true); // PrimitiveRef.prototype_or_dynclass - JSHandle prim_ref_obj_dynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, obj_func_prototype_val); + JSHandle primRefObjDynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, objFuncPrototypeVal); // init global object - 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); + JSHandle globalObject = factory_->NewNonMovableJSObject(globalObjFuncDynclass); + JSHandle newGlobalDynclass = JSHClass::Clone(thread_, globalObjFuncDynclass); + globalObject->SetClass(newGlobalDynclass); + env->SetJSGlobalObject(thread_, globalObject); // initialize Function, forbidden change order - InitializeFunction(env, empty_func_dynclass); + InitializeFunction(env, emptyFuncDynclass); - 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 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 async_await_status_func_class = factory_->CreateFunctionClass( + JSHandle asyncAwaitStatusFuncClass = factory_->CreateFunctionClass( FunctionKind::NORMAL_FUNCTION, JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION, env->GetFunctionPrototype()); - env->SetAsyncAwaitStatusFunctionClass(thread_, async_await_status_func_class); + env->SetAsyncAwaitStatusFunctionClass(thread_, asyncAwaitStatusFuncClass); - JSHandle async_generator_resolve_next_func_class = + JSHandle asyncGeneratorResolveNextFuncClass = factory_->CreateDynClass(JSType::JS_ASYNC_GENERATOR_RESOLVE_NEXT_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - async_generator_resolve_next_func_class->SetExtensible(true); - env->SetAsyncGeneratorResolveNextFunctionClass(thread_, async_generator_resolve_next_func_class); + asyncGeneratorResolveNextFuncClass->SetExtensible(true); + env->SetAsyncGeneratorResolveNextFunctionClass(thread_, asyncGeneratorResolveNextFuncClass); - JSHandle async_from_sync_iterator_value_unwrap_func_class = + JSHandle asyncFromSyncIteratorValueUnwrapFuncClass = factory_->CreateDynClass( JSType::JS_ASYNC_FROM_SYNC_ITERATOR_VALUE_UNWRAP_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - async_from_sync_iterator_value_unwrap_func_class->SetExtensible(true); - env->SetAsyncFromSyncIteratorValueUnwrapFunctionClass(thread_, async_from_sync_iterator_value_unwrap_func_class); + asyncFromSyncIteratorValueUnwrapFuncClass->SetExtensible(true); + env->SetAsyncFromSyncIteratorValueUnwrapFunctionClass(thread_, asyncFromSyncIteratorValueUnwrapFuncClass); - JSHandle promise_reaction_func_class = factory_->CreateDynClass( + JSHandle promiseReactionFuncClass = factory_->CreateDynClass( JSType::JS_PROMISE_REACTIONS_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - promise_reaction_func_class->SetExtensible(true); - env->SetPromiseReactionFunctionClass(thread_, promise_reaction_func_class); + promiseReactionFuncClass->SetExtensible(true); + env->SetPromiseReactionFunctionClass(thread_, promiseReactionFuncClass); - JSHandle promise_executor_func_class = factory_->CreateDynClass( + JSHandle promiseExecutorFuncClass = factory_->CreateDynClass( JSType::JS_PROMISE_EXECUTOR_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - promise_executor_func_class->SetExtensible(true); - env->SetPromiseExecutorFunctionClass(thread_, promise_executor_func_class); + promiseExecutorFuncClass->SetExtensible(true); + env->SetPromiseExecutorFunctionClass(thread_, promiseExecutorFuncClass); - JSHandle promise_all_resolve_element_function_class = + JSHandle promiseAllResolveElementFunctionClass = factory_->CreateDynClass(JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - promise_all_resolve_element_function_class->SetExtensible(true); - env->SetPromiseAllResolveElementFunctionClass(thread_, promise_all_resolve_element_function_class); + promiseAllResolveElementFunctionClass->SetExtensible(true); + env->SetPromiseAllResolveElementFunctionClass(thread_, promiseAllResolveElementFunctionClass); - JSHandle proxy_revoc_func_class = factory_->CreateDynClass( + JSHandle proxyRevocFuncClass = factory_->CreateDynClass( JSType::JS_PROXY_REVOC_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - proxy_revoc_func_class->SetExtensible(true); - env->SetProxyRevocFunctionClass(thread_, proxy_revoc_func_class); + proxyRevocFuncClass->SetExtensible(true); + env->SetProxyRevocFunctionClass(thread_, proxyRevocFuncClass); // Object = new Function() - JSHandle object_function( - NewBuiltinConstructor(env, obj_func_prototype, object::ObjectConstructor, "Object", FunctionLength::ONE)); - object_function.GetObject()->SetFunctionPrototype(thread_, obj_func_dynclass.GetTaggedValue()); + JSHandle objectFunction( + NewBuiltinConstructor(env, objFuncPrototype, object::ObjectConstructor, "Object", FunctionLength::ONE)); + objectFunction.GetObject()->SetFunctionPrototype(thread_, objFuncDynclass.GetTaggedValue()); // initialize object method. - env->SetObjectFunction(thread_, object_function); - env->SetObjectFunctionPrototype(thread_, obj_func_prototype); + env->SetObjectFunction(thread_, objectFunction); + env->SetObjectFunctionPrototype(thread_, objFuncPrototype); - JSHandle function_class = factory_->CreateFunctionClass( + JSHandle functionClass = factory_->CreateFunctionClass( FunctionKind::BASE_CONSTRUCTOR, JSType::JS_FUNCTION, env->GetFunctionPrototype()); - 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); + 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); if (env == vm_->GetGlobalEnv()) { - InitializeAllTypeError(env, obj_func_dynclass); - InitializeSymbol(env, prim_ref_obj_dynclass); + InitializeAllTypeError(env, objFuncDynclass); + InitializeSymbol(env, primRefObjDynclass); } else { // error and symbol need to be shared when initialize realm InitializeAllTypeErrorWithRealm(env); - InitializeSymbolWithRealm(env, prim_ref_obj_dynclass); + InitializeSymbolWithRealm(env, primRefObjDynclass); } - InitializeNumber(env, 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); + InitializeNumber(env, primRefObjDynclass); + InitializeBigInt(env, objFuncDynclass); + InitializeDate(env, objFuncDynclass); + InitializeObject(env, objFuncPrototype, objectFunction); + InitializeBoolean(env, primRefObjDynclass); InitializeRegExp(env); - 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); + 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); SetArgumentsSharedAccessor(env); - 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); + InitializeGlobalObject(env, globalObject); + InitializeMath(env, objFuncPrototypeVal); + InitializeJson(env, objFuncPrototypeVal); + InitializeIterator(env, objFuncDynclass); + InitializeAsyncIterator(env, objFuncDynclass); InitializeProxy(env); - 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); + InitializeReflect(env, objFuncPrototypeVal); + InitializeAsyncFunction(env, objFuncDynclass); + InitializeGenerator(env, objFuncDynclass); + InitializeGeneratorFunction(env, objFuncDynclass); + InitializeAsyncGenerator(env, objFuncDynclass); + InitializeAsyncGeneratorFunction(env, objFuncDynclass); + InitializeAsyncFromSyncIteratorPrototypeObject(env, objFuncDynclass); + InitializePromise(env, objFuncDynclass); InitializePromiseJob(env); - InitializeFinalizationRegistry(env, obj_func_dynclass); + InitializeFinalizationRegistry(env, objFuncDynclass); - std::string icu_path = vm_->GetJSOptions().GetIcuDataPath(); - if (icu_path == "default") { + std::string icuPath = vm_->GetJSOptions().GetIcuDataPath(); + if (icuPath == "default") { SetIcuDirectory(); } else { - u_setDataDirectory(icu_path.c_str()); + u_setDataDirectory(icuPath.c_str()); } - InitializeIntl(env, obj_func_prototype_val); + InitializeIntl(env, objFuncPrototypeVal); InitializeLocale(env); InitializeDateTimeFormat(env); InitializeNumberFormat(env); @@ -227,16 +226,16 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) InitializeCollator(env); InitializePluralRules(env); - JSHandle generator_func_class = factory_->CreateFunctionClass( + JSHandle generatorFuncClass = factory_->CreateFunctionClass( FunctionKind::GENERATOR_FUNCTION, JSType::JS_GENERATOR_FUNCTION, env->GetGeneratorFunctionPrototype()); - env->SetGeneratorFunctionClass(thread_, generator_func_class); + env->SetGeneratorFunctionClass(thread_, generatorFuncClass); - JSHandle async_generator_func_class = factory_->CreateFunctionClass( + JSHandle asyncGeneratorFuncClass = factory_->CreateFunctionClass( FunctionKind::ASYNC_GENERATOR_FUNCTION, JSType::JS_ASYNC_GENERATOR_FUNCTION, env->GetAsyncGeneratorFunctionPrototype()); - env->SetAsyncGeneratorFunctionClass(thread_, async_generator_func_class); + env->SetAsyncGeneratorFunctionClass(thread_, asyncGeneratorFuncClass); - env->SetObjectFunctionPrototypeClass(thread_, JSTaggedValue(obj_func_prototype->GetClass())); + env->SetObjectFunctionPrototypeClass(thread_, JSTaggedValue(objFuncPrototype->GetClass())); thread_->ResetGuardians(); #ifdef FUZZING_FUZZILLI_BUILTIN @@ -244,7 +243,7 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) #endif } -void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHandle &global_object) +void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHandle &globalObject) { [[maybe_unused]] EcmaHandleScope scope(thread_); @@ -252,13 +251,13 @@ void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHa // NOTE(ivagin): Remove ArkTools? if (vm_->GetJSOptions().IsEnableArkTools()) { - JSHandle ark_tools(InitializeArkTools(env)); - SetConstantObject(global_object, "ArkTools", ark_tools); + JSHandle arkTools(InitializeArkTools(env)); + SetConstantObject(globalObject, "ArkTools", arkTools); } #ifndef PANDA_PRODUCT_BUILD - JSHandle runtime_testing(InitializeRuntimeTesting(env)); - SetConstantObject(global_object, "RuntimeTesting", runtime_testing); + JSHandle runtimeTesting(InitializeRuntimeTesting(env)); + SetConstantObject(globalObject, "RuntimeTesting", runtimeTesting); #endif // PANDA_PRODUCT_BUILD #if ECMASCRIPT_ENABLE_ARK_CONTAINER @@ -268,198 +267,195 @@ void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHa #endif // Global object property - SetGlobalThis(global_object, "globalThis", JSHandle::Cast(global_object)); - SetConstant(global_object, "Infinity", JSTaggedValue(base::POSITIVE_INFINITY)); - SetConstant(global_object, "NaN", JSTaggedValue(base::NAN_VALUE)); - SetConstant(global_object, "undefined", JSTaggedValue::Undefined()); + 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()); - SetFunctionsGenGlobal(env, global_object); + SetFunctionsGenGlobal(env, globalObject); } -void Builtins::InitializeFunction(const JSHandle &env, const JSHandle &empty_func_dynclass) const +void Builtins::InitializeFunction(const JSHandle &env, const JSHandle &emptyFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Initialize Function.prototype - JSMethod *invoke_self = + JSMethod *invokeSelf = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionPrototypeInvokeSelf)); - JSHandle func_func_prototype = factory_->NewJSFunctionByDynClass(invoke_self, empty_func_dynclass); + JSHandle funcFuncPrototype = factory_->NewJSFunctionByDynClass(invokeSelf, emptyFuncDynclass); // ecma 19.2.3 The value of the name property of the Function prototype object is the empty String. - JSHandle empty_string(thread_->GlobalConstants()->GetHandledEmptyString()); - JSHandle undefined_string(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, JSHandle(func_func_prototype), empty_string, undefined_string); + JSHandle emptyString(thread_->GlobalConstants()->GetHandledEmptyString()); + JSHandle undefinedString(thread_, JSTaggedValue::Undefined()); + JSFunction::SetFunctionName(thread_, JSHandle(funcFuncPrototype), emptyString, undefinedString); // ecma 19.2.3 The value of the length property of the Function prototype object is 0. - JSFunction::SetFunctionLength(thread_, func_func_prototype, JSTaggedValue(FunctionLength::ZERO)); + JSFunction::SetFunctionLength(thread_, funcFuncPrototype, JSTaggedValue(FunctionLength::ZERO)); - JSHandle func_func_prototype_value(func_func_prototype); + JSHandle funcFuncPrototypeValue(funcFuncPrototype); // Function.prototype_or_dynclass - 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); + JSHandle funcFuncIntanceDynclass = factory_->CreateDynClass( + JSType::JS_FUNCTION, funcFuncPrototypeValue, HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); + funcFuncIntanceDynclass->SetConstructor(true); // Function = new Function() (forbidden use NewBuiltinConstructor) JSMethod *ctor = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionConstructor)); - JSHandle func_func = - factory_->NewJSFunctionByDynClass(ctor, func_func_intance_dynclass, FunctionKind::BUILTIN_CONSTRUCTOR); + JSHandle funcFunc = + factory_->NewJSFunctionByDynClass(ctor, funcFuncIntanceDynclass, FunctionKind::BUILTIN_CONSTRUCTOR); - auto func_func_prototype_obj = JSHandle(func_func_prototype); - InitializeCtor(env, func_func_prototype_obj, func_func, "Function", FunctionLength::ONE); + auto funcFuncPrototypeObj = JSHandle(funcFuncPrototype); + InitializeCtor(env, funcFuncPrototypeObj, funcFunc, "Function", FunctionLength::ONE); - func_func->SetFunctionPrototype(thread_, func_func_intance_dynclass.GetTaggedValue()); - env->SetFunctionFunction(thread_, func_func); - env->SetFunctionPrototype(thread_, func_func_prototype); + funcFunc->SetFunctionPrototype(thread_, funcFuncIntanceDynclass.GetTaggedValue()); + env->SetFunctionFunction(thread_, funcFunc); + env->SetFunctionPrototype(thread_, funcFuncPrototype); - JSHandle normal_func_class = + JSHandle normalFuncClass = factory_->CreateDynClass(JSType::JS_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - env->SetNormalFunctionClass(thread_, normal_func_class); + env->SetNormalFunctionClass(thread_, normalFuncClass); - JSHandle j_s_intl_bound_function_class = factory_->CreateFunctionClass( + JSHandle jSIntlBoundFunctionClass = factory_->CreateFunctionClass( FunctionKind::NORMAL_FUNCTION, JSType::JS_INTL_BOUND_FUNCTION, env->GetFunctionPrototype()); - env->SetJSIntlBoundFunctionClass(thread_, j_s_intl_bound_function_class); + env->SetJSIntlBoundFunctionClass(thread_, jSIntlBoundFunctionClass); - JSHandle constructor_function_class = factory_->CreateDynClass( + JSHandle constructorFunctionClass = factory_->CreateDynClass( JSType::JS_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); - constructor_function_class->SetConstructor(true); - env->SetConstructorFunctionClass(thread_, constructor_function_class); + constructorFunctionClass->SetConstructor(true); + env->SetConstructorFunctionClass(thread_, constructorFunctionClass); - StrictModeForbiddenAccessCallerArguments(env, func_func_prototype_obj); + StrictModeForbiddenAccessCallerArguments(env, funcFuncPrototypeObj); - SetFunctionsGenFunctionProto(env, func_func_prototype_obj); + SetFunctionsGenFunctionProto(env, funcFuncPrototypeObj); } -void Builtins::InitializeObject(const JSHandle &env, const JSHandle &obj_func_prototype, - const JSHandle &obj_func) +void Builtins::InitializeObject(const JSHandle &env, const JSHandle &objFuncPrototype, + const JSHandle &objFunc) { [[maybe_unused]] EcmaHandleScope scope(thread_); - SetFunctionsGenObject(env, obj_func); + SetFunctionsGenObject(env, objFunc); - SetFunctionsGenObjectProto(env, obj_func_prototype); + SetFunctionsGenObjectProto(env, objFuncPrototype); } -void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // Symbol.prototype - JSHandle symbol_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle symbol_func_prototype_value(symbol_func_prototype); + JSHandle symbolFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle symbolFuncPrototypeValue(symbolFuncPrototype); // Symbol.prototype_or_dynclass - JSHandle symbol_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbol_func_prototype_value); + JSHandle symbolFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbolFuncPrototypeValue); // Symbol = new Function() - JSHandle symbol_function(NewBuiltinConstructor( - env, symbol_func_prototype, builtins::symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); - JSHandle(symbol_function) - ->SetFunctionPrototype(thread_, symbol_func_instance_dynclass.GetTaggedValue()); + JSHandle symbolFunction(NewBuiltinConstructor( + env, symbolFuncPrototype, builtins::symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); + JSHandle(symbolFunction)->SetFunctionPrototype(thread_, symbolFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - 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); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + PropertyDescriptor descriptor(thread_, JSHandle::Cast(symbolFunction), true, false, true); + JSObject::DefineOwnProperty(thread_, symbolFuncPrototype, constructorKey, descriptor); // Symbol attribute - 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); - - 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); + 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); + + 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); // Setup %SymbolPrototype% - SetStringTagSymbol(env, symbol_func_prototype, "Symbol"); + SetStringTagSymbol(env, symbolFuncPrototype, "Symbol"); - 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()); + JSHandle holeySymbol(factory_->NewPrivateNameSymbolWithChar("holey")); + env->SetHoleySymbol(thread_, holeySymbol.GetTaggedValue()); + JSHandle elementIcSymbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); + env->SetElementICSymbol(thread_, elementIcSymbol.GetTaggedValue()); // ecma 19.2.3.6 Function.prototype[@@hasInstance] ( V ) - JSHandle func_func_prototype_obj = JSHandle(env->GetFunctionPrototype()); + JSHandle funcFuncPrototypeObj = JSHandle(env->GetFunctionPrototype()); SetFunctionAtSymbol( - env, func_func_prototype_obj, env->GetHasInstanceSymbol(), "[Symbol.hasInstance]", + env, funcFuncPrototypeObj, env->GetHasInstanceSymbol(), "[Symbol.hasInstance]", builtins::function::proto::HasInstance, FunctionLength::ONE); - SetFunctionsGenSymbol(env, symbol_function); - SetFunctionsGenSymbolProto(env, symbol_func_prototype); + SetFunctionsGenSymbol(env, symbolFunction); + SetFunctionsGenSymbolProto(env, symbolFuncPrototype); } void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, - const JSHandle &obj_func_instance_dynclass) + const JSHandle &objFuncInstanceDynclass) { [[maybe_unused]] EcmaHandleScope scope(thread_); JSHandle env = vm_->GetGlobalEnv(); // Symbol.prototype - JSHandle symbol_func_prototype = factory_->NewJSObject(obj_func_instance_dynclass); - JSHandle symbol_func_prototype_value(symbol_func_prototype); + JSHandle symbolFuncPrototype = factory_->NewJSObject(objFuncInstanceDynclass); + JSHandle symbolFuncPrototypeValue(symbolFuncPrototype); // Symbol.prototype_or_dynclass - JSHandle symbol_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbol_func_prototype_value); + JSHandle symbolFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbolFuncPrototypeValue); // Symbol = new Function() - JSHandle symbol_function(NewBuiltinConstructor( - realm, symbol_func_prototype, builtins::symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); - JSHandle(symbol_function) - ->SetFunctionPrototype(thread_, symbol_func_instance_dynclass.GetTaggedValue()); + JSHandle symbolFunction(NewBuiltinConstructor( + realm, symbolFuncPrototype, builtins::symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); + JSHandle(symbolFunction)->SetFunctionPrototype(thread_, symbolFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - 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); + JSHandle constructorKey = thread_->GlobalConstants()->GetHandledConstructorString(); + PropertyDescriptor descriptor(thread_, JSHandle::Cast(symbolFunction), true, false, true); + JSObject::DefineOwnProperty(thread_, symbolFuncPrototype, constructorKey, descriptor); // Symbol attribute - 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()); - - realm->SetSymbolFunction(thread_, symbol_function); + 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()); + + realm->SetSymbolFunction(thread_, symbolFunction); realm->SetHasInstanceSymbol(thread_, env->GetHasInstanceSymbol()); realm->SetIsConcatSpreadableSymbol(thread_, env->GetIsConcatSpreadableSymbol()); realm->SetToStringTagSymbol(thread_, env->GetToStringTagSymbol()); @@ -475,224 +471,222 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, realm->SetUnscopablesSymbol(thread_, env->GetUnscopablesSymbol()); // Setup %SymbolPrototype% - SetStringTagSymbol(realm, symbol_func_prototype, "Symbol"); + SetStringTagSymbol(realm, symbolFuncPrototype, "Symbol"); - 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()); + JSHandle holeySymbol(factory_->NewPrivateNameSymbolWithChar("holey")); + realm->SetHoleySymbol(thread_, holeySymbol.GetTaggedValue()); + JSHandle elementIcSymbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); + realm->SetElementICSymbol(thread_, elementIcSymbol.GetTaggedValue()); // ecma 19.2.3.6 Function.prototype[@@hasInstance] ( V ) - JSHandle func_func_prototype_obj = JSHandle(realm->GetFunctionPrototype()); + JSHandle funcFuncPrototypeObj = JSHandle(realm->GetFunctionPrototype()); SetFunctionAtSymbol( - realm, func_func_prototype_obj, realm->GetHasInstanceSymbol(), "[Symbol.hasInstance]", + realm, funcFuncPrototypeObj, realm->GetHasInstanceSymbol(), "[Symbol.hasInstance]", builtins::function::proto::HasInstance, FunctionLength::ONE); - SetFunctionsGenSymbol(realm, symbol_function); - SetFunctionsGenSymbolProto(realm, symbol_func_prototype); + SetFunctionsGenSymbol(realm, symbolFunction); + SetFunctionsGenSymbolProto(realm, symbolFuncPrototype); } -void Builtins::InitializeNumber(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) +void Builtins::InitializeNumber(const JSHandle &env, const JSHandle &primRefObjDynclass) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Number.prototype - 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); + JSHandle toObject(thread_, JSTaggedValue(FunctionLength::ZERO)); + JSHandle numFuncPrototype = + JSHandle::Cast(factory_->NewJSPrimitiveRef(primRefObjDynclass, toObject)); + JSHandle numFuncPrototypeValue(numFuncPrototype); // Number.prototype_or_dynclass - JSHandle num_func_instance_class = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, num_func_prototype_value); + JSHandle numFuncInstanceClass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, numFuncPrototypeValue); // Number = new Function() - JSHandle num_function(NewBuiltinConstructor(env, num_func_prototype, builtins::number::NumberConstructor, - "Number", FunctionLength::ONE)); - num_function.GetObject()->SetFunctionPrototype(thread_, num_func_instance_class.GetTaggedValue()); + JSHandle numFunction(NewBuiltinConstructor(env, numFuncPrototype, builtins::number::NumberConstructor, + "Number", FunctionLength::ONE)); + numFunction.GetObject()->SetFunctionPrototype(thread_, numFuncInstanceClass.GetTaggedValue()); - env->SetNumberFunction(thread_, num_function); + env->SetNumberFunction(thread_, numFunction); // Number method // Number constant const double epsilon = 2.220446049250313e-16; - 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)); + 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)); - SetFunctionsGenNumberProto(env, num_func_prototype); + SetFunctionsGenNumberProto(env, numFuncPrototype); - SetFunctionsGenNumber(env, num_function); + SetFunctionsGenNumber(env, numFunction); } -void Builtins::InitializeBigInt(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeBigInt(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigInt.prototype - JSHandle big_int_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle big_int_func_prototype_value(big_int_func_prototype); + JSHandle bigIntFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle bigIntFuncPrototypeValue(bigIntFuncPrototype); // BigInt.prototype_or_dynclass - JSHandle big_int_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, big_int_func_prototype_value); + JSHandle bigIntFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, bigIntFuncPrototypeValue); // BigInt = new Function() - JSHandle big_int_function(NewBuiltinConstructor( - env, big_int_func_prototype, builtins::big_int::BigIntConstructor, "BigInt", FunctionLength::ONE)); - JSHandle(big_int_function) - ->SetFunctionPrototype(thread_, big_int_func_instance_dynclass.GetTaggedValue()); + JSHandle bigIntFunction(NewBuiltinConstructor( + env, bigIntFuncPrototype, builtins::big_int::BigIntConstructor, "BigInt", FunctionLength::ONE)); + JSHandle(bigIntFunction)->SetFunctionPrototype(thread_, bigIntFuncInstanceDynclass.GetTaggedValue()); - env->SetBigIntFunction(thread_, big_int_function); + env->SetBigIntFunction(thread_, bigIntFunction); // @@ToStringTag - SetStringTagSymbol(env, big_int_func_prototype, "BigInt"); - SetFunctionsGenBigIntProto(env, big_int_func_prototype); - SetFunctionsGenBigInt(env, big_int_function); + SetStringTagSymbol(env, bigIntFuncPrototype, "BigInt"); + SetFunctionsGenBigIntProto(env, bigIntFuncPrototype); + SetFunctionsGenBigInt(env, bigIntFunction); } -void Builtins::InitializeDate(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeDate(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const int utc_length = 7; + const int utcLength = 7; // Date.prototype - JSHandle date_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle date_func_prototype_value(date_func_prototype); + JSHandle dateFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle dateFuncPrototypeValue(dateFuncPrototype); // Date.prototype_or_dynclass - JSHandle date_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_DATE, date_func_prototype_value); + JSHandle dateFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_DATE, dateFuncPrototypeValue); // Date = new Function() - JSHandle date_function( - NewBuiltinConstructor(env, date_func_prototype, builtins::date::DateConstructor, "Date", FunctionLength::ONE)); - JSHandle(date_function)->SetFunctionPrototype(thread_, date_func_instance_dynclass.GetTaggedValue()); + JSHandle dateFunction( + NewBuiltinConstructor(env, dateFuncPrototype, builtins::date::DateConstructor, "Date", FunctionLength::ONE)); + JSHandle(dateFunction)->SetFunctionPrototype(thread_, dateFuncInstanceDynclass.GetTaggedValue()); - env->SetDateFunction(thread_, date_function); + env->SetDateFunction(thread_, dateFunction); // Date.length - SetConstant(date_function, "length", JSTaggedValue(utc_length)); - SetFunctionsGenDateProto(env, date_func_prototype); + SetConstant(dateFunction, "length", JSTaggedValue(utcLength)); + SetFunctionsGenDateProto(env, dateFuncPrototype); - SetFunctionsGenDate(env, date_function); + SetFunctionsGenDate(env, dateFunction); } -void Builtins::InitializeBoolean(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const +void Builtins::InitializeBoolean(const JSHandle &env, const JSHandle &primRefObjDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Boolean.prototype - 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); + JSHandle toObject(thread_, JSTaggedValue::False()); + JSHandle booleanFuncPrototype = + JSHandle::Cast(factory_->NewJSPrimitiveRef(primRefObjDynclass, toObject)); + JSHandle booleanFuncPrototypeValue(booleanFuncPrototype); // Boolean.prototype_or_dynclass - JSHandle boolean_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, boolean_func_prototype_value); + JSHandle booleanFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, booleanFuncPrototypeValue); // new Boolean Function() - JSHandle boolean_function(NewBuiltinConstructor( - env, boolean_func_prototype, builtins::boolean::BooleanConstructor, "Boolean", FunctionLength::ONE)); - boolean_function->SetFunctionPrototype(thread_, boolean_func_instance_dynclass.GetTaggedValue()); + JSHandle booleanFunction(NewBuiltinConstructor( + env, booleanFuncPrototype, builtins::boolean::BooleanConstructor, "Boolean", FunctionLength::ONE)); + booleanFunction->SetFunctionPrototype(thread_, booleanFuncInstanceDynclass.GetTaggedValue()); - env->SetBooleanFunction(thread_, boolean_function); - SetFunctionsGenBooleanProto(env, boolean_func_prototype); + env->SetBooleanFunction(thread_, booleanFunction); + SetFunctionsGenBooleanProto(env, booleanFuncPrototype); } void Builtins::InitializeProxy(const JSHandle &env) { - JSHandle proxy_function(InitializeExoticConstructor(env, builtins::proxy::ProxyConstructor, "Proxy", 2)); - env->SetProxyFunction(thread_, proxy_function); - SetFunctionsGenProxy(env, proxy_function); + JSHandle proxyFunction(InitializeExoticConstructor(env, builtins::proxy::ProxyConstructor, "Proxy", 2)); + env->SetProxyFunction(thread_, proxyFunction); + SetFunctionsGenProxy(env, proxyFunction); } -JSHandle Builtins::InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctor_func, +JSHandle Builtins::InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctorFunc, const char *name, int length) { JSHandle ctor = - factory_->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_PROXY_CONSTRUCTOR); + factory_->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_PROXY_CONSTRUCTOR); JSFunction::SetFunctionLength(thread_, ctor, JSTaggedValue(length)); - JSHandle name_string(factory_->NewFromString(name)); - JSFunction::SetFunctionName(thread_, JSHandle(ctor), name_string, + JSHandle nameString(factory_->NewFromString(name)); + JSFunction::SetFunctionName(thread_, JSHandle(ctor), nameString, JSHandle(thread_, JSTaggedValue::Undefined())); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); PropertyDescriptor descriptor(thread_, JSHandle(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, global_object, name_string, descriptor); + JSObject::DefineOwnProperty(thread_, globalObject, nameString, descriptor); return ctor; } -void Builtins::InitializeAsyncFunction(const JSHandle &env, - const JSHandle &obj_func_dynclass) const +void Builtins::InitializeAsyncFunction(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // AsyncFunction.prototype - 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); + JSHandle asyncFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSObject::SetPrototype(thread_, asyncFuncPrototype, env->GetFunctionPrototype()); + JSHandle asyncFuncPrototypeValue(asyncFuncPrototype); // AsyncFunction.prototype_or_dynclass - JSHandle async_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_ASYNC_FUNCTION, async_func_prototype_value); + JSHandle asyncFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_ASYNC_FUNCTION, asyncFuncPrototypeValue); // AsyncFunction = new Function() - JSHandle async_function = - NewBuiltinConstructor(env, async_func_prototype, builtins::async_function::AsyncFunctionConstructor, + JSHandle asyncFunction = + NewBuiltinConstructor(env, asyncFuncPrototype, builtins::async_function::AsyncFunctionConstructor, "AsyncFunction", FunctionLength::ONE); - JSObject::SetPrototype(thread_, JSHandle::Cast(async_function), env->GetFunctionFunction()); - JSHandle constructor_key = global_const->GetHandledConstructorString(); - PropertyDescriptor async_desc(thread_, JSHandle::Cast(async_function), false, false, true); - JSObject::DefineOwnProperty(thread_, async_func_prototype, constructor_key, async_desc); - async_function->SetProtoOrDynClass(thread_, async_func_instance_dynclass.GetTaggedValue()); + 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()); // AsyncFunction.prototype property - SetStringTagSymbol(env, async_func_prototype, "AsyncFunction"); - env->SetAsyncFunction(thread_, async_function); - env->SetAsyncFunctionPrototype(thread_, async_func_prototype); + SetStringTagSymbol(env, asyncFuncPrototype, "AsyncFunction"); + env->SetAsyncFunction(thread_, asyncFunction); + env->SetAsyncFunctionPrototype(thread_, asyncFuncPrototype); } -void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHandle &objFuncDynclass) const { // Error.prototype - JSHandle error_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle error_func_prototype_value(error_func_prototype); + JSHandle errorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle errorFuncPrototypeValue(errorFuncPrototype); // Error.prototype_or_dynclass - JSHandle error_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_ERROR, error_func_prototype_value); + JSHandle errorFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_ERROR, errorFuncPrototypeValue); // Error() = new Function() - JSHandle error_function(NewBuiltinConstructor( - env, error_func_prototype, builtins::error::ErrorConstructor, "Error", FunctionLength::ONE)); - error_function->SetFunctionPrototype(thread_, error_func_instance_dynclass.GetTaggedValue()); - env->SetErrorFunction(thread_, error_function); + JSHandle errorFunction(NewBuiltinConstructor(env, errorFuncPrototype, builtins::error::ErrorConstructor, + "Error", FunctionLength::ONE)); + errorFunction->SetFunctionPrototype(thread_, errorFuncInstanceDynclass.GetTaggedValue()); + env->SetErrorFunction(thread_, errorFunction); // Error.prototype Attribute - SetAttribute(error_func_prototype, "name", "Error"); - SetAttribute(error_func_prototype, "message", ""); + SetAttribute(errorFuncPrototype, "name", "Error"); + SetAttribute(errorFuncPrototype, "message", ""); - SetFunctionsGenErrorProto(env, error_func_prototype); + SetFunctionsGenErrorProto(env, errorFuncPrototype); - JSHandle native_error_func_class = factory_->CreateDynClass( + JSHandle nativeErrorFuncClass = factory_->CreateDynClass( JSType::JS_FUNCTION, env->GetErrorFunction(), HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); - native_error_func_class->SetConstructor(true); - env->SetNativeErrorFunctionClass(thread_, native_error_func_class); + nativeErrorFuncClass->SetConstructor(true); + env->SetNativeErrorFunctionClass(thread_, nativeErrorFuncClass); - 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); + 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); } void Builtins::InitializeAllTypeErrorWithRealm(const JSHandle &realm) const @@ -710,95 +704,95 @@ void Builtins::InitializeAllTypeErrorWithRealm(const JSHandle &realm) SetErrorWithRealm(realm, JSType::JS_EVAL_ERROR); } -void Builtins::SetErrorWithRealm(const JSHandle &realm, const JSType &error_tag) const +void Builtins::SetErrorWithRealm(const JSHandle &realm, const JSType &errorTag) const { JSHandle env = vm_->GetGlobalEnv(); - JSHandle global_object(thread_, realm->GetGlobalObject()); - JSHandle name_string; - JSHandle native_error_function; - switch (error_tag) { + JSHandle globalObject(thread_, realm->GetGlobalObject()); + JSHandle nameString; + JSHandle nativeErrorFunction; + switch (errorTag) { case JSType::JS_RANGE_ERROR: - native_error_function = env->GetRangeErrorFunction(); - name_string = JSHandle(thread_->GlobalConstants()->GetHandledRangeErrorString()); - realm->SetRangeErrorFunction(thread_, native_error_function); + nativeErrorFunction = env->GetRangeErrorFunction(); + nameString = JSHandle(thread_->GlobalConstants()->GetHandledRangeErrorString()); + realm->SetRangeErrorFunction(thread_, nativeErrorFunction); break; case JSType::JS_EVAL_ERROR: - native_error_function = env->GetEvalErrorFunction(); - name_string = JSHandle(thread_->GlobalConstants()->GetHandledEvalErrorString()); - realm->SetEvalErrorFunction(thread_, native_error_function); + nativeErrorFunction = env->GetEvalErrorFunction(); + nameString = JSHandle(thread_->GlobalConstants()->GetHandledEvalErrorString()); + realm->SetEvalErrorFunction(thread_, nativeErrorFunction); break; case JSType::JS_REFERENCE_ERROR: - native_error_function = env->GetReferenceErrorFunction(); - name_string = JSHandle(thread_->GlobalConstants()->GetHandledReferenceErrorString()); - realm->SetReferenceErrorFunction(thread_, native_error_function); + nativeErrorFunction = env->GetReferenceErrorFunction(); + nameString = JSHandle(thread_->GlobalConstants()->GetHandledReferenceErrorString()); + realm->SetReferenceErrorFunction(thread_, nativeErrorFunction); break; case JSType::JS_TYPE_ERROR: - native_error_function = env->GetTypeErrorFunction(); - name_string = JSHandle(thread_->GlobalConstants()->GetHandledTypeErrorString()); - realm->SetTypeErrorFunction(thread_, native_error_function); + nativeErrorFunction = env->GetTypeErrorFunction(); + nameString = JSHandle(thread_->GlobalConstants()->GetHandledTypeErrorString()); + realm->SetTypeErrorFunction(thread_, nativeErrorFunction); realm->SetThrowTypeError(thread_, env->GetThrowTypeError()); break; case JSType::JS_URI_ERROR: - native_error_function = env->GetURIErrorFunction(); - name_string = JSHandle(thread_->GlobalConstants()->GetHandledURIErrorString()); - realm->SetURIErrorFunction(thread_, native_error_function); + nativeErrorFunction = env->GetURIErrorFunction(); + nameString = JSHandle(thread_->GlobalConstants()->GetHandledURIErrorString()); + realm->SetURIErrorFunction(thread_, nativeErrorFunction); break; case JSType::JS_SYNTAX_ERROR: - native_error_function = env->GetSyntaxErrorFunction(); - name_string = JSHandle(thread_->GlobalConstants()->GetHandledSyntaxErrorString()); - realm->SetSyntaxErrorFunction(thread_, native_error_function); + nativeErrorFunction = env->GetSyntaxErrorFunction(); + nameString = JSHandle(thread_->GlobalConstants()->GetHandledSyntaxErrorString()); + realm->SetSyntaxErrorFunction(thread_, nativeErrorFunction); break; default: break; } - PropertyDescriptor descriptor(thread_, native_error_function, true, false, true); - JSObject::DefineOwnProperty(thread_, global_object, name_string, descriptor); + PropertyDescriptor descriptor(thread_, nativeErrorFunction, true, false, true); + JSObject::DefineOwnProperty(thread_, globalObject, nameString, descriptor); } void Builtins::GeneralUpdateError(ErrorParameter *error, EcmaEntrypoint constructor, EcmaEntrypoint method, const char *name, JSType type) const { - error->native_constructor = constructor; - error->native_method = method; - error->native_property_name = name; - error->native_jstype = type; + error->nativeConstructor = constructor; + error->nativeMethod = method; + error->nativePropertyName = name; + error->nativeJstype = type; } // NOTE(dkofanov): Split errors initialization, use `SetFunctionsGenRangeErrorProto` from `builtins_initializers_gen.h` // and etc. -void Builtins::InitializeError(const JSHandle &env, const JSHandle &obj_func_dynclass, - const JSType &error_tag) const +void Builtins::InitializeError(const JSHandle &env, const JSHandle &objFuncDynclass, + const JSType &errorTag) const { // NativeError.prototype - JSHandle native_error_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle native_error_func_prototype_value(native_error_func_prototype); + JSHandle nativeErrorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle nativeErrorFuncPrototypeValue(nativeErrorFuncPrototype); - ErrorParameter error_parameter {builtins::range_error::RangeErrorConstructor, - builtins::range_error::proto::ToString, "RangeError", JSType::JS_RANGE_ERROR}; - switch (error_tag) { + ErrorParameter errorParameter {builtins::range_error::RangeErrorConstructor, builtins::range_error::proto::ToString, + "RangeError", JSType::JS_RANGE_ERROR}; + switch (errorTag) { case JSType::JS_RANGE_ERROR: - GeneralUpdateError(&error_parameter, builtins::range_error::RangeErrorConstructor, + GeneralUpdateError(&errorParameter, builtins::range_error::RangeErrorConstructor, builtins::range_error::proto::ToString, "RangeError", JSType::JS_RANGE_ERROR); break; case JSType::JS_EVAL_ERROR: - GeneralUpdateError(&error_parameter, builtins::eval_error::EvalErrorConstructor, + GeneralUpdateError(&errorParameter, builtins::eval_error::EvalErrorConstructor, builtins::eval_error::proto::ToString, "EvalError", JSType::JS_EVAL_ERROR); break; case JSType::JS_REFERENCE_ERROR: - GeneralUpdateError(&error_parameter, builtins::reference_error::ReferenceErrorConstructor, + GeneralUpdateError(&errorParameter, builtins::reference_error::ReferenceErrorConstructor, builtins::reference_error::proto::ToString, "ReferenceError", JSType::JS_REFERENCE_ERROR); break; case JSType::JS_TYPE_ERROR: - GeneralUpdateError(&error_parameter, builtins::type_error::TypeErrorConstructor, + GeneralUpdateError(&errorParameter, builtins::type_error::TypeErrorConstructor, builtins::type_error::proto::ToString, "TypeError", JSType::JS_TYPE_ERROR); break; case JSType::JS_URI_ERROR: - GeneralUpdateError(&error_parameter, builtins::uri_error::URIErrorConstructor, + GeneralUpdateError(&errorParameter, builtins::uri_error::URIErrorConstructor, builtins::uri_error::proto::ToString, "URIError", JSType::JS_URI_ERROR); break; case JSType::JS_SYNTAX_ERROR: - GeneralUpdateError(&error_parameter, builtins::syntax_error::SyntaxErrorConstructor, + GeneralUpdateError(&errorParameter, builtins::syntax_error::SyntaxErrorConstructor, builtins::syntax_error::proto::ToString, "SyntaxError", JSType::JS_SYNTAX_ERROR); break; default: @@ -806,926 +800,904 @@ void Builtins::InitializeError(const JSHandle &env, const JSHandle native_error_func_instance_dynclass = - factory_->CreateDynClass(error_parameter.native_jstype, native_error_func_prototype_value); + JSHandle nativeErrorFuncInstanceDynclass = + factory_->CreateDynClass(errorParameter.nativeJstype, nativeErrorFuncPrototypeValue); // NativeError() = new Error() - 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, + JSHandle nativeErrorFunction = + factory_->NewJSNativeErrorFunction(env, reinterpret_cast(errorParameter.nativeConstructor)); + InitializeCtor(env, nativeErrorFuncPrototype, nativeErrorFunction, errorParameter.nativePropertyName, FunctionLength::ONE); - native_error_function->SetFunctionPrototype(thread_, native_error_func_instance_dynclass.GetTaggedValue()); + nativeErrorFunction->SetFunctionPrototype(thread_, nativeErrorFuncInstanceDynclass.GetTaggedValue()); // NativeError.prototype method - SetFunction(env, native_error_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), - error_parameter.native_method, FunctionLength::ZERO); + SetFunction(env, nativeErrorFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), + errorParameter.nativeMethod, FunctionLength::ZERO); // Error.prototype Attribute - 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 = + 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 = factory_->NewJSFunction(env, reinterpret_cast(type_error::ThrowTypeError)); - JSFunction::SetFunctionLength(thread_, throw_type_error_function, JSTaggedValue(1), false); - JSObject::PreventExtensions(thread_, JSHandle::Cast(throw_type_error_function)); - env->SetThrowTypeError(thread_, throw_type_error_function); - } 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); + 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); } else { - env->SetEvalErrorFunction(thread_, native_error_function); + env->SetEvalErrorFunction(thread_, nativeErrorFunction); } } // namespace panda::ecmascript void Builtins::InitializeCtor(const JSHandle &env, const JSHandle &prototype, const JSHandle &ctor, const char *name, int length) const { - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); JSFunction::SetFunctionLength(thread_, ctor, JSTaggedValue(length)); - JSHandle name_string(factory_->NewFromString(name)); - JSFunction::SetFunctionName(thread_, JSHandle(ctor), name_string, + JSHandle nameString(factory_->NewFromString(name)); + JSFunction::SetFunctionName(thread_, JSHandle(ctor), nameString, JSHandle(thread_, JSTaggedValue::Undefined())); - JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); PropertyDescriptor descriptor1(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, prototype, constructor_key, descriptor1); + JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1); /* set "prototype" in constructor */ ctor->SetFunctionPrototype(thread_, prototype.GetTaggedValue()); - if (!JSTaggedValue::SameValue(name_string, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { - JSHandle global_object(thread_, env->GetGlobalObject()); + if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { + JSHandle globalObject(thread_, env->GetGlobalObject()); PropertyDescriptor descriptor2(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, global_object, name_string, descriptor2); + JSObject::DefineOwnProperty(thread_, globalObject, nameString, descriptor2); } } -void Builtins::InitializeSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeSet(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // Set.prototype - JSHandle set_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle set_func_prototype_value(set_func_prototype); + JSHandle setFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle setFuncPrototypeValue(setFuncPrototype); // Set.prototype_or_dynclass - JSHandle set_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_SET, set_func_prototype_value); + JSHandle setFuncInstanceDynclass = factory_->CreateDynClass(JSType::JS_SET, setFuncPrototypeValue); // Set() = new Function() - JSHandle set_function( - NewBuiltinConstructor(env, set_func_prototype, builtins::set::SetConstructor, "Set", FunctionLength::ZERO)); - JSHandle(set_function)->SetFunctionPrototype(thread_, set_func_instance_dynclass.GetTaggedValue()); + JSHandle setFunction( + NewBuiltinConstructor(env, setFuncPrototype, builtins::set::SetConstructor, "Set", FunctionLength::ZERO)); + JSHandle(setFunction)->SetFunctionPrototype(thread_, setFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(set_func_prototype), constructor_key, set_function); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(setFuncPrototype), constructorKey, setFunction); - env->SetSetFunction(thread_, set_function); - env->SetSetPrototype(thread_, set_func_prototype); + env->SetSetFunction(thread_, setFunction); + env->SetSetPrototype(thread_, setFuncPrototype); // @@ToStringTag - SetStringTagSymbol(env, set_func_prototype, "Set"); + SetStringTagSymbol(env, setFuncPrototype, "Set"); - SetFunctionsGenSetProto(env, set_func_prototype); + SetFunctionsGenSetProto(env, setFuncPrototype); - SetFunctionsGenSet(env, JSHandle(set_function)); + SetFunctionsGenSet(env, JSHandle(setFunction)); } -void Builtins::InitializeMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeMap(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // Map.prototype - JSHandle map_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle map_func_prototype_value(map_func_prototype); + JSHandle mapFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle mapFuncPrototypeValue(mapFuncPrototype); // Map.prototype_or_dynclass - JSHandle map_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_MAP, map_func_prototype_value); + JSHandle mapFuncInstanceDynclass = factory_->CreateDynClass(JSType::JS_MAP, mapFuncPrototypeValue); // Map() = new Function() - JSHandle map_function( - NewBuiltinConstructor(env, map_func_prototype, map::MapConstructor, "Map", FunctionLength::ZERO)); + JSHandle mapFunction( + NewBuiltinConstructor(env, mapFuncPrototype, map::MapConstructor, "Map", FunctionLength::ZERO)); // Map().prototype = Map.Prototype & Map.prototype.constructor = Map() - JSFunction::Cast(map_function->GetTaggedObject()) - ->SetFunctionPrototype(thread_, map_func_instance_dynclass.GetTaggedValue()); + JSFunction::Cast(mapFunction->GetTaggedObject()) + ->SetFunctionPrototype(thread_, mapFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(map_func_prototype), constructor_key, map_function); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(mapFuncPrototype), constructorKey, mapFunction); - env->SetMapFunction(thread_, map_function); - env->SetMapPrototype(thread_, map_func_prototype); - SetFunctionsGenMapProto(env, map_func_prototype); - SetFunctionsGenMap(env, JSHandle(map_function)); + env->SetMapFunction(thread_, mapFunction); + env->SetMapPrototype(thread_, mapFuncPrototype); + SetFunctionsGenMapProto(env, mapFuncPrototype); + SetFunctionsGenMap(env, JSHandle(mapFunction)); // @@ToStringTag - SetStringTagSymbol(env, map_func_prototype, "Map"); + SetStringTagSymbol(env, mapFuncPrototype, "Map"); } -void Builtins::InitializeWeakRef(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeWeakRef(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // WeakRef.prototype - JSHandle weak_ref_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle weak_ref_func_prototype_value(weak_ref_func_prototype); + JSHandle weakRefFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle weakRefFuncPrototypeValue(weakRefFuncPrototype); // WeakRef.prototype_or_dynclass - JSHandle weak_ref_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_WEAK_REF, weak_ref_func_prototype_value); - weak_ref_func_instance_dynclass->SetWeakContainer(true); + JSHandle weakRefFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_WEAK_REF, weakRefFuncPrototypeValue); + weakRefFuncInstanceDynclass->SetWeakContainer(true); // WeakRef() = new Function() - JSHandle weak_ref_function( - NewBuiltinConstructor(env, weak_ref_func_prototype, weak_ref::Constructor, "WeakRef", FunctionLength::ONE)); + JSHandle weakRefFunction( + NewBuiltinConstructor(env, weakRefFuncPrototype, weak_ref::Constructor, "WeakRef", FunctionLength::ONE)); // WeakRef().prototype = WeakRef.Prototype & WeakRef.prototype.constructor = WeakRef() - JSFunction::Cast(weak_ref_function->GetTaggedObject()) - ->SetProtoOrDynClass(thread_, weak_ref_func_instance_dynclass.GetTaggedValue()); + JSFunction::Cast(weakRefFunction->GetTaggedObject()) + ->SetProtoOrDynClass(thread_, weakRefFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(weak_ref_func_prototype), constructor_key, - weak_ref_function); - SetFunctionsGenWeakRefProto(env, weak_ref_func_prototype); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(weakRefFuncPrototype), constructorKey, weakRefFunction); + SetFunctionsGenWeakRefProto(env, weakRefFuncPrototype); // @@ToStringTag - SetStringTagSymbol(env, weak_ref_func_prototype, "WeakRef"); + SetStringTagSymbol(env, weakRefFuncPrototype, "WeakRef"); } -void Builtins::InitializeWeakMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeWeakMap(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // WeakMap.prototype - JSHandle weak_map_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle weak_map_func_prototype_value(weak_map_func_prototype); + JSHandle weakMapFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle weakMapFuncPrototypeValue(weakMapFuncPrototype); // WeakMap.prototype_or_dynclass - JSHandle weak_map_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_WEAK_MAP, weak_map_func_prototype_value); + JSHandle weakMapFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_WEAK_MAP, weakMapFuncPrototypeValue); // WeakMap() = new Function() - JSHandle weak_map_function(NewBuiltinConstructor( - env, weak_map_func_prototype, weak_map::WeakMapConstructor, "WeakMap", FunctionLength::ZERO)); + JSHandle weakMapFunction(NewBuiltinConstructor( + env, weakMapFuncPrototype, weak_map::WeakMapConstructor, "WeakMap", FunctionLength::ZERO)); // WeakMap().prototype = WeakMap.Prototype & WeakMap.prototype.constructor = WeakMap() - JSFunction::Cast(weak_map_function->GetTaggedObject()) - ->SetProtoOrDynClass(thread_, weak_map_func_instance_dynclass.GetTaggedValue()); + JSFunction::Cast(weakMapFunction->GetTaggedObject()) + ->SetProtoOrDynClass(thread_, weakMapFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(weak_map_func_prototype), constructor_key, - weak_map_function); - env->SetWeakMapFunction(thread_, weak_map_function); - SetFunctionsGenWeakMapProto(env, weak_map_func_prototype); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(weakMapFuncPrototype), constructorKey, weakMapFunction); + env->SetWeakMapFunction(thread_, weakMapFunction); + SetFunctionsGenWeakMapProto(env, weakMapFuncPrototype); // @@ToStringTag - SetStringTagSymbol(env, weak_map_func_prototype, "WeakMap"); + SetStringTagSymbol(env, weakMapFuncPrototype, "WeakMap"); } -void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // Set.prototype - JSHandle weak_set_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle weak_set_func_prototype_value(weak_set_func_prototype); + JSHandle weakSetFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle weakSetFuncPrototypeValue(weakSetFuncPrototype); // Set.prototype_or_dynclass - JSHandle weak_set_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_WEAK_SET, weak_set_func_prototype_value); + JSHandle weakSetFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_WEAK_SET, weakSetFuncPrototypeValue); // Set() = new Function() - JSHandle weak_set_function(NewBuiltinConstructor( - env, weak_set_func_prototype, weak_set::WeakSetConstructor, "WeakSet", FunctionLength::ZERO)); - JSHandle(weak_set_function) - ->SetProtoOrDynClass(thread_, weak_set_func_instance_dynclass.GetTaggedValue()); + JSHandle weakSetFunction(NewBuiltinConstructor( + env, weakSetFuncPrototype, weak_set::WeakSetConstructor, "WeakSet", FunctionLength::ZERO)); + JSHandle(weakSetFunction)->SetProtoOrDynClass(thread_, weakSetFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(weak_set_func_prototype), constructor_key, - weak_set_function); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(weakSetFuncPrototype), constructorKey, weakSetFunction); - env->SetWeakSetFunction(thread_, weak_set_function); - SetFunctionsGenWeakSetProto(env, weak_set_func_prototype); + env->SetWeakSetFunction(thread_, weakSetFunction); + SetFunctionsGenWeakSetProto(env, weakSetFuncPrototype); // @@ToStringTag - SetStringTagSymbol(env, weak_set_func_prototype, "WeakSet"); + SetStringTagSymbol(env, weakSetFuncPrototype, "WeakSet"); } -void Builtins::InitializeMath(const JSHandle &env, - const JSHandle &obj_func_prototype_val) const +void Builtins::InitializeMath(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle math_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); - JSHandle math_object = factory_->NewJSObject(math_dynclass); - - env->SetMathFunction(thread_, math_object); - SetFunctionsGenMath(env, math_object); - - SetConstant(math_object, "E", math::GetPropE()); - SetConstant(math_object, "LN10", math::GetPropLN10()); - SetConstant(math_object, "LN2", math::GetPropLN2()); - SetConstant(math_object, "LOG10E", math::GetPropLOG10E()); - SetConstant(math_object, "LOG2E", math::GetPropLOG2E()); - SetConstant(math_object, "PI", math::GetPropPI()); - SetConstant(math_object, "SQRT1_2", math::GetPropSQRT1_2()); - SetConstant(math_object, "SQRT2", math::GetPropSQRT2()); - - JSHandle math_string(factory_->NewFromCanBeCompressString("Math")); - JSHandle global_object(thread_, env->GetGlobalObject()); - PropertyDescriptor math_desc(thread_, JSHandle::Cast(math_object), true, false, true); - JSObject::DefineOwnProperty(thread_, global_object, math_string, math_desc); + JSHandle mathDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); + JSHandle mathObject = factory_->NewJSObject(mathDynclass); + + env->SetMathFunction(thread_, mathObject); + SetFunctionsGenMath(env, mathObject); + + SetConstant(mathObject, "E", math::GetPropE()); + SetConstant(mathObject, "LN10", math::GetPropLN10()); + SetConstant(mathObject, "LN2", math::GetPropLN2()); + SetConstant(mathObject, "LOG10E", math::GetPropLOG10E()); + SetConstant(mathObject, "LOG2E", math::GetPropLOG2E()); + SetConstant(mathObject, "PI", math::GetPropPI()); + SetConstant(mathObject, "SQRT1_2", math::GetPropSQRT1_2()); + SetConstant(mathObject, "SQRT2", math::GetPropSQRT2()); + + 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); // @@ToStringTag - SetStringTagSymbol(env, math_object, "Math"); + SetStringTagSymbol(env, mathObject, "Math"); } -void Builtins::InitializeJson(const JSHandle &env, - const JSHandle &obj_func_prototype_val) const +void Builtins::InitializeJson(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle json_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); - JSHandle json_object = factory_->NewJSObject(json_dynclass); + JSHandle jsonDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); + JSHandle jsonObject = factory_->NewJSObject(jsonDynclass); - env->SetJsonFunction(thread_, json_object); - SetFunctionsGenJson(env, json_object); + env->SetJsonFunction(thread_, jsonObject); + SetFunctionsGenJson(env, jsonObject); - 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); + 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); // @@ToStringTag - SetStringTagSymbol(env, json_object, "JSON"); + SetStringTagSymbol(env, jsonObject, "JSON"); } -void Builtins::InitializeString(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const +void Builtins::InitializeString(const JSHandle &env, const JSHandle &primRefObjDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // String.prototype - 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); + JSHandle toObject(factory_->GetEmptyString()); + JSHandle stringFuncPrototype = + JSHandle::Cast(factory_->NewJSPrimitiveRef(primRefObjDynclass, toObject)); + JSHandle stringFuncPrototypeValue(stringFuncPrototype); // String.prototype_or_dynclass - JSHandle string_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, string_func_prototype_value); + JSHandle stringFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, stringFuncPrototypeValue); // String = new Function() - JSHandle string_function( - NewBuiltinConstructor(env, string_func_prototype, string::StringConstructor, "String", FunctionLength::ONE)); - string_function.GetObject()->SetFunctionPrototype(thread_, - string_func_instance_dynclass.GetTaggedValue()); + JSHandle stringFunction( + NewBuiltinConstructor(env, stringFuncPrototype, string::StringConstructor, "String", FunctionLength::ONE)); + stringFunction.GetObject()->SetFunctionPrototype(thread_, stringFuncInstanceDynclass.GetTaggedValue()); - env->SetStringFunction(thread_, string_function); - env->SetStringPrototype(thread_, string_func_prototype); + env->SetStringFunction(thread_, stringFunction); + env->SetStringPrototype(thread_, stringFuncPrototype); - SetFunctionsGenString(env, string_function); - SetFunctionsGenStringProto(env, string_func_prototype); + SetFunctionsGenString(env, stringFunction); + SetFunctionsGenStringProto(env, stringFuncPrototype); } void Builtins::InitializeStringIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const + const JSHandle &iteratorFuncDynclass) const { // StringIterator.prototype - JSHandle str_iter_prototype(factory_->NewJSObject(iterator_func_dynclass)); + JSHandle strIterPrototype(factory_->NewJSObject(iteratorFuncDynclass)); // StringIterator.prototype_or_dynclass - JSHandle str_iter_func_instance_dynclass = factory_->CreateDynClass( - JSType::JS_STRING_ITERATOR, JSHandle(str_iter_prototype)); + JSHandle strIterFuncInstanceDynclass = factory_->CreateDynClass( + JSType::JS_STRING_ITERATOR, JSHandle(strIterPrototype)); - JSHandle str_iter_function( + JSHandle strIterFunction( factory_->NewJSFunction(env, static_cast(nullptr), FunctionKind::BASE_CONSTRUCTOR)); - str_iter_function->SetFunctionPrototype(thread_, str_iter_func_instance_dynclass.GetTaggedValue()); + strIterFunction->SetFunctionPrototype(thread_, strIterFuncInstanceDynclass.GetTaggedValue()); - env->SetStringIteratorFunction(thread_, str_iter_function); - env->SetStringIteratorPrototype(thread_, str_iter_prototype); - SetFunctionsGenStringIteratorProto(env, str_iter_prototype); - SetStringTagSymbol(env, str_iter_prototype, "String Iterator"); + env->SetStringIteratorFunction(thread_, strIterFunction); + env->SetStringIteratorPrototype(thread_, strIterPrototype); + SetFunctionsGenStringIteratorProto(env, strIterPrototype); + SetStringTagSymbol(env, strIterPrototype, "String Iterator"); } -void Builtins::InitializeIterator(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Iterator.prototype - JSHandle iterator_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle iteratorPrototype = factory_->NewJSObject(objFuncDynclass); - env->SetIteratorPrototype(thread_, iterator_prototype); - SetFunctionsGenIteratorProto(env, iterator_prototype); + env->SetIteratorPrototype(thread_, iteratorPrototype); + SetFunctionsGenIteratorProto(env, iteratorPrototype); // Iterator.dynclass - JSHandle iterator_func_dynclass = - factory_->CreateDynClass(JSType::JS_ITERATOR, JSHandle(iterator_prototype)); + JSHandle iteratorFuncDynclass = + factory_->CreateDynClass(JSType::JS_ITERATOR, JSHandle(iteratorPrototype)); - 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); + InitializeForinIterator(env, iteratorFuncDynclass); + InitializeSetIterator(env, iteratorFuncDynclass); + InitializeMapIterator(env, iteratorFuncDynclass); + InitializeArrayIterator(env, iteratorFuncDynclass); + InitializeStringIterator(env, iteratorFuncDynclass); + InitializeRegexpIterator(env, iteratorFuncDynclass); } -void Builtins::InitializeAsyncIterator(const JSHandle &env, - const JSHandle &obj_func_dynclass) const +void Builtins::InitializeAsyncIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // AsyncIterator.prototype - JSHandle async_iterator_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle asyncIteratorPrototype = factory_->NewJSObject(objFuncDynclass); - SetFunctionsGenAsyncIteratorProto(env, async_iterator_prototype); + SetFunctionsGenAsyncIteratorProto(env, asyncIteratorPrototype); - env->SetAsyncIteratorPrototype(thread_, async_iterator_prototype); + env->SetAsyncIteratorPrototype(thread_, asyncIteratorPrototype); } void Builtins::InitializeForinIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const + const JSHandle &iteratorFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Iterator.prototype - JSHandle forin_iterator_prototype = factory_->NewJSObject(iterator_func_dynclass); + JSHandle forinIteratorPrototype = factory_->NewJSObject(iteratorFuncDynclass); JSHandle dynclass = factory_->CreateDynClass( - JSType::JS_FORIN_ITERATOR, JSHandle(forin_iterator_prototype)); + JSType::JS_FORIN_ITERATOR, JSHandle(forinIteratorPrototype)); - env->SetForinIteratorPrototype(thread_, forin_iterator_prototype); + env->SetForinIteratorPrototype(thread_, forinIteratorPrototype); env->SetForinIteratorClass(thread_, dynclass); - SetFunctionsGenForInIteratorProto(env, forin_iterator_prototype); + SetFunctionsGenForInIteratorProto(env, forinIteratorPrototype); } void Builtins::InitializeSetIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const + const JSHandle &iteratorFuncDynclass) const { // SetIterator.prototype - JSHandle set_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); + JSHandle setIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); - SetFunctionsGenSetIteratorProto(env, set_iterator_prototype); - SetStringTagSymbol(env, set_iterator_prototype, "Set Iterator"); - env->SetSetIteratorPrototype(thread_, set_iterator_prototype); + SetFunctionsGenSetIteratorProto(env, setIteratorPrototype); + SetStringTagSymbol(env, setIteratorPrototype, "Set Iterator"); + env->SetSetIteratorPrototype(thread_, setIteratorPrototype); } void Builtins::InitializeMapIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const + const JSHandle &iteratorFuncDynclass) const { // MapIterator.prototype - JSHandle map_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); - SetFunctionsGenMapIteratorProto(env, map_iterator_prototype); + JSHandle mapIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + SetFunctionsGenMapIteratorProto(env, mapIteratorPrototype); - SetStringTagSymbol(env, map_iterator_prototype, "Map Iterator"); - env->SetMapIteratorPrototype(thread_, map_iterator_prototype); + SetStringTagSymbol(env, mapIteratorPrototype, "Map Iterator"); + env->SetMapIteratorPrototype(thread_, mapIteratorPrototype); } void Builtins::InitializeArrayIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const + const JSHandle &iteratorFuncDynclass) const { // ArrayIterator.prototype - JSHandle array_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); + JSHandle arrayIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); - SetFunctionsGenArrayIteratorProto(env, array_iterator_prototype); - SetStringTagSymbol(env, array_iterator_prototype, "Array Iterator"); - env->SetArrayIteratorPrototype(thread_, array_iterator_prototype); + SetFunctionsGenArrayIteratorProto(env, arrayIteratorPrototype); + SetStringTagSymbol(env, arrayIteratorPrototype, "Array Iterator"); + env->SetArrayIteratorPrototype(thread_, arrayIteratorPrototype); } void Builtins::InitializeRegexpIterator(const JSHandle &env, - const JSHandle &iterator_func_class) const + const JSHandle &iteratorFuncClass) const { // RegExpIterator.prototype - JSHandle reg_exp_iterator_prototype(factory_->NewJSObject(iterator_func_class)); + JSHandle regExpIteratorPrototype(factory_->NewJSObject(iteratorFuncClass)); - SetFunctionsGenRegExpIteratorProto(env, reg_exp_iterator_prototype); - SetStringTagSymbol(env, reg_exp_iterator_prototype, "RegExp String Iterator"); - env->SetRegExpIteratorPrototype(thread_, reg_exp_iterator_prototype); + SetFunctionsGenRegExpIteratorProto(env, regExpIteratorPrototype); + SetStringTagSymbol(env, regExpIteratorPrototype, "RegExp String Iterator"); + env->SetRegExpIteratorPrototype(thread_, regExpIteratorPrototype); } void Builtins::InitializeRegExp(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // RegExp.prototype - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle reg_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle reg_prototype_value(reg_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle regPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle regPrototypeValue(regPrototype); // RegExp.prototype_or_dynclass - JSHandle regexp_func_instance_dynclass = factory_->CreateJSRegExpInstanceClass(reg_prototype_value); + JSHandle regexpFuncInstanceDynclass = factory_->CreateJSRegExpInstanceClass(regPrototypeValue); // RegExp = new Function() - JSHandle regexp_function( - NewBuiltinConstructor(env, reg_prototype, reg_exp::RegExpConstructor, "RegExp", FunctionLength::TWO)); + JSHandle regexpFunction( + NewBuiltinConstructor(env, regPrototype, reg_exp::RegExpConstructor, "RegExp", FunctionLength::TWO)); - JSHandle(regexp_function) - ->SetFunctionPrototype(thread_, regexp_func_instance_dynclass.GetTaggedValue()); + JSHandle(regexpFunction)->SetFunctionPrototype(thread_, regexpFuncInstanceDynclass.GetTaggedValue()); - SetFunctionsGenRegExpProto(env, reg_prototype); - SetFunctionsGenRegExp(env, regexp_function); + SetFunctionsGenRegExpProto(env, regPrototype); + SetFunctionsGenRegExp(env, regexpFunction); - 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()); + env->SetRegExpFunction(thread_, regexpFunction); + auto globalConst = const_cast(thread_->GlobalConstants()); + globalConst->SetConstant(ConstantIndex::JS_REGEXP_CLASS_INDEX, regexpFuncInstanceDynclass.GetTaggedValue()); } -void Builtins::InitializeArray(const JSHandle &env, - const JSHandle &obj_func_prototype_val) const +void Builtins::InitializeArray(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Arraybase.prototype - JSHandle arr_base_func_instance_dynclass = factory_->CreateJSArrayInstanceClass(obj_func_prototype_val); + JSHandle arrBaseFuncInstanceDynclass = factory_->CreateJSArrayInstanceClass(objFuncPrototypeVal); // Array.prototype - JSHandle arr_func_prototype = factory_->NewJSObject(arr_base_func_instance_dynclass); - JSHandle::Cast(arr_func_prototype)->SetLength(thread_, JSTaggedValue(FunctionLength::ZERO)); + JSHandle arrFuncPrototype = factory_->NewJSObject(arrBaseFuncInstanceDynclass); + JSHandle::Cast(arrFuncPrototype)->SetLength(thread_, JSTaggedValue(FunctionLength::ZERO)); auto accessor = thread_->GlobalConstants()->GetArrayLengthAccessor(); - JSArray::Cast(*arr_func_prototype) - ->SetPropertyInlinedProps(thread_, JSArray::LENGTH_INLINE_PROPERTY_INDEX, accessor); - JSHandle arr_func_prototype_value(arr_func_prototype); + JSArray::Cast(*arrFuncPrototype)->SetPropertyInlinedProps(thread_, JSArray::LENGTH_INLINE_PROPERTY_INDEX, accessor); + JSHandle arrFuncPrototypeValue(arrFuncPrototype); // Array.prototype_or_dynclass - JSHandle arr_func_instance_dynclass = factory_->CreateJSArrayInstanceClass(arr_func_prototype_value); + JSHandle arrFuncInstanceDynclass = factory_->CreateJSArrayInstanceClass(arrFuncPrototypeValue); // Array = new Function() - JSHandle array_function(NewBuiltinConstructor(env, arr_func_prototype, builtins::array::ArrayConstructor, - "Array", FunctionLength::ONE)); - JSHandle array_func_function(array_function); + JSHandle arrayFunction( + NewBuiltinConstructor(env, arrFuncPrototype, builtins::array::ArrayConstructor, "Array", FunctionLength::ONE)); + JSHandle arrayFuncFunction(arrayFunction); // Set the [[Realm]] internal slot of F to the running execution context's Realm - JSHandle lexical_env = factory_->NewLexicalEnv(0); - lexical_env->SetParentEnv(thread_, env.GetTaggedValue()); - array_func_function->SetLexicalEnv(thread_, lexical_env.GetTaggedValue()); + JSHandle lexicalEnv = factory_->NewLexicalEnv(0); + lexicalEnv->SetParentEnv(thread_, env.GetTaggedValue()); + arrayFuncFunction->SetLexicalEnv(thread_, lexicalEnv.GetTaggedValue()); - array_func_function->SetFunctionPrototype(thread_, arr_func_instance_dynclass.GetTaggedValue()); + arrayFuncFunction->SetFunctionPrototype(thread_, arrFuncInstanceDynclass.GetTaggedValue()); - env->SetArrayFunction(thread_, array_function); - env->SetArrayPrototype(thread_, arr_func_prototype); + env->SetArrayFunction(thread_, arrayFunction); + env->SetArrayPrototype(thread_, arrFuncPrototype); - SetFunctionsGenArrayProto(env, arr_func_prototype); + SetFunctionsGenArrayProto(env, arrFuncPrototype); - SetFunctionsGenArray(env, array_function); + SetFunctionsGenArray(env, arrayFunction); - const int arr_proto_len = 0; - JSHandle key_string = thread_->GlobalConstants()->GetHandledLengthString(); - PropertyDescriptor descriptor(thread_, JSHandle(thread_, JSTaggedValue(arr_proto_len)), true, false, + const int arrProtoLen = 0; + JSHandle keyString = thread_->GlobalConstants()->GetHandledLengthString(); + PropertyDescriptor descriptor(thread_, JSHandle(thread_, JSTaggedValue(arrProtoLen)), true, false, false); - JSObject::DefineOwnProperty(thread_, arr_func_prototype, key_string, descriptor); + JSObject::DefineOwnProperty(thread_, arrFuncPrototype, keyString, descriptor); - JSHandle values_key(factory_->NewFromCanBeCompressString("values")); + JSHandle valuesKey(factory_->NewFromCanBeCompressString("values")); PropertyDescriptor desc(thread_); - JSObject::GetOwnProperty(thread_, arr_func_prototype, values_key, desc); + JSObject::GetOwnProperty(thread_, arrFuncPrototype, valuesKey, desc); env->SetArrayProtoValuesFunction(thread_, desc.GetValue()); } -void Builtins::InitializeTypedArray(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeTypedArray(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // TypedArray.prototype - JSHandle typed_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle typed_arr_func_prototype_value(typed_arr_func_prototype); + JSHandle typedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle typedArrFuncPrototypeValue(typedArrFuncPrototype); // TypedArray.prototype_or_dynclass - JSHandle typed_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_TYPED_ARRAY, typed_arr_func_prototype_value); + JSHandle typedArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_TYPED_ARRAY, typedArrFuncPrototypeValue); // TypedArray = new Function() - JSHandle typed_array_function(NewBuiltinConstructor( - env, typed_arr_func_prototype, typed_array::TypedArrayBaseConstructor, "TypedArray", FunctionLength::ZERO)); + JSHandle typedArrayFunction(NewBuiltinConstructor( + env, typedArrFuncPrototype, typed_array::TypedArrayBaseConstructor, "TypedArray", FunctionLength::ZERO)); - JSHandle(typed_array_function) - ->SetProtoOrDynClass(thread_, typed_arr_func_instance_dynclass.GetTaggedValue()); + JSHandle(typedArrayFunction) + ->SetProtoOrDynClass(thread_, typedArrFuncInstanceDynclass.GetTaggedValue()); - env->SetTypedArrayFunction(thread_, typed_array_function.GetTaggedValue()); - env->SetTypedArrayPrototype(thread_, typed_arr_func_prototype); + env->SetTypedArrayFunction(thread_, typedArrayFunction.GetTaggedValue()); + env->SetTypedArrayPrototype(thread_, typedArrFuncPrototype); - JSHandle specific_typed_array_func_class = factory_->CreateDynClass( + JSHandle specificTypedArrayFuncClass = factory_->CreateDynClass( JSType::JS_FUNCTION, env->GetTypedArrayFunction(), HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); - specific_typed_array_func_class->SetConstructor(true); - env->SetSpecificTypedArrayFunctionClass(thread_, specific_typed_array_func_class); + specificTypedArrayFuncClass->SetConstructor(true); + env->SetSpecificTypedArrayFunctionClass(thread_, specificTypedArrayFuncClass); - SetFunctionsGenTypedArrayProto(env, typed_arr_func_prototype); + SetFunctionsGenTypedArrayProto(env, typedArrFuncPrototype); - SetFunctionsGenTypedArray(env, typed_array_function); + SetFunctionsGenTypedArray(env, typedArrayFunction); - 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); + 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); } -void Builtins::InitializeInt8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeInt8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int8Array.prototype - JSHandle int8_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle int8_arr_func_prototype_value(int8_arr_func_prototype); + JSHandle int8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle int8ArrFuncPrototypeValue(int8ArrFuncPrototype); // Int8Array.prototype_or_dynclass - JSHandle int8_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_INT8_ARRAY, int8_arr_func_prototype_value); + JSHandle int8ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_INT8_ARRAY, int8ArrFuncPrototypeValue); // Int8Array = new Function() - JSHandle int8_array_function = + JSHandle int8ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(int8_array::Int8ArrayConstructor)); - InitializeCtor(env, int8_arr_func_prototype, int8_array_function, "Int8Array", FunctionLength::THREE); + InitializeCtor(env, int8ArrFuncPrototype, int8ArrayFunction, "Int8Array", FunctionLength::THREE); - int8_array_function->SetProtoOrDynClass(thread_, int8_arr_func_instance_dynclass.GetTaggedValue()); + int8ArrayFunction->SetProtoOrDynClass(thread_, int8ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 1; + SetConstant(int8ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(int8ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetInt8ArrayFunction(thread_, int8ArrayFunction); } -void Builtins::InitializeUint8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeUint8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint8Array.prototype - JSHandle uint8_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle uint8_arr_func_prototype_value(uint8_arr_func_prototype); + JSHandle uint8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint8ArrFuncPrototypeValue(uint8ArrFuncPrototype); // Uint8Array.prototype_or_dynclass - JSHandle uint8_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_UINT8_ARRAY, uint8_arr_func_prototype_value); + JSHandle uint8ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_UINT8_ARRAY, uint8ArrFuncPrototypeValue); // Uint8Array = new Function() - JSHandle uint8_array_function = + JSHandle uint8ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(uint8_array::Uint8ArrayConstructor)); - InitializeCtor(env, uint8_arr_func_prototype, uint8_array_function, "Uint8Array", FunctionLength::THREE); + InitializeCtor(env, uint8ArrFuncPrototype, uint8ArrayFunction, "Uint8Array", FunctionLength::THREE); - uint8_array_function->SetProtoOrDynClass(thread_, uint8_arr_func_instance_dynclass.GetTaggedValue()); + uint8ArrayFunction->SetProtoOrDynClass(thread_, uint8ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 1; + SetConstant(uint8ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(uint8ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetUint8ArrayFunction(thread_, uint8ArrayFunction); } void Builtins::InitializeUint8ClampedArray(const JSHandle &env, - const JSHandle &obj_func_dynclass) const + const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint8ClampedArray.prototype - JSHandle uint8_clamped_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle uint8_clamped_arr_func_prototype_value(uint8_clamped_arr_func_prototype); + JSHandle uint8ClampedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint8ClampedArrFuncPrototypeValue(uint8ClampedArrFuncPrototype); // Uint8ClampedArray.prototype_or_dynclass - JSHandle uint8_clamped_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_UINT8_CLAMPED_ARRAY, uint8_clamped_arr_func_prototype_value); + JSHandle uint8ClampedArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_UINT8_CLAMPED_ARRAY, uint8ClampedArrFuncPrototypeValue); // Uint8ClampedArray = new Function() - JSHandle uint8_clamped_array_function = factory_->NewSpecificTypedArrayFunction( + JSHandle uint8ClampedArrayFunction = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(uint8_clamped_array::Uint8ClampedArrayConstructor)); - InitializeCtor(env, uint8_clamped_arr_func_prototype, uint8_clamped_array_function, "Uint8ClampedArray", + InitializeCtor(env, uint8ClampedArrFuncPrototype, uint8ClampedArrayFunction, "Uint8ClampedArray", FunctionLength::THREE); - uint8_clamped_array_function->SetProtoOrDynClass(thread_, - uint8_clamped_arr_func_instance_dynclass.GetTaggedValue()); + uint8ClampedArrayFunction->SetProtoOrDynClass(thread_, uint8ClampedArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 1; + SetConstant(uint8ClampedArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(uint8ClampedArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetUint8ClampedArrayFunction(thread_, uint8ClampedArrayFunction); } -void Builtins::InitializeInt16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeInt16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int16Array.prototype - JSHandle int16_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle int16_arr_func_prototype_value(int16_arr_func_prototype); + JSHandle int16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle int16ArrFuncPrototypeValue(int16ArrFuncPrototype); // Int16Array.prototype_or_dynclass - JSHandle int16_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_INT16_ARRAY, int16_arr_func_prototype_value); + JSHandle int16ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_INT16_ARRAY, int16ArrFuncPrototypeValue); // Int16Array = new Function() - JSHandle int16_array_function = + JSHandle int16ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(int16_array::Int16ArrayConstructor)); - InitializeCtor(env, int16_arr_func_prototype, int16_array_function, "Int16Array", FunctionLength::THREE); + InitializeCtor(env, int16ArrFuncPrototype, int16ArrayFunction, "Int16Array", FunctionLength::THREE); - int16_array_function->SetProtoOrDynClass(thread_, int16_arr_func_instance_dynclass.GetTaggedValue()); + int16ArrayFunction->SetProtoOrDynClass(thread_, int16ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 2; + SetConstant(int16ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(int16ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetInt16ArrayFunction(thread_, int16ArrayFunction); } -void Builtins::InitializeUint16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeUint16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint16Array.prototype - JSHandle uint16_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle uint16_arr_func_prototype_value(uint16_arr_func_prototype); + JSHandle uint16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint16ArrFuncPrototypeValue(uint16ArrFuncPrototype); // Uint16Array.prototype_or_dynclass - JSHandle uint16_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_UINT16_ARRAY, uint16_arr_func_prototype_value); + JSHandle uint16ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_UINT16_ARRAY, uint16ArrFuncPrototypeValue); // Uint16Array = new Function() - JSHandle uint16_array_function = + JSHandle uint16ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(uint16_array::Uint16ArrayConstructor)); - InitializeCtor(env, uint16_arr_func_prototype, uint16_array_function, "Uint16Array", FunctionLength::THREE); + InitializeCtor(env, uint16ArrFuncPrototype, uint16ArrayFunction, "Uint16Array", FunctionLength::THREE); - uint16_array_function->SetProtoOrDynClass(thread_, uint16_arr_func_instance_dynclass.GetTaggedValue()); + uint16ArrayFunction->SetProtoOrDynClass(thread_, uint16ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 2; + SetConstant(uint16ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(uint16ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetUint16ArrayFunction(thread_, uint16ArrayFunction); } -void Builtins::InitializeInt32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeInt32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int32Array.prototype - JSHandle int32_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle int32_arr_func_prototype_value(int32_arr_func_prototype); + JSHandle int32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle int32ArrFuncPrototypeValue(int32ArrFuncPrototype); // Int32Array.prototype_or_dynclass - JSHandle int32_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_INT32_ARRAY, int32_arr_func_prototype_value); + JSHandle int32ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_INT32_ARRAY, int32ArrFuncPrototypeValue); // Int32Array = new Function() - JSHandle int32_array_function = + JSHandle int32ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(int32_array::Int32ArrayConstructor)); - InitializeCtor(env, int32_arr_func_prototype, int32_array_function, "Int32Array", FunctionLength::THREE); + InitializeCtor(env, int32ArrFuncPrototype, int32ArrayFunction, "Int32Array", FunctionLength::THREE); - int32_array_function->SetProtoOrDynClass(thread_, int32_arr_func_instance_dynclass.GetTaggedValue()); + int32ArrayFunction->SetProtoOrDynClass(thread_, int32ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 4; + SetConstant(int32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(int32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetInt32ArrayFunction(thread_, int32ArrayFunction); } -void Builtins::InitializeUint32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeUint32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint32Array.prototype - JSHandle uint32_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle uint32_arr_func_prototype_value(uint32_arr_func_prototype); + JSHandle uint32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint32ArrFuncPrototypeValue(uint32ArrFuncPrototype); // Uint32Array.prototype_or_dynclass - JSHandle uint32_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_UINT32_ARRAY, uint32_arr_func_prototype_value); + JSHandle uint32ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_UINT32_ARRAY, uint32ArrFuncPrototypeValue); // Uint32Array = new Function() - JSHandle uint32_array_function = + JSHandle uint32ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(uint32_array::Uint32ArrayConstructor)); - InitializeCtor(env, uint32_arr_func_prototype, uint32_array_function, "Uint32Array", FunctionLength::THREE); + InitializeCtor(env, uint32ArrFuncPrototype, uint32ArrayFunction, "Uint32Array", FunctionLength::THREE); - uint32_array_function->SetProtoOrDynClass(thread_, uint32_arr_func_instance_dynclass.GetTaggedValue()); + uint32ArrayFunction->SetProtoOrDynClass(thread_, uint32ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 4; + SetConstant(uint32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(uint32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetUint32ArrayFunction(thread_, uint32ArrayFunction); } -void Builtins::InitializeFloat32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeFloat32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Float32Array.prototype - JSHandle float32_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle float32_arr_func_prototype_value(float32_arr_func_prototype); + JSHandle float32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle float32ArrFuncPrototypeValue(float32ArrFuncPrototype); // Float32Array.prototype_or_dynclass - JSHandle float32_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_FLOAT32_ARRAY, float32_arr_func_prototype_value); + JSHandle float32ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_FLOAT32_ARRAY, float32ArrFuncPrototypeValue); // Float32Array = new Function() - JSHandle float32_array_function = + JSHandle float32ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(float32_array::Float32ArrayConstructor)); - InitializeCtor(env, float32_arr_func_prototype, float32_array_function, "Float32Array", FunctionLength::THREE); + InitializeCtor(env, float32ArrFuncPrototype, float32ArrayFunction, "Float32Array", FunctionLength::THREE); - float32_array_function->SetProtoOrDynClass(thread_, float32_arr_func_instance_dynclass.GetTaggedValue()); + float32ArrayFunction->SetProtoOrDynClass(thread_, float32ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 4; + SetConstant(float32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(float32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetFloat32ArrayFunction(thread_, float32ArrayFunction); } -void Builtins::InitializeFloat64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeFloat64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Float64Array.prototype - JSHandle float64_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle float64_arr_func_prototype_value(float64_arr_func_prototype); + JSHandle float64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle float64ArrFuncPrototypeValue(float64ArrFuncPrototype); // Float64Array.prototype_or_dynclass - JSHandle float64_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_FLOAT64_ARRAY, float64_arr_func_prototype_value); + JSHandle float64ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_FLOAT64_ARRAY, float64ArrFuncPrototypeValue); // Float64Array = new Function() - JSHandle float64_array_function = + JSHandle float64ArrayFunction = factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(float64_array::Float64ArrayConstructor)); - InitializeCtor(env, float64_arr_func_prototype, float64_array_function, "Float64Array", FunctionLength::THREE); + InitializeCtor(env, float64ArrFuncPrototype, float64ArrayFunction, "Float64Array", FunctionLength::THREE); - float64_array_function->SetProtoOrDynClass(thread_, float64_arr_func_instance_dynclass.GetTaggedValue()); + float64ArrayFunction->SetProtoOrDynClass(thread_, float64ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 8; + SetConstant(float64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(float64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetFloat64ArrayFunction(thread_, float64ArrayFunction); } -void Builtins::InitializeBigInt64Array(const JSHandle &env, - const JSHandle &obj_func_dynclass) const +void Builtins::InitializeBigInt64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigInt64Array.prototype - JSHandle big_int64_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle big_int64_arr_func_prototype_value(big_int64_arr_func_prototype); + JSHandle bigInt64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle bigInt64ArrFuncPrototypeValue(bigInt64ArrFuncPrototype); // BigInt64Array.prototype_or_dynclass - JSHandle big_int64_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_BIGINT64_ARRAY, big_int64_arr_func_prototype_value); + JSHandle bigInt64ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_BIGINT64_ARRAY, bigInt64ArrFuncPrototypeValue); // BigInt64Array = new Function() - JSHandle big_int64_array_function = factory_->NewSpecificTypedArrayFunction( + JSHandle bigInt64ArrayFunction = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(big_int64_array::BigInt64ArrayConstructor)); - InitializeCtor(env, big_int64_arr_func_prototype, big_int64_array_function, "BigInt64Array", FunctionLength::THREE); + InitializeCtor(env, bigInt64ArrFuncPrototype, bigInt64ArrayFunction, "BigInt64Array", FunctionLength::THREE); - big_int64_array_function->SetProtoOrDynClass(thread_, big_int64_arr_func_instance_dynclass.GetTaggedValue()); + bigInt64ArrayFunction->SetProtoOrDynClass(thread_, bigInt64ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 8; + SetConstant(bigInt64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(bigInt64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetBigInt64ArrayFunction(thread_, bigInt64ArrayFunction); } -void Builtins::InitializeBigUint64Array(const JSHandle &env, - const JSHandle &obj_func_dynclass) const +void Builtins::InitializeBigUint64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigUint64Array.prototype - JSHandle big_uint64_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle big_uint64_arr_func_prototype_value(big_uint64_arr_func_prototype); + JSHandle bigUint64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle bigUint64ArrFuncPrototypeValue(bigUint64ArrFuncPrototype); // BigUint64Array.prototype_or_dynclass - JSHandle big_uint64_arr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_BIGUINT64_ARRAY, big_uint64_arr_func_prototype_value); + JSHandle bigUint64ArrFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_BIGUINT64_ARRAY, bigUint64ArrFuncPrototypeValue); // BigUint64Array = new Function() - JSHandle big_uint64_array_function = factory_->NewSpecificTypedArrayFunction( + JSHandle bigUint64ArrayFunction = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(big_uint64_array::BigUint64ArrayConstructor)); - InitializeCtor(env, big_uint64_arr_func_prototype, big_uint64_array_function, "BigUint64Array", - FunctionLength::THREE); + InitializeCtor(env, bigUint64ArrFuncPrototype, bigUint64ArrayFunction, "BigUint64Array", FunctionLength::THREE); - big_uint64_array_function->SetProtoOrDynClass(thread_, big_uint64_arr_func_instance_dynclass.GetTaggedValue()); + bigUint64ArrayFunction->SetProtoOrDynClass(thread_, bigUint64ArrFuncInstanceDynclass.GetTaggedValue()); - 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); + const int bytesPerElement = 8; + SetConstant(bigUint64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + SetConstant(JSHandle(bigUint64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); + env->SetBigUint64ArrayFunction(thread_, bigUint64ArrayFunction); } -void Builtins::InitializeArrayBuffer(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeArrayBuffer(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // ArrayBuffer.prototype - JSHandle array_buffer_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle array_buffer_func_prototype_value(array_buffer_func_prototype); + JSHandle arrayBufferFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle arrayBufferFuncPrototypeValue(arrayBufferFuncPrototype); // ArrayBuffer.prototype_or_dynclass - JSHandle array_buffer_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_ARRAY_BUFFER, array_buffer_func_prototype_value); + JSHandle arrayBufferFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_ARRAY_BUFFER, arrayBufferFuncPrototypeValue); // ArrayBuffer = new Function() - JSHandle array_buffer_function(NewBuiltinConstructor(env, array_buffer_func_prototype, - builtins::array_buffer::ArrayBufferConstructor, - "ArrayBuffer", FunctionLength::ONE)); + JSHandle arrayBufferFunction(NewBuiltinConstructor(env, arrayBufferFuncPrototype, + builtins::array_buffer::ArrayBufferConstructor, + "ArrayBuffer", FunctionLength::ONE)); - JSHandle(array_buffer_function) - ->SetFunctionPrototype(thread_, array_buffer_func_instance_dynclass.GetTaggedValue()); + JSHandle(arrayBufferFunction) + ->SetFunctionPrototype(thread_, arrayBufferFuncInstanceDynclass.GetTaggedValue()); - SetFunctionsGenArrayBufferProto(env, array_buffer_func_prototype); - SetFunctionsGenArrayBuffer(env, array_buffer_function); + SetFunctionsGenArrayBufferProto(env, arrayBufferFuncPrototype); + SetFunctionsGenArrayBuffer(env, arrayBufferFunction); // 24.1.4.4 ArrayBuffer.prototype[@@toStringTag] - SetStringTagSymbol(env, array_buffer_func_prototype, "ArrayBuffer"); + SetStringTagSymbol(env, arrayBufferFuncPrototype, "ArrayBuffer"); - env->SetArrayBufferFunction(thread_, array_buffer_function.GetTaggedValue()); + env->SetArrayBufferFunction(thread_, arrayBufferFunction.GetTaggedValue()); } void Builtins::InitializeReflect(const JSHandle &env, - const JSHandle &obj_func_prototype_val) const + const JSHandle &objFuncPrototypeVal) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle reflect_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); - JSHandle reflect_object = factory_->NewJSObject(reflect_dynclass); + JSHandle reflectDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); + JSHandle reflectObject = factory_->NewJSObject(reflectDynclass); - SetFunctionsGenReflect(env, reflect_object); + SetFunctionsGenReflect(env, reflectObject); - 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); + 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); // @@ToStringTag - SetStringTagSymbol(env, reflect_object, "Reflect"); + SetStringTagSymbol(env, reflectObject, "Reflect"); - env->SetReflectFunction(thread_, reflect_object.GetTaggedValue()); + env->SetReflectFunction(thread_, reflectObject.GetTaggedValue()); } -void Builtins::InitializePromise(const JSHandle &env, const JSHandle &promise_func_dynclass) +void Builtins::InitializePromise(const JSHandle &env, const JSHandle &promiseFuncDynclass) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Promise.prototype - JSHandle promise_func_prototype = factory_->NewJSObject(promise_func_dynclass); - JSHandle promise_func_prototype_value(promise_func_prototype); + JSHandle promiseFuncPrototype = factory_->NewJSObject(promiseFuncDynclass); + JSHandle promiseFuncPrototypeValue(promiseFuncPrototype); // Promise.prototype_or_dynclass - JSHandle promise_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_PROMISE, promise_func_prototype_value); + JSHandle promiseFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_PROMISE, promiseFuncPrototypeValue); // Promise() = new Function() - JSHandle promise_function(NewBuiltinConstructor(env, promise_func_prototype, promise::PromiseConstructor, - "Promise", FunctionLength::ONE)); - JSHandle(promise_function) - ->SetFunctionPrototype(thread_, promise_func_instance_dynclass.GetTaggedValue()); - SetFunctionsGenPromise(env, promise_function); + JSHandle promiseFunction( + NewBuiltinConstructor(env, promiseFuncPrototype, promise::PromiseConstructor, "Promise", FunctionLength::ONE)); + JSHandle(promiseFunction)->SetFunctionPrototype(thread_, promiseFuncInstanceDynclass.GetTaggedValue()); + SetFunctionsGenPromise(env, promiseFunction); - SetFunctionsGenPromiseProto(env, promise_func_prototype); + SetFunctionsGenPromiseProto(env, promiseFuncPrototype); // Promise.prototype [ @@toStringTag ] - SetStringTagSymbol(env, promise_func_prototype, "Promise"); + SetStringTagSymbol(env, promiseFuncPrototype, "Promise"); - env->SetPromiseFunction(thread_, promise_function); + env->SetPromiseFunction(thread_, promiseFunction); } void Builtins::InitializePromiseJob(const JSHandle &env) { - JSHandle key_string(thread_->GlobalConstants()->GetHandledEmptyString()); - auto func = NewFunction(env, key_string, promise_job::PromiseReactionJob, FunctionLength::TWO); + JSHandle keyString(thread_->GlobalConstants()->GetHandledEmptyString()); + auto func = NewFunction(env, keyString, promise_job::PromiseReactionJob, FunctionLength::TWO); env->SetPromiseReactionJob(thread_, func); - func = NewFunction(env, key_string, promise_job::PromiseResolveThenableJob, FunctionLength::THREE); + func = NewFunction(env, keyString, promise_job::PromiseResolveThenableJob, FunctionLength::THREE); env->SetPromiseResolveThenableJob(thread_, func); } void Builtins::InitializeFinalizationRegistry(const JSHandle &env, - const JSHandle &obj_func_dynclass) const + const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // FinalizationRegistry.prototype - JSHandle registry_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle registry_func_prototype_value(registry_func_prototype); + JSHandle registryFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle registryFuncPrototypeValue(registryFuncPrototype); // FinalizationRegistry.prototype_or_dynclass - JSHandle registry_func_instance_dynclass = - factory_->CreateDynClass(JSType::FINALIZATION_REGISTRY, registry_func_prototype_value); + JSHandle registryFuncInstanceDynclass = + factory_->CreateDynClass(JSType::FINALIZATION_REGISTRY, registryFuncPrototypeValue); // FinalizationRegistry() = new Function() - JSHandle registry_function(NewBuiltinConstructor( - env, registry_func_prototype, finalization_registry::Constructor, "FinalizationRegistry", FunctionLength::ONE)); + JSHandle registryFunction(NewBuiltinConstructor( + env, registryFuncPrototype, finalization_registry::Constructor, "FinalizationRegistry", FunctionLength::ONE)); // FinalizationRegistry().prototype = FinalizationRegistry.Prototype & // FinalizationRegistry.prototype.constructor = Finalizationregistry() - JSFunction::Cast(registry_function->GetTaggedObject()) - ->SetProtoOrDynClass(thread_, registry_func_instance_dynclass.GetTaggedValue()); + JSFunction::Cast(registryFunction->GetTaggedObject()) + ->SetProtoOrDynClass(thread_, registryFuncInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(registry_func_prototype), constructor_key, - registry_function); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(registryFuncPrototype), constructorKey, registryFunction); - SetFunctionsGenFinalizationRegistryProto(env, registry_func_prototype); + SetFunctionsGenFinalizationRegistryProto(env, registryFuncPrototype); // @@ToStringTag - SetStringTagSymbol(env, registry_func_prototype, "FinalizationRegistry"); + SetStringTagSymbol(env, registryFuncPrototype, "FinalizationRegistry"); - const_cast(global_const) - ->SetConstant(ConstantIndex::FINALIZATION_REGISTRY_CLASS_INDEX, - registry_func_instance_dynclass.GetTaggedValue()); + const_cast(globalConst) + ->SetConstant(ConstantIndex::FINALIZATION_REGISTRY_CLASS_INDEX, registryFuncInstanceDynclass.GetTaggedValue()); } -void Builtins::InitializeDataView(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeDataView(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // ArrayBuffer.prototype - JSHandle data_view_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle data_view_func_prototype_value(data_view_func_prototype); + JSHandle dataViewFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle dataViewFuncPrototypeValue(dataViewFuncPrototype); // ArrayBuffer.prototype_or_dynclass - JSHandle data_view_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_DATA_VIEW, data_view_func_prototype_value); + JSHandle dataViewFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_DATA_VIEW, dataViewFuncPrototypeValue); // ArrayBuffer = new Function() - JSHandle data_view_function(NewBuiltinConstructor( - env, data_view_func_prototype, data_view::DataViewConstructor, "DataView", FunctionLength::ONE)); + JSHandle dataViewFunction(NewBuiltinConstructor( + env, dataViewFuncPrototype, data_view::DataViewConstructor, "DataView", FunctionLength::ONE)); - JSHandle(data_view_function) - ->SetProtoOrDynClass(thread_, data_view_func_instance_dynclass.GetTaggedValue()); + JSHandle(dataViewFunction)->SetProtoOrDynClass(thread_, dataViewFuncInstanceDynclass.GetTaggedValue()); - SetFunctionsGenDataViewProto(env, data_view_func_prototype); + SetFunctionsGenDataViewProto(env, dataViewFuncPrototype); // 24.2.4.21 DataView.prototype[ @@toStringTag ] - SetStringTagSymbol(env, data_view_func_prototype, "DataView"); - env->SetDataViewFunction(thread_, data_view_function.GetTaggedValue()); + SetStringTagSymbol(env, dataViewFuncPrototype, "DataView"); + env->SetDataViewFunction(thread_, dataViewFunction.GetTaggedValue()); } JSHandle Builtins::NewBuiltinConstructor(const JSHandle &env, - const JSHandle &prototype, EcmaEntrypoint ctor_func, + const JSHandle &prototype, EcmaEntrypoint ctorFunc, const char *name, int length) const { JSHandle ctor = - factory_->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_CONSTRUCTOR); + factory_->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_CONSTRUCTOR); InitializeCtor(env, prototype, ctor, name, length); return ctor; } @@ -1735,17 +1707,17 @@ JSHandle Builtins::NewFunction(const JSHandle &env, const { JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle base_function(function); - JSHandle handle_undefine(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, base_function, key, handle_undefine); + JSHandle baseFunction(function); + JSHandle handleUndefine(thread_, JSTaggedValue::Undefined()); + JSFunction::SetFunctionName(thread_, baseFunction, key, handleUndefine); return function; } void Builtins::SetFunction(const JSHandle &env, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length) const { - JSHandle key_string(factory_->NewFromString(key)); - SetFunction(env, obj, key_string, func, length); + JSHandle keyString(factory_->NewFromString(key)); + SetFunction(env, obj, keyString, func, length); } void Builtins::SetFunction(const JSHandle &env, const JSHandle &obj, @@ -1765,10 +1737,10 @@ void Builtins::SetFunction(const JSHandle &obj, const JSHandle &env, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length) const { - JSHandle key_string(factory_->NewFromString(key)); - JSHandle function = NewFunction(env, key_string, func, length); + JSHandle keyString(factory_->NewFromString(key)); + JSHandle function = NewFunction(env, keyString, func, length); PropertyDescriptor descriptor(thread_, JSHandle(function), false, false, false); - JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); + JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); } template @@ -1778,10 +1750,10 @@ void Builtins::SetFunctionAtSymbol(const JSHandle &env, const JSHandl { JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - 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); + JSHandle nameString(factory_->NewFromString(name)); + JSHandle baseFunction(function); + JSHandle handleUndefine(thread_, JSTaggedValue::Undefined()); + JSFunction::SetFunctionName(thread_, baseFunction, nameString, handleUndefine); SetFunctionAtSymbol(obj, symbol, JSHandle::Cast(function)); } @@ -1820,9 +1792,9 @@ JSHandle Builtins::CreateGetter(const JSHandle &env, E ASSERT(length == 0); JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle func_name(factory_->NewFromString(name)); + JSHandle funcName(factory_->NewFromString(name)); JSHandle prefix = thread_->GlobalConstants()->GetHandledGetString(); - JSFunction::SetFunctionName(thread_, JSHandle(function), func_name, prefix); + JSFunction::SetFunctionName(thread_, JSHandle(function), funcName, prefix); return JSHandle(function); } @@ -1832,48 +1804,47 @@ JSHandle Builtins::CreateSetter(const JSHandle &env, E ASSERT(length == 1); JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle func_name(factory_->NewFromString(name)); + JSHandle funcName(factory_->NewFromString(name)); JSHandle prefix = thread_->GlobalConstants()->GetHandledSetString(); - JSFunction::SetFunctionName(thread_, JSHandle(function), func_name, prefix); + JSFunction::SetFunctionName(thread_, JSHandle(function), funcName, prefix); return JSHandle(function); } void Builtins::SetConstant(const JSHandle &obj, const char *key, JSTaggedValue value) const { - 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); + JSHandle valueHandle(thread_, value); + JSHandle keyString(factory_->NewFromString(key)); + PropertyDescriptor descriptor(thread_, valueHandle, false, false, false); + JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); } void Builtins::SetConstantObject(const JSHandle &obj, const char *key, JSHandle &value) const { - JSHandle key_string(factory_->NewFromString(key)); + JSHandle keyString(factory_->NewFromString(key)); PropertyDescriptor descriptor(thread_, value, false, false, false); - JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); + JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); } -void Builtins::SetGlobalThis(const JSHandle &obj, const char *key, - const JSHandle &global_value) +void Builtins::SetGlobalThis(const JSHandle &obj, const char *key, const JSHandle &globalValue) { - JSHandle key_string(factory_->NewFromString(key)); - PropertyDescriptor descriptor(thread_, global_value, true, false, true); - JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); + JSHandle keyString(factory_->NewFromString(key)); + PropertyDescriptor descriptor(thread_, globalValue, true, false, true); + JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); } void Builtins::SetAttribute(const JSHandle &obj, const char *key, const char *value) const { - JSHandle key_string(factory_->NewFromString(key)); + JSHandle keyString(factory_->NewFromString(key)); PropertyDescriptor descriptor(thread_, JSHandle(factory_->NewFromString(value)), true, false, true); - JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); + JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); } void Builtins::SetNoneAttributeProperty(const JSHandle &obj, const char *key, const JSHandle &value) const { - JSHandle key_string(factory_->NewFromString(key)); + JSHandle keyString(factory_->NewFromString(key)); PropertyDescriptor des(thread_, value, false, false, false); - JSObject::DefineOwnProperty(thread_, obj, key_string, des); + JSObject::DefineOwnProperty(thread_, obj, keyString, des); } void Builtins::StrictModeForbiddenAccessCallerArguments(const JSHandle &env, @@ -1890,176 +1861,171 @@ void Builtins::StrictModeForbiddenAccessCallerArguments(const JSHandle &env, - const JSHandle &obj_func_dynclass) const + const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); - JSHandle generator_func_prototype_value(generator_func_prototype); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle generatorFuncPrototypeValue(generatorFuncPrototype); // 26.3.3.1 GeneratorFunction.prototype.constructor // GeneratorFunction.prototype_or_dynclass - JSHandle generator_func_instance_dynclass = factory_->CreateDynClass( - JSType::JS_GENERATOR_FUNCTION, generator_func_prototype_value, HClass::IS_CALLABLE); - generator_func_instance_dynclass->SetExtensible(true); + JSHandle generatorFuncInstanceDynclass = factory_->CreateDynClass( + JSType::JS_GENERATOR_FUNCTION, generatorFuncPrototypeValue, HClass::IS_CALLABLE); + generatorFuncInstanceDynclass->SetExtensible(true); // GeneratorFunction = new GeneratorFunction() - JSHandle generator_function = - NewBuiltinConstructor(env, generator_func_prototype, builtins::generator_function::GeneratorFunctionConstructor, + JSHandle generatorFunction = + NewBuiltinConstructor(env, generatorFuncPrototype, builtins::generator_function::GeneratorFunctionConstructor, "GeneratorFunction", FunctionLength::ONE); - 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); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + PropertyDescriptor generatorDesc(thread_, JSHandle::Cast(generatorFunction), false, false, true); + JSObject::DefineOwnProperty(thread_, generatorFuncPrototype, constructorKey, generatorDesc); + generatorFunction->SetProtoOrDynClass(thread_, generatorFuncInstanceDynclass.GetTaggedValue()); + env->SetGeneratorFunctionFunction(thread_, generatorFunction); // 26.3.3.2 GeneratorFunction.prototype.prototype -> Generator prototype object. PropertyDescriptor descriptor(thread_, env->GetGeneratorPrototype(), false, false, true); - JSObject::DefineOwnProperty(thread_, generator_func_prototype, global_const->GetHandledPrototypeString(), - descriptor); + JSObject::DefineOwnProperty(thread_, generatorFuncPrototype, globalConst->GetHandledPrototypeString(), descriptor); // 26.3.3.3 GeneratorFunction.prototype[@@toStringTag] - SetStringTagSymbol(env, generator_func_prototype, "GeneratorFunction"); + SetStringTagSymbol(env, generatorFuncPrototype, "GeneratorFunction"); // GeneratorFunction prototype __proto__ -> Function. - JSObject::SetPrototype(thread_, generator_func_prototype, env->GetFunctionPrototype()); + JSObject::SetPrototype(thread_, generatorFuncPrototype, env->GetFunctionPrototype()); // 26.5.1.1 Generator.prototype.constructor -> %GeneratorFunction.prototype%. - PropertyDescriptor generator_obj_desc(thread_, generator_func_prototype_value, false, false, true); + PropertyDescriptor generatorObjDesc(thread_, generatorFuncPrototypeValue, false, false, true); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialGenerator()), - global_const->GetHandledConstructorString(), generator_obj_desc); + globalConst->GetHandledConstructorString(), generatorObjDesc); // Generator instances prototype -> GeneratorFunction.prototype.prototype - PropertyDescriptor generator_obj_proto_desc(thread_, generator_func_prototype_value, true, false, false); + PropertyDescriptor generatorObjProtoDesc(thread_, generatorFuncPrototypeValue, true, false, false); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialGenerator()), - global_const->GetHandledPrototypeString(), generator_obj_proto_desc); + globalConst->GetHandledPrototypeString(), generatorObjProtoDesc); - env->SetGeneratorFunctionPrototype(thread_, generator_func_prototype); + env->SetGeneratorFunctionPrototype(thread_, generatorFuncPrototype); } -void Builtins::InitializeGenerator(const JSHandle &env, const JSHandle &obj_func_dynclass) const +void Builtins::InitializeGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - SetFunctionsGenGeneratorProto(env, generator_func_prototype); + SetFunctionsGenGeneratorProto(env, generatorFuncPrototype); // 26.5.1.5 Generator.prototype[@@toStringTag] - SetStringTagSymbol(env, generator_func_prototype, "Generator"); + SetStringTagSymbol(env, generatorFuncPrototype, "Generator"); // Generator with constructor, symbolTag, next/return/throw etc. PropertyDescriptor descriptor(thread_, env->GetIteratorPrototype(), true, false, false); - JSObject::DefineOwnProperty(thread_, generator_func_prototype, global_const->GetHandledPrototypeString(), - descriptor); - env->SetGeneratorPrototype(thread_, generator_func_prototype); - JSObject::SetPrototype(thread_, generator_func_prototype, env->GetIteratorPrototype()); + JSObject::DefineOwnProperty(thread_, generatorFuncPrototype, globalConst->GetHandledPrototypeString(), descriptor); + env->SetGeneratorPrototype(thread_, generatorFuncPrototype); + JSObject::SetPrototype(thread_, generatorFuncPrototype, env->GetIteratorPrototype()); // Generator {} - 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); + JSHandle initialGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, JSHandle(generatorFuncPrototype)); + env->SetInitialGenerator(thread_, initialGeneratorFuncPrototype); } void Builtins::InitializeAsyncGeneratorFunction(const JSHandle &env, - const JSHandle &obj_func_dynclass) const + const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - 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); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle asyncGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle asyncGeneratorFuncPrototypeValue(asyncGeneratorFuncPrototype); // 26.3.3.1 AsyncGeneratorFunction.prototype.constructor // AsyncGeneratorFunction.prototype_or_dynclass - 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); + JSHandle asyncGeneratorFuncInstanceDynclass = factory_->CreateDynClass( + JSType::JS_ASYNC_GENERATOR_FUNCTION, asyncGeneratorFuncPrototypeValue, HClass::IS_CALLABLE); + asyncGeneratorFuncInstanceDynclass->SetExtensible(true); // AsyncGeneratorFunction = new AsyncGeneratorFunction() - JSHandle async_generator_function = NewBuiltinConstructor( - env, async_generator_func_prototype, builtins::async_generator_function::AsyncGeneratorFunctionConstructor, + JSHandle asyncGeneratorFunction = NewBuiltinConstructor( + env, asyncGeneratorFuncPrototype, builtins::async_generator_function::AsyncGeneratorFunctionConstructor, "AsyncGeneratorFunction", FunctionLength::ONE); - JSHandle constructor_key = global_const->GetHandledConstructorString(); - PropertyDescriptor async_generator_desc(thread_, JSHandle::Cast(async_generator_function), false, - 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); + 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); // 26.3.3.2 AsyncGeneratorFunction.prototype.prototype -> AsyncGenerator prototype object. PropertyDescriptor descriptor(thread_, env->GetAsyncGeneratorPrototype(), false, false, true); - JSObject::DefineOwnProperty(thread_, async_generator_func_prototype, global_const->GetHandledPrototypeString(), + JSObject::DefineOwnProperty(thread_, asyncGeneratorFuncPrototype, globalConst->GetHandledPrototypeString(), descriptor); // 26.3.3.3 AsyncGeneratorFunction.prototype[@@toStringTag] - SetStringTagSymbol(env, async_generator_func_prototype, "AsyncGeneratorFunction"); + SetStringTagSymbol(env, asyncGeneratorFuncPrototype, "AsyncGeneratorFunction"); // AsyncGeneratorFunction prototype __proto__ -> Function. - JSObject::SetPrototype(thread_, async_generator_func_prototype, env->GetFunctionPrototype()); + JSObject::SetPrototype(thread_, asyncGeneratorFuncPrototype, env->GetFunctionPrototype()); // 26.5.1.1 AsyncGenerator.prototype.constructor -> %AsyncGeneratorFunction.prototype%. - PropertyDescriptor async_generator_obj_desc(thread_, async_generator_func_prototype_value, false, false, true); + PropertyDescriptor asyncGeneratorObjDesc(thread_, asyncGeneratorFuncPrototypeValue, false, false, true); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialAsyncGenerator()), - global_const->GetHandledConstructorString(), async_generator_obj_desc); + globalConst->GetHandledConstructorString(), asyncGeneratorObjDesc); // AsyncGenerator instances prototype -> AsyncGeneratorFunction.prototype.prototype - PropertyDescriptor async_generator_obj_proto_desc(thread_, async_generator_func_prototype_value, true, false, - false); + PropertyDescriptor asyncGeneratorObjProtoDesc(thread_, asyncGeneratorFuncPrototypeValue, true, false, false); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialAsyncGenerator()), - global_const->GetHandledPrototypeString(), async_generator_obj_proto_desc); + globalConst->GetHandledPrototypeString(), asyncGeneratorObjProtoDesc); - env->SetAsyncGeneratorFunctionPrototype(thread_, async_generator_func_prototype); + env->SetAsyncGeneratorFunctionPrototype(thread_, asyncGeneratorFuncPrototype); } -void Builtins::InitializeAsyncGenerator(const JSHandle &env, - const JSHandle &obj_func_dynclass) const +void Builtins::InitializeAsyncGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle async_generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle asyncGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - SetFunctionsGenAsyncGeneratorProto(env, async_generator_func_prototype); + SetFunctionsGenAsyncGeneratorProto(env, asyncGeneratorFuncPrototype); // 27.6.1.5 AsyncGenerator.prototype[@@toStringTag] - SetStringTagSymbol(env, async_generator_func_prototype, "AsyncGenerator"); + SetStringTagSymbol(env, asyncGeneratorFuncPrototype, "AsyncGenerator"); PropertyDescriptor descriptor(thread_, env->GetAsyncIteratorPrototype(), true, false, false); - JSObject::DefineOwnProperty(thread_, async_generator_func_prototype, global_const->GetHandledPrototypeString(), + JSObject::DefineOwnProperty(thread_, asyncGeneratorFuncPrototype, globalConst->GetHandledPrototypeString(), descriptor); - env->SetAsyncGeneratorPrototype(thread_, async_generator_func_prototype); - JSObject::SetPrototype(thread_, async_generator_func_prototype, env->GetAsyncIteratorPrototype()); + env->SetAsyncGeneratorPrototype(thread_, asyncGeneratorFuncPrototype); + JSObject::SetPrototype(thread_, asyncGeneratorFuncPrototype, env->GetAsyncIteratorPrototype()); // AsyncGenerator {} - 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); + JSHandle initialAsyncGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSObject::SetPrototype(thread_, initialAsyncGeneratorFuncPrototype, + JSHandle(asyncGeneratorFuncPrototype)); + env->SetInitialAsyncGenerator(thread_, initialAsyncGeneratorFuncPrototype); } void Builtins::InitializeAsyncFromSyncIteratorPrototypeObject(const JSHandle &env, - const JSHandle &obj_func_dynclass) const + const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle async_from_sync_iterator_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle asyncFromSyncIteratorPrototype = factory_->NewJSObject(objFuncDynclass); - SetFunctionsGenAsyncFromSyncIteratorProto(env, async_from_sync_iterator_prototype); + SetFunctionsGenAsyncFromSyncIteratorProto(env, asyncFromSyncIteratorPrototype); - JSObject::SetPrototype(thread_, async_from_sync_iterator_prototype, env->GetAsyncIteratorPrototype()); - env->SetAsyncFromSyncIteratorPrototype(thread_, async_from_sync_iterator_prototype); + JSObject::SetPrototype(thread_, asyncFromSyncIteratorPrototype, env->GetAsyncIteratorPrototype()); + env->SetAsyncFromSyncIteratorPrototype(thread_, asyncFromSyncIteratorPrototype); } void Builtins::SetArgumentsSharedAccessor(const JSHandle &env) { - JSHandle throw_function = env->GetThrowTypeError(); + JSHandle throwFunction = env->GetThrowTypeError(); JSHandle accessor = factory_->NewAccessorData(); - accessor->SetGetter(thread_, throw_function); - accessor->SetSetter(thread_, throw_function); + accessor->SetGetter(thread_, throwFunction); + accessor->SetSetter(thread_, throwFunction); env->SetArgumentsCallerAccessor(thread_, accessor); accessor = factory_->NewAccessorData(); - accessor->SetGetter(thread_, throw_function); - accessor->SetSetter(thread_, throw_function); + accessor->SetGetter(thread_, throwFunction); + accessor->SetSetter(thread_, throwFunction); env->SetArgumentsCalleeAccessor(thread_, accessor); } @@ -2083,10 +2049,10 @@ void Builtins::SetGetter(const JSHandle &obj, const JSHandle Builtins::NewIntlConstructor(const JSHandle &env, const JSHandle &prototype, - EcmaEntrypoint ctor_func, const char *name, int length) + EcmaEntrypoint ctorFunc, const char *name, int length) { JSHandle ctor = - factory_->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_CONSTRUCTOR); + factory_->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_CONSTRUCTOR); InitializeIntlCtor(env, prototype, ctor, name, length); return ctor; } @@ -2094,208 +2060,207 @@ 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 *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); JSFunction::SetFunctionLength(thread_, ctor, JSTaggedValue(length)); - JSHandle name_string(factory_->NewFromString(name)); - JSFunction::SetFunctionName(thread_, JSHandle(ctor), name_string, + JSHandle nameString(factory_->NewFromString(name)); + JSFunction::SetFunctionName(thread_, JSHandle(ctor), nameString, JSHandle(thread_, JSTaggedValue::Undefined())); - JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); PropertyDescriptor descriptor1(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, prototype, constructor_key, descriptor1); + JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1); // set "prototype" in constructor. ctor->SetFunctionPrototype(thread_, prototype.GetTaggedValue()); - if (!JSTaggedValue::SameValue(name_string, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { - JSHandle intl_object(thread_, env->GetIntlFunction().GetTaggedValue()); + if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { + JSHandle intlObject(thread_, env->GetIntlFunction().GetTaggedValue()); PropertyDescriptor descriptor2(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, intl_object, name_string, descriptor2); + JSObject::DefineOwnProperty(thread_, intlObject, nameString, descriptor2); } } -void Builtins::InitializeIntl(const JSHandle &env, const JSHandle &obj_func_prototype_value) +void Builtins::InitializeIntl(const JSHandle &env, const JSHandle &objFuncPrototypeValue) { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle intl_dynclass = factory_->CreateDynClass(JSType::JS_INTL, obj_func_prototype_value); - JSHandle intl_object = factory_->NewJSObject(intl_dynclass); + JSHandle intlDynclass = factory_->CreateDynClass(JSType::JS_INTL, objFuncPrototypeValue); + JSHandle intlObject = factory_->NewJSObject(intlDynclass); - JSHandle init_intl_symbol(factory_->NewPublicSymbolWithChar("Symbol.IntlLegacyConstructedSymbol")); - SetNoneAttributeProperty(intl_object, "fallbackSymbol", init_intl_symbol); + JSHandle initIntlSymbol(factory_->NewPublicSymbolWithChar("Symbol.IntlLegacyConstructedSymbol")); + SetNoneAttributeProperty(intlObject, "fallbackSymbol", initIntlSymbol); - SetFunctionsGenIntl(env, intl_object); + SetFunctionsGenIntl(env, intlObject); // initial value of the "Intl" property of the global object. - 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); + 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); - SetStringTagSymbol(env, intl_object, "Intl"); + SetStringTagSymbol(env, intlObject, "Intl"); - env->SetIntlFunction(thread_, intl_object); + env->SetIntlFunction(thread_, intlObject); } void Builtins::InitializeDateTimeFormat(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // DateTimeFormat.prototype - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle dtf_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle dtf_prototype_value(dtf_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle dtfPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle dtfPrototypeValue(dtfPrototype); // DateTimeFormat.prototype_or_dynclass - JSHandle dtf_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_DATE_TIME_FORMAT, dtf_prototype_value); + JSHandle dtfFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_DATE_TIME_FORMAT, dtfPrototypeValue); // DateTimeFormat = new Function() // 13.4.1 Intl.DateTimeFormat.prototype.constructor - JSHandle dtf_function(NewIntlConstructor(env, dtf_prototype, date_time_format::DateTimeFormatConstructor, - "DateTimeFormat", FunctionLength::ZERO)); - JSHandle(dtf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*dtf_func_instance_dynclass)); + JSHandle dtfFunction(NewIntlConstructor(env, dtfPrototype, date_time_format::DateTimeFormatConstructor, + "DateTimeFormat", FunctionLength::ZERO)); + JSHandle(dtfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*dtfFuncInstanceDynclass)); - SetFunctionsGenDateTimeFormat(env, dtf_function); + SetFunctionsGenDateTimeFormat(env, dtfFunction); // DateTimeFormat.prototype method // 13.4.2 Intl.DateTimeFormat.prototype [ @@toStringTag ] - SetStringTagSymbol(env, dtf_prototype, "Intl.DateTimeFormat"); - env->SetDateTimeFormatFunction(thread_, dtf_function); + SetStringTagSymbol(env, dtfPrototype, "Intl.DateTimeFormat"); + env->SetDateTimeFormatFunction(thread_, dtfFunction); - SetFunctionsGenDateTimeFormatProto(env, dtf_prototype); + SetFunctionsGenDateTimeFormatProto(env, dtfPrototype); } void Builtins::InitializeRelativeTimeFormat(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // RelativeTimeFormat.prototype - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle rtf_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle rtf_prototype_value(rtf_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle rtfPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle rtfPrototypeValue(rtfPrototype); // RelativeTimeFormat.prototype_or_dynclass - JSHandle rtf_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_RELATIVE_TIME_FORMAT, rtf_prototype_value); + JSHandle rtfFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_RELATIVE_TIME_FORMAT, rtfPrototypeValue); // RelativeTimeFormat = new Function() // 14.2.1 Intl.RelativeTimeFormat.prototype.constructor - JSHandle rtf_function(NewIntlConstructor(env, rtf_prototype, - relative_time_format::RelativeTimeFormatConstructor, - "RelativeTimeFormat", FunctionLength::ZERO)); - JSHandle(rtf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*rtf_func_instance_dynclass)); - SetFunctionsGenRelativeTimeFormat(env, rtf_function); + JSHandle rtfFunction(NewIntlConstructor(env, rtfPrototype, + relative_time_format::RelativeTimeFormatConstructor, + "RelativeTimeFormat", FunctionLength::ZERO)); + JSHandle(rtfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*rtfFuncInstanceDynclass)); + SetFunctionsGenRelativeTimeFormat(env, rtfFunction); // RelativeTimeFormat.prototype method // 14.4.2 Intl.RelativeTimeFormat.prototype [ @@toStringTag ] - SetStringTagSymbol(env, rtf_prototype, "Intl.RelativeTimeFormat"); - env->SetRelativeTimeFormatFunction(thread_, rtf_function); + SetStringTagSymbol(env, rtfPrototype, "Intl.RelativeTimeFormat"); + env->SetRelativeTimeFormatFunction(thread_, rtfFunction); - SetFunctionsGenRelativeTimeFormatProto(env, rtf_prototype); + SetFunctionsGenRelativeTimeFormatProto(env, rtfPrototype); } void Builtins::InitializeNumberFormat(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // NumberFormat.prototype - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle nf_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle nf_prototype_value(nf_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle nfPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle nfPrototypeValue(nfPrototype); // NumberFormat.prototype_or_dynclass - JSHandle nf_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_NUMBER_FORMAT, nf_prototype_value); + JSHandle nfFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_NUMBER_FORMAT, nfPrototypeValue); // NumberFormat = new Function() // 12.4.1 Intl.NumberFormat.prototype.constructor - JSHandle nf_function(NewIntlConstructor(env, nf_prototype, number_format::NumberFormatConstructor, - "NumberFormat", FunctionLength::ZERO)); - JSHandle(nf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*nf_func_instance_dynclass)); + JSHandle nfFunction(NewIntlConstructor(env, nfPrototype, number_format::NumberFormatConstructor, + "NumberFormat", FunctionLength::ZERO)); + JSHandle(nfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*nfFuncInstanceDynclass)); - SetFunctionsGenNumberFormat(env, nf_function); + SetFunctionsGenNumberFormat(env, nfFunction); // NumberFormat.prototype method // 12.4.2 Intl.NumberFormat.prototype [ @@toStringTag ] - SetStringTagSymbol(env, nf_prototype, "Intl.NumberFormat"); - env->SetNumberFormatFunction(thread_, nf_function); + SetStringTagSymbol(env, nfPrototype, "Intl.NumberFormat"); + env->SetNumberFormatFunction(thread_, nfFunction); - SetFunctionsGenNumberFormatProto(env, nf_prototype); + SetFunctionsGenNumberFormatProto(env, nfPrototype); } void Builtins::InitializeLocale(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Locale.prototype - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle locale_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle locale_prototype_value(locale_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle localePrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle localePrototypeValue(localePrototype); // Locale.prototype_or_dynclass - JSHandle locale_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_LOCALE, locale_prototype_value); + JSHandle localeFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_LOCALE, localePrototypeValue); // Locale = new Function() - JSHandle locale_function( - NewIntlConstructor(env, locale_prototype, locale::LocaleConstructor, "Locale", FunctionLength::ONE)); - JSHandle(locale_function)->SetFunctionPrototype(thread_, JSTaggedValue(*locale_func_instance_dynclass)); - SetFunctionsGenLocaleProto(env, locale_prototype); + JSHandle localeFunction( + NewIntlConstructor(env, localePrototype, locale::LocaleConstructor, "Locale", FunctionLength::ONE)); + JSHandle(localeFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*localeFuncInstanceDynclass)); + SetFunctionsGenLocaleProto(env, localePrototype); // 10.3.2 Intl.Locale.prototype[ @@toStringTag ] - SetStringTagSymbol(env, locale_prototype, "Intl.Locale"); - env->SetLocaleFunction(thread_, locale_function); + SetStringTagSymbol(env, localePrototype, "Intl.Locale"); + env->SetLocaleFunction(thread_, localeFunction); } void Builtins::InitializeCollator(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Collator.prototype - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle collator_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle collator_prototype_value(collator_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle collatorPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle collatorPrototypeValue(collatorPrototype); // Collator.prototype_or_dynclass - JSHandle collator_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_COLLATOR, collator_prototype_value); + JSHandle collatorFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_COLLATOR, collatorPrototypeValue); // Collator = new Function() // 11.1.2 Intl.Collator.prototype.constructor - JSHandle collator_function( - NewIntlConstructor(env, collator_prototype, collator::CollatorConstructor, "Collator", FunctionLength::ZERO)); - JSHandle(collator_function) - ->SetFunctionPrototype(thread_, JSTaggedValue(*collator_func_instance_dynclass)); + JSHandle collatorFunction( + NewIntlConstructor(env, collatorPrototype, collator::CollatorConstructor, "Collator", FunctionLength::ZERO)); + JSHandle(collatorFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*collatorFuncInstanceDynclass)); - SetFunctionsGenCollator(env, collator_function); + SetFunctionsGenCollator(env, collatorFunction); // Collator.prototype method // 11.3.2 Intl.Collator.prototype [ @@toStringTag ] - SetStringTagSymbol(env, collator_prototype, "Intl.Collator"); - env->SetCollatorFunction(thread_, collator_function); + SetStringTagSymbol(env, collatorPrototype, "Intl.Collator"); + env->SetCollatorFunction(thread_, collatorFunction); - SetFunctionsGenCollatorProto(env, collator_prototype); + SetFunctionsGenCollatorProto(env, collatorPrototype); } void Builtins::InitializePluralRules(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // PluralRules.prototype - JSHandle obj_fun(env->GetObjectFunction()); - JSHandle pr_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle pr_prototype_value(pr_prototype); + JSHandle objFun(env->GetObjectFunction()); + JSHandle prPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle prPrototypeValue(prPrototype); // PluralRules.prototype_or_dynclass - JSHandle pr_func_instance_dynclass = - factory_->CreateDynClass(JSType::JS_PLURAL_RULES, pr_prototype_value); + JSHandle prFuncInstanceDynclass = + factory_->CreateDynClass(JSType::JS_PLURAL_RULES, prPrototypeValue); // PluralRules = new Function() // 15.2.1 Intl.PluralRules.prototype.constructor - JSHandle pr_function(NewIntlConstructor(env, pr_prototype, plural_rules::PluralRulesConstructor, - "PluralRules", FunctionLength::ZERO)); - JSHandle(pr_function)->SetFunctionPrototype(thread_, JSTaggedValue(*pr_func_instance_dynclass)); + JSHandle prFunction(NewIntlConstructor(env, prPrototype, plural_rules::PluralRulesConstructor, + "PluralRules", FunctionLength::ZERO)); + JSHandle(prFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*prFuncInstanceDynclass)); - env->SetPluralRulesFunction(thread_, pr_function); - SetFunctionsGenPluralRules(env, pr_function); + env->SetPluralRulesFunction(thread_, prFunction); + SetFunctionsGenPluralRules(env, prFunction); // PluralRules.prototype method // 15.4.2 Intl.PluralRules.prototype [ @@toStringTag ] - SetStringTagSymbol(env, pr_prototype, "Intl.PluralRules"); + SetStringTagSymbol(env, prPrototype, "Intl.PluralRules"); - SetFunctionsGenPluralRulesProto(env, pr_prototype); + SetFunctionsGenPluralRulesProto(env, prPrototype); } void Builtins::InitializeGcMarker(const JSHandle &env) const @@ -2314,33 +2279,33 @@ JSHandle Builtins::InitializeArkTools(const JSHandle &env) JSHandle Builtins::InitializeArkPrivate(const JSHandle &env) const { - 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", + JSHandle arkPrivate = factory_->NewEmptyJSObject(); + SetFrozenFunction(env, arkPrivate, "Load", ContainersPrivate::Load, FunctionLength::ZERO); + SetConstant(arkPrivate, "ArrayList", JSTaggedValue(static_cast(containers::ContainerTag::ARRAY_LIST))); + 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::LINKED_LIST))); + SetConstant(arkPrivate, "TreeMap", JSTaggedValue(static_cast(containers::ContainerTag::TREE_MAP))); + SetConstant(arkPrivate, "TreeSet", JSTaggedValue(static_cast(containers::ContainerTag::TREE_SET))); + SetConstant(arkPrivate, "HashMap", JSTaggedValue(static_cast(containers::ContainerTag::HASH_MAP))); + SetConstant(arkPrivate, "HashSet", JSTaggedValue(static_cast(containers::ContainerTag::HASH_SET))); + SetConstant(arkPrivate, "LightWightMap", JSTaggedValue(static_cast(containers::ContainerTag::LIGHT_WIGHT_MAP))); - SetConstant(ark_private, "LightWightSet", + SetConstant(arkPrivate, "LightWightSet", JSTaggedValue(static_cast(containers::ContainerTag::LIGHT_WIGHT_SET))); - SetConstant(ark_private, "PlainArray", JSTaggedValue(static_cast(containers::ContainerTag::PLAIN_ARRAY))); - return ark_private; + SetConstant(arkPrivate, "PlainArray", JSTaggedValue(static_cast(containers::ContainerTag::PLAIN_ARRAY))); + return arkPrivate; } #ifndef PANDA_PRODUCT_BUILD JSHandle Builtins::InitializeRuntimeTesting(const JSHandle &env) const { - JSHandle runtime_testing = factory_->NewEmptyJSObject(); - SetFunctionsGenRuntimeTesting(env, runtime_testing); - return runtime_testing; + JSHandle runtimeTesting = factory_->NewEmptyJSObject(); + SetFunctionsGenRuntimeTesting(env, runtimeTesting); + return runtimeTesting; } #endif // PANDA_PRODUCT_BUILD diff --git a/runtime/builtins.h b/runtime/builtins.h index c795b1f653f3bca3dbe84a777b062ea78d2d66b9..09695ff5f83156754a11fcff2532aa3d8c86e214 100644 --- a/runtime/builtins.h +++ b/runtime/builtins.h @@ -36,10 +36,10 @@ namespace panda::ecmascript::builtins { using ErrorType = base::ErrorType; struct ErrorParameter { - EcmaEntrypoint native_constructor {nullptr}; - EcmaEntrypoint native_method {nullptr}; - const char *native_property_name {nullptr}; - JSType native_jstype {JSType::INVALID}; + EcmaEntrypoint nativeConstructor {nullptr}; + EcmaEntrypoint nativeMethod {nullptr}; + const char *nativePropertyName {nullptr}; + JSType nativeJstype {JSType::INVALID}; }; enum FunctionLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN }; @@ -59,7 +59,7 @@ private: EcmaVM *vm_ {nullptr}; JSHandle NewBuiltinConstructor(const JSHandle &env, const JSHandle &prototype, - EcmaEntrypoint ctor_func, const char *name, int length) const; + EcmaEntrypoint ctorFunc, const char *name, int length) const; JSHandle NewFunction(const JSHandle &env, const JSHandle &key, EcmaEntrypoint func, int length) const; @@ -67,69 +67,68 @@ 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 &global_object); + void InitializeGlobalObject(const JSHandle &env, const JSHandle &globalObject); - void InitializeFunction(const JSHandle &env, const JSHandle &empty_func_dynclass) const; + void InitializeFunction(const JSHandle &env, const JSHandle &emptyFuncDynclass) const; - void InitializeObject(const JSHandle &env, const JSHandle &obj_func_prototype, - const JSHandle &obj_func); + void InitializeObject(const JSHandle &env, const JSHandle &objFuncPrototype, + const JSHandle &objFunc); - void InitializeNumber(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass); + void InitializeNumber(const JSHandle &env, const JSHandle &primRefObjDynclass); - void InitializeBigInt(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeBigInt(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeDate(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeDate(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeBoolean(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const; + void InitializeBoolean(const JSHandle &env, const JSHandle &primRefObjDynclass) const; - void InitializeSymbol(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeSymbol(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeSymbolWithRealm(const JSHandle &realm, - const JSHandle &obj_func_instance_dynclass); + void InitializeSymbolWithRealm(const JSHandle &realm, const JSHandle &objFuncInstanceDynclass); - void InitializeArray(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; + void InitializeArray(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; - void InitializeTypedArray(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeTypedArray(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeInt8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeInt8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeUint8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeUint8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeUint8ClampedArray(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeUint8ClampedArray(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeInt16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeInt16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeUint16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeUint16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeInt32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeInt32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeUint32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeUint32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeFloat32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeFloat32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeFloat64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeFloat64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeBigInt64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeBigInt64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeBigUint64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeBigUint64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeAllTypeError(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeAllTypeError(const JSHandle &env, const JSHandle &objFuncDynclass) const; void InitializeAllTypeErrorWithRealm(const JSHandle &realm) const; - void InitializeError(const JSHandle &env, const JSHandle &obj_func_dynclass, - const JSType &error_tag) const; + void InitializeError(const JSHandle &env, const JSHandle &objFuncDynclass, + const JSType &errorTag) const; - void SetErrorWithRealm(const JSHandle &realm, const JSType &error_tag) const; + void SetErrorWithRealm(const JSHandle &realm, const JSType &errorTag) const; void InitializeRegExp(const JSHandle &env); // for Intl. JSHandle NewIntlConstructor(const JSHandle &env, const JSHandle &prototype, - EcmaEntrypoint ctor_func, const char *name, int length); + EcmaEntrypoint ctorFunc, 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 &obj_func_prototype_value); + void InitializeIntl(const JSHandle &env, const JSHandle &objFuncPrototypeValue); void InitializeLocale(const JSHandle &env); void InitializeDateTimeFormat(const JSHandle &env); void InitializeRelativeTimeFormat(const JSHandle &env); @@ -140,72 +139,69 @@ private: void GeneralUpdateError(ErrorParameter *error, EcmaEntrypoint constructor, EcmaEntrypoint method, const char *name, JSType type) const; - void InitializeSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeSet(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeMap(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeWeakRef(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeWeakRef(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeWeakMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeWeakMap(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeWeakSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeWeakSet(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeMath(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; + void InitializeMath(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; - void InitializeJson(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; + void InitializeJson(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; - void InitializeString(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const; + void InitializeString(const JSHandle &env, const JSHandle &primRefObjDynclass) const; - void InitializeIterator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeAsyncIterator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeAsyncIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeStringIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const; + void InitializeStringIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; - void InitializeForinIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const; + void InitializeForinIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; - void InitializeMapIterator(const JSHandle &env, const JSHandle &iterator_func_dynclass) const; + void InitializeMapIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; - void InitializeSetIterator(const JSHandle &env, const JSHandle &iterator_func_dynclass) const; + void InitializeSetIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; - void InitializeArrayIterator(const JSHandle &env, - const JSHandle &iterator_func_dynclass) const; + void InitializeArrayIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; - void InitializeRegexpIterator(const JSHandle &env, const JSHandle &iterator_func_class) const; + void InitializeRegexpIterator(const JSHandle &env, const JSHandle &iteratorFuncClass) const; - void InitializeArrayBuffer(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeArrayBuffer(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeDataView(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeDataView(const JSHandle &env, const JSHandle &objFuncDynclass) const; void InitializeProxy(const JSHandle &env); - void InitializeReflect(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; + void InitializeReflect(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; - void InitializeAsyncFunction(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeAsyncFunction(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeGeneratorFunction(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeGeneratorFunction(const JSHandle &env, const JSHandle &objFuncDynclass) const; - void InitializeGenerator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const; void InitializeAsyncGeneratorFunction(const JSHandle &env, - const JSHandle &obj_func_dynclass) const; + const JSHandle &objFuncDynclass) const; - void InitializeAsyncGenerator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; + void InitializeAsyncGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const; void InitializeAsyncFromSyncIteratorPrototypeObject(const JSHandle &env, - const JSHandle &obj_func_dynclass) const; + const JSHandle &objFuncDynclass) const; - JSHandle InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctor_func, + JSHandle InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctorFunc, const char *name, int length); - void InitializePromise(const JSHandle &env, const JSHandle &promise_func_dynclass); + void InitializePromise(const JSHandle &env, const JSHandle &promiseFuncDynclass); void InitializePromiseJob(const JSHandle &env); void InitializeFinalizationRegistry(const JSHandle &env, - const JSHandle &obj_func_dynclass) const; + const JSHandle &objFuncDynclass) const; void SetFunction(const JSHandle &env, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length) const; @@ -230,7 +226,7 @@ private: void SetConstant(const JSHandle &obj, const char *key, JSTaggedValue value) const; - void SetGlobalThis(const JSHandle &obj, const char *key, const JSHandle &global_value); + void SetGlobalThis(const JSHandle &obj, const char *key, const JSHandle &globalValue); 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 3d2fe138299ccac0287d93e5a768f7c7003d4507..b7306b768ff2012f2d8113b6e7f8727a097b6a43 100644 --- a/runtime/builtins/builtins_ark_tools.cpp +++ b/runtime/builtins/builtins_ark_tools.cpp @@ -25,14 +25,14 @@ JSTaggedValue ark_tools::Print(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle str = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); // The default log level of ace_engine and js_runtime is error LOG(ERROR, RUNTIME) << ": " << base::StringHelper::ToStdString(*str); - uint32_t num_args = argv->GetArgsNumber(); - for (uint32_t i = 1; i < num_args; i++) { + uint32_t numArgs = argv->GetArgsNumber(); + for (uint32_t i = 1; i < numArgs; i++) { JSHandle obj = builtins_common::GetCallArg(argv, i); std::ostringstream oss; obj->Dump(thread, oss); diff --git a/runtime/builtins/builtins_array.cpp b/runtime/builtins/builtins_array.cpp index 33339cb213279546bc7f5d397178bf200d1b6232..446ec3f9862e425eeea040ccfdf79f1e18ede2d7 100644 --- a/runtime/builtins/builtins_array.cpp +++ b/runtime/builtins/builtins_array.cpp @@ -46,7 +46,7 @@ JSTaggedValue builtins::array::ArrayConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, ArrayConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let numberOfArgs be the number of arguments passed to this function call. @@ -54,9 +54,9 @@ JSTaggedValue builtins::array::ArrayConstructor(EcmaRuntimeCallInfo *argv) // 3. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { - new_target = constructor; + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { + newTarget = constructor; } // 4. Let proto be GetPrototypeFromConstructor(new_target, "%ArrayPrototype%"). @@ -66,14 +66,14 @@ JSTaggedValue builtins::array::ArrayConstructor(EcmaRuntimeCallInfo *argv) // 22.1.1.1 Array ( ) if (argc == 0) { // 6. Return ArrayCreate(0, proto). - return JSTaggedValue(JSArray::ArrayCreate(thread, JSTaggedNumber(0), new_target).GetObject()); + return JSTaggedValue(JSArray::ArrayCreate(thread, JSTaggedNumber(0), newTarget).GetObject()); } // 22.1.1.2 Array(len) if (argc == 1) { // 6. Let array be ArrayCreate(0, proto). - uint32_t new_len = 0; - JSHandle new_array_handle(JSArray::ArrayCreate(thread, JSTaggedNumber(new_len), new_target)); + uint32_t newLen = 0; + JSHandle newArrayHandle(JSArray::ArrayCreate(thread, JSTaggedNumber(newLen), newTarget)); JSHandle len = builtins_common::GetCallArg(argv, 0); // 7. If Type(len) is not Number, then // a. Let defineStatus be CreateDataProperty(array, "0", len). @@ -86,25 +86,25 @@ JSTaggedValue builtins::array::ArrayConstructor(EcmaRuntimeCallInfo *argv) // 10. Assert: setStatus is not an abrupt completion. if (!len->IsNumber()) { JSHandle key0(factory->NewFromCanBeCompressString("0")); - JSObject::CreateDataProperty(thread, new_array_handle, key0, len); - new_len = 1; + JSObject::CreateDataProperty(thread, newArrayHandle, key0, len); + newLen = 1; } else { - new_len = JSTaggedValue::ToUint32(thread, len); + newLen = JSTaggedValue::ToUint32(thread, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedNumber(len.GetTaggedValue()).GetNumber() != new_len) { + if (JSTaggedNumber(len.GetTaggedValue()).GetNumber() != newLen) { THROW_RANGE_ERROR_AND_RETURN(thread, "The length is out of range.", JSTaggedValue::Exception()); } } - JSArray::Cast(*new_array_handle)->SetArrayLength(thread, new_len); + JSArray::Cast(*newArrayHandle)->SetArrayLength(thread, newLen); // 11. Return array. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.1.3 Array(...items ) - JSTaggedValue new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(argc), new_target).GetTaggedValue(); - JSHandle new_array_handle(thread, new_array); - if (!new_array.IsArray(thread)) { + JSTaggedValue newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(argc), newTarget).GetTaggedValue(); + JSHandle newArrayHandle(thread, newArray); + if (!newArray.IsArray(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to create array.", JSTaggedValue::Exception()); } @@ -119,14 +119,14 @@ JSTaggedValue builtins::array::ArrayConstructor(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); - JSHandle item_k = builtins_common::GetCallArg(argv, k); - JSObject::CreateDataProperty(thread, new_array_handle, key, item_k); + JSHandle itemK = builtins_common::GetCallArg(argv, k); + JSObject::CreateDataProperty(thread, newArrayHandle, key, itemK); } // 11. Assert: the value of array’s length property is numberOfArgs. // 12. Return array. - JSArray::Cast(*new_array_handle)->SetArrayLength(thread, argc); - return new_array_handle.GetTaggedValue(); + JSArray::Cast(*newArrayHandle)->SetArrayLength(thread, argc); + return newArrayHandle.GetTaggedValue(); } // 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) @@ -136,18 +136,18 @@ JSTaggedValue builtins::array::From(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, From); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); // 1. Let C be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If mapfn is undefined, let mapping be false. bool mapping = false; // 3. else // a. If IsCallable(mapfn) is false, throw a TypeError exception. // b. If thisArg was supplied, let T be thisArg; else let T be undefined. // c. Let mapping be true - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, INDEX_TWO); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, INDEX_TWO); JSHandle mapfn = builtins_common::GetCallArg(argv, 1); if (!mapfn->IsUndefined()) { if (!mapfn->IsCallable()) { @@ -161,40 +161,40 @@ JSTaggedValue builtins::array::From(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "The items is null.", JSTaggedValue::Exception()); } JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSHandle using_iterator = JSObject::GetMethod(thread, items, iterator_symbol); + JSHandle iteratorSymbol = env->GetIteratorSymbol(); + JSHandle usingIterator = JSObject::GetMethod(thread, items, iteratorSymbol); // 5. ReturnIfAbrupt(usingIterator). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. If usingIterator is not undefined, then - if (!using_iterator->IsUndefined()) { + if (!usingIterator->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 new_array; - if (this_handle->IsConstructor()) { + JSTaggedValue newArray; + if (thisHandle->IsConstructor()) { auto info = - NewRuntimeCallInfo(thread, this_handle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 0); - new_array = JSFunction::Construct(info.Get()); + NewRuntimeCallInfo(thread, thisHandle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 0); + newArray = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue(); + newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (!new_array.IsECMAObject()) { + if (!newArray.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the array.", JSTaggedValue::Exception()); } - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); // d. Let iterator be GetIterator(items, usingIterator). - JSHandle iterator = JSIterator::GetIterator(thread, items, using_iterator); + JSHandle iterator = JSIterator::GetIterator(thread, items, usingIterator); // 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 map_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); while (true) { key.Update(JSTaggedValue(k)); // i. Let Pk be ToString(k). @@ -207,13 +207,12 @@ JSTaggedValue builtins::array::From(EcmaRuntimeCallInfo *argv) // 2. ReturnIfAbrupt(setStatus). // 3. Return A. if (next->IsFalse()) { - JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, key, - true); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, key, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return JSTaggedValue(new_array_handle.GetTaggedValue()); + return JSTaggedValue(newArrayHandle.GetTaggedValue()); } // v. Let nextValue be IteratorValue(next). - JSHandle next_value = JSIterator::IteratorValue(thread, next); + JSHandle nextValue = JSIterator::IteratorValue(thread, next); // vi. ReturnIfAbrupt(nextValue). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // vii. If mapping is true, then @@ -222,33 +221,33 @@ JSTaggedValue builtins::array::From(EcmaRuntimeCallInfo *argv) // 3. Let mappedValue be mappedValue.[[value]]. // viii. Else, let mappedValue be nextValue. if (mapping) { - 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)); + 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)); } else { - map_value.Update(next_value.GetTaggedValue()); + mapValue.Update(nextValue.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 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)); + 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)); k++; } } // 7. Assert: items is not an Iterable so assume it is an array-like object. // 8. Let arrayLike be ToObject(items). - JSHandle array_like_obj = JSTaggedValue::ToObject(thread, items); + JSHandle arrayLikeObj = JSTaggedValue::ToObject(thread, items); // 9. ReturnIfAbrupt(arrayLike). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle array_like(array_like_obj); + JSHandle arrayLike(arrayLikeObj); // 10. Let len be ToLength(Get(arrayLike, "length")). - double len = ArrayHelper::GetArrayLength(thread, array_like); + double len = ArrayHelper::GetArrayLength(thread, arrayLike); // 11. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 12. If IsConstructor(C) is true, then @@ -256,20 +255,20 @@ JSTaggedValue builtins::array::From(EcmaRuntimeCallInfo *argv) // 13. Else, // a. Let A be ArrayCreate(len). // 14. ReturnIfAbrupt(A). - JSTaggedValue new_array; - if (this_handle->IsConstructor()) { - auto info = NewRuntimeCallInfo(thread, this_handle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); + JSTaggedValue newArray; + if (thisHandle->IsConstructor()) { + auto info = NewRuntimeCallInfo(thread, thisHandle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); info->SetCallArgs(JSTaggedValue(len)); - new_array = JSFunction::Construct(info.Get()); + newArray = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(len)).GetTaggedValue(); + newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(len)).GetTaggedValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (!new_array.IsECMAObject()) { + if (!newArray.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the array.", JSTaggedValue::Exception()); } - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); // 15. Let k be 0. // 16. Repeat, while k < len // a. Let Pk be ToString(k). @@ -279,33 +278,33 @@ JSTaggedValue builtins::array::From(EcmaRuntimeCallInfo *argv) // e. Else, let mappedValue be kValue. // f. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue). JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle map_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, array_like, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, arrayLike, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (mapping) { key.Update(JSTaggedValue(k)); - 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 + auto info = NewRuntimeCallInfo(thread, mapfn, thisArgHandle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(kValue, key); + JSTaggedValue callResult = JSFunction::Call(info.Get()); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - map_value.Update(call_result); + mapValue.Update(callResult); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - map_value.Update(k_value.GetTaggedValue()); + mapValue.Update(kValue.GetTaggedValue()); } - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, k, map_value); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, k, mapValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 17. Let setStatus be Set(A, "length", len, true). - JSHandle len_handle(thread, JSTaggedValue(len)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, len_handle, true); + JSHandle lenHandle(thread, JSTaggedValue(len)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, lenHandle, true); // 18. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 19. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.2.2 Array.isArray ( arg ) @@ -326,37 +325,37 @@ JSTaggedValue builtins::array::Of(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Of); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle length_key = global_const->GetHandledLengthString(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle lengthKey = globalConst->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 this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::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 new_array; - if (this_handle->IsConstructor()) { - JSHandle undefined = global_const->GetHandledUndefined(); + JSHandle newArray; + if (thisHandle->IsConstructor()) { + JSHandle undefined = globalConst->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, this_handle, JSTaggedValue::Undefined(), undefined, 1); + auto info = NewRuntimeCallInfo(thread, thisHandle, JSTaggedValue::Undefined(), undefined, 1); info->SetCallArgs(JSTaggedValue(argc)); - JSTaggedValue tagged_array = JSFunction::Construct(info.Get()); + JSTaggedValue taggedArray = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - new_array = JSHandle(thread, tagged_array); + newArray = JSHandle(thread, taggedArray); } else { - new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(argc)); + newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(argc)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (!new_array->IsECMAObject()) { + if (!newArray->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to create Object.", JSTaggedValue::Exception()); } - JSHandle new_array_handle(new_array); + JSHandle newArrayHandle(newArray); // 7. Let k be 0. // 8. Repeat, while k < len @@ -368,16 +367,16 @@ JSTaggedValue builtins::array::Of(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); - JSHandle k_value = builtins_common::GetCallArg(argv, k); - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, key, k_value); + JSHandle kValue = builtins_common::GetCallArg(argv, k); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, key, kValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 9. Let setStatus be Set(A, "length", len, true). - JSHandle len_handle(thread, JSTaggedValue(argc)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, len_handle, true); + JSHandle lenHandle(thread, JSTaggedValue(argc)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, lenHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.2.5 get Array [ @@species ] @@ -394,46 +393,45 @@ JSTaggedValue builtins::array::proto::Concat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Concat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let A be ArraySpeciesCreate(O, 0). - uint32_t array_len = 0; - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(array_len)); + uint32_t arrayLen = 0; + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen)); // 4. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); // 5. Let n be 0. double n = 0; - JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); - bool is_spreadable = ArrayHelper::IsConcatSpreadable(thread, this_handle); + JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); + bool isSpreadable = ArrayHelper::IsConcatSpreadable(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (is_spreadable) { - double this_len = ArrayHelper::GetArrayLength(thread, this_obj_val); + if (isSpreadable) { + double thisLen = ArrayHelper::GetArrayLength(thread, thisObjVal); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (n + this_len > ecmascript::base::MAX_SAFE_INTEGER) { + if (n + thisLen > ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } double k = 0; - while (k < this_len) { - from_key.Update(JSTaggedValue(k)); - to_key.Update(JSTaggedValue(n)); - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); + while (k < thisLen) { + fromKey.Update(JSTaggedValue(k)); + toKey.Update(JSTaggedValue(n)); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_val_handle = - JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); + JSHandle fromValHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_key, from_val_handle); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } n++; @@ -443,25 +441,25 @@ JSTaggedValue builtins::array::proto::Concat(EcmaRuntimeCallInfo *argv) if (n >= ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, n, this_obj_val); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, n, thisObjVal); 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 add_handle = builtins_common::GetCallArg(argv, i); + JSHandle addHandle = builtins_common::GetCallArg(argv, i); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle add_obj_handle(add_handle); + JSHandle addObjHandle(addHandle); // b. Let spreadable be IsConcatSpreadable(E). - is_spreadable = ArrayHelper::IsConcatSpreadable(thread, add_handle); + isSpreadable = ArrayHelper::IsConcatSpreadable(thread, addHandle); // c. ReturnIfAbrupt(spreadable). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. If spreadable is true, then - if (is_spreadable) { + if (isSpreadable) { // ii. Let len be ToLength(Get(E, "length")). - double len = ArrayHelper::GetArrayLength(thread, JSHandle::Cast(add_obj_handle)); + double len = ArrayHelper::GetArrayLength(thread, JSHandle::Cast(addObjHandle)); // iii. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iv. If n + len > 253-1, throw a TypeError exception. @@ -471,21 +469,19 @@ JSTaggedValue builtins::array::proto::Concat(EcmaRuntimeCallInfo *argv) double k = 0; // v. Repeat, while k < len while (k < len) { - from_key.Update(JSTaggedValue(k)); - to_key.Update(JSTaggedValue(n)); + fromKey.Update(JSTaggedValue(k)); + toKey.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(add_obj_handle), from_key); + bool exists = JSTaggedValue::HasProperty(thread, JSHandle::Cast(addObjHandle), fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { // a. Let subElement be Get(E, P). - JSHandle from_val_handle = - JSArray::FastGetPropertyByValue(thread, add_handle, from_key); + JSHandle fromValHandle = JSArray::FastGetPropertyByValue(thread, addHandle, fromKey); // b. ReturnIfAbrupt(subElement). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_key, from_val_handle); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValHandle); // d. ReturnIfAbrupt(status). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -500,7 +496,7 @@ JSTaggedValue builtins::array::proto::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, new_array_handle, n, add_handle); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, n, addHandle); // iii. ReturnIfAbrupt(status). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -509,14 +505,14 @@ JSTaggedValue builtins::array::proto::Concat(EcmaRuntimeCallInfo *argv) } } // 8. Let setStatus be Set(A, "length", n, 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); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lenHandle(thread, JSTaggedValue(n)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, lenHandle, true); // 9. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) @@ -525,45 +521,45 @@ JSTaggedValue builtins::array::proto::CopyWithin(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, CopyWithin); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double copy_to; - double copy_from; - double copy_end; + double copyTo; + double copyFrom; + double copyEnd; // 5. Let relativeTarget be ToInteger(target). - JSTaggedNumber target_temp = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); + JSTaggedNumber targetTemp = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); // 6. ReturnIfAbrupt(relativeTarget). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double target = target_temp.GetNumber(); + double target = targetTemp.GetNumber(); // 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to be min(relativeTarget, len). if (target < 0) { - copy_to = target + len > 0 ? target + len : 0; + copyTo = target + len > 0 ? target + len : 0; } else { - copy_to = target < len ? target : len; + copyTo = target < len ? target : len; } // 8. Let relativeStart be ToInteger(start). - JSTaggedNumber start_t = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 1)); + JSTaggedNumber startT = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 1)); // 9. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double start = start_t.GetNumber(); + double start = startT.GetNumber(); // 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let from be min(relativeStart, len). if (start < 0) { - copy_from = start + len > 0 ? start + len : 0; + copyFrom = start + len > 0 ? start + len : 0; } else { - copy_from = start < len ? start : len; + copyFrom = start < len ? start : len; } // 11. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). @@ -578,13 +574,13 @@ JSTaggedValue builtins::array::proto::CopyWithin(EcmaRuntimeCallInfo *argv) // 13. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). if (end < 0) { - copy_end = end + len > 0 ? end + len : 0; + copyEnd = end + len > 0 ? end + len : 0; } else { - copy_end = end < len ? end : len; + copyEnd = end < len ? end : len; } // 14. Let count be min(final-from, len-to). - double count = (copy_end - copy_from < len - copy_to) ? (copy_end - copy_from) : (len - copy_to); + double count = (copyEnd - copyFrom < len - copyTo) ? (copyEnd - copyFrom) : (len - copyTo); // 15. If from 0 @@ -615,32 +611,32 @@ JSTaggedValue builtins::array::proto::CopyWithin(EcmaRuntimeCallInfo *argv) // g. Let from be from + direction. // h. Let to be to + direction. // i. Let count be count − 1. - JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); while (count > 0) { - 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)); + fromKey.Update(JSTaggedValue(copyFrom)); + toKey.Update(JSTaggedValue(copyTo)); + bool exists = (thisObjVal->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, fromKey)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_val_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); + JSHandle fromValHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_val_handle); + JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - if (this_obj_val->IsJSProxy()) { - to_key.Update(JSTaggedValue::ToString(thread, to_key).GetTaggedValue()); + if (thisObjVal->IsJSProxy()) { + toKey.Update(JSTaggedValue::ToString(thread, toKey).GetTaggedValue()); } - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - copy_from = copy_from + direction; - copy_to = copy_to + direction; + copyFrom = copyFrom + direction; + copyTo = copyTo + direction; count--; } // 18. Return O. - return this_obj_handle.GetTaggedValue(); + return thisObjHandle.GetTaggedValue(); } // 22.1.3.4 Array.prototype.entries ( ) @@ -649,7 +645,7 @@ JSTaggedValue builtins::array::proto::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). @@ -665,28 +661,28 @@ JSTaggedValue builtins::array::proto::Every(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -704,18 +700,18 @@ JSTaggedValue builtins::array::proto::Every(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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 + auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(kValue, key, thisObjVal); + JSTaggedValue callResult = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool bool_result = call_result.ToBoolean(); - if (!bool_result) { + bool boolResult = callResult.ToBoolean(); + if (!boolResult) { return builtins_common::GetTaggedBoolean(false); } } @@ -728,24 +724,24 @@ JSTaggedValue builtins::array::proto::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 source_len, double start, - double depth, const JSHandle &mapper_func, - const JSHandle &this_arg) + const JSHandle &source, double sourceLen, double start, + double depth, const JSHandle &mapperFunc, + const JSHandle &thisArg) { - JSTaggedValue target_idx(start); + JSTaggedValue targetIdx(start); // 1. - 3. - for (uint32_t src_idx = 0; src_idx < source_len; ++src_idx) { + for (uint32_t srcIdx = 0; srcIdx < sourceLen; ++srcIdx) { // a. Let P be ! ToString(sourceIndex). JSTaggedValue prop = - JSTaggedValue::ToString(thread, JSHandle(thread, JSTaggedValue(src_idx))).GetTaggedValue(); - JSHandle prop_handle(thread, prop); + JSTaggedValue::ToString(thread, JSHandle(thread, JSTaggedValue(srcIdx))).GetTaggedValue(); + JSHandle propHandle(thread, prop); // b. Let exists be ? HasProperty(source, P). // c. If exists is true, then - bool is_exists = JSTaggedValue::HasProperty(thread, source, prop_handle); + bool isExists = JSTaggedValue::HasProperty(thread, source, propHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!is_exists) { + if (!isExists) { continue; } @@ -753,13 +749,13 @@ 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, prop_handle).GetValue()); + JSHandle element(JSTaggedValue::GetProperty(thread, source, propHandle).GetValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!mapper_func->IsHole()) { - ASSERT(!this_arg->IsHole()); + if (!mapperFunc->IsHole()) { + ASSERT(!thisArg->IsHole()); - auto info = NewRuntimeCallInfo(thread, mapper_func, this_arg, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(element.GetTaggedValue(), JSTaggedNumber(src_idx), source.GetTaggedValue()); + 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 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); element = JSHandle(thread, res); @@ -777,32 +773,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 element_len = ArrayHelper::GetLength(thread, element); + double elementLen = ArrayHelper::GetLength(thread, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - target_idx = FlattenIntoArray(thread, target, element, element_len, target_idx.GetNumber(), depth - 1, - JSHandle(thread, JSTaggedValue::Hole()), - JSHandle(thread, JSTaggedValue::Hole())); + targetIdx = FlattenIntoArray(thread, target, element, elementLen, targetIdx.GetNumber(), depth - 1, + JSHandle(thread, JSTaggedValue::Hole()), + JSHandle(thread, JSTaggedValue::Hole())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - if (target_idx.GetNumber() >= ecmascript::base::MAX_SAFE_INTEGER) { + if (targetIdx.GetNumber() >= ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range", JSTaggedValue::Exception()); } JSTaggedValue str = // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue // (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - JSTaggedValue::ToString(thread, JSHandle(thread, target_idx)).GetTaggedValue(); - JSHandle str_handle(thread, str); - JSObject::CreateDataPropertyOrThrow(thread, target, str_handle, element); + JSTaggedValue::ToString(thread, JSHandle(thread, targetIdx)).GetTaggedValue(); + JSHandle strHandle(thread, str); + JSObject::CreateDataPropertyOrThrow(thread, target, strHandle, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - target_idx = JSTaggedValue(target_idx.GetNumber() + 1); + targetIdx = JSTaggedValue(targetIdx.GetNumber() + 1); } } // 4. Return targetIndex. // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - return target_idx; + return targetIdx; } // ES2019 22.1.3.10 Array.prototype.flat( [ depth ] ) @@ -811,39 +807,39 @@ JSTaggedValue builtins::array::proto::Flat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Flat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ? ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let sourceLen be ? ToLength(? Get(O, "length")). - double source_len = ArrayHelper::GetLength(thread, this_handle); + double sourceLen = ArrayHelper::GetLength(thread, thisHandle); 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 depth_num = 1; + double depthNum = 1; JSHandle msg1 = builtins_common::GetCallArg(argv, 0); if (!msg1->IsUndefined()) { JSTaggedValue depth = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - depth_num = depth.GetNumber(); + depthNum = depth.GetNumber(); } // 5. Let A be ? ArraySpeciesCreate(O, 0) - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(0)); + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); // 6. Perform FlattenIntoArray(target, source, sourceLen, start, depth) - FlattenIntoArray(thread, new_array_handle, this_handle, source_len, 0, depth_num, + FlattenIntoArray(thread, newArrayHandle, thisHandle, sourceLen, 0, depthNum, JSHandle(thread, JSTaggedValue::Hole()), JSHandle(thread, JSTaggedValue::Hole())); - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // ES2019 22.1.3.11 Array.prototype.flatMap(mapperFunction [ , thisArg ]]) @@ -852,38 +848,38 @@ JSTaggedValue builtins::array::proto::FlatMap(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, FlatMap); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ? ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. Let sourceLen be ? ToLength(? Get(O, "length")). - double source_len = ArrayHelper::GetLength(thread, this_handle); + double sourceLen = ArrayHelper::GetLength(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If IsCallable(mapperFunction) is false, throw a TypeError exception. - JSHandle mapper_function = builtins_common::GetCallArg(argv, 0); - if (!mapper_function->IsCallable()) { + JSHandle mapperFunction = builtins_common::GetCallArg(argv, 0); + if (!mapperFunction->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Object is not callable", JSTaggedValue::Exception()); } // 4. If thisArg is present, let T be thisArg; else let T be undefined. - JSMutableHandle this_arg(thread, JSTaggedValue::Undefined()); + JSMutableHandle thisArg(thread, JSTaggedValue::Undefined()); if (argc > 1) { - this_arg.Update(builtins_common::GetCallArg(argv, 1).GetTaggedValue()); + thisArg.Update(builtins_common::GetCallArg(argv, 1).GetTaggedValue()); } // 5. Let A be ? ArraySpeciesCreate(O, 0). - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(0)); - JSHandle new_array_handle(thread, new_array); + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(0)); + JSHandle newArrayHandle(thread, newArray); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, 1, mapperFunction, T). - FlattenIntoArray(thread, new_array_handle, this_handle, source_len, 0, 1, mapper_function, this_arg); + FlattenIntoArray(thread, newArrayHandle, thisHandle, sourceLen, 0, 1, mapperFunction, thisArg); // 7. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) @@ -892,19 +888,19 @@ JSTaggedValue builtins::array::proto::Fill(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Fill); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); JSHandle value = builtins_common::GetCallArg(argv, 0); - if (this_handle->IsTypedArray()) { - ContentType content_type = JSHandle::Cast(this_handle)->GetContentType(); - if (content_type == ContentType::BIG_INT) { + if (thisHandle->IsTypedArray()) { + ContentType contentType = JSHandle::Cast(thisHandle)->GetContentType(); + if (contentType == ContentType::BIG_INT) { value = JSHandle(thread, JSTaggedValue::ToBigInt(thread, value)); } else { value = JSHandle(thread, JSTaggedValue::ToNumber(thread, value)); @@ -913,40 +909,40 @@ JSTaggedValue builtins::array::proto::Fill(EcmaRuntimeCallInfo *argv) } // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let relativeStart be ToInteger(start). double start; JSHandle msg1 = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg1); + JSTaggedNumber argStartTemp = JSTaggedValue::ToInteger(thread, msg1); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double arg_start = arg_start_temp.GetNumber(); + double argStart = argStartTemp.GetNumber(); // 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be min(relativeStart, len). - if (arg_start < 0) { - start = arg_start + len > 0 ? arg_start + len : 0; + if (argStart < 0) { + start = argStart + len > 0 ? argStart + len : 0; } else { - start = arg_start < len ? arg_start : len; + start = argStart < len ? argStart : len; } // 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). - double arg_end = len; + double argEnd = len; JSHandle msg2 = builtins_common::GetCallArg(argv, INDEX_TWO); if (!msg2->IsUndefined()) { - JSTaggedNumber arg_end_temp = JSTaggedValue::ToInteger(thread, msg2); + JSTaggedNumber argEndTemp = JSTaggedValue::ToInteger(thread, msg2); // 9. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - arg_end = arg_end_temp.GetNumber(); + argEnd = argEndTemp.GetNumber(); } // 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). double end; - if (arg_end < 0) { - end = arg_end + len > 0 ? arg_end + len : 0; + if (argEnd < 0) { + end = argEnd + len > 0 ? argEnd + len : 0; } else { - end = arg_end < len ? arg_end : len; + end = argEnd < len ? argEnd : len; } // 11. Repeat, while k < final @@ -958,13 +954,13 @@ JSTaggedValue builtins::array::proto::Fill(EcmaRuntimeCallInfo *argv) double k = start; while (k < end) { key.Update(JSTaggedValue(k)); - JSArray::FastSetPropertyByValue(thread, this_obj_val, key, value); + JSArray::FastSetPropertyByValue(thread, thisObjVal, key, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 12. Return O. - return this_obj_handle.GetTaggedValue(); + return thisObjHandle.GetTaggedValue(); } // 22.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] ) @@ -972,35 +968,35 @@ JSTaggedValue builtins::array::proto::Filter(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let A be ArraySpeciesCreate(O, 0). - int32_t array_len = 0; - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(array_len)); + int32_t arrayLen = 0; + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen)); // 8. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); // 9. Let k be 0. // 10. Let to be 0. @@ -1018,35 +1014,35 @@ JSTaggedValue builtins::array::proto::Filter(EcmaRuntimeCallInfo *argv) // 2. ReturnIfAbrupt(status). // 3. Increase to by 1. // e. Increase k by 1. - double to_index = 0; + double toIndex = 0; JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle to_index_handle(thread, JSTaggedValue::Undefined()); + JSMutableHandle toIndexHandle(thread, JSTaggedValue::Undefined()); uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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(); + 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(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (bool_result) { - to_index_handle.Update(JSTaggedValue(to_index)); - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_index_handle, k_value); + if (boolResult) { + toIndexHandle.Update(JSTaggedValue(toIndex)); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toIndexHandle, kValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - to_index++; + toIndex++; } } k++; } // 12. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ) @@ -1055,28 +1051,28 @@ JSTaggedValue builtins::array::proto::Find(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Find); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(predicate) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the predicate is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1091,16 +1087,16 @@ JSTaggedValue builtins::array::proto::Find(EcmaRuntimeCallInfo *argv) uint32_t k = 0; while (k < len) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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 + auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(kValue, key, thisObjVal); + JSTaggedValue callResult = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool bool_result = call_result.ToBoolean(); - if (bool_result) { - return k_value.GetTaggedValue(); + bool boolResult = callResult.ToBoolean(); + if (boolResult) { + return kValue.GetTaggedValue(); } k++; } @@ -1115,28 +1111,28 @@ JSTaggedValue builtins::array::proto::FindIndex(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, FindIndex); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(predicate) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the predicate is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1151,15 +1147,15 @@ JSTaggedValue builtins::array::proto::FindIndex(EcmaRuntimeCallInfo *argv) uint32_t k = 0; while (k < len) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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(); + 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(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (bool_result) { + if (boolResult) { return builtins_common::GetTaggedDouble(k); } k++; @@ -1174,28 +1170,28 @@ JSTaggedValue builtins::array::proto::ForEach(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1212,16 +1208,16 @@ JSTaggedValue builtins::array::proto::ForEach(EcmaRuntimeCallInfo *argv) uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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); + 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); } k++; } @@ -1236,17 +1232,17 @@ JSTaggedValue builtins::array::proto::Includes(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Includes); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 2. Let len be ? LengthOfArrayLike(O). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If len is 0, return false. @@ -1255,15 +1251,15 @@ JSTaggedValue builtins::array::proto::Includes(EcmaRuntimeCallInfo *argv) } ArraySizeT argc = argv->GetArgsNumber(); - double from_index = 0; + double fromIndex = 0; if (argc > 1) { // 4-5. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0. JSHandle msg1 = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); + fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber()); // 6. If n is positiveInfinity, return false. if (JSTaggedValue::Equal(thread, msg1, @@ -1274,7 +1270,7 @@ JSTaggedValue builtins::array::proto::Includes(EcmaRuntimeCallInfo *argv) // 7. Else if n is negativeInfinity, set n to 0. if (JSTaggedValue::Equal(thread, msg1, JSHandle(thread, JSTaggedValue(-base::POSITIVE_INFINITY)))) { - from_index = 0; + fromIndex = 0; } } @@ -1283,19 +1279,19 @@ JSTaggedValue builtins::array::proto::Includes(EcmaRuntimeCallInfo *argv) // 9. Else, // a. Let k be len + n. // b. If k < 0, set k to 0. - double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); + double from = (fromIndex >= 0) ? fromIndex : ((len + fromIndex) >= 0 ? len + fromIndex : 0); // 10. - const JSHandle search_element = builtins_common::GetCallArg(argv, 0); + const JSHandle searchElement = builtins_common::GetCallArg(argv, 0); while (from < len) { // a) - JSHandle index_handle(thread, JSTaggedValue(from)); + JSHandle indexHandle(thread, JSTaggedValue(from)); JSHandle handle = - JSHandle(thread, JSTaggedValue::ToString(thread, index_handle).GetTaggedValue()); - JSHandle element = JSTaggedValue::GetProperty(thread, this_obj_val, handle).GetValue(); + JSHandle(thread, JSTaggedValue::ToString(thread, indexHandle).GetTaggedValue()); + JSHandle element = JSTaggedValue::GetProperty(thread, thisObjVal, handle).GetValue(); // b) - if (JSTaggedValue::SameValueZero(search_element.GetTaggedValue(), element.GetTaggedValue())) { + if (JSTaggedValue::SameValueZero(searchElement.GetTaggedValue(), element.GetTaggedValue())) { return builtins_common::GetTaggedBoolean(true); } @@ -1312,21 +1308,21 @@ JSTaggedValue builtins::array::proto::IndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, IndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); - JSHandle search_element = builtins_common::GetCallArg(argv, 0); + JSHandle searchElement = builtins_common::GetCallArg(argv, 0); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1336,17 +1332,17 @@ JSTaggedValue builtins::array::proto::IndexOf(EcmaRuntimeCallInfo *argv) } // 6. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0. - double from_index = 0; + double fromIndex = 0; if (argc > 1) { JSHandle msg1 = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); // 7. ReturnIfAbrupt(n). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); + fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber()); } // 8. If n ≥ len, return −1. - if (from_index >= len) { + if (fromIndex >= len) { return builtins_common::GetTaggedInt(-1); } @@ -1355,7 +1351,7 @@ JSTaggedValue builtins::array::proto::IndexOf(EcmaRuntimeCallInfo *argv) // 10. Else n<0, // a. Let k be len - abs(n). // b. If k < 0, let k be 0. - double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); + double from = (fromIndex >= 0) ? fromIndex : ((len + fromIndex) >= 0 ? len + fromIndex : 0); // 11. Repeat, while k key(thread, JSTaggedValue::Undefined()); while (from < len) { key.Update(JSTaggedValue(from)); - bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, key)); + bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, key)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); + JSHandle kValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::StrictEqual(thread, search_element, k_value_handle)) { + if (JSTaggedValue::StrictEqual(thread, searchElement, kValueHandle)) { return builtins_common::GetTaggedDouble(from); } } @@ -1391,52 +1387,52 @@ JSTaggedValue builtins::array::proto::Join(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Join); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = builtins_common::GetThis(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisHandle = builtins_common::GetThis(argv); // Prevent inifinity joining of recursive arrays - static std::vector visited_stack = {}; - if (std::find(visited_stack.begin(), visited_stack.end(), this_handle->GetRawData()) != visited_stack.end()) { + static std::vector visitedStack = {}; + if (std::find(visitedStack.begin(), visitedStack.end(), thisHandle->GetRawData()) != visitedStack.end()) { return builtins_common::GetTaggedString(thread, ""); } - visited_stack.push_back(this_handle->GetRawData()); + visitedStack.push_back(thisHandle->GetRawData()); auto unvisit = std::unique_ptr>( - reinterpret_cast(1), [&](void * /* unused */) { visited_stack.pop_back(); }); + reinterpret_cast(1), [&](void * /* unused */) { visitedStack.pop_back(); }); - if (this_handle->IsStableJSArray(thread)) { - return JSStableArray::Join(JSHandle::Cast(this_handle), argv); + if (thisHandle->IsStableJSArray(thread)) { + return JSStableArray::Join(JSHandle::Cast(thisHandle), argv); } auto factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 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 sep_handle; + JSHandle sepHandle; if ((builtins_common::GetCallArg(argv, 0)->IsUndefined())) { - sep_handle = JSHandle::Cast(factory->NewFromCanBeCompressString(",")); + sepHandle = JSHandle::Cast(factory->NewFromCanBeCompressString(",")); } else { - sep_handle = builtins_common::GetCallArg(argv, 0); + sepHandle = builtins_common::GetCallArg(argv, 0); } - JSHandle sep_string_handle = JSTaggedValue::ToString(thread, sep_handle); + JSHandle sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); // 7. ReturnIfAbrupt(sep). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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); + int32_t sepLen = sepStringHandle->GetLength(); + std::u16string sepStr; + if (sepStringHandle->IsUtf16()) { + sepStr = ecmascript::base::StringHelper::Utf16ToU16String(sepStringHandle->GetDataUtf16(), sepLen); } else { - sep_str = ecmascript::base::StringHelper::Utf8ToU16String(sep_string_handle->GetDataUtf8(), sep_len); + sepStr = ecmascript::base::StringHelper::Utf8ToU16String(sepStringHandle->GetDataUtf8(), sepLen); } // 8. If len is zero, return the empty String. @@ -1455,37 +1451,36 @@ JSTaggedValue builtins::array::proto::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 concat_str; - std::u16string concat_str_new; + std::u16string concatStr; + std::u16string concatStrNew; for (int32_t k = 0; k < len; k++) { - std::u16string next_str; - JSHandle element = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + std::u16string nextStr; + JSHandle element = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!element->IsUndefined() && !element->IsNull()) { - JSHandle next_string_handle = JSTaggedValue::ToString(thread, element); + JSHandle nextStringHandle = JSTaggedValue::ToString(thread, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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); + int32_t nextLen = nextStringHandle->GetLength(); + if (nextStringHandle->IsUtf16()) { + nextStr = ecmascript::base::StringHelper::Utf16ToU16String(nextStringHandle->GetDataUtf16(), nextLen); } else { - next_str = ecmascript::base::StringHelper::Utf8ToU16String(next_string_handle->GetDataUtf8(), next_len); + nextStr = ecmascript::base::StringHelper::Utf8ToU16String(nextStringHandle->GetDataUtf8(), nextLen); } } if (k > 0) { - concat_str_new = ecmascript::base::StringHelper::Append(concat_str, sep_str); - concat_str = ecmascript::base::StringHelper::Append(concat_str_new, next_str); + concatStrNew = ecmascript::base::StringHelper::Append(concatStr, sepStr); + concatStr = ecmascript::base::StringHelper::Append(concatStrNew, nextStr); continue; } - concat_str = ecmascript::base::StringHelper::Append(concat_str, next_str); + concatStr = ecmascript::base::StringHelper::Append(concatStr, nextStr); } // 14. Return R. - 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(); + 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(); } // 22.1.3.13 Array.prototype.keys ( ) @@ -1494,7 +1489,7 @@ JSTaggedValue builtins::array::proto::Keys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). @@ -1511,21 +1506,21 @@ JSTaggedValue builtins::array::proto::LastIndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, LastIndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); - JSHandle search_element = builtins_common::GetCallArg(argv, 0); + JSHandle searchElement = builtins_common::GetCallArg(argv, 0); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1535,19 +1530,19 @@ JSTaggedValue builtins::array::proto::LastIndexOf(EcmaRuntimeCallInfo *argv) } // 6. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be len-1. - double from_index = len - 1; + double fromIndex = len - 1; if (argc > 1) { JSHandle msg1 = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); // 7. ReturnIfAbrupt(n). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); + fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.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 = (from_index >= 0) ? ((len - 1) < from_index ? len - 1 : from_index) : len + from_index; + double from = (fromIndex >= 0) ? ((len - 1) < fromIndex ? len - 1 : fromIndex) : len + fromIndex; // 10. Repeat, while k≥ 0 // a. Let kPresent be HasProperty(O, ToString(k)). @@ -1561,12 +1556,12 @@ JSTaggedValue builtins::array::proto::LastIndexOf(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (from >= 0) { key.Update(JSTaggedValue(from)); - bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, key)); + bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, key)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); + JSHandle kValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::StrictEqual(thread, search_element, k_value_handle)) { + if (JSTaggedValue::StrictEqual(thread, searchElement, kValueHandle)) { return builtins_common::GetTaggedDouble(from); } } @@ -1583,37 +1578,37 @@ JSTaggedValue builtins::array::proto::Map(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Map); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let A be ArraySpeciesCreate(O, len). - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(len)); + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(len)); // 8. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!new_array.IsECMAObject()) { + if (!newArray.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to create Object.", JSTaggedValue::Exception()); } - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); // 9. Let k be 0. // 10. Repeat, while k < len @@ -1629,29 +1624,29 @@ JSTaggedValue builtins::array::proto::Map(EcmaRuntimeCallInfo *argv) // vi. ReturnIfAbrupt(status). // e. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle map_result_handle(thread, JSTaggedValue::Undefined()); + JSMutableHandle mapResultHandle(thread, JSTaggedValue::Undefined()); uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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 + auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(kValue, key, thisObjVal); + JSTaggedValue mapResult = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - map_result_handle.Update(map_result); - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, k, map_result_handle); + mapResultHandle.Update(mapResult); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, k, mapResultHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } // 11. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.3.16 Array.prototype.pop ( ) @@ -1660,30 +1655,30 @@ JSTaggedValue builtins::array::proto::Pop(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Pop); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - if (this_handle->IsStableJSArray(thread)) { - return JSStableArray::Pop(JSHandle::Cast(this_handle), argv); + JSHandle thisHandle = builtins_common::GetThis(argv); + if (thisHandle->IsStableJSArray(thread)) { + return JSStableArray::Pop(JSHandle::Cast(thisHandle), argv); } - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 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 length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); if (len == 0) { - JSHandle length_value(thread, JSTaggedValue(0)); - JSTaggedValue::SetProperty(thread, this_obj_val, length_key, length_value, true); + JSHandle lengthValue(thread, JSTaggedValue(0)); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, lengthValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Undefined(); } @@ -1698,13 +1693,13 @@ JSTaggedValue builtins::array::proto::Pop(EcmaRuntimeCallInfo *argv) // g. Let setStatus be Set(O, "length", newLen, true). // h. ReturnIfAbrupt(setStatus). // i. Return element. - double new_len = len - 1; - JSHandle index_handle(thread, JSTaggedValue(new_len)); - JSHandle element = JSTaggedValue::GetProperty(thread, this_obj_val, index_handle).GetValue(); + double newLen = len - 1; + JSHandle indexHandle(thread, JSTaggedValue(newLen)); + JSHandle element = JSTaggedValue::GetProperty(thread, thisObjVal, indexHandle).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, index_handle); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, indexHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, this_obj_val, length_key, index_handle, true); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, indexHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return element.GetTaggedValue(); @@ -1716,22 +1711,22 @@ JSTaggedValue builtins::array::proto::Push(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Push); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = builtins_common::GetThis(argv); - if (this_handle->IsStableJSArray(thread)) { - return JSStableArray::Push(JSHandle::Cast(this_handle), argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisHandle = builtins_common::GetThis(argv); + if (thisHandle->IsStableJSArray(thread)) { + return JSStableArray::Push(JSHandle::Cast(thisHandle), argv); } // 6. Let argCount be the number of elements in items. uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. If len + argCount > 253-1, throw a TypeError exception. @@ -1748,17 +1743,17 @@ JSTaggedValue builtins::array::proto::Push(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (k < argc) { key.Update(JSTaggedValue(len)); - JSHandle k_value = builtins_common::GetCallArg(argv, k); - JSArray::FastSetPropertyByValue(thread, this_obj_val, key, k_value); + JSHandle kValue = builtins_common::GetCallArg(argv, k); + JSArray::FastSetPropertyByValue(thread, thisObjVal, key, kValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; len++; } // 9. Let setStatus be Set(O, "length", len, true). - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); key.Update(JSTaggedValue(len)); - JSTaggedValue::SetProperty(thread, this_obj_val, length_key, key, true); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, key, true); // 10. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1772,25 +1767,25 @@ JSTaggedValue builtins::array::proto::Reduce(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Reduce); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } @@ -1818,17 +1813,17 @@ JSTaggedValue builtins::array::proto::Reduce(EcmaRuntimeCallInfo *argv) if (argc == 2) { // 2:2 means the number of parameters accumulator.Update(builtins_common::GetCallArg(argv, 1).GetTaggedValue()); } else { - bool k_present = false; - while (!k_present && k < len) { - k_present = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); + bool kPresent = false; + while (!kPresent && k < len) { + kPresent = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (k_present) { - accumulator.Update(JSArray::FastGetPropertyByValue(thread, this_obj_val, k).GetTaggedValue()); + if (kPresent) { + accumulator.Update(JSArray::FastGetPropertyByValue(thread, thisObjVal, k).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } - if (!k_present) { + if (!kPresent) { THROW_TYPE_ERROR_AND_RETURN(thread, "accumulator can't be initialized.", JSTaggedValue::Exception()); } } @@ -1843,22 +1838,22 @@ JSTaggedValue builtins::array::proto::Reduce(EcmaRuntimeCallInfo *argv) // iii. Let accumulator be Call(callbackfn, undefined, «accumulator, kValue, k, O»). // iv. ReturnIfAbrupt(accumulator). // e. Increase k by 1. - JSTaggedValue call_result = JSTaggedValue::Undefined(); + JSTaggedValue callResult = JSTaggedValue::Undefined(); JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (k < len) { - bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); + bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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 + 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 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - accumulator.Update(call_result); + accumulator.Update(callResult); } k++; } @@ -1873,26 +1868,26 @@ JSTaggedValue builtins::array::proto::ReduceRight(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, ReduceRight); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } @@ -1920,17 +1915,17 @@ JSTaggedValue builtins::array::proto::ReduceRight(EcmaRuntimeCallInfo *argv) if (argc == 2) { // 2:2 means the number of parameters accumulator.Update(builtins_common::GetCallArg(argv, 1).GetTaggedValue()); } else { - bool k_present = false; - while (!k_present && k >= 0) { - k_present = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); + bool kPresent = false; + while (!kPresent && k >= 0) { + kPresent = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (k_present) { - accumulator.Update(JSArray::FastGetPropertyByValue(thread, this_obj_val, k).GetTaggedValue()); + if (kPresent) { + accumulator.Update(JSArray::FastGetPropertyByValue(thread, thisObjVal, k).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k--; } - if (!k_present) { + if (!kPresent) { THROW_TYPE_ERROR_AND_RETURN(thread, "accumulator can't be initialized.", JSTaggedValue::Exception()); } } @@ -1946,21 +1941,21 @@ JSTaggedValue builtins::array::proto::ReduceRight(EcmaRuntimeCallInfo *argv) // iv. ReturnIfAbrupt(accumulator). // e. Decrease k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSTaggedValue call_result = JSTaggedValue::Undefined(); + JSTaggedValue callResult = JSTaggedValue::Undefined(); while (k >= 0) { key.Update(JSTaggedValue(k)); - bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, key)); + bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, key)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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 + 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 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - accumulator.Update(call_result); + accumulator.Update(callResult); } k--; } @@ -1975,17 +1970,17 @@ JSTaggedValue builtins::array::proto::Reverse(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Reverse); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2027,40 +2022,40 @@ JSTaggedValue builtins::array::proto::Reverse(EcmaRuntimeCallInfo *argv) // m. Else both lowerExists and upperExists are false, // i. No action is required. // n. Increase lower by 1. - 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()); + JSMutableHandle lowerP(thread, JSTaggedValue::Undefined()); + JSMutableHandle upperP(thread, JSTaggedValue::Undefined()); + JSHandle lowerValueHandle(thread, JSTaggedValue::Undefined()); + JSHandle upperValueHandle(thread, JSTaggedValue::Undefined()); while (lower != middle) { double upper = len - lower - 1; - lower_p.Update(JSTaggedValue(lower)); - upper_p.Update(JSTaggedValue(upper)); - bool lower_exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, lower_p)); + lowerP.Update(JSTaggedValue(lower)); + upperP.Update(JSTaggedValue(upper)); + bool lowerExists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, lowerP)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (lower_exists) { - lower_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, lower_p); + if (lowerExists) { + lowerValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, lowerP); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - bool upper_exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, upper_p)); + bool upperExists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, upperP)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (upper_exists) { - upper_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, upper_p); + if (upperExists) { + upperValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, upperP); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (lower_exists && upper_exists) { - JSArray::FastSetPropertyByValue(thread, this_obj_val, lower_p, upper_value_handle); + if (lowerExists && upperExists) { + JSArray::FastSetPropertyByValue(thread, thisObjVal, lowerP, upperValueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, this_obj_val, upper_p, lower_value_handle); + JSArray::FastSetPropertyByValue(thread, thisObjVal, upperP, lowerValueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - } else if (upper_exists) { - JSArray::FastSetPropertyByValue(thread, this_obj_val, lower_p, upper_value_handle); + } else if (upperExists) { + JSArray::FastSetPropertyByValue(thread, thisObjVal, lowerP, upperValueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, upper_p); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, upperP); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - } else if (lower_exists) { - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, lower_p); + } else if (lowerExists) { + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, lowerP); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, this_obj_val, upper_p, lower_value_handle); + JSArray::FastSetPropertyByValue(thread, thisObjVal, upperP, lowerValueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { } @@ -2068,7 +2063,7 @@ JSTaggedValue builtins::array::proto::Reverse(EcmaRuntimeCallInfo *argv) } // 8. Return O . - return this_obj_handle.GetTaggedValue(); + return thisObjHandle.GetTaggedValue(); } // 22.1.3.21 Array.prototype.shift ( ) @@ -2077,37 +2072,37 @@ JSTaggedValue builtins::array::proto::Shift(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Shift); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - if (this_handle->IsStableJSArray(thread)) { - return JSStableArray::Shift(JSHandle::Cast(this_handle), argv); + JSHandle thisHandle = builtins_common::GetThis(argv); + if (thisHandle->IsStableJSArray(thread)) { + return JSStableArray::Shift(JSHandle::Cast(thisHandle), argv); } - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 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 length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); if (len == 0) { - JSHandle zero_len_handle(thread, JSTaggedValue(len)); - JSTaggedValue::SetProperty(thread, this_obj_val, length_key, zero_len_handle, true); + JSHandle zeroLenHandle(thread, JSTaggedValue(len)); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, zeroLenHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Undefined(); } // 6. Let first be Get(O, "0"). - JSHandle first_key(thread, JSTaggedValue(0)); - JSHandle first_value = JSTaggedValue::GetProperty(thread, this_obj_val, first_key).GetValue(); + JSHandle firstKey(thread, JSTaggedValue(0)); + JSHandle firstValue = JSTaggedValue::GetProperty(thread, thisObjVal, firstKey).GetValue(); // 7. ReturnIfAbrupt(first). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2126,37 +2121,37 @@ JSTaggedValue builtins::array::proto::Shift(EcmaRuntimeCallInfo *argv) // i. Let deleteStatus be DeletePropertyOrThrow(O, to). // ii. ReturnIfAbrupt(deleteStatus). // g. Increase k by 1. - JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); double k = 1; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, this_obj_val, k - 1, from_value); + JSArray::FastSetPropertyByValue(thread, thisObjVal, k - 1, fromValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - to_key.Update(JSTaggedValue(k - 1)); - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); + toKey.Update(JSTaggedValue(k - 1)); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } // 10. Let deleteStatus be DeletePropertyOrThrow(O, ToString(len–1)). - JSHandle delete_key(thread, JSTaggedValue(len - 1)); - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, delete_key); + JSHandle deleteKey(thread, JSTaggedValue(len - 1)); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, deleteKey); // 11. ReturnIfAbrupt(deleteStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 12. Let setStatus be Set(O, "length", len–1, true). - JSHandle new_len_handle(thread, JSTaggedValue(len - 1)); - JSTaggedValue::SetProperty(thread, this_obj_val, length_key, new_len_handle, true); + JSHandle newLenHandle(thread, JSTaggedValue(len - 1)); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true); // 13. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 14. Return first. - return first_value.GetTaggedValue(); + return firstValue.GetTaggedValue(); } // 22.1.3.22 Array.prototype.slice (start, end) @@ -2165,49 +2160,49 @@ JSTaggedValue builtins::array::proto::Slice(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Slice); ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let relativeStart be ToInteger(start). JSHandle msg0 = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg0); + JSTaggedNumber argStartTemp = JSTaggedValue::ToInteger(thread, msg0); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double arg_start = arg_start_temp.GetNumber(); + double argStart = argStartTemp.GetNumber(); double k; // 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be min(relativeStart, len). - if (arg_start < 0) { - k = arg_start + len > 0 ? arg_start + len : 0; + if (argStart < 0) { + k = argStart + len > 0 ? argStart + len : 0; } else { - k = arg_start < len ? arg_start : len; + k = argStart < len ? argStart : 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 = builtins_common::GetCallArg(argv, 1); - double arg_end = len; + double argEnd = len; if (!msg1->IsUndefined()) { - JSTaggedNumber arg_end_temp = JSTaggedValue::ToInteger(thread, msg1); + JSTaggedNumber argEndTemp = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - arg_end = arg_end_temp.GetNumber(); + argEnd = argEndTemp.GetNumber(); } double final; - if (arg_end < 0) { - final = arg_end + len > 0 ? arg_end + len : 0; + if (argEnd < 0) { + final = argEnd + len > 0 ? argEnd + len : 0; } else { - final = arg_end < len ? arg_end : len; + final = argEnd < len ? argEnd : len; } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2215,24 +2210,24 @@ JSTaggedValue builtins::array::proto::Slice(EcmaRuntimeCallInfo *argv) double count = (final - k) > 0 ? (final - k) : 0; // 12. Let A be ArraySpeciesCreate(O, count). - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(count)); + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(count)); // 13. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (count == 0) { - return new_array; + return newArray; } - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); - 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()); + if (thisHandle->IsStableJSArray(thread) && newArray.IsStableJSArray(thread)) { + TaggedArray *destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, count); + TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); for (uint32_t idx = 0; idx < count; idx++) { - dest_elements->Set(thread, idx, src_elements->Get(k + idx)); + destElements->Set(thread, idx, srcElements->Get(k + idx)); } - JSHandle::Cast(new_array_handle)->SetArrayLength(thread, count); - return new_array_handle.GetTaggedValue(); + JSHandle::Cast(newArrayHandle)->SetArrayLength(thread, count); + return newArrayHandle.GetTaggedValue(); } // 14. Let n be 0. @@ -2249,16 +2244,16 @@ JSTaggedValue builtins::array::proto::Slice(EcmaRuntimeCallInfo *argv) // f. Increase n by 1. double n = 0; JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle n_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle nKey(thread, JSTaggedValue::Undefined()); while (k < final) { key.Update(JSTaggedValue(k)); - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, key); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - n_key.Update(JSTaggedValue(n)); - JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); + nKey.Update(JSTaggedValue(n)); + JSHandle kValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, n_key, k_value_handle); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, nKey, kValueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; @@ -2266,15 +2261,14 @@ JSTaggedValue builtins::array::proto::Slice(EcmaRuntimeCallInfo *argv) } // 16. Let setStatus be Set(A, "length", n, 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); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle newLenHandle(thread, JSTaggedValue(n)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, newLenHandle, true); // 17. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 18. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.3.23 Array.prototype.some ( callbackfn [ , thisArg ] ) @@ -2283,28 +2277,28 @@ JSTaggedValue builtins::array::proto::Some(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Some); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -2322,18 +2316,18 @@ JSTaggedValue builtins::array::proto::Some(EcmaRuntimeCallInfo *argv) double k = 0; while (k < len) { - bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); + bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { key.Update(JSTaggedValue(k)); - JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); + JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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(); + 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(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (bool_result) { + if (boolResult) { return builtins_common::GetTaggedBoolean(true); } } @@ -2350,62 +2344,61 @@ JSTaggedValue builtins::array::proto::Sort(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Sort); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let obj be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsUndefined() && !callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsUndefined() && !callbackFnHandle->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(this_obj_handle)); + double len = ArrayHelper::GetArrayLength(thread, JSHandle(thisObjHandle)); // 3. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSMutableHandle present_value(thread, JSTaggedValue::Undefined()); - JSMutableHandle middle_value(thread, JSTaggedValue::Undefined()); - JSMutableHandle previous_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle presentValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle middleValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle previousValue(thread, JSTaggedValue::Undefined()); for (int i = 1; i < len; i++) { - int begin_index = 0; - int end_index = i; - present_value.Update( - FastRuntimeStub::FastGetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), i)); + int beginIndex = 0; + int endIndex = i; + presentValue.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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)); + while (beginIndex < endIndex) { + int middleIndex = (beginIndex + endIndex) / 2; // 2 : half + middleValue.Update( + FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), middleIndex)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t compare_result = ArrayHelper::SortCompare(thread, callback_fn_handle, middle_value, present_value); + int32_t compareResult = ArrayHelper::SortCompare(thread, callbackFnHandle, middleValue, presentValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (compare_result > 0) { - end_index = middle_index; + if (compareResult > 0) { + endIndex = middleIndex; } else { - begin_index = middle_index + 1; + beginIndex = middleIndex + 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)); + if (endIndex >= 0 && endIndex < i) { + for (int j = i; j > endIndex; j--) { + previousValue.Update( + FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), j - 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - FastRuntimeStub::FastSetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), j, - previous_value.GetTaggedValue()); + FastRuntimeStub::FastSetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), j, + previousValue.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - FastRuntimeStub::FastSetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), end_index, - present_value.GetTaggedValue()); + FastRuntimeStub::FastSetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), endIndex, + presentValue.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } - return this_obj_handle.GetTaggedValue(); + return thisObjHandle.GetTaggedValue(); } // 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items ) @@ -2415,38 +2408,38 @@ JSTaggedValue builtins::array::proto::Splice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Splice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let relativeStart be ToInteger(start). double start = 0; - double insert_count = 0; - double actual_delete_count = 0; + double insertCount = 0; + double actualDeleteCount = 0; double end = len; - double arg_start = 0; + double argStart = 0; if (argc > 0) { JSHandle msg0 = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg0); + JSTaggedNumber argStartTemp = JSTaggedValue::ToInteger(thread, msg0); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - arg_start = arg_start_temp.GetNumber(); + argStart = argStartTemp.GetNumber(); // 7. If relativeStart < 0, let actualStart be max((len + relativeStart),0); else let actualStart be // min(relativeStart, len). - if (arg_start < 0) { - start = arg_start + len > 0 ? arg_start + len : 0; + if (argStart < 0) { + start = argStart + len > 0 ? argStart + len : 0; } else { - start = arg_start < end ? arg_start : end; + start = argStart < end ? argStart : end; } - actual_delete_count = len - start; + actualDeleteCount = len - start; } // 8. If the number of actual arguments is 0, then // a. Let insertCount be 0. @@ -2460,27 +2453,26 @@ JSTaggedValue builtins::array::proto::Splice(EcmaRuntimeCallInfo *argv) // c. ReturnIfAbrupt(dc). // d. Let actualDeleteCount be min(max(dc,0), len – actualStart). if (argc > 1) { - insert_count = argc - 2; // 2:2 means there are two arguments before the insert items. + insertCount = argc - 2; // 2:2 means there are two arguments before the insert items. JSHandle msg1 = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber arg_delete_count = JSTaggedValue::ToInteger(thread, msg1); + JSTaggedNumber argDeleteCount = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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; + double deleteCount = argDeleteCount.GetNumber(); + deleteCount = deleteCount > 0 ? deleteCount : 0; + actualDeleteCount = deleteCount < (len - start) ? deleteCount : len - start; } // 11. If len+insertCount−actualDeleteCount > 253-1, throw a TypeError exception. - if (len + insert_count - actual_delete_count > ecmascript::base::MAX_SAFE_INTEGER) { + if (len + insertCount - actualDeleteCount > ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } - if (this_handle->IsStableJSArray(thread)) { - return JSStableArray::Splice(JSHandle::Cast(this_handle), argv, start, insert_count, - actual_delete_count); + if (thisHandle->IsStableJSArray(thread)) { + return JSStableArray::Splice(JSHandle::Cast(thisHandle), argv, start, insertCount, actualDeleteCount); } // 12. Let A be ArraySpeciesCreate(O, actualDeleteCount). - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(actual_delete_count)); + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(actualDeleteCount)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); // 14. Let k be 0. // 15. Repeat, while k < actualDeleteCount // a. Let from be ToString(actualStart+k). @@ -2489,30 +2481,30 @@ JSTaggedValue builtins::array::proto::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 from_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); double k = 0; - while (k < actual_delete_count) { + while (k < actualDeleteCount) { double from = start + k; - from_key.Update(JSTaggedValue(from)); - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); + fromKey.Update(JSTaggedValue(from)); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); + JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - to_key.Update(JSTaggedValue(k)); - if (new_array_handle->IsJSProxy()) { - to_key.Update(JSTaggedValue::ToString(thread, to_key).GetTaggedValue()); + toKey.Update(JSTaggedValue(k)); + if (newArrayHandle->IsJSProxy()) { + toKey.Update(JSTaggedValue::ToString(thread, toKey).GetTaggedValue()); } - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_key, from_value); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } // 16. Let setStatus be Set(A, "length", actualDeleteCount, true). - 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, + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle deleteCountHandle(thread, JSTaggedValue(actualDeleteCount)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, deleteCountHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 19. Let itemCount be the number of elements in items. @@ -2532,33 +2524,33 @@ JSTaggedValue builtins::array::proto::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 (insert_count < actual_delete_count) { + if (insertCount < actualDeleteCount) { k = start; - 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); + while (k < len - actualDeleteCount) { + fromKey.Update(JSTaggedValue(k + actualDeleteCount)); + toKey.Update(JSTaggedValue(k + insertCount)); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); + JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_value); + JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } k = len; - 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); + JSMutableHandle deleteKey(thread, JSTaggedValue::Undefined()); + while (k > len - actualDeleteCount + insertCount) { + deleteKey.Update(JSTaggedValue(k - 1)); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, deleteKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k--; } - } else if (insert_count > actual_delete_count) { + } else if (insertCount > actualDeleteCount) { // 21. Else if itemCount > actualDeleteCount, then // a. Let k be (len – actualDeleteCount). // b. Repeat, while k > actualStart @@ -2575,19 +2567,19 @@ JSTaggedValue builtins::array::proto::Splice(EcmaRuntimeCallInfo *argv) // 1. Let deleteStatus be DeletePropertyOrThrow(O, to). // 2. ReturnIfAbrupt(deleteStatus). // vii. Decrease k by 1. - k = len - actual_delete_count; + k = len - actualDeleteCount; while (k > start) { - 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); + fromKey.Update(JSTaggedValue(k + actualDeleteCount - 1)); + toKey.Update(JSTaggedValue(k + insertCount - 1)); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); + JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_value); + JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k--; @@ -2598,20 +2590,20 @@ JSTaggedValue builtins::array::proto::Splice(EcmaRuntimeCallInfo *argv) // 23. Repeat, while items is not empty JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t i = 2; i < argc; i++) { - JSHandle item_value = builtins_common::GetCallArg(argv, i); + JSHandle itemValue = builtins_common::GetCallArg(argv, i); key.Update(JSTaggedValue(k)); - JSArray::FastSetPropertyByValue(thread, this_obj_val, key, item_value); + JSArray::FastSetPropertyByValue(thread, thisObjVal, key, itemValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 24. Let setStatus be Set(O, "length", len – actualDeleteCount + itemCount, 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); + double newLen = len - actualDeleteCount + insertCount; + JSHandle newLenHandle(thread, JSTaggedValue(newLen)); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true); // 25. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 26. Return A. - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } // 22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) @@ -2620,33 +2612,33 @@ JSTaggedValue builtins::array::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, ToLocaleString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, this_obj_val); + double len = ArrayHelper::GetLength(thread, thisObjVal); // 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 sep_handle; + JSHandle sepHandle; if ((builtins_common::GetCallArg(argv, 0)->IsUndefined())) { - sep_handle = JSHandle::Cast(ecma_vm->GetFactory()->NewFromCanBeCompressString(",")); + sepHandle = JSHandle::Cast(ecmaVm->GetFactory()->NewFromCanBeCompressString(",")); } else { - sep_handle = builtins_common::GetCallArg(argv, 0); + sepHandle = builtins_common::GetCallArg(argv, 0); } - JSHandle sep_string_handle = JSTaggedValue::ToString(thread, sep_handle); + JSHandle sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - PandaString sep_string = ConvertToPandaString(*sep_string_handle); + PandaString sepString = ConvertToPandaString(*sepStringHandle); // 6. If len is zero, return the empty String. if (len == 0) { return builtins_common::GetTaggedString(thread, ""); @@ -2656,7 +2648,7 @@ JSTaggedValue builtins::array::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - PandaString concat_str; + PandaString concatStr; // 7. Let firstElement be Get(array, "0"). // 8. ReturnIfAbrupt(firstElement). // 9. If firstElement is undefined or null, then @@ -2676,37 +2668,37 @@ JSTaggedValue builtins::array::proto::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 global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); for (int32_t k = 0; k < len; k++) { - JSTaggedValue next = global_const->GetEmptyString(); - JSHandle next_element = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); + JSTaggedValue next = globalConst->GetEmptyString(); + JSHandle nextElement = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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, + if (!nextElement->IsUndefined() && !nextElement->IsNull()) { + JSHandle nextValueHandle = nextElement; + JSHandle key = globalConst->GetHandledToLocaleStringString(); + auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), nextValueHandle, JSTaggedValue::Undefined(), 2); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArgs(locales, options); - JSTaggedValue call_result = JSFunction::Invoke(info.Get(), key); + JSTaggedValue callResult = JSFunction::Invoke(info.Get(), key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - next = call_result; + next = callResult; } - JSHandle next_handle(thread, next); - JSHandle next_string_handle = JSTaggedValue::ToString(thread, next_handle); + JSHandle nextHandle(thread, next); + JSHandle nextStringHandle = JSTaggedValue::ToString(thread, nextHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - PandaString next_string = ConvertToPandaString(*next_string_handle); + PandaString nextString = ConvertToPandaString(*nextStringHandle); if (k > 0) { - concat_str += sep_string; - concat_str += next_string; + concatStr += sepString; + concatStr += nextString; continue; } - concat_str += next_string; + concatStr += nextString; } // 13. Return R. - return factory->NewFromString(concat_str).GetTaggedValue(); + return factory->NewFromString(concatStr).GetTaggedValue(); } // 22.1.3.27 Array.prototype.toString ( ) @@ -2715,35 +2707,35 @@ JSTaggedValue builtins::array::proto::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. Let array be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(array). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let func be Get(array, "join"). - JSHandle join_key(factory->NewFromCanBeCompressString("join")); - JSHandle callback_fn_handle = JSTaggedValue::GetProperty(thread, this_obj_val, join_key).GetValue(); + JSHandle joinKey(factory->NewFromCanBeCompressString("join")); + JSHandle callbackFnHandle = JSTaggedValue::GetProperty(thread, thisObjVal, joinKey).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 (!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(); + if (!callbackFnHandle->IsCallable()) { + JSHandle env = ecmaVm->GetGlobalEnv(); + JSHandle objectPrototype = env->GetObjectFunctionPrototype(); + JSHandle toStringKey = thread->GlobalConstants()->GetHandledToStringString(); + callbackFnHandle = JSTaggedValue::GetProperty(thread, objectPrototype, toStringKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } auto info = - NewRuntimeCallInfo(thread, callback_fn_handle, this_obj_val, JSTaggedValue::Undefined(), argv->GetArgsNumber()); + NewRuntimeCallInfo(thread, callbackFnHandle, thisObjVal, JSTaggedValue::Undefined(), argv->GetArgsNumber()); if (argv->GetArgsNumber() > 0) { info->SetCallArg(argv->GetArgsNumber(), reinterpret_cast(argv->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS))); @@ -2757,20 +2749,20 @@ JSTaggedValue builtins::array::proto::Unshift(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Unshift); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 5. Let argCount be the number of actual arguments. uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, this_obj_val); + double len = ArrayHelper::GetArrayLength(thread, thisObjVal); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2795,21 +2787,21 @@ JSTaggedValue builtins::array::proto::Unshift(EcmaRuntimeCallInfo *argv) if (len + argc > ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } - JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); double k = len; while (k > 0) { - from_key.Update(JSTaggedValue(k - 1)); - to_key.Update(JSTaggedValue(k + argc - 1)); - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); + fromKey.Update(JSTaggedValue(k - 1)); + toKey.Update(JSTaggedValue(k + argc - 1)); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); + JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_value); + JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); + JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k--; @@ -2824,24 +2816,24 @@ JSTaggedValue builtins::array::proto::Unshift(EcmaRuntimeCallInfo *argv) // iv. Increase j by 1. double j = 0; while (j < argc) { - to_key.Update(JSTaggedValue(j)); - JSHandle to_value = builtins_common::GetCallArg(argv, j); - JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, to_value); + toKey.Update(JSTaggedValue(j)); + JSHandle toValue = builtins_common::GetCallArg(argv, j); + JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, toValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); j++; } } // 7. Let setStatus be Set(O, "length", len+argCount, 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); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + double newLen = len + argc; + JSHandle newLenHandle(thread, JSTaggedValue(newLen)); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true); // 8. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. Return len+argCount. - return builtins_common::GetTaggedDouble(new_len); + return builtins_common::GetTaggedDouble(newLen); } // 22.1.3.29 Array.prototype.values ( ) @@ -2850,7 +2842,7 @@ JSTaggedValue builtins::array::proto::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayPrototype, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). @@ -2864,43 +2856,43 @@ JSTaggedValue builtins::array::proto::Values(EcmaRuntimeCallInfo *argv) JSTaggedValue builtins::array::proto::GetUnscopables(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle null_handle(thread, JSTaggedValue::Null()); - JSHandle unscopable_list = factory->OrdinaryNewJSObjectCreate(null_handle); + JSHandle nullHandle(thread, JSTaggedValue::Null()); + JSHandle unscopableList = factory->OrdinaryNewJSObjectCreate(nullHandle); - JSHandle true_val(thread, JSTaggedValue::True()); - JSHandle copy_with_key(factory->NewFromCanBeCompressString("copyWithin")); - JSObject::CreateDataProperty(thread, unscopable_list, copy_with_key, true_val); + JSHandle trueVal(thread, JSTaggedValue::True()); + JSHandle copyWithKey(factory->NewFromCanBeCompressString("copyWithin")); + JSObject::CreateDataProperty(thread, unscopableList, copyWithKey, trueVal); - JSHandle entries_key(factory->NewFromCanBeCompressString("entries")); - JSObject::CreateDataProperty(thread, unscopable_list, entries_key, true_val); + JSHandle entriesKey(factory->NewFromCanBeCompressString("entries")); + JSObject::CreateDataProperty(thread, unscopableList, entriesKey, trueVal); - JSHandle fill_key(factory->NewFromCanBeCompressString("fill")); - JSObject::CreateDataProperty(thread, unscopable_list, fill_key, true_val); + JSHandle fillKey(factory->NewFromCanBeCompressString("fill")); + JSObject::CreateDataProperty(thread, unscopableList, fillKey, trueVal); - JSHandle find_key(factory->NewFromCanBeCompressString("find")); - JSObject::CreateDataProperty(thread, unscopable_list, find_key, true_val); + JSHandle findKey(factory->NewFromCanBeCompressString("find")); + JSObject::CreateDataProperty(thread, unscopableList, findKey, trueVal); - JSHandle find_index_key(factory->NewFromCanBeCompressString("findIndex")); - JSObject::CreateDataProperty(thread, unscopable_list, find_index_key, true_val); + JSHandle findIndexKey(factory->NewFromCanBeCompressString("findIndex")); + JSObject::CreateDataProperty(thread, unscopableList, findIndexKey, trueVal); - JSHandle flat_key(factory->NewFromCanBeCompressString("flat")); - JSObject::CreateDataProperty(thread, unscopable_list, flat_key, true_val); + JSHandle flatKey(factory->NewFromCanBeCompressString("flat")); + JSObject::CreateDataProperty(thread, unscopableList, flatKey, trueVal); - JSHandle flat_map_key(factory->NewFromCanBeCompressString("flatMap")); - JSObject::CreateDataProperty(thread, unscopable_list, flat_map_key, true_val); + JSHandle flatMapKey(factory->NewFromCanBeCompressString("flatMap")); + JSObject::CreateDataProperty(thread, unscopableList, flatMapKey, trueVal); - JSHandle includes_key(factory->NewFromCanBeCompressString("includes")); - JSObject::CreateDataProperty(thread, unscopable_list, includes_key, true_val); + JSHandle includesKey(factory->NewFromCanBeCompressString("includes")); + JSObject::CreateDataProperty(thread, unscopableList, includesKey, trueVal); - JSHandle keys_key(factory->NewFromCanBeCompressString("keys")); - JSObject::CreateDataProperty(thread, unscopable_list, keys_key, true_val); + JSHandle keysKey(factory->NewFromCanBeCompressString("keys")); + JSObject::CreateDataProperty(thread, unscopableList, keysKey, trueVal); - JSHandle values_key(factory->NewFromCanBeCompressString("values")); - JSObject::CreateDataProperty(thread, unscopable_list, values_key, true_val); + JSHandle valuesKey(factory->NewFromCanBeCompressString("values")); + JSObject::CreateDataProperty(thread, unscopableList, valuesKey, trueVal); - return unscopable_list.GetTaggedValue(); + return unscopableList.GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_arraybuffer.cpp b/runtime/builtins/builtins_arraybuffer.cpp index 42c6f3b743c3bc64774dc8418ace3fcd20ac5dab..f3a2168c5ef81f2b7265514c2f766b9cc686e8a4 100644 --- a/runtime/builtins/builtins_arraybuffer.cpp +++ b/runtime/builtins/builtins_arraybuffer.cpp @@ -41,11 +41,11 @@ enum NumberSize : uint8_t { BIGUINT64 = 8 }; union UnionType32 { - uint32_t u_value; + uint32_t uValue; float value; } __attribute__((packed, may_alias)); union UnionType64 { - uint64_t u_value; + uint64_t uValue; double value; } __attribute__((packed, may_alias)); @@ -55,24 +55,24 @@ JSTaggedValue builtins::array_buffer::ArrayBufferConstructor(EcmaRuntimeCallInfo ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayBuffer, ArrayBufferConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = builtins_common::GetNewTarget(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle newTarget = builtins_common::GetNewTarget(argv); // 1. If NewTarget is undefined, throw a TypeError exception. - if (new_target->IsUndefined()) { + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "newtarget is undefined", JSTaggedValue::Exception()); } - JSHandle length_handle = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber len_num = JSTaggedValue::ToIndex(thread, length_handle); + JSHandle lengthHandle = builtins_common::GetCallArg(argv, 0); + JSTaggedNumber lenNum = JSTaggedValue::ToIndex(thread, lengthHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double length = len_num.GetNumber(); - return AllocateArrayBuffer(thread, new_target, length); + double length = lenNum.GetNumber(); + return AllocateArrayBuffer(thread, newTarget, length); } // 24.1.3.1 ArrayBuffer.isView(arg) JSTaggedValue builtins::array_buffer::IsView(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); JSHandle arg = builtins_common::GetCallArg(argv, 0); // 1. If Type(arg) is not Object, return false. if (!arg->IsECMAObject()) { @@ -97,25 +97,25 @@ JSTaggedValue builtins::array_buffer::GetSpecies(EcmaRuntimeCallInfo *argv) JSTaggedValue builtins::array_buffer::proto::GetByteLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); JSThread *thread = argv->GetThread(); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsArrayBuffer()) { + if (!thisHandle->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(this_handle.GetTaggedValue())) { + if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "IsDetachedBuffer", JSTaggedValue::Exception()); } - JSHandle arr_buf(this_handle); + JSHandle arrBuf(thisHandle); // 5. Let length be the value of O’s [[ArrayBufferByteLength]] internal slot. - JSTaggedValue length = arr_buf->GetArrayBufferByteLength(); + JSTaggedValue length = arrBuf->GetArrayBufferByteLength(); // 6. Return length. return JSTaggedValue(length); } @@ -126,34 +126,34 @@ JSTaggedValue builtins::array_buffer::proto::Slice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayBufferPrototype, Slice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsObject()) { + if (!thisHandle->IsObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not an object", JSTaggedValue::Exception()); } - JSHandle arr_buf(this_handle); + JSHandle arrBuf(thisHandle); // 3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. - if (!this_handle->IsArrayBuffer()) { + if (!thisHandle->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(this_handle.GetTaggedValue())) { + if (IsDetachedBuffer(thisHandle.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 length_num = JSTaggedNumber::FromIntOrDouble(thread, arr_buf->GetArrayBufferByteLength()); + JSTaggedNumber lengthNum = JSTaggedNumber::FromIntOrDouble(thread, arrBuf->GetArrayBufferByteLength()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle start_handle = builtins_common::GetCallArg(argv, 0); + JSHandle startHandle = builtins_common::GetCallArg(argv, 0); // 6. Let relativeStart be ToInteger(start). - JSTaggedNumber relative_start = JSTaggedValue::ToInteger(thread, start_handle); + JSTaggedNumber relativeStart = JSTaggedValue::ToInteger(thread, startHandle); // 7. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t len = length_num.ToInt32(); - int32_t start = ecmascript::base::NumberHelper::DoubleInRangeInt32(relative_start.GetNumber()); + int32_t len = lengthNum.ToInt32(); + int32_t start = ecmascript::base::NumberHelper::DoubleInRangeInt32(relativeStart.GetNumber()); int32_t end; int32_t first; int32_t last; @@ -164,14 +164,14 @@ JSTaggedValue builtins::array_buffer::proto::Slice(EcmaRuntimeCallInfo *argv) first = std::min(start, len); } // 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). - JSHandle end_handle = builtins_common::GetCallArg(argv, 1); - if (end_handle->IsUndefined()) { + JSHandle endHandle = builtins_common::GetCallArg(argv, 1); + if (endHandle->IsUndefined()) { end = len; } else { - JSTaggedNumber relative_end = JSTaggedValue::ToInteger(thread, end_handle); + JSTaggedNumber relativeEnd = JSTaggedValue::ToInteger(thread, endHandle); // 10. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = ecmascript::base::NumberHelper::DoubleInRangeInt32(relative_end.GetNumber()); + end = ecmascript::base::NumberHelper::DoubleInRangeInt32(relativeEnd.GetNumber()); } // 11. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). if (end < 0) { @@ -180,61 +180,61 @@ JSTaggedValue builtins::array_buffer::proto::Slice(EcmaRuntimeCallInfo *argv) last = std::min(end, len); } // 12. Let newLen be max(final-first,0). - int32_t new_len = std::max((last - first), 0); + int32_t newLen = std::max((last - first), 0); // 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). - JSHandle default_constructor = env->GetArrayBufferFunction(); - JSHandle obj_handle(this_handle); - JSHandle constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); + JSHandle defaultConstructor = env->GetArrayBufferFunction(); + JSHandle objHandle(thisHandle); + JSHandle constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); // 14. ReturnIfAbrupt(ctor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 15. Let new be Construct(ctor, «newLen»). - JSHandle undefined = global_const->GetHandledUndefined(); + JSHandle undefined = globalConst->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), undefined, 1); - info->SetCallArgs(JSTaggedValue(new_len)); - JSTaggedValue tagged_new_arr_buf = JSFunction::Construct(info.Get()); - JSHandle new_arr_buf(thread, tagged_new_arr_buf); + info->SetCallArgs(JSTaggedValue(newLen)); + JSTaggedValue taggedNewArrBuf = JSFunction::Construct(info.Get()); + JSHandle newArrBuf(thread, taggedNewArrBuf); // 16. ReturnIfAbrupt(new). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 17. If new does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. - if (!new_arr_buf->IsArrayBuffer()) { + if (!newArrBuf->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(new_arr_buf.GetTaggedValue())) { + if (IsDetachedBuffer(newArrBuf.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(new_arr_buf.GetTaggedValue(), this_handle.GetTaggedValue())) { + if (JSTaggedValue::SameValue(newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "value of new arraybuffer and this is same", JSTaggedValue::Exception()); } - JSHandle new_js_arr_buf(new_arr_buf); + JSHandle newJsArrBuf(newArrBuf); // 20. If the value of new’s [[ArrayBufferByteLength]] internal slot < newLen, throw a TypeError exception. - 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) { + JSTaggedNumber newLengthNum = JSTaggedNumber::FromIntOrDouble(thread, newJsArrBuf->GetArrayBufferByteLength()); + int32_t newArrBufLen = newLengthNum.ToInt32(); + if (newArrBufLen < newLen) { 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(this_handle.GetTaggedValue())) { + if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } - if (new_len > 0) { + if (newLen > 0) { // 23. Let fromBuf be the value of O’s [[ArrayBufferData]] internal slot. - JSTaggedValue from = arr_buf->GetArrayBufferData(); + JSTaggedValue from = arrBuf->GetArrayBufferData(); // 24. Let toBuf be the value of new’s [[ArrayBufferData]] internal slot. - JSTaggedValue to = new_js_arr_buf->GetArrayBufferData(); + JSTaggedValue to = newJsArrBuf->GetArrayBufferData(); // 25. Perform CopyDataBlockBytes(toBuf, fromBuf, first, newLen). - JSArrayBuffer::CopyDataBlockBytes(to, from, first, new_len); + JSArrayBuffer::CopyDataBlockBytes(to, from, first, newLen); } // Return new. - return new_arr_buf.GetTaggedValue(); + return newArrBuf.GetTaggedValue(); } // 24.1.1.1 AllocateArrayBuffer(constructor, byteLength) -JSTaggedValue builtins::array_buffer::AllocateArrayBuffer(JSThread *thread, const JSHandle &new_target, - double byte_length) +JSTaggedValue builtins::array_buffer::AllocateArrayBuffer(JSThread *thread, const JSHandle &newTarget, + double byteLength) { BUILTINS_API_TRACE(thread, ArrayBuffer, AllocateArrayBuffer); /** @@ -243,102 +243,102 @@ JSTaggedValue builtins::array_buffer::AllocateArrayBuffer(JSThread *thread, cons */ ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle arr_buf_func = env->GetArrayBufferFunction(); + JSHandle arrBufFunc = env->GetArrayBufferFunction(); JSHandle obj; - if (!new_target->IsBoundFunction()) { - obj = factory->NewJSObjectByConstructor(JSHandle(arr_buf_func), new_target); + if (!newTarget->IsBoundFunction()) { + obj = factory->NewJSObjectByConstructor(JSHandle(arrBufFunc), newTarget); // 2. ReturnIfAbrupt RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - 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)); + JSHandle prototypeKey = thread->GlobalConstants()->GetHandledPrototypeString(); + JSHandle constructTag(newTarget); + JSHandle constructProto = + JSTaggedValue::GetProperty(thread, constructTag, prototypeKey).GetValue(); + obj = JSObject::ObjectCreate(thread, JSHandle(constructProto)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 3. Assert: byteLength is a positive integer. - ASSERT(JSTaggedValue(byte_length).IsInteger()); - ASSERT(byte_length >= 0); + ASSERT(JSTaggedValue(byteLength).IsInteger()); + ASSERT(byteLength >= 0); // 4. Let block be CreateByteDataBlock(byteLength). - if (byte_length > INT_MAX) { + if (byteLength > INT_MAX) { THROW_RANGE_ERROR_AND_RETURN(thread, "Out of range", JSTaggedValue::Exception()); } - JSHandle array_buffer(obj); + JSHandle arrayBuffer(obj); // 6. Set obj’s [[ArrayBufferData]] internal slot to block. - factory->NewJSArrayBufferData(array_buffer, byte_length); + factory->NewJSArrayBufferData(arrayBuffer, byteLength); // 7. Set obj’s [[ArrayBufferByteLength]] internal slot to byteLength. - array_buffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byte_length))); + arrayBuffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byteLength))); // 8. Return obj. - return array_buffer.GetTaggedValue(); + return arrayBuffer.GetTaggedValue(); } // 24.1.1.2 IsDetachedBuffer() -bool builtins::array_buffer::IsDetachedBuffer(JSTaggedValue array_buffer) +bool builtins::array_buffer::IsDetachedBuffer(JSTaggedValue arrayBuffer) { // 1. Assert: Type(arrayBuffer) is Object and it has an [[ArrayBufferData]] internal slot. - ASSERT(array_buffer.IsArrayBuffer()); - JSArrayBuffer *buffer = JSArrayBuffer::Cast(array_buffer.GetTaggedObject()); - JSTaggedValue data_slot = buffer->GetArrayBufferData(); + ASSERT(arrayBuffer.IsArrayBuffer()); + JSArrayBuffer *buffer = JSArrayBuffer::Cast(arrayBuffer.GetTaggedObject()); + JSTaggedValue dataSlot = buffer->GetArrayBufferData(); // 2. If arrayBuffer’s [[ArrayBufferData]] internal slot is null, return true. // 3. Return false. - return data_slot == JSTaggedValue::Null(); + return dataSlot == JSTaggedValue::Null(); } // 24.1.1.4 -JSTaggedValue builtins::array_buffer::CloneArrayBuffer(JSThread *thread, const JSHandle &src_buffer, - int32_t src_byte_offset, JSHandle constructor) +JSTaggedValue builtins::array_buffer::CloneArrayBuffer(JSThread *thread, const JSHandle &srcBuffer, + int32_t srcByteOffset, JSHandle constructor) { BUILTINS_API_TRACE(thread, ArrayBuffer, CloneArrayBuffer); // 1. Assert: Type(srcBuffer) is Object and it has an [[ArrayBufferData]] internal slot. - ASSERT(src_buffer->IsArrayBuffer()); + ASSERT(srcBuffer->IsArrayBuffer()); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 2. If cloneConstructor is not present if (constructor->IsUndefined()) { // a. Let cloneConstructor be SpeciesConstructor(srcBuffer, %ArrayBuffer%). - JSHandle default_constructor = env->GetArrayBufferFunction(); - JSHandle obj_handle(src_buffer); - constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); + JSHandle defaultConstructor = env->GetArrayBufferFunction(); + JSHandle objHandle(srcBuffer); + constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); // b. ReturnIfAbrupt(cloneConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(src_buffer.GetTaggedValue())) { + if (IsDetachedBuffer(srcBuffer.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 arr_buf(src_buffer); - JSTaggedNumber length_number = JSTaggedNumber::FromIntOrDouble(thread, arr_buf->GetArrayBufferByteLength()); - int32_t src_len = length_number.ToInt32(); + JSHandle arrBuf(srcBuffer); + JSTaggedNumber lengthNumber = JSTaggedNumber::FromIntOrDouble(thread, arrBuf->GetArrayBufferByteLength()); + int32_t srcLen = lengthNumber.ToInt32(); // 5. Assert: srcByteOffset ≤ srcLength. - ASSERT(src_byte_offset <= src_len); + ASSERT(srcByteOffset <= srcLen); // 6. Let cloneLength be srcLength – srcByteOffset. - int32_t clone_len = src_len - src_byte_offset; + int32_t cloneLen = srcLen - srcByteOffset; // 8. Let targetBuffer be AllocateArrayBuffer(cloneConstructor, cloneLength). - JSTaggedValue tagged_buf = AllocateArrayBuffer(thread, constructor, clone_len); + JSTaggedValue taggedBuf = AllocateArrayBuffer(thread, constructor, cloneLen); // 9. ReturnIfAbrupt(targetBuffer). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(src_buffer.GetTaggedValue())) { + if (IsDetachedBuffer(srcBuffer.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 new_arr_buf(thread, tagged_buf); + JSHandle newArrBuf(thread, taggedBuf); // Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, cloneLength). // 7. Let srcBlock be the value of srcBuffer’s [[ArrayBufferData]] internal slot. - 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); + JSTaggedValue srcBlock = arrBuf->GetArrayBufferData(); + JSTaggedValue targetBlock = newArrBuf->GetArrayBufferData(); + if (cloneLen > 0) { + JSArrayBuffer::CopyDataBlockBytes(targetBlock, srcBlock, srcByteOffset, cloneLen); } - return tagged_buf; + return taggedBuf; } template // NOLINTNEXTLINE(readability-non-const-parameter) -JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byte_index, bool little_endian) +JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byteIndex, bool littleEndian) { static_assert(std::is_integral_v, "T must be integral"); static_assert(sizeof(T) == SIZE, "Invalid number size"); @@ -348,8 +348,8 @@ JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byte_index, b static_assert(SIZE >= NumberSize::UINT16 || SIZE <= NumberSize::FLOAT64); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - T res = UnalignedLoad(reinterpret_cast(block + byte_index)); - if (!little_endian) { + T res = UnalignedLoad(reinterpret_cast(block + byteIndex)); + if (!littleEndian) { res = BSWAP(res); } @@ -365,100 +365,96 @@ JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byte_index, b } template -JSTaggedValue GetValueFromBufferForBigInt(JSThread *thread, const uint8_t *block, uint32_t byte_index, - bool little_endian) +JSTaggedValue GetValueFromBufferForBigInt(JSThread *thread, const uint8_t *block, uint32_t byteIndex, bool littleEndian) { static_assert(std::is_same_v || std::is_same_v, "T must be uint64_t/int64_t"); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto p_tmp = UnalignedLoad(reinterpret_cast(block + byte_index)); - if (!little_endian) { - p_tmp = BSWAP(p_tmp); + auto pTmp = UnalignedLoad(reinterpret_cast(block + byteIndex)); + if (!littleEndian) { + pTmp = BSWAP(pTmp); } // NOLINTNEXTLINE(readability-braces-around-statements,bugprone-suspicious-semicolon) if constexpr (std::is_same_v) { - return BigInt::Uint64ToBigInt(thread, p_tmp).GetTaggedValue(); + return BigInt::Uint64ToBigInt(thread, pTmp).GetTaggedValue(); } - return BigInt::Int64ToBigInt(thread, p_tmp).GetTaggedValue(); + return BigInt::Int64ToBigInt(thread, pTmp).GetTaggedValue(); } template // NOLINTNEXTLINE(readability-non-const-parameter) -JSTaggedValue GetValueFromBufferForFloat(uint8_t *block, int32_t byte_index, bool little_endian) +JSTaggedValue GetValueFromBufferForFloat(uint8_t *block, int32_t byteIndex, bool littleEndian) { static_assert(std::is_same_v || std::is_same_v, "T must be float type"); static_assert(sizeof(T) == SIZE, "Invalid number size"); - UnionType union_value = {0}; + UnionType unionValue = {0}; // NOLINTNEXTLINE(readability-braces-around-statements) if constexpr (std::is_same_v) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic) - union_value.u_value = UnalignedLoad(reinterpret_cast(block + byte_index)); + unionValue.uValue = UnalignedLoad(reinterpret_cast(block + byteIndex)); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - if (std::isnan(union_value.value)) { + if (std::isnan(unionValue.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return builtins_common::GetTaggedDouble(union_value.value); + return builtins_common::GetTaggedDouble(unionValue.value); } - if (!little_endian) { + if (!littleEndian) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return builtins_common::GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); + return builtins_common::GetTaggedDouble(bit_cast(BSWAP(unionValue.uValue))); } // NOLINTNEXTLINE(readability-misleading-indentation) } else if constexpr (std::is_same_v) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic) - union_value.u_value = UnalignedLoad(reinterpret_cast(block + byte_index)); + unionValue.uValue = UnalignedLoad(reinterpret_cast(block + byteIndex)); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - if (std::isnan(union_value.value) && !JSTaggedValue::IsImpureNaN(union_value.value)) { + if (std::isnan(unionValue.value) && !JSTaggedValue::IsImpureNaN(unionValue.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return builtins_common::GetTaggedDouble(union_value.value); + return builtins_common::GetTaggedDouble(unionValue.value); } - if (!little_endian) { + if (!littleEndian) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return builtins_common::GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); + return builtins_common::GetTaggedDouble(bit_cast(BSWAP(unionValue.uValue))); } } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return builtins_common::GetTaggedDouble(union_value.value); + return builtins_common::GetTaggedDouble(unionValue.value); } // 24.1.1.5 // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue builtins::array_buffer::GetValueFromBuffer(JSThread *thread, JSHandle arr_buf, - int32_t byte_index, DataViewType type, bool little_endian) +JSTaggedValue builtins::array_buffer::GetValueFromBuffer(JSThread *thread, JSHandle arrBuf, + int32_t byteIndex, DataViewType type, bool littleEndian) { - JSArrayBuffer *js_array_buffer = JSArrayBuffer::Cast(arr_buf->GetTaggedObject()); - JSTaggedValue data = js_array_buffer->GetArrayBufferData(); + JSArrayBuffer *jsArrayBuffer = JSArrayBuffer::Cast(arrBuf->GetTaggedObject()); + JSTaggedValue data = jsArrayBuffer->GetArrayBufferData(); void *pointer = JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer(); auto *block = reinterpret_cast(pointer); switch (type) { case DataViewType::UINT8: case DataViewType::UINT8_CLAMPED: { - uint8_t res = block[byte_index]; // NOLINT + uint8_t res = block[byteIndex]; // NOLINT return builtins_common::GetTaggedInt(res); } case DataViewType::INT8: { - uint8_t res = block[byte_index]; // NOLINT - auto int8_res = static_cast(res); - return builtins_common::GetTaggedInt(int8_res); + uint8_t res = block[byteIndex]; // NOLINT + auto int8Res = static_cast(res); + return builtins_common::GetTaggedInt(int8Res); } case DataViewType::UINT16: - return GetValueFromBufferForInteger(block, byte_index, little_endian); + return GetValueFromBufferForInteger(block, byteIndex, littleEndian); case DataViewType::INT16: - return GetValueFromBufferForInteger(block, byte_index, little_endian); + return GetValueFromBufferForInteger(block, byteIndex, littleEndian); case DataViewType::UINT32: - return GetValueFromBufferForInteger(block, byte_index, little_endian); + return GetValueFromBufferForInteger(block, byteIndex, littleEndian); case DataViewType::INT32: - return GetValueFromBufferForInteger(block, byte_index, little_endian); + return GetValueFromBufferForInteger(block, byteIndex, littleEndian); case DataViewType::FLOAT32: - return GetValueFromBufferForFloat(block, byte_index, - little_endian); + return GetValueFromBufferForFloat(block, byteIndex, littleEndian); case DataViewType::FLOAT64: - return GetValueFromBufferForFloat(block, byte_index, - little_endian); + return GetValueFromBufferForFloat(block, byteIndex, littleEndian); case DataViewType::BIGINT64: - return GetValueFromBufferForBigInt(thread, block, byte_index, little_endian); + return GetValueFromBufferForBigInt(thread, block, byteIndex, littleEndian); case DataViewType::BIGUINT64: - return GetValueFromBufferForBigInt(thread, block, byte_index, - little_endian); + return GetValueFromBufferForBigInt(thread, block, byteIndex, littleEndian); default: break; } @@ -469,79 +465,79 @@ JSTaggedValue builtins::array_buffer::GetValueFromBuffer(JSThread *thread, JSHan template void SetTypeData(uint8_t *block, T value, int32_t index) { - int32_t size_count = sizeof(T); + int32_t sizeCount = sizeof(T); auto *res = reinterpret_cast(&value); - for (int i = 0; i < size_count; i++) { + for (int i = 0; i < sizeCount; i++) { *(block + index + i) = *(res + i); // NOLINT } } template -void SetValueInBufferForByte(double val, uint8_t *block, int32_t byte_index) +void SetValueInBufferForByte(double val, uint8_t *block, int32_t byteIndex) { 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, byte_index); + SetTypeData(block, res, byteIndex); return; } - auto int64_val = static_cast(val); - res = UnalignedLoad(reinterpret_cast(&int64_val)); - SetTypeData(block, res, byte_index); + auto int64Val = static_cast(val); + res = UnalignedLoad(reinterpret_cast(&int64Val)); + SetTypeData(block, res, byteIndex); } -void SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byte_index) +void SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byteIndex) { uint8_t res; if (std::isnan(val) || val <= 0) { res = 0; - SetTypeData(block, res, byte_index); + SetTypeData(block, res, byteIndex); 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, byte_index); + SetTypeData(block, res, byteIndex); } template -void SetValueInBufferForInteger(double val, uint8_t *block, int32_t byte_index, bool little_endian) +void SetValueInBufferForInteger(double val, uint8_t *block, int32_t byteIndex, bool littleEndian) { 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, byte_index); + SetTypeData(block, res, byteIndex); return; } - auto int64_val = static_cast(val); + auto int64Val = static_cast(val); // NOLINTNEXTLINE(readability-braces-around-statements) if constexpr (std::is_same_v) { - auto tmp = UnalignedLoad(reinterpret_cast(&int64_val)); + auto tmp = UnalignedLoad(reinterpret_cast(&int64Val)); res = static_cast(tmp); } else { // NOLINTNEXTLINE(readability-braces-around-statements) - res = UnalignedLoad(reinterpret_cast(&int64_val)); + res = UnalignedLoad(reinterpret_cast(&int64Val)); } - if (!little_endian) { + if (!littleEndian) { res = BSWAP(res); } - SetTypeData(block, res, byte_index); + SetTypeData(block, res, byteIndex); } template -void SetValueInBufferForFloat(double val, uint8_t *block, int32_t byte_index, bool little_endian) +void SetValueInBufferForFloat(double val, uint8_t *block, int32_t byteIndex, bool littleEndian) { 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, byte_index); + SetTypeData(block, data, byteIndex); return; } - if (!little_endian) { + if (!littleEndian) { // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (std::is_same_v) { data = bit_cast(BSWAP(bit_cast(data))); @@ -551,12 +547,12 @@ void SetValueInBufferForFloat(double val, uint8_t *block, int32_t byte_index, bo data = bit_cast(BSWAP(bit_cast(data))); } } - SetTypeData(block, data, byte_index); + SetTypeData(block, data, byteIndex); } template -void SetValueInBufferForBigInt(JSThread *thread, const JSHandle &val, uint8_t *block, - uint32_t byte_index, bool little_endian) +void SetValueInBufferForBigInt(JSThread *thread, const JSHandle &val, uint8_t *block, uint32_t byteIndex, + bool littleEndian) { static_assert(std::is_same_v || std::is_same_v, "T must be int64_t/uint64_t"); T value = 0; @@ -569,10 +565,10 @@ void SetValueInBufferForBigInt(JSThread *thread, const JSHandle & BigInt::BigIntToInt64(thread, val, reinterpret_cast(&value), &lossless); } RETURN_IF_ABRUPT_COMPLETION(thread); - if (!little_endian) { + if (!littleEndian) { value = BSWAP(value); } - SetTypeData(block, value, byte_index); + SetTypeData(block, value, byteIndex); } // es12 25.1.2.7 IsBigIntElementType ( type ) @@ -582,23 +578,23 @@ bool IsBigIntElementType(DataViewType type) } // 24.1.1.6 -JSTaggedValue builtins::array_buffer::SetValueInBuffer(JSThread *thread, JSHandle arr_buf, - int32_t byte_index, DataViewType type, - const JSHandle &value, bool little_endian) +JSTaggedValue builtins::array_buffer::SetValueInBuffer(JSThread *thread, JSHandle arrBuf, + int32_t byteIndex, DataViewType type, + const JSHandle &value, bool littleEndian) { - JSArrayBuffer *js_array_buffer = JSArrayBuffer::Cast(arr_buf->GetTaggedObject()); - JSTaggedValue data = js_array_buffer->GetArrayBufferData(); + JSArrayBuffer *jsArrayBuffer = JSArrayBuffer::Cast(arrBuf->GetTaggedObject()); + JSTaggedValue data = jsArrayBuffer->GetArrayBufferData(); void *pointer = JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer(); auto *block = reinterpret_cast(pointer); if (IsBigIntElementType(type)) { switch (type) { case DataViewType::BIGINT64: - SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); + SetValueInBufferForBigInt(thread, value, block, byteIndex, littleEndian); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); break; case DataViewType::BIGUINT64: - SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); + SetValueInBufferForBigInt(thread, value, block, byteIndex, littleEndian); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); break; default: @@ -611,31 +607,31 @@ JSTaggedValue builtins::array_buffer::SetValueInBuffer(JSThread *thread, JSHandl switch (type) { case DataViewType::UINT8: - SetValueInBufferForByte(val, block, byte_index); + SetValueInBufferForByte(val, block, byteIndex); break; case DataViewType::UINT8_CLAMPED: - SetValueInBufferForUint8Clamped(val, block, byte_index); + SetValueInBufferForUint8Clamped(val, block, byteIndex); break; case DataViewType::INT8: - SetValueInBufferForByte(val, block, byte_index); + SetValueInBufferForByte(val, block, byteIndex); break; case DataViewType::UINT16: - SetValueInBufferForInteger(val, block, byte_index, little_endian); + SetValueInBufferForInteger(val, block, byteIndex, littleEndian); break; case DataViewType::INT16: - SetValueInBufferForInteger(val, block, byte_index, little_endian); + SetValueInBufferForInteger(val, block, byteIndex, littleEndian); break; case DataViewType::UINT32: - SetValueInBufferForInteger(val, block, byte_index, little_endian); + SetValueInBufferForInteger(val, block, byteIndex, littleEndian); break; case DataViewType::INT32: - SetValueInBufferForInteger(val, block, byte_index, little_endian); + SetValueInBufferForInteger(val, block, byteIndex, littleEndian); break; case DataViewType::FLOAT32: - SetValueInBufferForFloat(val, block, byte_index, little_endian); + SetValueInBufferForFloat(val, block, byteIndex, littleEndian); break; case DataViewType::FLOAT64: - SetValueInBufferForFloat(val, block, byte_index, little_endian); + SetValueInBufferForFloat(val, block, byteIndex, littleEndian); break; default: UNREACHABLE(); diff --git a/runtime/builtins/builtins_async_from_sync_iterator.cpp b/runtime/builtins/builtins_async_from_sync_iterator.cpp index ab63e56c65487da6a603b54e163ba9c99b1263dc..6dba349c97eec074b319d546d59fb32f51c1d483 100644 --- a/runtime/builtins/builtins_async_from_sync_iterator.cpp +++ b/runtime/builtins/builtins_async_from_sync_iterator.cpp @@ -19,20 +19,20 @@ JSTaggedValue builtins::async_from_sync_iterator::proto::Next(EcmaRuntimeCallInf JSThread *thread = argv->GetThread(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_object = builtins_common::GetThis(argv); + JSHandle thisObject = builtins_common::GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. - JSHandle async_from_sync_iterator_object( - thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); + JSHandle asyncFromSyncIteratorObject( + thread, JSAsyncFromSyncIteratorObject::Cast(thisObject->GetHeapObject())); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. - JSHandle iterator(thread, async_from_sync_iterator_object->GetIterator()); - JSHandle next_method(thread, async_from_sync_iterator_object->GetNextMethod()); + JSHandle iterator(thread, asyncFromSyncIteratorObject->GetIterator()); + JSHandle nextMethod(thread, asyncFromSyncIteratorObject->GetNextMethod()); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - JSHandle promise_capability = + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -41,21 +41,21 @@ JSTaggedValue builtins::async_from_sync_iterator::proto::Next(EcmaRuntimeCallInf // 5. If value is present, then if (argv->GetArgsNumber() > 0) { // a. Let result be IteratorNext(syncIteratorRecord, value). - result.Update(JSIterator::IteratorNext(thread, iterator, next_method, builtins_common::GetCallArg(argv, 0))); + result.Update(JSIterator::IteratorNext(thread, iterator, nextMethod, builtins_common::GetCallArg(argv, 0))); } else { // 6. Else, // a. Let result be IteratorNext(syncIteratorRecord). - result.Update(JSIterator::IteratorNext(thread, iterator, next_method)); + result.Update(JSIterator::IteratorNext(thread, iterator, nextMethod)); } // 7. IfAbruptRejectPromise(result, promiseCapability). if (UNLIKELY(thread->HasPendingException())) { result.Update(JSPromise::IfThrowGetThrowValue(thread)); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); // 8. Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). - return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promise_capability); + return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promiseCapability); } // 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.return(value) @@ -65,60 +65,60 @@ JSTaggedValue builtins::async_from_sync_iterator::proto::Return(EcmaRuntimeCallI JSThread *thread = argv->GetThread(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_constants = thread->GlobalConstants(); + const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_object = builtins_common::GetThis(argv); + JSHandle thisObject = builtins_common::GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. - JSHandle async_from_sync_iterator_object( - thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); + JSHandle asyncFromSyncIteratorObject( + thread, JSAsyncFromSyncIteratorObject::Cast(thisObject->GetHeapObject())); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - JSHandle promise_capability = + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. - JSHandle iterator(thread, async_from_sync_iterator_object->GetIterator()); + JSHandle iterator(thread, asyncFromSyncIteratorObject->GetIterator()); // 5. Let return be GetMethod(syncIterator, "return"). - JSHandle return_key = global_constants->GetHandledReturnString(); - JSHandle return_method = JSObject::GetMethod(thread, iterator, return_key); + JSHandle returnKey = globalConstants->GetHandledReturnString(); + JSHandle returnMethod = JSObject::GetMethod(thread, iterator, returnKey); // 6. IfAbruptRejectPromise(return, promiseCapability). - RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, return_method, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, returnMethod, promiseCapability); // 7. If return is undefined, then - if (return_method->IsUndefined()) { + if (returnMethod->IsUndefined()) { // a. Let iterResult be ! CreateIterResultObject(value, true). - JSHandle iter_result = + JSHandle iterResult = JSIterator::CreateIterResultObject(thread, builtins_common::GetCallArg(argv, 0), true); // b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »). - JSHandle resolve(thread, promise_capability->GetResolve()); + JSHandle resolve(thread, promiseCapability->GetResolve()); auto info = NewRuntimeCallInfo(thread, resolve, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(iter_result); + info->SetCallArgs(iterResult); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); // c. Return promiseCapability.[[Promise]]. - return promise_capability->GetPromise(); + return promiseCapability->GetPromise(); } - JSMutableHandle result(thread, global_constants->GetHandledUndefined()); + JSMutableHandle result(thread, globalConstants->GetHandledUndefined()); { ScopedCallInfo info; // 8. If value is present, then if (argv->GetArgsNumber() > 0) { // a. Let result be Call(return, syncIterator, « value »). - info = NewRuntimeCallInfo(thread, return_method, iterator, JSTaggedValue::Undefined(), 1); + info = NewRuntimeCallInfo(thread, returnMethod, iterator, JSTaggedValue::Undefined(), 1); info->SetCallArgs(builtins_common::GetCallArg(argv, 0)); } else { // 9. Else, // a. Let result be Call(return, syncIterator). - info = NewRuntimeCallInfo(thread, return_method, iterator, JSTaggedValue::Undefined(), 0); + info = NewRuntimeCallInfo(thread, returnMethod, iterator, JSTaggedValue::Undefined(), 0); } result.Update(JSFunction::Call(info.Get())); } @@ -127,25 +127,25 @@ JSTaggedValue builtins::async_from_sync_iterator::proto::Return(EcmaRuntimeCallI if (UNLIKELY(thread->HasPendingException())) { result.Update(JSPromise::IfThrowGetThrowValue(thread)); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); // 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 type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "Return is not an object"); - JSHandle reject(thread, promise_capability->GetReject()); + JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "Return is not an object"); + JSHandle reject(thread, promiseCapability->GetReject()); auto info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(type_error); + info->SetCallArgs(typeError); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); // b. Return promiseCapability.[[Promise]]. - return promise_capability->GetPromise(); + return promiseCapability->GetPromise(); } // 12. Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). - return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promise_capability); + return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promiseCapability); } // 27.1.4.2.4 %AsyncFromSyncIteratorPrototype%.throw(exception) @@ -156,35 +156,35 @@ JSTaggedValue builtins::async_from_sync_iterator::proto::Throw(EcmaRuntimeCallIn JSThread *thread = argv->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_constants = thread->GlobalConstants(); + const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_object = builtins_common::GetThis(argv); + JSHandle thisObject = builtins_common::GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. - JSHandle async_from_sync_iterator_object( - thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); + JSHandle asyncFromSyncIteratorObject( + thread, JSAsyncFromSyncIteratorObject::Cast(thisObject->GetHeapObject())); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - JSHandle promise_capability = + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. - JSHandle iterator(thread, async_from_sync_iterator_object->GetIterator()); + JSHandle iterator(thread, asyncFromSyncIteratorObject->GetIterator()); // 5. Let return be GetMethod(syncIterator, "throw"). - JSHandle throw_key = global_constants->GetHandledThrowString(); - JSHandle throw_method = JSObject::GetMethod(thread, iterator, throw_key); + JSHandle throwKey = globalConstants->GetHandledThrowString(); + JSHandle throwMethod = JSObject::GetMethod(thread, iterator, throwKey); // 6. IfAbruptRejectPromise(return, promiseCapability). - RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, throw_method, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, throwMethod, promiseCapability); // 7. If throw is undefined, then - if (throw_method->IsUndefined()) { + if (throwMethod->IsUndefined()) { // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »). - JSHandle reject(thread, promise_capability->GetReject()); + JSHandle reject(thread, promiseCapability->GetReject()); ScopedCallInfo info; if (argv->GetArgsNumber() > 0) { info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); @@ -192,25 +192,25 @@ JSTaggedValue builtins::async_from_sync_iterator::proto::Throw(EcmaRuntimeCallIn } else { info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 0); } - [[maybe_unused]] JSTaggedValue call_result = JSFunction::Call(info.Get()); + [[maybe_unused]] JSTaggedValue callResult = JSFunction::Call(info.Get()); // b. Return promiseCapability.[[Promise]]. - return promise_capability->GetPromise(); + return promiseCapability->GetPromise(); } - JSMutableHandle result(thread, global_constants->GetHandledUndefined()); + JSMutableHandle result(thread, globalConstants->GetHandledUndefined()); { ScopedCallInfo info; // 8. If value is present, then if (argv->GetArgsNumber() > 0) { // a. Let result be Call(throw, syncIterator, « value »). - info = NewRuntimeCallInfo(thread, throw_method, iterator, JSTaggedValue::Undefined(), 1); + info = NewRuntimeCallInfo(thread, throwMethod, iterator, JSTaggedValue::Undefined(), 1); info->SetCallArgs(builtins_common::GetCallArg(argv, 0)); } else { // 9. Else, // a. Let result be Call(throw, syncIterator). - info = NewRuntimeCallInfo(thread, throw_method, iterator, JSTaggedValue::Undefined(), 0); + info = NewRuntimeCallInfo(thread, throwMethod, iterator, JSTaggedValue::Undefined(), 0); } result.Update(JSFunction::Call(info.Get())); } @@ -219,21 +219,21 @@ JSTaggedValue builtins::async_from_sync_iterator::proto::Throw(EcmaRuntimeCallIn if (UNLIKELY(thread->HasPendingException())) { result.Update(JSPromise::IfThrowGetThrowValue(thread)); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); // 11. If Type(result) is not Object, then if (!result->IsECMAObject()) { // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).. - JSHandle type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "Throw is not an object"); - JSHandle reject(thread, promise_capability->GetReject()); + JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "Throw is not an object"); + JSHandle reject(thread, promiseCapability->GetReject()); auto info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(type_error); - [[maybe_unused]] JSTaggedValue call_result = JSFunction::Call(info.Get()); + info->SetCallArgs(typeError); + [[maybe_unused]] JSTaggedValue callResult = JSFunction::Call(info.Get()); // b. Return promiseCapability.[[Promise]]. - return promise_capability->GetPromise(); + return promiseCapability->GetPromise(); } // 12. Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). - return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promise_capability); + return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promiseCapability); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_async_generator.cpp b/runtime/builtins/builtins_async_generator.cpp index c4372adf4c9f4d14c0a11d0d1994f9119d281d78..a87ddcce596c040c1a09f15daa9c6961bbba1ffc 100644 --- a/runtime/builtins/builtins_async_generator.cpp +++ b/runtime/builtins/builtins_async_generator.cpp @@ -21,17 +21,16 @@ JSTaggedValue async_generator::proto::Next(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), AsyncGeneratorPrototype, Next); // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle generator = builtins_common::GetThis(argv); // 2. Let completion be NormalCompletion(value). JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::NORMAL, value); + JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::NORMAL, value); // 3. Return ! AsyncGeneratorEnqueue(generator, completion, empty). - JSHandle result = - JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completion_record); + JSHandle result = JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completionRecord); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -42,17 +41,16 @@ JSTaggedValue async_generator::proto::Return(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), AsyncGeneratorPrototype, Return); // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle generator = builtins_common::GetThis(argv); // 2. Let completion be Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }. JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::RETURN, value); + JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::RETURN, value); // 3. Return ! AsyncGeneratorEnqueue(generator, completion, empty). - JSHandle result = - JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completion_record); + JSHandle result = JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completionRecord); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -64,17 +62,16 @@ JSTaggedValue async_generator::proto::Throw(EcmaRuntimeCallInfo *argv) // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle generator = builtins_common::GetThis(argv); // 2. Let completion be ThrowCompletion(exception). JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::THROW, value); + JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::THROW, value); // 3. Return ! AsyncGeneratorEnqueue(generator, completion, empty). - JSHandle result = - JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completion_record); + JSHandle result = JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completionRecord); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_bigint.cpp b/runtime/builtins/builtins_bigint.cpp index d353e7cb12abc7bcab56527715add360b404ffa0..465edc4b363ed34db114ab7d6a4111a3b15fb26e 100644 --- a/runtime/builtins/builtins_bigint.cpp +++ b/runtime/builtins/builtins_bigint.cpp @@ -51,11 +51,11 @@ JSTaggedValue big_int::BigIntConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, BigIntConstructor); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = builtins_common::GetNewTarget(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle newTarget = builtins_common::GetNewTarget(argv); // 1. If NewTarget is not undefined, throw a TypeError exception. JSHandle value = builtins_common::GetCallArg(argv, 0); - if (!new_target->IsUndefined()) { + if (!newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "BigInt is not a constructor", JSTaggedValue::Exception()); } // 2. Let prim be ? ToPrimitive(value). @@ -73,17 +73,17 @@ JSTaggedValue big_int::AsUintN(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, AsUintN); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle bits = builtins_common::GetCallArg(argv, 0); JSHandle bigint = builtins_common::GetCallArg(argv, 1); // 1. Let bits be ? ToIndex(bits). JSTaggedNumber index = JSTaggedValue::ToIndex(thread, bits); // 2. Let bigint be ? ToBigInt(bigint). - JSTaggedValue js_bigint = JSTaggedValue::ToBigInt(thread, bigint); + JSTaggedValue jsBigint = JSTaggedValue::ToBigInt(thread, bigint); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle js_bigint_val(thread, js_bigint); + JSHandle jsBigintVal(thread, jsBigint); // 3. Return a BigInt representing bigint modulo 2bits. - return BigInt::AsUintN(thread, index, js_bigint_val); + return BigInt::AsUintN(thread, index, jsBigintVal); } JSTaggedValue big_int::AsIntN(EcmaRuntimeCallInfo *argv) @@ -91,18 +91,18 @@ JSTaggedValue big_int::AsIntN(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, AsIntN); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle bits = builtins_common::GetCallArg(argv, 0); JSHandle bigint = builtins_common::GetCallArg(argv, 1); // 1. Let bits be ? ToIndex(bits). JSTaggedNumber index = JSTaggedValue::ToIndex(thread, bits); // 2. Let bigint be ? ToBigInt(bigint). - JSTaggedValue js_bigint = JSTaggedValue::ToBigInt(thread, bigint); + JSTaggedValue jsBigint = JSTaggedValue::ToBigInt(thread, bigint); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle js_bigint_val(thread, js_bigint); + JSHandle jsBigintVal(thread, jsBigint); // 3. Let mod be ℝ(bigint) modulo 2bits. // 4. If mod ≥ 2bits - 1, return ℤ(mod - 2bits); otherwise, return ℤ(mod). - return BigInt::AsintN(thread, index, js_bigint_val); + return BigInt::AsintN(thread, index, jsBigintVal); } JSTaggedValue big_int::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) @@ -110,24 +110,24 @@ JSTaggedValue big_int::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigIntPrototype, ToLocaleString); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let x be ? ThisBigIntValue(this value). JSTaggedValue value = ThisBigIntValue(argv); - JSHandle this_val(thread, value); + JSHandle thisVal(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 number_format = JSHandle::Cast(obj); + JSHandle numberFormat = JSHandle::Cast(obj); JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); + JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatNumeric(numberFormat, x). - JSHandle result = JSNumberFormat::FormatNumeric(thread, number_format, this_val.GetTaggedValue()); + JSHandle result = JSNumberFormat::FormatNumeric(thread, numberFormat, thisVal.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -137,20 +137,20 @@ JSTaggedValue big_int::proto::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigIntPrototype, ToString); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let x be ? thisBigIntValue(this value). JSTaggedValue value = ThisBigIntValue(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_bigint(thread, value); + JSHandle thisBigint(thread, value); // 2. If radix is not present, let radixNumber be 10 double radix = base::DECIMAL; - JSHandle radix_value = builtins_common::GetCallArg(argv, 0); + JSHandle radixValue = builtins_common::GetCallArg(argv, 0); // 3. Else, let radixNumber be ? ToIntegerOrInfinity(radix). - if (!radix_value->IsUndefined()) { - JSTaggedNumber radix_number = JSTaggedValue::ToInteger(thread, radix_value); + if (!radixValue->IsUndefined()) { + JSTaggedNumber radixNumber = JSTaggedValue::ToInteger(thread, radixValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - radix = radix_number.GetNumber(); + radix = radixNumber.GetNumber(); } // 4. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception. if (radix < base::MIN_RADIX || radix > base::MAX_RADIX) { @@ -159,10 +159,10 @@ JSTaggedValue big_int::proto::ToString(EcmaRuntimeCallInfo *argv) } // 5. If radixNumber = 10, return ToString(x). if (radix == base::DECIMAL) { - return BigInt::ToString(thread, this_bigint).GetTaggedValue(); + return BigInt::ToString(thread, thisBigint).GetTaggedValue(); } // 6. Return the String representation of this BigInt value using the radix specified by radixNumber - return BigInt::ToString(thread, this_bigint, static_cast(radix)).GetTaggedValue(); + return BigInt::ToString(thread, thisBigint, static_cast(radix)).GetTaggedValue(); } JSTaggedValue big_int::proto::ValueOf(EcmaRuntimeCallInfo *argv) @@ -170,7 +170,7 @@ JSTaggedValue big_int::proto::ValueOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigIntPrototype, ValueOf); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(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 878f9771c18c303b417a1a222f3e7721328e0e3e..687e799e4c0894a33c5c10db8c610edd0ac9c09c 100644 --- a/runtime/builtins/builtins_boolean.cpp +++ b/runtime/builtins/builtins_boolean.cpp @@ -26,21 +26,21 @@ JSTaggedValue boolean::BooleanConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Boolean, BooleanConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let b be ToBoolean(value). - bool bool_value = builtins_common::GetCallArg(argv, 0)->ToBoolean(); + bool boolValue = builtins_common::GetCallArg(argv, 0)->ToBoolean(); // 2. If NewTarget is undefined, return b. - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { - return builtins_common::GetTaggedBoolean(bool_value); + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { + return builtins_common::GetTaggedBoolean(boolValue); } // 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(builtins_common::GetConstructor(argv)); - JSHandle result = factory->NewJSObjectByConstructor(ctor, new_target); - JSTaggedValue obj_value = bool_value ? JSTaggedValue::True() : JSTaggedValue::False(); - JSPrimitiveRef::Cast(*result)->SetValue(thread, obj_value); + JSHandle result = factory->NewJSObjectByConstructor(ctor, newTarget); + JSTaggedValue objValue = boolValue ? JSTaggedValue::True() : JSTaggedValue::False(); + JSPrimitiveRef::Cast(*result)->SetValue(thread, objValue); // 4. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Return O. @@ -66,7 +66,7 @@ static JSTaggedValue ThisBooleanValue(JSThread *thread, JSTaggedValue value) : builtins_common::GetTaggedBoolean(false); } } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 3. Throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "the type can not convert to BooleanValue", JSTaggedValue::Exception()); } @@ -76,15 +76,15 @@ JSTaggedValue boolean::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let b be thisBooleanValue(this value). - JSTaggedValue this_value_to_boolean = ThisBooleanValue(thread, builtins_common::GetThis(argv).GetTaggedValue()); + JSTaggedValue thisValueToBoolean = ThisBooleanValue(thread, builtins_common::GetThis(argv).GetTaggedValue()); // 2. ReturnIfAbrupt(b) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If b is true, return "true"; else return "false". - return this_value_to_boolean.IsTrue() ? builtins_common::GetTaggedString(thread, "true") - : builtins_common::GetTaggedString(thread, "false"); + return thisValueToBoolean.IsTrue() ? builtins_common::GetTaggedString(thread, "true") + : builtins_common::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 9d8c0c5cbb7f29df0b977f45ed659a2d345cc9c0..978e8b68ef34bd337f0e3cababef564ca7b3b781 100644 --- a/runtime/builtins/builtins_collator.cpp +++ b/runtime/builtins/builtins_collator.cpp @@ -27,14 +27,14 @@ JSTaggedValue collator::CollatorConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { - new_target = constructor; + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { + newTarget = constructor; } // 2. Let internalSlotsList be « [[InitializedCollator]], [[Locale]], [[Usage]], [[Sensitivity]], // [[IgnorePunctuation]], [[Collation]], [[BoundCompare]] ». @@ -45,7 +45,7 @@ JSTaggedValue collator::CollatorConstructor(EcmaRuntimeCallInfo *argv) // 5. Let collator be ? OrdinaryCreateFromConstructor(new_target, "%CollatorPrototype%", internalSlotsList). JSHandle collator = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Return ? InitializeCollator(collator, locales, options). @@ -62,16 +62,16 @@ JSTaggedValue collator::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %Collator%.[[AvailableLocales]]. - JSHandle available_locales = JSCollator::GetAvailableLocales(thread); + JSHandle availableLocales = JSCollator::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = builtins_common::GetCallArg(argv, 0); - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); + JSHandle result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -83,11 +83,11 @@ static JSTaggedValue 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 intl_bound_func = + JSHandle intlBoundFunc = JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let collator be F.[[Collator]]. - JSHandle collator(thread, intl_bound_func->GetCollator()); + JSHandle collator(thread, intlBoundFunc->GetCollator()); // 2. Assert: Type(collator) is Object and collator has an [[InitializedCollator]] internal slot. ASSERT_PRINT(collator->IsJSObject() && collator->IsJSCollator(), "collator is not object or JSCollator"); @@ -99,14 +99,14 @@ static JSTaggedValue AnonymousCollator(EcmaRuntimeCallInfo *argv) JSHandle y = builtins_common::GetCallArg(argv, 1); // 5. Let X be ? ToString(x). - JSHandle x_value = JSTaggedValue::ToString(thread, x); + JSHandle xValue = JSTaggedValue::ToString(thread, x); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); // 6. Let Y be ? ToString(y). - JSHandle y_value = JSTaggedValue::ToString(thread, y); + JSHandle yValue = JSTaggedValue::ToString(thread, y); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); // 7. Return CompareStrings(collator, X, Y). - icu::Collator *icu_collator = (JSHandle::Cast(collator))->GetIcuCollator(); - return JSCollator::CompareStrings(icu_collator, x_value, y_value); + icu::Collator *icuCollator = (JSHandle::Cast(collator))->GetIcuCollator(); + return JSCollator::CompareStrings(icuCollator, xValue, yValue); } // 11.3.3 get Intl.Collator.prototype.compare @@ -115,10 +115,10 @@ JSTaggedValue collator::proto::GetCompare(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let collator be this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]). - if (!this_value->IsJSCollator()) { + if (!thisValue->IsJSCollator()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not collator", JSTaggedValue::Exception()); } // 3. If collator.[[BoundCompare]] is undefined, then @@ -126,14 +126,14 @@ JSTaggedValue collator::proto::GetCompare(EcmaRuntimeCallInfo *argv) // b. Set F.[[Collator]] to collator. // c. Set collator.[[BoundCompare]] to F. // 4. Return collator.[[BoundCompare]]. - JSHandle collator = JSHandle::Cast(this_value); - JSHandle bound_compare(thread, collator->GetBoundCompare()); - if (bound_compare->IsUndefined()) { + JSHandle collator = JSHandle::Cast(thisValue); + JSHandle boundCompare(thread, collator->GetBoundCompare()); + if (boundCompare->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intl_bound_func = + JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction(reinterpret_cast(AnonymousCollator), FUNCTION_LENGTH_TWO); - intl_bound_func->SetCollator(thread, collator); - collator->SetBoundCompare(thread, intl_bound_func); + intlBoundFunc->SetCollator(thread, collator); + collator->SetBoundCompare(thread, intlBoundFunc); } return collator->GetBoundCompare(); } @@ -143,11 +143,11 @@ JSTaggedValue collator::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle this_value = builtins_common::GetThis(argv); - if (!this_value->IsJSCollator()) { + JSHandle thisValue = builtins_common::GetThis(argv); + if (!thisValue->IsJSCollator()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Collator object", JSTaggedValue::Exception()); } - JSHandle options = JSCollator::ResolvedOptions(thread, JSHandle::Cast(this_value)); + JSHandle options = JSCollator::ResolvedOptions(thread, JSHandle::Cast(thisValue)); return options.GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_dataview.cpp b/runtime/builtins/builtins_dataview.cpp index 044fd21bd9d420c705eba5f3901436c4be9e0862..5472335c99a8a7c7495c34e2b8d4b4dd1afe1463 100644 --- a/runtime/builtins/builtins_dataview.cpp +++ b/runtime/builtins/builtins_dataview.cpp @@ -29,77 +29,77 @@ JSTaggedValue data_view::DataViewConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, DataViewConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle ctor = builtins_common::GetConstructor(argv); - JSHandle new_target = builtins_common::GetNewTarget(argv); + JSHandle newTarget = builtins_common::GetNewTarget(argv); // 1. If NewTarget is undefined, throw a TypeError exception. - if (new_target->IsUndefined()) { + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "newtarget is undefined", JSTaggedValue::Exception()); } - JSHandle buffer_handle = builtins_common::GetCallArg(argv, 0); + JSHandle bufferHandle = builtins_common::GetCallArg(argv, 0); // 2. If Type(buffer) is not Object, throw a TypeError exception. - if (!buffer_handle->IsECMAObject()) { + if (!bufferHandle->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 (!buffer_handle->IsArrayBuffer()) { + if (!bufferHandle->IsArrayBuffer()) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not ArrayBuffer", JSTaggedValue::Exception()); } - JSHandle offset_handle = builtins_common::GetCallArg(argv, 1); + JSHandle offsetHandle = builtins_common::GetCallArg(argv, 1); // 4. Let numberOffset be ToNumber(byteOffset). - JSTaggedNumber offset_number = JSTaggedValue::ToNumber(thread, offset_handle); + JSTaggedNumber offsetNumber = JSTaggedValue::ToNumber(thread, offsetHandle); // 6. ReturnIfAbrupt(offset). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t offset = ecmascript::base::NumberHelper::DoubleInRangeInt32(offset_number.GetNumber()); + int32_t offset = ecmascript::base::NumberHelper::DoubleInRangeInt32(offsetNumber.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 (builtins::array_buffer::IsDetachedBuffer(buffer_handle.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(bufferHandle.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 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(); + JSHandle arrBufHandle(bufferHandle); + JSTaggedNumber bufLenNum = JSTaggedNumber::FromIntOrDouble(thread, arrBufHandle->GetArrayBufferByteLength()); + int32_t bufByteLen = bufLenNum.ToInt32(); // 10. If offset > bufferByteLength, throw a RangeError exception. - if (offset > buf_byte_len) { + if (offset > bufByteLen) { THROW_RANGE_ERROR_AND_RETURN(thread, "offset > bufferByteLength", JSTaggedValue::Exception()); } - int32_t view_byte_len; - JSHandle byte_len_handle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); + int32_t viewByteLen; + JSHandle byteLenHandle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); // 11. If byteLength is undefined, then Let viewByteLength be bufferByteLength – offset. - if (byte_len_handle->IsUndefined()) { - view_byte_len = buf_byte_len - offset; + if (byteLenHandle->IsUndefined()) { + viewByteLen = bufByteLen - offset; } else { // Let viewByteLength be ToIndex(byteLength). - JSTaggedNumber byte_len = JSTaggedValue::ToIndex(thread, byte_len_handle); + JSTaggedNumber byteLen = JSTaggedValue::ToIndex(thread, byteLenHandle); // ReturnIfAbrupt(viewByteLength). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - view_byte_len = byte_len.ToInt32(); + viewByteLen = byteLen.ToInt32(); // If offset+viewByteLength > bufferByteLength, throw a RangeError exception. - if (offset + view_byte_len > buf_byte_len) { + if (offset + viewByteLen > bufByteLen) { THROW_RANGE_ERROR_AND_RETURN(thread, "offset + viewByteLen > bufByteLen", JSTaggedValue::Exception()); } } // 13. Let O be OrdinaryCreateFromConstructor OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", // «[[DataView]],[[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]]» ). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), newTarget); // 14. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle data_view(obj); + JSHandle dataView(obj); // 15. Set O’s [[DataView]] internal slot to true. - data_view->SetDataView(thread, JSTaggedValue::True()); + dataView->SetDataView(thread, JSTaggedValue::True()); // 16. Set O’s [[ViewedArrayBuffer]] internal slot to buffer. - data_view->SetViewedArrayBuffer(thread, buffer_handle.GetTaggedValue()); + dataView->SetViewedArrayBuffer(thread, bufferHandle.GetTaggedValue()); // 17. Set O’s [[ByteLength]] internal slot to viewByteLength. - data_view->SetByteLength(thread, JSTaggedValue(view_byte_len)); + dataView->SetByteLength(thread, JSTaggedValue(viewByteLen)); // 18. Set O’s [[ByteOffset]] internal slot to offset. - data_view->SetByteOffset(thread, JSTaggedValue(offset)); + dataView->SetByteOffset(thread, JSTaggedValue(offset)); // 19. Return O. - return JSTaggedValue(data_view.GetTaggedValue()); + return JSTaggedValue(dataView.GetTaggedValue()); } // 24.2.4.1 @@ -108,20 +108,20 @@ JSTaggedValue data_view::proto::GetBuffer(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataViewPrototype, GetBuffer); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. f Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsDataView()) { + if (!thisHandle->IsDataView()) { THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception()); } - JSHandle data_view(this_handle); + JSHandle dataView(thisHandle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); // 5. Return buffer. return JSTaggedValue(buffer); } @@ -132,26 +132,26 @@ JSTaggedValue data_view::proto::GetByteLength(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataViewPrototype, GetByteLength); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsDataView()) { + if (!thisHandle->IsDataView()) { THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception()); } - JSHandle data_view(this_handle); + JSHandle dataView(thisHandle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. - JSTaggedValue size = data_view->GetByteLength(); + JSTaggedValue size = dataView->GetByteLength(); // 7. Return size. return JSTaggedValue(size); } @@ -162,33 +162,33 @@ JSTaggedValue data_view::proto::GetByteOffset(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataViewPrototype, GetByteOffset); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsDataView()) { + if (!thisHandle->IsDataView()) { THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception()); } - JSHandle data_view(this_handle); + JSHandle dataView(thisHandle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. - JSTaggedValue offset = data_view->GetByteOffset(); + JSTaggedValue offset = dataView->GetByteOffset(); // 7. Return offset. return JSTaggedValue(offset); } // 24.2.1.1 static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &request_index, JSTaggedValue little_endian, + const JSHandle &requestIndex, JSTaggedValue littleEndian, DataViewType type) { BUILTINS_API_TRACE(thread, DataView, GetViewValue); @@ -201,58 +201,58 @@ static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle data_view(view); + JSHandle dataView(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 = data_view->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::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 offset_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteOffset()); - int32_t offset = offset_num.ToInt32(); + JSTaggedNumber offsetNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteOffset()); + int32_t offset = offsetNum.ToInt32(); // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot. - JSTaggedNumber view_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteLength()); - int32_t size = view_num.ToInt32(); + JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength()); + int32_t size = viewNum.ToInt32(); // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. - int32_t element_size = JSDataView::GetElementSize(type); + int32_t elementSize = JSDataView::GetElementSize(type); // 13. If getIndex +elementSize > viewSize, throw a RangeError exception. - if (index + element_size > size) { + if (index + elementSize > size) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception()); } // 14. Let bufferIndex be getIndex + viewOffset. - int32_t buffer_index = index + offset; + int32_t bufferIndex = 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, data_view->GetViewedArrayBuffer()); - return builtins::array_buffer::GetValueFromBuffer(thread, buffer, buffer_index, type, is_little_endian); + JSHandle buffer(thread, dataView->GetViewedArrayBuffer()); + return builtins::array_buffer::GetValueFromBuffer(thread, buffer, bufferIndex, type, isLittleEndian); } } // 24.2.1.2 JSTaggedValue SetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &request_index, JSTaggedValue little_endian, DataViewType type, + const JSHandle &requestIndex, JSTaggedValue littleEndian, DataViewType type, const JSHandle &value) { // 1. If Type(view) is not Object, throw a TypeError exception. @@ -265,83 +265,83 @@ JSTaggedValue SetViewValue(JSThread *thread, const JSHandle &view THROW_TYPE_ERROR_AND_RETURN(thread, "view is not dataview", JSTaggedValue::Exception()); } // 3. Let numberIndex be ToNumber(requestIndex). - JSTaggedNumber number_index = JSTaggedValue::ToIndex(thread, request_index); + JSTaggedNumber numberIndex = JSTaggedValue::ToIndex(thread, requestIndex); // 5. ReturnIfAbrupt(getIndex). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int64_t index = ecmascript::base::NumberHelper::DoubleInRangeInt32(number_index.GetNumber()); + int64_t index = ecmascript::base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber()); // 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception. if (index < 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception()); } - JSHandle num_val = JSTaggedValue::ToNumeric(thread, value); + JSHandle numVal = JSTaggedValue::ToNumeric(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let isLittleEndian be ToBoolean(isLittleEndian). - bool is_little_endian; - if (little_endian.IsUndefined()) { - is_little_endian = false; + bool isLittleEndian; + if (littleEndian.IsUndefined()) { + isLittleEndian = false; } else { - is_little_endian = little_endian.ToBoolean(); + isLittleEndian = littleEndian.ToBoolean(); } // 8. Let buffer be the value of view’s [[ViewedArrayBuffer]] internal slot. - JSHandle data_view(view); + JSHandle dataView(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 = data_view->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::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 offset_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteOffset()); - int32_t offset = offset_num.ToInt32(); + JSTaggedNumber offsetNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteOffset()); + int32_t offset = offsetNum.ToInt32(); // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot. - JSTaggedNumber view_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteLength()); - int32_t size = view_num.ToInt32(); + JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength()); + int32_t size = viewNum.ToInt32(); // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. - int32_t element_size = JSDataView::GetElementSize(type); + int32_t elementSize = JSDataView::GetElementSize(type); // 13. If getIndex +elementSize > viewSize, throw a RangeError exception. - if (index + element_size > size) { + if (index + elementSize > size) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception()); } // 14. Let bufferIndex be getIndex + viewOffset. - int32_t buffer_index = index + offset; + int32_t bufferIndex = 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, data_view->GetViewedArrayBuffer()); + JSHandle buffer(thread, dataView->GetViewedArrayBuffer()); // 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian). - return builtins::array_buffer::SetValueInBuffer(thread, buffer, buffer_index, type, num_val, is_little_endian); + return builtins::array_buffer::SetValueInBuffer(thread, buffer, bufferIndex, type, numVal, isLittleEndian); } } JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle offset_handle = builtins_common::GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle offsetHandle = builtins_common::GetCallArg(argv, 0); if (type == DataViewType::UINT8 || type == DataViewType::INT8) { - return GetViewValue(thread, this_handle, offset_handle, JSTaggedValue::True(), type); + return GetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type); } - JSHandle little_endian_handle = builtins_common::GetCallArg(argv, 1); - return GetViewValue(thread, this_handle, offset_handle, little_endian_handle.GetTaggedValue(), type); + JSHandle littleEndianHandle = builtins_common::GetCallArg(argv, 1); + return GetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type); } JSTaggedValue SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = builtins_common::GetThis(argv); - JSHandle offset_handle = builtins_common::GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisHandle = builtins_common::GetThis(argv); + JSHandle offsetHandle = builtins_common::GetCallArg(argv, 0); JSHandle value = builtins_common::GetCallArg(argv, 1); if (type == DataViewType::UINT8 || type == DataViewType::INT8) { - return SetViewValue(thread, this_handle, offset_handle, JSTaggedValue::True(), type, value); + return SetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type, value); } - JSHandle little_endian_handle = + JSHandle littleEndianHandle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); - return SetViewValue(thread, this_handle, offset_handle, little_endian_handle.GetTaggedValue(), type, value); + return SetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type, value); } // 24.2.4.5 diff --git a/runtime/builtins/builtins_date.cpp b/runtime/builtins/builtins_date.cpp index cba0e2f3cb43c13001d65c875aab07733a1a3510..4d58eb5ee3809fdc6c0a34f27accbeced4907303 100644 --- a/runtime/builtins/builtins_date.cpp +++ b/runtime/builtins/builtins_date.cpp @@ -41,35 +41,35 @@ JSTaggedValue date::DateConstructor(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, DateConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { double now = JSDate::Now().GetDouble(); PandaString str = JSDate::ToDateString(now); return builtins_common::GetTaggedString(thread, str.c_str()); } - JSTaggedValue time_value(0.0); + JSTaggedValue timeValue(0.0); uint32_t length = argv->GetArgsNumber(); if (length == 0) { // no value - time_value = JSDate::Now(); + timeValue = JSDate::Now(); } else if (length == 1) { // one value JSHandle value = builtins_common::GetCallArg(argv, 0); if (value->IsDate()) { // The value is a date object. - JSHandle js_date(thread, JSDate::Cast(value->GetTaggedObject())); - time_value = js_date->GetTimeValue(); + JSHandle jsDate(thread, JSDate::Cast(value->GetTaggedObject())); + timeValue = jsDate->GetTimeValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSHandle obj_value(thread, JSTaggedValue::ToPrimitive(thread, value)); + JSHandle objValue(thread, JSTaggedValue::ToPrimitive(thread, value)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (obj_value->IsString()) { // The value is a string object. - time_value = JSDate::Parse(argv); + if (objValue->IsString()) { // The value is a string object. + timeValue = JSDate::Parse(argv); } else { // The value is a number. - JSTaggedNumber val = JSTaggedValue::ToNumber(thread, obj_value); + JSTaggedNumber val = JSTaggedValue::ToNumber(thread, objValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - time_value = JSTaggedValue(val.GetNumber()); + timeValue = JSTaggedValue(val.GetNumber()); } - time_value = JSTaggedValue(JSDate::TimeClip(time_value.GetDouble())); + timeValue = JSTaggedValue(JSDate::TimeClip(timeValue.GetDouble())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } else { // two or more values @@ -91,16 +91,16 @@ JSTaggedValue date::DateConstructor(EcmaRuntimeCallInfo *argv) fields[0] += JSDate::NINETEEN_HUNDRED_YEAR; } } - time_value = JSTaggedValue((i == length) ? JSDate::SetDateValues(&fields, true) : ecmascript::base::NAN_VALUE); + timeValue = JSTaggedValue((i == length) ? JSDate::SetDateValues(&fields, true) : ecmascript::base::NAN_VALUE); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle date_object = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle dateObject = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - date_object->SetTimeValue(thread, time_value); - return JSTaggedValue(JSObject::Cast(static_cast(*date_object))); + dateObject->SetTimeValue(thread, timeValue); + return JSTaggedValue(JSObject::Cast(static_cast(*dateObject))); } // 20.4.3.1 @@ -114,7 +114,7 @@ JSTaggedValue date::Now([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSTaggedValue date::Parse(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, Parse); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); return JSDate::Parse(argv); } @@ -122,7 +122,7 @@ JSTaggedValue date::Parse(EcmaRuntimeCallInfo *argv) JSTaggedValue date::UTC(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, UTC); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); return JSDate::UTC(argv); } @@ -151,18 +151,18 @@ JSTaggedValue date::proto::SetTime(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DatePrototype, SetTime); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } - JSHandle js_data(thread, JSDate::Cast(msg->GetTaggedObject())); + JSHandle jsData(thread, JSDate::Cast(msg->GetTaggedObject())); JSTaggedNumber res = JSTaggedValue::ToNumber(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); double number = res.GetNumber(); double value = JSDate::TimeClip(number); - js_data->SetTimeValue(thread, JSTaggedValue(value)); + jsData->SetTimeValue(thread, JSTaggedValue(value)); return builtins_common::GetTaggedDouble(value); } @@ -172,7 +172,7 @@ JSTaggedValue date::proto::ToJSON(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DatePrototype, ToJSON); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). JSHandle msg = builtins_common::GetThis(argv); @@ -180,9 +180,9 @@ JSTaggedValue date::proto::ToJSON(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let tv be ToPrimitive(hint Number) - JSHandle object_handle = JSHandle::Cast(object); - JSHandle tv( - thread, JSTaggedValue::ToPrimitive(thread, object_handle, PreferredPrimitiveType::PREFER_NUMBER)); + JSHandle objectHandle = JSHandle::Cast(object); + JSHandle tv(thread, + JSTaggedValue::ToPrimitive(thread, objectHandle, PreferredPrimitiveType::PREFER_NUMBER)); // 3. If Type(tv) is Number and tv is not finite, return null if (tv->IsNumber()) { @@ -190,9 +190,9 @@ JSTaggedValue date::proto::ToJSON(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Null(); } } - 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); + JSHandle calleeKey(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("toISOString")); + auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), objectHandle, JSTaggedValue::Undefined(), 0); + return JSFunction::Invoke(info.Get(), calleeKey); } // 20.4.4.44 @@ -203,7 +203,7 @@ JSTaggedValue date::proto::ValueOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } return JSDate::Cast(msg->GetTaggedObject())->ValueOf(); @@ -215,7 +215,7 @@ JSTaggedValue date::proto::ToPrimitive(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DatePrototype, ToPrimitive); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle object = builtins_common::GetThis(argv); @@ -223,17 +223,17 @@ JSTaggedValue date::proto::ToPrimitive(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "Not a JSObject", JSTaggedValue::Exception()); } JSHandle hint = builtins_common::GetCallArg(argv, 0); - PreferredPrimitiveType try_first = PREFER_STRING; + PreferredPrimitiveType tryFirst = PREFER_STRING; if (hint->IsString()) { - JSHandle number_str_handle = factory->NewFromCanBeCompressString("number"); - if (EcmaString::StringsAreEqual(hint.GetObject(), *number_str_handle)) { - try_first = PREFER_NUMBER; + JSHandle numberStrHandle = factory->NewFromCanBeCompressString("number"); + if (EcmaString::StringsAreEqual(hint.GetObject(), *numberStrHandle)) { + tryFirst = PREFER_NUMBER; } else { - 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; + JSHandle stringStrHandle = factory->NewFromCanBeCompressString("string"); + JSHandle defaultStrHandle = factory->NewFromCanBeCompressString("default"); + if (EcmaString::StringsAreEqual(hint.GetObject(), *stringStrHandle) || + EcmaString::StringsAreEqual(hint.GetObject(), *defaultStrHandle)) { + tryFirst = PREFER_STRING; } else { THROW_TYPE_ERROR_AND_RETURN(thread, "This is not a primitiveType.", JSTaggedValue::Exception()); } @@ -241,7 +241,7 @@ JSTaggedValue date::proto::ToPrimitive(EcmaRuntimeCallInfo *argv) } else { THROW_TYPE_ERROR_AND_RETURN(thread, "This is not an primitiveType.", JSTaggedValue::Exception()); } - return JSTaggedValue::OrdinaryToPrimitive(thread, object, try_first); + return JSTaggedValue::OrdinaryToPrimitive(thread, object, tryFirst); } // ecma 402 16.4.1 Date.prototype.toLocaleString ( [ locales [ , options ] ] ) @@ -249,10 +249,10 @@ JSTaggedValue date::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle env = ecma_vm->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle env = ecmaVm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // Let x be ? thisTimeValue(this value). JSHandle msg = builtins_common::GetThis(argv); @@ -271,7 +271,7 @@ JSTaggedValue date::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) // Let options be ? ToDateTimeOptions(options, "any", "all"). JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle date_time_options = + JSHandle dateTimeOptions = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::ANY, DefaultsOption::ALL); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -279,7 +279,7 @@ JSTaggedValue date::proto::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(date_time_options)); + thread, JSHandle::Cast(obj), locales, JSHandle::Cast(dateTimeOptions)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatDateTime(dateFormat, x). @@ -292,10 +292,10 @@ JSTaggedValue date::proto::ToLocaleDateString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle env = ecma_vm->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle env = ecmaVm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // Let x be ? thisTimeValue(this value). JSHandle msg = builtins_common::GetThis(argv); @@ -314,7 +314,7 @@ JSTaggedValue date::proto::ToLocaleDateString(EcmaRuntimeCallInfo *argv) // Let options be ? ToDateTimeOptions(options, "any", "all"). JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle date_time_options = + JSHandle dateTimeOptions = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::DATE, DefaultsOption::DATE); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -322,7 +322,7 @@ JSTaggedValue date::proto::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(date_time_options)); + thread, JSHandle::Cast(obj), locales, JSHandle::Cast(dateTimeOptions)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatDateTime(dateFormat, x). @@ -335,10 +335,10 @@ JSTaggedValue date::proto::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle env = ecma_vm->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle env = ecmaVm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // Let x be ? thisTimeValue(this value). JSHandle msg = builtins_common::GetThis(argv); @@ -357,7 +357,7 @@ JSTaggedValue date::proto::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) // Let options be ? ToDateTimeOptions(options, "any", "all"). JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle date_time_options = + JSHandle dateTimeOptions = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::TIME, DefaultsOption::TIME); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -365,7 +365,7 @@ JSTaggedValue date::proto::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(date_time_options)); + thread, JSHandle::Cast(obj), locales, JSHandle::Cast(dateTimeOptions)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatDateTime(dateFormat, x). @@ -536,7 +536,7 @@ JSTaggedValue date::proto::ToISOString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); diff --git a/runtime/builtins/builtins_date_time_format.cpp b/runtime/builtins/builtins_date_time_format.cpp index 0f884e9fe2df8dd6f7b80db372254058363e2f3f..a62b8348b92738a3a04b5566864e4511338c3b3f 100644 --- a/runtime/builtins/builtins_date_time_format.cpp +++ b/runtime/builtins/builtins_date_time_format.cpp @@ -30,47 +30,47 @@ JSTaggedValue date_time_format::DateTimeFormatConstructor(EcmaRuntimeCallInfo *a { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { - new_target = constructor; + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { + newTarget = constructor; } // 2. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(new_target, "%DateTimeFormatPrototype%", « // [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], // [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], // [[Pattern]], [[BoundFormat]] »). - JSHandle date_time_format = JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle dateTimeFormat = JSHandle::Cast( + factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Perform ? InitializeDateTimeFormat(dateTimeFormat, locales, options). JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle dtf = - JSDateTimeFormat::InitializeDateTimeFormat(thread, date_time_format, locales, options); + JSDateTimeFormat::InitializeDateTimeFormat(thread, dateTimeFormat, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let this be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::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 is_instance_of = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), this_value); + bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (new_target->IsUndefined() && this_value->IsJSObject() && is_instance_of) { + if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { PropertyDescriptor descriptor(thread, JSHandle::Cast(dtf), false, false, false); JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, this_value, key, descriptor); + JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return this_value.GetTaggedValue(); + return thisValue.GetTaggedValue(); } // 6. Return dateTimeFormat. @@ -83,16 +83,16 @@ JSTaggedValue date_time_format::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %DateTimeFormat%.[[AvailableLocales]]. - JSHandle available_locales = JSDateTimeFormat::GainAvailableLocales(thread); + JSHandle availableLocales = JSDateTimeFormat::GainAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = builtins_common::GetCallArg(argv, 0); - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); + JSHandle result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -104,17 +104,17 @@ JSTaggedValue date_time_format::proto::GetFormat(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!this_value->IsJSObject()) { + if (!thisValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "dtf is not object", JSTaggedValue::Exception()); } // 3. Let dtf be ? UnwrapDateTimeFormat(dtf). - JSHandle dtf_value = JSDateTimeFormat::UnwrapDateTimeFormat(thread, this_value); + JSHandle dtfValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (dtf_value->IsUndefined()) { + if (dtfValue->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "dtfValue is not object", JSTaggedValue::Exception()); } @@ -123,14 +123,14 @@ JSTaggedValue date_time_format::proto::GetFormat(EcmaRuntimeCallInfo *argv) // b. Set F.[[DateTimeFormat]] to dtf. // c. Set dtf.[[BoundFormat]] to F. // 5. Return dtf.[[BoundFormat]]. - JSHandle dtf = JSHandle::Cast(dtf_value); - JSHandle bound_format(thread, dtf->GetBoundFormat()); - if (bound_format->IsUndefined()) { + JSHandle dtf = JSHandle::Cast(dtfValue); + JSHandle boundFormat(thread, dtf->GetBoundFormat()); + if (boundFormat->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intl_bound_func = + JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction(reinterpret_cast(AnonymousDateTimeFormat)); - intl_bound_func->SetDateTimeFormat(thread, dtf); - dtf->SetBoundFormat(thread, intl_bound_func); + intlBoundFunc->SetDateTimeFormat(thread, dtf); + dtf->SetBoundFormat(thread, intlBoundFunc); } return dtf->GetBoundFormat(); } @@ -142,11 +142,11 @@ JSTaggedValue AnonymousDateTimeFormat(EcmaRuntimeCallInfo *argv) // When a DateTime format function F is called with optional argument date, the following steps are taken: JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle intl_bound_func = + JSHandle intlBoundFunc = JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let dtf be F.[[DateTimeFormat]]. - JSHandle dtf(thread, intl_bound_func->GetDateTimeFormat()); + JSHandle dtf(thread, intlBoundFunc->GetDateTimeFormat()); // 2. Assert: Type(dtf) is Object and dtf has an [[InitializedDateTimeFormat]] internal slot. ASSERT_PRINT(dtf->IsJSObject() && dtf->IsJSDateTimeFormat(), "dtf is not object or JSDateTimeFormat"); @@ -160,9 +160,9 @@ JSTaggedValue AnonymousDateTimeFormat(EcmaRuntimeCallInfo *argv) if (date->IsUndefined()) { x = JSDate::Now().GetNumber(); } else { - JSTaggedNumber x_number = JSTaggedValue::ToNumber(thread, date); + JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - x = x_number.GetNumber(); + x = xNumber.GetNumber(); } // 5. Return ? FormatDateTime(dtf, x). @@ -192,19 +192,19 @@ JSTaggedValue date_time_format::proto::FormatToParts(EcmaRuntimeCallInfo *argv) if (date->IsUndefined()) { x = JSDate::Now().GetNumber(); } else { - JSTaggedNumber x_number = JSTaggedValue::ToNumber(thread, date); + JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - x = x_number.GetNumber(); + x = xNumber.GetNumber(); } - double x_value = JSDate::TimeClip(x); - if (std::isnan(x_value)) { + double xValue = JSDate::TimeClip(x); + if (std::isnan(xValue)) { THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid time value", JSTaggedValue::Exception()); } // 5. Return ? FormatDateTimeToParts(dtf, x). JSHandle result = - JSDateTimeFormat::FormatDateTimeToParts(thread, JSHandle::Cast(dtf), x_value); + JSDateTimeFormat::FormatDateTimeToParts(thread, JSHandle::Cast(dtf), xValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -215,21 +215,21 @@ JSTaggedValue date_time_format::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!this_value->IsJSObject()) { + if (!thisValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. Let dtf be ? UnwrapDateTimeFormat(dtf). - this_value = JSDateTimeFormat::UnwrapDateTimeFormat(thread, this_value); + thisValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); - JSDateTimeFormat::ResolvedOptions(thread, JSHandle::Cast(this_value), options); + JSDateTimeFormat::ResolvedOptions(thread, JSHandle::Cast(thisValue), options); // 6. Return options. return options.GetTaggedValue(); } @@ -241,40 +241,40 @@ JSTaggedValue date_time_format::proto::FormatRange(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!this_value->IsJSObject()) { + if (!thisValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. - if (!this_value->IsJSDateTimeFormat()) { + if (!thisValue->IsJSDateTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception()); } // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. - JSHandle start_date = builtins_common::GetCallArg(argv, 0); - JSHandle end_date = builtins_common::GetCallArg(argv, 1); - if (start_date->IsUndefined() || end_date->IsUndefined()) { + JSHandle startDate = builtins_common::GetCallArg(argv, 0); + JSHandle endDate = builtins_common::GetCallArg(argv, 1); + if (startDate->IsUndefined() || endDate->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception()); } // 5. Let x be ? ToNumber(startDate). - JSTaggedNumber value_x = JSTaggedValue::ToNumber(thread, start_date); + JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double x = value_x.GetNumber(); + double x = valueX.GetNumber(); // 6. Let y be ? ToNumber(endDate). - JSTaggedNumber value_y = JSTaggedValue::ToNumber(thread, end_date); + JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double y = value_y.GetNumber(); + double y = valueY.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(this_value); + JSHandle dtf = JSHandle::Cast(thisValue); JSHandle result = JSDateTimeFormat::NormDateTimeRange(thread, dtf, x, y); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); @@ -286,41 +286,41 @@ JSTaggedValue date_time_format::proto::FormatRangeToParts(EcmaRuntimeCallInfo *a JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!this_value->IsJSObject()) { + if (!thisValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, // throw a TypeError exception. - if (!this_value->IsJSDateTimeFormat()) { + if (!thisValue->IsJSDateTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception()); } // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. - JSHandle start_date = builtins_common::GetCallArg(argv, 0); - JSHandle end_date = builtins_common::GetCallArg(argv, 1); - if (start_date->IsUndefined() || end_date->IsUndefined()) { + JSHandle startDate = builtins_common::GetCallArg(argv, 0); + JSHandle endDate = builtins_common::GetCallArg(argv, 1); + if (startDate->IsUndefined() || endDate->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception()); } // 5. Let x be ? ToNumber(startDate). - JSTaggedNumber value_x = JSTaggedValue::ToNumber(thread, start_date); + JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double x = value_x.GetNumber(); + double x = valueX.GetNumber(); // 6. Let y be ? ToNumber(endDate). - JSTaggedNumber value_y = JSTaggedValue::ToNumber(thread, end_date); + JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double y = value_y.GetNumber(); + double y = valueY.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(this_value); + JSHandle dtf = JSHandle::Cast(thisValue); 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 cc15be15a4b757f653912b6bb7b45668cf711514..9199b6a9470458bb1c2c91d609462dbc498967eb 100644 --- a/runtime/builtins/builtins_finalization_registry.cpp +++ b/runtime/builtins/builtins_finalization_registry.cpp @@ -27,11 +27,11 @@ JSTaggedValue finalization_registry::Constructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistry, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } @@ -42,15 +42,15 @@ JSTaggedValue finalization_registry::Constructor(EcmaRuntimeCallInfo *argv) // 3.Let FinalizationRegistry be OrdinaryCreateFromConstructor( // NewTarget, "%FinalizationRegistry.prototype%", «[[Realm]], [[CleanupCallback]], [[Cells]]») JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle registry = JSHandle::Cast(obj); // 4. Let fn be the active function object. - JSHandle cleanup_callback = JSHandle::Cast(constructor); + JSHandle cleanupCallback = 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(cleanup_callback.GetTaggedValue()); + registry->SetCleanupCallback(cleanupCallback.GetTaggedValue()); // 7. Set finalizationRegistry.[[Cells]] to a new empty List. JSHandle cells = factory->EmptyArray(); registry->SetCells(cells.GetTaggedValue()); @@ -66,7 +66,7 @@ JSTaggedValue finalization_registry::proto::Register(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistryPrototype, Register); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 1. Let finalizationRegistry be the this value. if (!self->IsJSFinalizationRegistry()) { @@ -80,27 +80,27 @@ JSTaggedValue finalization_registry::proto::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 held_value(thread, JSTaggedValue::Hole()); + JSMutableHandle heldValue(thread, JSTaggedValue::Hole()); if (argv->GetArgsNumber() >= 2U) { - held_value.Update(builtins_common::GetCallArg(argv, 1U)); - if (JSTaggedValue::SameValue(target.GetTaggedValue(), held_value.GetTaggedValue())) { + heldValue.Update(builtins_common::GetCallArg(argv, 1U)); + if (JSTaggedValue::SameValue(target.GetTaggedValue(), heldValue.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 unregister_token(thread, builtins_common::GetCallArg(argv, 2U)); - if (!unregister_token->IsECMAObject()) { - if (!unregister_token->IsUndefined()) { + JSMutableHandle unregisterToken(thread, builtins_common::GetCallArg(argv, 2U)); + if (!unregisterToken->IsECMAObject()) { + if (!unregisterToken->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "unregisterToken must be an object.", JSTaggedValue::Exception()); } - unregister_token.Update(JSTaggedValue::Hole()); + unregisterToken.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, held_value, unregister_token); + JSFinalizationRegistry::Register(thread, registry, target, heldValue, unregisterToken); // 8. Return undefined. return JSTaggedValue::Undefined(); } @@ -111,7 +111,7 @@ JSTaggedValue finalization_registry::proto::Unregister(EcmaRuntimeCallInfo *argv ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistryPrototype, Unregister); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 1. Let finalizationRegistry be the this value. if (!self->IsJSFinalizationRegistry()) { @@ -120,14 +120,14 @@ JSTaggedValue finalization_registry::proto::Unregister(EcmaRuntimeCallInfo *argv JSHandle registry = JSHandle::Cast(self); // 2. Perform ? RequireInternalSlot(finalizationRegistry, [[Cells]]). // 3. If Type(unregisterToken) is not Object, throw a TypeError exception. - JSHandle unregister_token = builtins_common::GetCallArg(argv, 0U); - if (!unregister_token->IsECMAObject()) { + JSHandle unregisterToken = builtins_common::GetCallArg(argv, 0U); + if (!unregisterToken->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, unregister_token); + bool removed = JSFinalizationRegistry::Unregister(thread, registry, unregisterToken); // 8. Return removed. return JSTaggedValue(removed); } diff --git a/runtime/builtins/builtins_function.cpp b/runtime/builtins/builtins_function.cpp index e09a120a5548751255c539e4bc51906ac4eced33..775dfd6d62ea8a8f596b869b5bc6609ca59b8060 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 &array_obj) +std::pair BuildArgumentsListFast(JSThread *thread, const JSHandle &arrayObj) { - if (!array_obj->HasStableElements(thread)) { + if (!arrayObj->HasStableElements(thread)) { return std::make_pair(nullptr, 0); } - if (array_obj->IsStableJSArguments(thread)) { - JSHandle arg_list = JSHandle::Cast(array_obj); - TaggedArray *elements = TaggedArray::Cast(arg_list->GetElements().GetTaggedObject()); + if (arrayObj->IsStableJSArguments(thread)) { + JSHandle argList = JSHandle::Cast(arrayObj); + TaggedArray *elements = TaggedArray::Cast(argList->GetElements().GetTaggedObject()); auto env = thread->GetEcmaVM()->GetGlobalEnv(); - if (arg_list->GetClass() != env->GetArgumentsClass().GetObject()) { + if (argList->GetClass() != env->GetArgumentsClass().GetObject()) { return std::make_pair(nullptr, 0); } - auto result = arg_list->GetPropertyInlinedProps(JSArguments::LENGTH_INLINE_PROPERTY_INDEX); + auto result = argList->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 (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(); + if (arrayObj->IsStableJSArray(thread)) { + JSHandle argList = JSHandle::Cast(arrayObj); + TaggedArray *elements = TaggedArray::Cast(argList->GetElements().GetTaggedObject()); + size_t length = argList->GetArrayLength(); size_t res = MakeArgListWithHole(thread, elements, length); return std::make_pair(elements, res); } @@ -90,7 +90,7 @@ JSTaggedValue function::proto::Apply(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FunctionPrototype, Apply); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If IsCallable(func) is false, throw a TypeError exception. if (!builtins_common::GetThis(argv)->IsCallable()) { @@ -98,33 +98,33 @@ JSTaggedValue function::proto::Apply(EcmaRuntimeCallInfo *argv) } JSHandle func = builtins_common::GetThis(argv); - JSHandle this_arg = builtins_common::GetCallArg(argv, 0); + JSHandle thisArg = builtins_common::GetCallArg(argv, 0); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); // 2. If argArray is null or undefined, then if (builtins_common::GetCallArg(argv, 1)->IsUndefined()) { // null will also get undefined // a. Return Call(func, thisArg). - auto info = NewRuntimeCallInfo(thread, func, this_arg, undefined, 0); + auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, 0); return JSFunction::Call(info.Get()); } // 3. Let argList be CreateListFromArrayLike(argArray). - JSHandle array_obj = builtins_common::GetCallArg(argv, 1); - auto [array, length] = BuildArgumentsListFast(thread, array_obj); + JSHandle arrayObj = builtins_common::GetCallArg(argv, 1); + auto [array, length] = BuildArgumentsListFast(thread, arrayObj); if (array == nullptr) { - auto arg_list_res = JSObject::CreateListFromArrayLike(thread, array_obj); + auto argListRes = JSObject::CreateListFromArrayLike(thread, arrayObj); // 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, this_arg, undefined, args_length); + JSHandle argList = JSHandle::Cast(argListRes); + const auto argsLength = static_cast(argList->GetLength()); + auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info->SetCallArg(args_length, arg_list->GetData()); + info->SetCallArg(argsLength, argList->GetData()); return JSFunction::Call(info.Get()); } // 6. Return Call(func, thisArg, argList). - const auto args_length = static_cast(length); - auto info = NewRuntimeCallInfo(thread, func, this_arg, undefined, args_length); + const auto argsLength = static_cast(length); + auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info->SetCallArg(args_length, array->GetData()); + info->SetCallArg(argsLength, array->GetData()); return JSFunction::Call(info.Get()); } @@ -134,7 +134,7 @@ JSTaggedValue function::proto::Bind(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FunctionPrototype, Bind); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let Target be the this value. @@ -144,37 +144,37 @@ JSTaggedValue function::proto::Bind(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "bind target is not callable", JSTaggedValue::Exception()); } - JSHandle this_arg = builtins_common::GetCallArg(argv, 0); - uint32_t args_length = 0; + JSHandle thisArg = builtins_common::GetCallArg(argv, 0); + uint32_t argsLength = 0; if (argv->GetArgsNumber() > 1) { - args_length = argv->GetArgsNumber() - 1; + argsLength = 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 args_array = factory->NewTaggedArray(args_length); - for (uint32_t index = 0; index < args_length; ++index) { - args_array->Set(thread, index, builtins_common::GetCallArg(argv, index + 1)); + JSHandle argsArray = factory->NewTaggedArray(argsLength); + for (uint32_t index = 0; index < argsLength; ++index) { + argsArray->Set(thread, index, builtins_common::GetCallArg(argv, index + 1)); } // 4. Let F be BoundFunctionCreate(Target, thisArg, args). - JSHandle target_function = JSHandle::Cast(target); - JSHandle bound_function = factory->NewJSBoundFunction(target_function, this_arg, args_array); + JSHandle targetFunction = JSHandle::Cast(target); + JSHandle boundFunction = factory->NewJSBoundFunction(targetFunction, thisArg, argsArray); // 5. ReturnIfAbrupt(F) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Let targetHasLength be HasOwnProperty(Target, "length"). - auto global_const = thread->GlobalConstants(); - JSHandle length_key = global_const->GetHandledLengthString(); - bool target_has_length = - JSTaggedValue::HasOwnProperty(thread, JSHandle::Cast(target_function), length_key); + auto globalConst = thread->GlobalConstants(); + JSHandle lengthKey = globalConst->GetHandledLengthString(); + bool targetHasLength = + JSTaggedValue::HasOwnProperty(thread, JSHandle::Cast(targetFunction), lengthKey); // 7. ReturnIfAbrupt(targetHasLength). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double length_value = 0.0; + double lengthValue = 0.0; // 8. If targetHasLength is true, then - if (target_has_length) { + if (targetHasLength) { // a. Let targetLen be Get(Target, "length"). - JSHandle target_len = JSObject::GetProperty(thread, target, length_key).GetValue(); + JSHandle targetLen = JSObject::GetProperty(thread, target, lengthKey).GetValue(); // b. ReturnIfAbrupt(targetLen). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -182,43 +182,42 @@ JSTaggedValue function::proto::Bind(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 (target_len->IsNumber()) { + if (targetLen->IsNumber()) { // argv include thisArg - length_value = std::max(0.0, JSTaggedValue::ToNumber(thread, target_len).GetNumber() - - static_cast(args_length)); + lengthValue = + std::max(0.0, JSTaggedValue::ToNumber(thread, targetLen).GetNumber() - static_cast(argsLength)); } } // 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(length_value)), false, false, true); + PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(lengthValue)), false, false, true); [[maybe_unused]] bool status = - JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(bound_function), length_key, desc); + JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(boundFunction), lengthKey, desc); // 11. Assert: status is not an abrupt completion. ASSERT_PRINT(status, "DefinePropertyOrThrow failed"); // 12. Let targetName be Get(Target, "name"). - JSHandle name_key = global_const->GetHandledNameString(); - JSHandle target_name = JSObject::GetProperty(thread, target, name_key).GetValue(); + JSHandle nameKey = globalConst->GetHandledNameString(); + JSHandle targetName = JSObject::GetProperty(thread, target, nameKey).GetValue(); // 13. ReturnIfAbrupt(targetName). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle bound_name(factory->NewFromCanBeCompressString("bound")); + JSHandle boundName(factory->NewFromCanBeCompressString("bound")); // 14. If Type(targetName) is not String, let targetName be the empty string. // 15. Perform SetFunctionName(F, targetName, "bound"). - if (!target_name->IsString()) { - JSHandle empty_string(factory->GetEmptyString()); - status = - JSFunction::SetFunctionName(thread, JSHandle(bound_function), empty_string, bound_name); + if (!targetName->IsString()) { + JSHandle emptyString(factory->GetEmptyString()); + status = JSFunction::SetFunctionName(thread, JSHandle(boundFunction), emptyString, boundName); } else { - status = JSFunction::SetFunctionName(thread, JSHandle(bound_function), target_name, bound_name); + status = JSFunction::SetFunctionName(thread, JSHandle(boundFunction), targetName, boundName); } // Assert: status is not an abrupt completion. ASSERT_PRINT(status, "SetFunctionName failed"); // 16. Return F. - return bound_function.GetTaggedValue(); + return boundFunction.GetTaggedValue(); } // ecma 19.2.3.3 Function.prototype.call (thisArg , ...args) @@ -227,7 +226,7 @@ JSTaggedValue function::proto::Call(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FunctionPrototype, Call); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If IsCallable(func) is false, throw a TypeError exception. if (!builtins_common::GetThis(argv)->IsCallable()) { @@ -235,20 +234,20 @@ JSTaggedValue function::proto::Call(EcmaRuntimeCallInfo *argv) } JSHandle func = builtins_common::GetThis(argv); - JSHandle this_arg = builtins_common::GetCallArg(argv, 0); - uint32_t args_length = 0; + JSHandle thisArg = builtins_common::GetCallArg(argv, 0); + uint32_t argsLength = 0; if (argv->GetArgsNumber() > 1) { - args_length = argv->GetArgsNumber() - 1; + argsLength = 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, this_arg, undefined, args_length); + auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (args_length > 0) { - info->SetCallArg(args_length, + if (argsLength > 0) { + info->SetCallArg(argsLength, reinterpret_cast(argv->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS + 1))); } return JSFunction::Call(info.Get()); @@ -260,9 +259,9 @@ JSTaggedValue function::proto::ToString(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), FunctionPrototype, ToString); // not implement due to that runtime can not get JS Source Code now. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_value = builtins_common::GetThis(argv); - if (!this_value->IsCallable()) { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisValue = builtins_common::GetThis(argv); + if (!thisValue->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "function.toString() target is not callable", JSTaggedValue::Exception()); } return builtins_common::GetTaggedString( @@ -273,12 +272,12 @@ JSTaggedValue function::proto::ToString(EcmaRuntimeCallInfo *argv) JSTaggedValue function::proto::HasInstance(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), FunctionPrototype, HasInstance); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); // 1. Let F be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. Return OrdinaryHasInstance(F, V). JSHandle arg = builtins_common::GetCallArg(argv, 0); - return JSFunction::OrdinaryHasInstance(argv->GetThread(), this_value, arg) + return JSFunction::OrdinaryHasInstance(argv->GetThread(), thisValue, arg) ? builtins_common::GetTaggedBoolean(true) : builtins_common::GetTaggedBoolean(false); } diff --git a/runtime/builtins/builtins_generator.cpp b/runtime/builtins/builtins_generator.cpp index 0dc16418e6f8b1597212cf9a21495fef98f182f8..3c2e671f0d477fc8c1f03889e30097722c40ab01 100644 --- a/runtime/builtins/builtins_generator.cpp +++ b/runtime/builtins/builtins_generator.cpp @@ -31,7 +31,7 @@ JSTaggedValue generator::proto::Next(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Next); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); @@ -51,7 +51,7 @@ JSTaggedValue generator::proto::Return(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Return); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); @@ -61,10 +61,10 @@ JSTaggedValue generator::proto::Return(EcmaRuntimeCallInfo *argv) // 2.Let C be Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }. JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::RETURN, value); + JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::RETURN, value); // 3.Return ? GeneratorResumeAbrupt(g, C). - JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completion_record); + JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completionRecord); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -75,7 +75,7 @@ JSTaggedValue generator::proto::Throw(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Throw); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); @@ -85,10 +85,10 @@ JSTaggedValue generator::proto::Throw(EcmaRuntimeCallInfo *argv) // 2.Let C be ThrowCompletion(exception). JSHandle exception = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::THROW, exception); + JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::THROW, exception); // 3.Return ? GeneratorResumeAbrupt(g, C). - JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completion_record); + JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completionRecord); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_global.cpp b/runtime/builtins/builtins_global.cpp index 241649277f3821f39e268c8c22730262c9f95c98..452b49256bbead549c3bca3307b72688d94f69a8 100644 --- a/runtime/builtins/builtins_global.cpp +++ b/runtime/builtins/builtins_global.cpp @@ -44,8 +44,8 @@ using NumberHelper = ecmascript::base::NumberHelper; using StringHelper = ecmascript::base::StringHelper; static void PrintString(JSThread *thread, EcmaString *string); -static JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set); -static JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set); +static JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriFunc isInUriSet); +static JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriFunc isInUriSet); inline bool IsAlNum(uint16_t ch) { @@ -98,7 +98,7 @@ inline int IsHex(uint16_t cc) return -1; } uint8_t GetValueFromTwoHex(uint16_t front, uint16_t behind); -JSHandle GCSpecialisedObjectSpaceType(JSThread *thread, const JSHandle &obj_handle); +JSHandle GCSpecialisedObjectSpaceType(JSThread *thread, const JSHandle &objHandle); /** * Class tracks GC tasks already processed by GC. @@ -111,23 +111,23 @@ public: bool IsInitialized(); void AddTaskId(uint64_t id); bool HasId(uint64_t id); - void SetCallbackForTask(uint32_t task_id, uintptr_t callback_handle); - void GCStarted(const GCTask &task, size_t heap_size) override; - void GCFinished(const GCTask &task, size_t heap_size_before_gc, size_t heap_size) override; + void SetCallbackForTask(uint32_t taskId, uintptr_t callbackHandle); + void GCStarted(const GCTask &task, size_t heapSize) override; + void GCFinished(const GCTask &task, size_t heapSizeBeforeGc, size_t heapSize) override; void GCPhaseStarted(mem::GCPhase phase) override; void RemoveId(uint64_t id); private: bool initialized_ = false; - std::vector task_ids_ GUARDED_BY(lock_); - uint32_t current_task_id_ = 0; - uint32_t callback_task_id_ = 0; - uintptr_t callback_handle_ = 0; + std::vector taskIds_ GUARDED_BY(lock_); + uint32_t currentTaskId_ = 0; + uint32_t callbackTaskId_ = 0; + uintptr_t callbackHandle_ = 0; os::memory::Mutex lock_; }; // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) -GCTaskTracker G_GCTASK_TRACKER; +GCTaskTracker g_gGctaskTracker; void GCTaskTracker::InitIfNeeded(mem::GC *gc) { @@ -146,29 +146,29 @@ bool GCTaskTracker::IsInitialized() void GCTaskTracker::AddTaskId(uint64_t id) { os::memory::LockHolder lock(lock_); - task_ids_.push_back(id); + taskIds_.push_back(id); } bool GCTaskTracker::HasId(uint64_t id) { os::memory::LockHolder lock(lock_); - return std::find(task_ids_.begin(), task_ids_.end(), id) != task_ids_.end(); + return std::find(taskIds_.begin(), taskIds_.end(), id) != taskIds_.end(); } -void GCTaskTracker::SetCallbackForTask(uint32_t task_id, uintptr_t callback_handle) +void GCTaskTracker::SetCallbackForTask(uint32_t taskId, uintptr_t callbackHandle) { - callback_task_id_ = task_id; - callback_handle_ = callback_handle; + callbackTaskId_ = taskId; + callbackHandle_ = callbackHandle; } void GCTaskTracker::GCPhaseStarted(mem::GCPhase phase) { - if (phase == mem::GCPhase::GC_PHASE_MARK && callback_handle_ != 0 && current_task_id_ == callback_task_id_) { + if (phase == mem::GCPhase::GC_PHASE_MARK && callbackHandle_ != 0 && currentTaskId_ == callbackTaskId_) { JSThread *thread = JSThread::GetCurrent(); - JSHandle callback(thread, *reinterpret_cast(callback_handle_)); + JSHandle callback(thread, *reinterpret_cast(callbackHandle_)); JSHandle fn = JSHandle::Cast(callback); JSHandle global(thread, thread->GetGlobalObject()); - JSHandle new_target(thread, JSTaggedValue::Undefined()); + JSHandle newTarget(thread, JSTaggedValue::Undefined()); auto info = NewRuntimeCallInfo(thread, fn, global, JSTaggedValue::Undefined(), 1); // JS has only one thread, therefore, we run this callback from the mutator thread during concurrent marking. ASSERT(!thread->GetVM()->GetMutatorLock()->HasLock()); @@ -178,30 +178,30 @@ void GCTaskTracker::GCPhaseStarted(mem::GCPhase phase) } } -void GCTaskTracker::GCStarted(const GCTask &task, [[maybe_unused]] size_t heap_size) +void GCTaskTracker::GCStarted(const GCTask &task, [[maybe_unused]] size_t heapSize) { - current_task_id_ = task.GetId(); + currentTaskId_ = task.GetId(); } -void GCTaskTracker::GCFinished(const GCTask &task, [[maybe_unused]] size_t heap_size_before_gc, - [[maybe_unused]] size_t heap_size) +void GCTaskTracker::GCFinished(const GCTask &task, [[maybe_unused]] size_t heapSizeBeforeGc, + [[maybe_unused]] size_t heapSize) { RemoveId(task.GetId()); } void GCTaskTracker::RemoveId(uint64_t id) { - current_task_id_ = 0; - if (id == callback_task_id_ && callback_handle_ != 0) { - JSThread::GetCurrent()->GetEcmaGlobalStorage()->DisposeGlobalHandle(callback_handle_); - callback_handle_ = 0; + currentTaskId_ = 0; + if (id == callbackTaskId_ && callbackHandle_ != 0) { + JSThread::GetCurrent()->GetEcmaGlobalStorage()->DisposeGlobalHandle(callbackHandle_); + callbackHandle_ = 0; } if (id != 0) { os::memory::LockHolder lock(lock_); - auto it = std::find(task_ids_.begin(), task_ids_.end(), id); + auto it = std::find(taskIds_.begin(), taskIds_.end(), id); // There may be no such id if the corresponding GC has been triggered not by startGC - if (it != task_ids_.end()) { - task_ids_.erase(it); + if (it != taskIds_.end()) { + taskIds_.erase(it); } } } @@ -210,7 +210,7 @@ void GCTaskTracker::RemoveId(uint64_t id) JSTaggedValue global::Eval(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); if (argv->GetArgsNumber() == 0) { return JSTaggedValue(JSTaggedValue::VALUE_UNDEFINED); } @@ -224,10 +224,10 @@ JSTaggedValue global::IsFinite(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, IsFinite); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle number_input = builtins_common::GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle numberInput = builtins_common::GetCallArg(argv, 0); // 1. Let num be ToNumber(number). - JSTaggedNumber number = JSTaggedValue::ToNumber(thread, number_input); + JSTaggedNumber number = JSTaggedValue::ToNumber(thread, numberInput); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If num is NaN, +Infinite, or -Infinite, return false. // 4. Otherwise, return true. @@ -243,10 +243,10 @@ JSTaggedValue global::IsNaN(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, IsNaN); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle number_input = builtins_common::GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle numberInput = builtins_common::GetCallArg(argv, 0); // 1. Let num be ToNumber(number). - JSTaggedNumber number = JSTaggedValue::ToNumber(thread, number_input); + JSTaggedNumber number = JSTaggedValue::ToNumber(thread, numberInput); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If num is NaN, return true. @@ -302,7 +302,7 @@ JSTaggedValue global::Unescape(EcmaRuntimeCallInfo *argv) constexpr uint16_t LATIN_SMALL_LETTER_U = 0x0075; JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, Unescape); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Set string to ? ToString(string). [[maybe_unused]] JSHandle sstring = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); @@ -325,51 +325,51 @@ JSTaggedValue global::Unescape(EcmaRuntimeCallInfo *argv) continue; } // i. Let hexEscape be the empty String. - std::u16string hex_escape; + std::u16string hexEscape; // ii. Let skip be 0. auto skip = 0; // iii. If k ≤ length - 6 and the code unit at index k + 1 within string is the code unit 0x0075 // (LATIN_SMALL_LETTER_U), then - bool is_valid_hex_sequence = false; - int res_char = 0; + bool isValidHexSequence = false; + int resChar = 0; if (k <= length - 6 && sstring->At(k + 1) == LATIN_SMALL_LETTER_U) { // 1. Set hexEscape to the substring of string from k + 2 to k + 6 - hex_escape = StringHelper::StringToU16string(StringHelper::SubString(sstring, k + 2, 4)); + hexEscape = StringHelper::StringToU16string(StringHelper::SubString(sstring, k + 2, 4)); // 2. Set skip to 5 skip = 5; // check if hex sequence is valid - int digit_1 = IsHex(hex_escape[0]); - int digit_2 = IsHex(hex_escape[1]); - int digit_3 = IsHex(hex_escape[2]); - int digit_4 = IsHex(hex_escape[3]); - if (digit_1 != -1 && digit_2 != -1 && digit_3 != -1 && digit_4 != -1) { + int digit1 = IsHex(hexEscape[0]); + int digit2 = IsHex(hexEscape[1]); + int digit3 = IsHex(hexEscape[2]); + int digit4 = IsHex(hexEscape[3]); + if (digit1 != -1 && digit2 != -1 && digit3 != -1 && digit4 != -1) { // NOLINTNEXTLINE(hicpp-signed-bitwise,readability-magic-numbers) - res_char = (digit_1 << 12) + (digit_2 << 8) + (digit_3 << 4) + digit_4; - is_valid_hex_sequence = true; + resChar = (digit1 << 12) + (digit2 << 8) + (digit3 << 4) + digit4; + isValidHexSequence = true; } } // iv. Else if k ≤ length - 3, then else if (k <= length - 3) { // 1. Set hexEscape to the substring of string from k + 1 to k + 3. - hex_escape = StringHelper::StringToU16string(StringHelper::SubString(sstring, k + 1, 2)); + hexEscape = StringHelper::StringToU16string(StringHelper::SubString(sstring, k + 1, 2)); // 2. Set skip to 2. skip = 2; // check if hex sequence is valid - int digit_1 = IsHex(hex_escape[0]); - int digit_2 = IsHex(hex_escape[1]); + int digit1 = IsHex(hexEscape[0]); + int digit2 = IsHex(hexEscape[1]); - if (digit_1 != -1 && digit_2 != -1) { + if (digit1 != -1 && digit2 != -1) { // NOLINTNEXTLINE(hicpp-signed-bitwise,readability-magic-numbers) - res_char = (digit_1 << 4) + digit_2; - is_valid_hex_sequence = true; + resChar = (digit1 << 4) + digit2; + isValidHexSequence = true; } } // v. If hexEscape can be interpreted as an expansion of HexDigits[~Sep], then - if (is_valid_hex_sequence) { + if (isValidHexSequence) { // 1. Let hexIntegerLiteral be the string-concatenation of "0x" and hexEscape. // 2. Let n be ! ToNumber(hexIntegerLiteral). // 3. Set c to the code unit whose value is ℝ(n). - cc = res_char; + cc = resChar; // 4. Set k to k + skip k += skip; } @@ -377,9 +377,9 @@ JSTaggedValue global::Unescape(EcmaRuntimeCallInfo *argv) rr.append(StringHelper::Utf16ToU16String(&cc, 1)); } // 6. Return R. - auto *rr_data = reinterpret_cast(rr.data()); - int32_t rr_size = rr.size(); - return factory->NewFromUtf16Literal(rr_data, rr_size).GetTaggedValue(); + auto *rrData = reinterpret_cast(rr.data()); + int32_t rrSize = rr.size(); + return factory->NewFromUtf16Literal(rrData, rrSize).GetTaggedValue(); } JSTaggedValue global::Escape(EcmaRuntimeCallInfo *argv) @@ -389,7 +389,7 @@ JSTaggedValue global::Escape(EcmaRuntimeCallInfo *argv) static const std::u16string HEX_STR = u"0123456789ABCDEF"; JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, Escape); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Set string to ? ToString(string). [[maybe_unused]] JSHandle sstring = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); @@ -423,8 +423,8 @@ JSTaggedValue global::Escape(EcmaRuntimeCallInfo *argv) 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 hexC = HEX_STR[cc >> ((N_DIGITS - 1 - j) * 4U) & BIT_MASK]; + ss.append(StringHelper::Utf16ToU16String(&hexC, 1)); } } // d. Else @@ -440,8 +440,8 @@ JSTaggedValue global::Escape(EcmaRuntimeCallInfo *argv) 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 hexC = HEX_STR[cc >> ((N_DIGITS - 1 - j) * 4U) & BIT_MASK]; + ss.append(StringHelper::Utf16ToU16String(&hexC, 1)); } } // e. Set R to the string-concatenation of R and S. @@ -449,9 +449,9 @@ JSTaggedValue global::Escape(EcmaRuntimeCallInfo *argv) // f. Set k to k + 1 } // 6. Return R. - auto *rr_data = reinterpret_cast(rr.data()); - int32_t rr_size = rr.size(); - return factory->NewFromUtf16Literal(rr_data, rr_size).GetTaggedValue(); + auto *rrData = reinterpret_cast(rr.data()); + int32_t rrSize = rr.size(); + return factory->NewFromUtf16Literal(rrData, rrSize).GetTaggedValue(); } // 18.2.6 @@ -460,16 +460,16 @@ JSTaggedValue global::DecodeURI(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, DecodeURI); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let uriString be ToString(encodedURI). // 2. ReturnIfAbrupt(uriString). - [[maybe_unused]] JSHandle uri_string = + [[maybe_unused]] JSHandle uriString = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let reservedURISet be a String containing one instance of each code unit valid in uriReserved plus "#". // 4. Return Decode(uriString, reservedURISet). - return Decode(thread, uri_string, IsInReservedURISet); + return Decode(thread, uriString, IsInReservedURISet); } JSTaggedValue global::EncodeURI(EcmaRuntimeCallInfo *argv) @@ -477,17 +477,17 @@ JSTaggedValue global::EncodeURI(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, EncodeURI); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let uriString be ToString(uri). // 2. ReturnIfAbrupt(uriString). - [[maybe_unused]] JSHandle uri_string = + [[maybe_unused]] JSHandle uriString = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 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, uri_string, IsInUnescapedURISet); + return Encode(thread, uriString, IsInUnescapedURISet); } JSTaggedValue global::DecodeURIComponent(EcmaRuntimeCallInfo *argv) @@ -495,16 +495,16 @@ JSTaggedValue global::DecodeURIComponent(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, DecodeURIComponent); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let componentString be ToString(encodedURIComponent). // 2. ReturnIfAbrupt(componentString). - [[maybe_unused]] JSHandle component_string = + [[maybe_unused]] JSHandle componentString = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let reservedURIComponentSet be the empty String. // 4. Return Decode(componentString, reservedURIComponentSet). - return Decode(thread, component_string, []([[maybe_unused]] uint16_t unused) { return false; }); + return Decode(thread, componentString, []([[maybe_unused]] uint16_t unused) { return false; }); } JSTaggedValue global::EncodeURIComponent(EcmaRuntimeCallInfo *argv) @@ -512,36 +512,36 @@ JSTaggedValue global::EncodeURIComponent(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, EncodeURIComponent); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let componentString be ToString(uriComponent). // 2. ReturnIfAbrupt(componentString). - [[maybe_unused]] JSHandle component_string = + [[maybe_unused]] JSHandle componentString = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let unescapedURIComponentSet be a String containing one instance of each code unit valid in uriUnescaped. // 4. Return Encode(componentString, unescapedURIComponentSet). - return Encode(thread, component_string, IsUnescapedURI); + return Encode(thread, componentString, IsUnescapedURI); } // Runtime Semantics -JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set) +JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriFunc isInUriSet) { // 1. Let strLen be the number of code units in string. - uint32_t str_len = str->GetLength(); + uint32_t strLen = str->GetLength(); // 2. Let R be the empty String. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string res_str; + std::u16string resStr; // 3. Let k be 0. // 4. Repeat uint32_t k = 0; while (true) { // a. If k equals strLen, return R. - 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(); + if (k == strLen) { + auto *uint16tData = reinterpret_cast(resStr.data()); + int32_t resSize = resStr.size(); + return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue(); } // b. Let C be the code unit at index k within string. @@ -550,9 +550,9 @@ JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriF // ii. Let R be a new String value computed by concatenating the previous value of R and S. // d. Else C is not in unescapedSet, uint16_t cc = str->At(k); - if (is_in_uri_set(cc)) { - std::u16string s_str = StringHelper::Utf16ToU16String(&cc, 1); - res_str.append(s_str); + if (isInUriSet(cc)) { + std::u16string sStr = StringHelper::Utf16ToU16String(&cc, 1); + resStr.append(sStr); } else { // i. If the code unit value of C is not less than 0xDC00 and not greater than 0xDFFF, // throw a URIError exception. @@ -574,7 +574,7 @@ JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriF vv = cc; } else { k++; - if (k == str_len) { + if (k == strLen) { THROW_URI_ERROR_AND_RETURN(thread, "k is invalid", JSTaggedValue::Exception()); } uint16_t kc = str->At(k); @@ -595,16 +595,16 @@ JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriF // 3. Let R be a new String value computed by concatenating the previous value of R and S. // 4. Increase j by 1. std::string oct = StringHelper::Utf32ToString(vv); - std::string hex_str("0123456789ABCDEF"); + std::string hexStr("0123456789ABCDEF"); uint32_t length = oct.length(); - std::stringstream tmp_str; + std::stringstream tmpStr; for (uint32_t j = 0; j < length; j++) { uint8_t joct = oct.at(j); - tmp_str << '%' << hex_str.at((joct >> 4U) & BIT_MASK) // NOLINT - << hex_str.at(joct & BIT_MASK); // 4: means shift right by 4 digits + tmpStr << '%' << hexStr.at((joct >> 4U) & BIT_MASK) // NOLINT + << hexStr.at(joct & BIT_MASK); // 4: means shift right by 4 digits } - res_str.append(StringHelper::StringToU16string(tmp_str.str())); + resStr.append(StringHelper::StringToU16string(tmpStr.str())); } // e. Increase k by 1. @@ -615,32 +615,32 @@ JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriF uint8_t GetValueFromTwoHex(uint16_t front, uint16_t behind) { ASSERT(IsHexDigits(front) && IsHexDigits(behind)); - std::u16string hex_string(u"0123456789ABCDEF"); + std::u16string hexString(u"0123456789ABCDEF"); - size_t idxf = StringHelper::FindFromU16ToUpper(hex_string, &front); - size_t idxb = StringHelper::FindFromU16ToUpper(hex_string, &behind); + size_t idxf = StringHelper::FindFromU16ToUpper(hexString, &front); + size_t idxb = StringHelper::FindFromU16ToUpper(hexString, &behind); uint8_t res = ((idxf << 4U) | idxb) & BIT_MASK_FF; // NOLINT 4: means shift left by 4 digits return res; } // Runtime Semantics -JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set) +JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriFunc isInUriSet) { // 1. Let strLen be the number of code units in string. - [[maybe_unused]] uint32_t str_len = str->GetLength(); + [[maybe_unused]] uint32_t strLen = str->GetLength(); // 2. Let R be the empty String. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string res_str; + std::u16string resStr; // 3. Let k be 0. // 4. Repeat uint32_t k = 0; while (true) { // a. If k equals strLen, return R. - 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(); + if (k == strLen) { + auto *uint16tData = reinterpret_cast(resStr.data()); + int32_t resSize = resStr.size(); + return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue(); } // b. Let C be the code unit at index k within string. @@ -657,20 +657,20 @@ JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriF // 3. Else C is in reservedSet, // a. Let S be the substring of string from index start to index k inclusive. uint16_t cc = str->At(k); - std::u16string s_str; + std::u16string sStr; if (cc != '%') { - if (cc == 0 && str_len == 1) { - JSHandle tmp_ecma_string = factory->NewFromUtf16Literal(&cc, 1); - return tmp_ecma_string.GetTaggedValue(); + if (cc == 0 && strLen == 1) { + JSHandle tmpEcmaString = factory->NewFromUtf16Literal(&cc, 1); + return tmpEcmaString.GetTaggedValue(); } - s_str = StringHelper::Utf16ToU16String(&cc, 1); + sStr = 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) >= str_len) { // 2: means plus 2 + if ((k + 2) >= strLen) { // 2: means plus 2 THROW_URI_ERROR_AND_RETURN(thread, "DecodeURI: The format of the URI to be parsed is incorrect", JSTaggedValue::Exception()); } @@ -679,19 +679,19 @@ JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriF JSTaggedValue::Exception()); } - 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); + uint16_t frontChar = str->At(k + 1); + uint16_t behindChar = str->At(k + 2); // 2: means plus 2 + uint8_t bb = GetValueFromTwoHex(frontChar, behindChar); k += 2; // 2: means plus 2 if ((bb & BIT_MASK_ONE) == 0) { - if (!is_in_uri_set(bb)) { - s_str = StringHelper::Utf8ToU16String(&bb, 1); + if (!isInUriSet(bb)) { + sStr = StringHelper::Utf8ToU16String(&bb, 1); if (bb == 0) { - return factory->NewFromUtf16Literal(reinterpret_cast(s_str.data()), 1) + return factory->NewFromUtf16Literal(reinterpret_cast(sStr.data()), 1) .GetTaggedValue(); } } else { - s_str = StringHelper::StringToU16string(StringHelper::SubString(str, start, k - start + 1)); + sStr = StringHelper::StringToU16string(StringHelper::SubString(str, start, k - start + 1)); } } else { // vii. Else the most significant bit in B is 1, @@ -733,18 +733,18 @@ JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriF std::vector oct = {bb}; // 5. If k + (3 × (n – 1)) is greater than or equal to strLen, throw a URIError exception. - if (k + (3 * (n - 1)) >= str_len) { // 3: means multiply by 3 + if (k + (3 * (n - 1)) >= strLen) { // 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 code_unit = str->At(k); + uint16_t codeUnit = 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 (!(code_unit == '%')) { + if (!(codeUnit == '%')) { THROW_URI_ERROR_AND_RETURN(thread, "DecodeURI: The format of the URI to be parsed is incorrect", JSTaggedValue::Exception()); } @@ -753,9 +753,9 @@ JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriF JSTaggedValue::Exception()); } - 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); + uint16_t frontChart = str->At(k + 1); + uint16_t behindChart = str->At(k + 2); // 2: means plus 2 + bb = GetValueFromTwoHex(frontChart, behindChart); // 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", @@ -776,23 +776,23 @@ JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriF } uint32_t vv = StringHelper::Utf8ToU32String(oct); if (vv < utf::DECODE_SECOND_FACTOR) { - if (!is_in_uri_set(vv)) { - s_str = StringHelper::Utf16ToU16String(reinterpret_cast(&vv), 1); + if (!isInUriSet(vv)) { + sStr = StringHelper::Utf16ToU16String(reinterpret_cast(&vv), 1); } else { - s_str = StringHelper::StringToU16string(StringHelper::SubString(str, start, k - start + 1)); + sStr = 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 - s_str = StringHelper::Append(StringHelper::Utf16ToU16String(&hv, 1), - StringHelper::Utf16ToU16String(&lv, 1)); + sStr = 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. - res_str.append(s_str); + resStr.append(sStr); k++; } } @@ -813,16 +813,16 @@ JSTaggedValue global::Print(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); BUILTINS_API_TRACE(thread, Global, Print); - uint32_t num_args = argv->GetArgsNumber(); - for (uint32_t i = 0; i < num_args; i++) { - JSHandle string_content = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, i)); + uint32_t numArgs = argv->GetArgsNumber(); + for (uint32_t i = 0; i < numArgs; i++) { + JSHandle stringContent = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - PrintString(thread, *string_content); + PrintString(thread, *stringContent); - if (i != num_args - 1) { + if (i != numArgs - 1) { std::cout << " "; } } @@ -834,7 +834,7 @@ JSTaggedValue global::Gc(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); ASSERT(thread != nullptr); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); BUILTINS_API_TRACE(thread, Global, Gc); thread->GetEcmaVM()->GetGC()->WaitForGCInManaged(GCTask(GCTaskCause::EXPLICIT_CAUSE)); @@ -843,23 +843,23 @@ JSTaggedValue global::Gc(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } -static GCTaskCause GCCauseFromString(JSThread *thread, const JSHandle &str_cause) +static GCTaskCause GCCauseFromString(JSThread *thread, const JSHandle &strCause) { auto young = thread->GlobalConstants()->GetHandledYoungGCString(); auto threshold = thread->GlobalConstants()->GetHandledThresholdGCString(); auto mixed = thread->GlobalConstants()->GetHandledMixedGCString(); auto full = thread->GlobalConstants()->GetHandledFullGCString(); - if (JSTaggedValue::StrictEqual(thread, young, str_cause)) { + if (JSTaggedValue::StrictEqual(thread, young, strCause)) { return GCTaskCause::YOUNG_GC_CAUSE; } - if (JSTaggedValue::StrictEqual(thread, threshold, str_cause)) { + if (JSTaggedValue::StrictEqual(thread, threshold, strCause)) { return GCTaskCause::HEAP_USAGE_THRESHOLD_CAUSE; } - if (JSTaggedValue::StrictEqual(thread, mixed, str_cause)) { + if (JSTaggedValue::StrictEqual(thread, mixed, strCause)) { return GCTaskCause::MIXED; } - if (JSTaggedValue::StrictEqual(thread, full, str_cause)) { + if (JSTaggedValue::StrictEqual(thread, full, strCause)) { return GCTaskCause::OOM_CAUSE; } return GCTaskCause::INVALID_CAUSE; @@ -880,48 +880,48 @@ JSTaggedValue global::StartGC(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); ASSERT(thread != nullptr); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); BUILTINS_API_TRACE(thread, Global, StartGC); - bool run_gc_in_place = Runtime::GetOptions().IsRunGcInPlace("ecmascript"); + bool runGcInPlace = Runtime::GetOptions().IsRunGcInPlace("ecmascript"); GCTaskCause reason = GCCauseFromString(thread, builtins_common::GetCallArg(argv, 0)); - JSHandle callback_fn = builtins_common::GetCallArg(argv, 1); + JSHandle callbackFn = builtins_common::GetCallArg(argv, 1); mem::GC *gc = thread->GetEcmaVM()->GetGC(); if (!gc->CheckGCCause(reason)) { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Invalid GC cause for this GC type"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } - G_GCTASK_TRACKER.InitIfNeeded(gc); + g_gGctaskTracker.InitIfNeeded(gc); auto task = MakePandaUnique(reason); - if (!callback_fn->IsUndefined()) { - if (!callback_fn->IsJSFunction()) { + if (!callbackFn->IsUndefined()) { + if (!callbackFn->IsJSFunction()) { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Invalid GC callback"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } - run_gc_in_place = true; - uintptr_t global_handle = - thread->GetEcmaGlobalStorage()->NewGlobalHandle(callback_fn.GetTaggedValue().GetRawData()); - G_GCTASK_TRACKER.SetCallbackForTask(task->GetId(), global_handle); + runGcInPlace = true; + uintptr_t globalHandle = + thread->GetEcmaGlobalStorage()->NewGlobalHandle(callbackFn.GetTaggedValue().GetRawData()); + g_gGctaskTracker.SetCallbackForTask(task->GetId(), globalHandle); } if (reason == GCTaskCause::YOUNG_GC_CAUSE) { - run_gc_in_place = true; + runGcInPlace = true; } - bool task_executed = false; + bool taskExecuted = false; uint32_t id = task->GetId(); - if (run_gc_in_place) { - task_executed = gc->WaitForGCInManaged(*task); + if (runGcInPlace) { + taskExecuted = gc->WaitForGCInManaged(*task); } else { - G_GCTASK_TRACKER.AddTaskId(id); - task_executed = gc->Trigger(std::move(task)); + g_gGctaskTracker.AddTaskId(id); + taskExecuted = gc->Trigger(std::move(task)); } - if (run_gc_in_place) { - return task_executed ? JSTaggedValue(0) : JSTaggedValue(-1); + if (runGcInPlace) { + return taskExecuted ? JSTaggedValue(0) : JSTaggedValue(-1); } - if (!task_executed) { - G_GCTASK_TRACKER.RemoveId(id); + if (!taskExecuted) { + g_gGctaskTracker.RemoveId(id); return JSTaggedValue(-1); } return JSTaggedValue(static_cast(id)); @@ -935,7 +935,7 @@ JSTaggedValue global::StartGC(EcmaRuntimeCallInfo *argv) JSTaggedValue global::WaitForFinishGC(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); BUILTINS_API_TRACE(thread, Global, WaitForFinishGC); JSHandle arg = builtins_common::GetCallArg(argv, 0); if (!arg->IsNumber()) { @@ -946,9 +946,9 @@ JSTaggedValue global::WaitForFinishGC(EcmaRuntimeCallInfo *argv) if (id <= 0) { return JSTaggedValue::Undefined(); } - ASSERT(G_GCTASK_TRACKER.IsInitialized()); + ASSERT(g_gGctaskTracker.IsInitialized()); ScopedNativeCodeThread s(thread); - while (G_GCTASK_TRACKER.HasId(static_cast(id))) { + while (g_gGctaskTracker.HasId(static_cast(id))) { constexpr uint64_t WAIT_TIME_MS = 10; os::thread::NativeSleep(WAIT_TIME_MS); } @@ -960,7 +960,7 @@ JSTaggedValue global::WaitForFinishGC(EcmaRuntimeCallInfo *argv) JSTaggedValue global::ScheduleGcAfterNthAlloc(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); BUILTINS_API_TRACE(thread, Global, ScheduleGcAfterNthAlloc); JSHandle arg = builtins_common::GetCallArg(argv, 0); if (!arg->IsInt()) { @@ -988,8 +988,8 @@ JSTaggedValue global::ScheduleGcAfterNthAlloc(EcmaRuntimeCallInfo *argv) ErrorType::TYPE_ERROR, "VM is running with unsupported GC trigger"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } - auto sched_trigger = reinterpret_cast(vm->GetGCTrigger()); - sched_trigger->ScheduleGc(reason, counter); + auto schedTrigger = reinterpret_cast(vm->GetGCTrigger()); + schedTrigger->ScheduleGc(reason, counter); return JSTaggedValue::Undefined(); } @@ -1004,8 +1004,8 @@ JSTaggedValue global::IsScheduledGcTriggered(EcmaRuntimeCallInfo *argv) if (trigger->GetType() != mem::GCTriggerType::ON_NTH_ALLOC) { return JSTaggedValue::Undefined(); } - auto sched_trigger = reinterpret_cast(vm->GetGCTrigger()); - return JSTaggedValue(sched_trigger->IsTriggered()); + auto schedTrigger = reinterpret_cast(vm->GetGCTrigger()); + return JSTaggedValue(schedTrigger->IsTriggered()); } JSTaggedValue global::AllocateArrayObject(EcmaRuntimeCallInfo *argv) @@ -1013,45 +1013,45 @@ JSTaggedValue global::AllocateArrayObject(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); ASSERT(thread != nullptr); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); BUILTINS_API_TRACE(thread, Global, AllocateArrayObject); - int64_t size_in_bytes = 0; + int64_t sizeInBytes = 0; if (builtins_common::GetCallArg(argv, 0)->IsInt()) { - size_in_bytes = builtins_common::GetCallArg(argv, 0)->GetInt(); + sizeInBytes = builtins_common::GetCallArg(argv, 0)->GetInt(); } else if (builtins_common::GetCallArg(argv, 0)->IsDouble()) { - size_in_bytes = builtins_common::GetCallArg(argv, 0)->GetDouble(); + sizeInBytes = builtins_common::GetCallArg(argv, 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 (size_in_bytes < 0) { + if (sizeInBytes < 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()); } - size_in_bytes = RoundUp(size_in_bytes, sizeof(TaggedType)) - JSArray::SIZE; + sizeInBytes = RoundUp(sizeInBytes, sizeof(TaggedType)) - JSArray::SIZE; - if (size_in_bytes < 0) { - size_in_bytes = 0; + if (sizeInBytes < 0) { + sizeInBytes = 0; } - uint32_t num_elements = size_in_bytes / sizeof(TaggedType); + uint32_t numElements = sizeInBytes / sizeof(TaggedType); JSHandle array = factory->NewJSArray(); - if (num_elements > 0) { - JSHandle elements = factory->NewTaggedArray(num_elements); + if (numElements > 0) { + JSHandle elements = factory->NewTaggedArray(numElements); if (elements.IsEmpty()) { return JSTaggedValue::Exception(); } array->SetElements(thread, elements); - array->SetArrayLength(thread, num_elements); + array->SetArrayLength(thread, numElements); } return array.GetTaggedValue(); @@ -1074,7 +1074,7 @@ JSTaggedValue global::GetMarkQueue(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, GetMarkQueue); EcmaVM *vm = thread->GetEcmaVM(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle array = vm->GetFactory()->NewJSArray(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); size_t index = 0; @@ -1099,21 +1099,21 @@ JSTaggedValue gc_marker::MarkObjectRecursively(EcmaRuntimeCallInfo *argv) mem::GC *gc = thread->GetEcmaVM()->GetGC(); JSHandle arg = builtins_common::GetCallArg(argv, 0); if (!arg->IsHeapObject()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Argument is not an object", JSTaggedValue::Exception()); } ObjectHeader *obj = arg->GetHeapObject(); - PandaStack mark_stack; + PandaStack markStack; gc->MarkObject(obj); - mark_stack.push(obj); - while (!mark_stack.empty()) { - obj = mark_stack.top(); - mark_stack.pop(); + markStack.push(obj); + while (!markStack.empty()) { + obj = markStack.top(); + markStack.pop(); mem::ObjectHelpers::TraverseAllObjects( - obj, [gc, &mark_stack]([[maybe_unused]] ObjectHeader *object, ObjectHeader *ref) { + obj, [gc, &markStack]([[maybe_unused]] ObjectHeader *object, ObjectHeader *ref) { if (ref != nullptr && gc->MarkObjectIfNotMarked(ref)) { - mark_stack.push(ref); + markStack.push(ref); } }); } @@ -1127,41 +1127,41 @@ JSTaggedValue global::GetObjectSpaceType(EcmaRuntimeCallInfo *argv) ASSERT(thread != nullptr); BUILTINS_API_TRACE(thread, Global, GetObjectSpaceType); - JSHandle obj_handle = builtins_common::GetCallArg(argv, 0); - auto global_constants = thread->GlobalConstants(); - if (!obj_handle.GetTaggedValue().IsHeapObject()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle objHandle = builtins_common::GetCallArg(argv, 0); + auto globalConstants = thread->GlobalConstants(); + if (!objHandle.GetTaggedValue().IsHeapObject()) { + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Non Heap Object"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } - SpaceType obj_space_type = PoolManager::GetMmapMemPool()->GetSpaceTypeForAddr( - static_cast(obj_handle.GetTaggedValue().GetHeapObject())); - switch (obj_space_type) { + SpaceType objSpaceType = PoolManager::GetMmapMemPool()->GetSpaceTypeForAddr( + static_cast(objHandle.GetTaggedValue().GetHeapObject())); + switch (objSpaceType) { case SpaceType::SPACE_TYPE_OBJECT: - return GCSpecialisedObjectSpaceType(thread, obj_handle).GetTaggedValue(); + return GCSpecialisedObjectSpaceType(thread, objHandle).GetTaggedValue(); case SpaceType::SPACE_TYPE_HUMONGOUS_OBJECT: - return global_constants->GetHandledHumongousObjectSpaceString().GetTaggedValue(); + return globalConstants->GetHandledHumongousObjectSpaceString().GetTaggedValue(); case SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT: - return global_constants->GetHandledNonMovableObjectSpaceString().GetTaggedValue(); + return globalConstants->GetHandledNonMovableObjectSpaceString().GetTaggedValue(); default: - return global_constants->GetHandledUndefinedSpaceString().GetTaggedValue(); + return globalConstants->GetHandledUndefinedSpaceString().GetTaggedValue(); } } -JSHandle GCSpecialisedObjectSpaceType(JSThread *thread, const JSHandle &obj_handle) +JSHandle GCSpecialisedObjectSpaceType(JSThread *thread, const JSHandle &objHandle) { - auto global_constants = thread->GlobalConstants(); + auto globalConstants = thread->GlobalConstants(); if (!thread->GetEcmaVM()->GetGC()->IsGenerational()) { - return global_constants->GetHandledObjectSpaceString(); + return globalConstants->GetHandledObjectSpaceString(); } - auto heap_manager = thread->GetEcmaVM()->GetHeapManager(); - if (heap_manager->IsObjectInYoungSpace(obj_handle.GetTaggedValue().GetHeapObject())) { - return global_constants->GetHandledYoungSpaceString(); + auto heapManager = thread->GetEcmaVM()->GetHeapManager(); + if (heapManager->IsObjectInYoungSpace(objHandle.GetTaggedValue().GetHeapObject())) { + return globalConstants->GetHandledYoungSpaceString(); } - return global_constants->GetHandledTenuredSpaceString(); + return globalConstants->GetHandledTenuredSpaceString(); } JSTaggedValue global::PinObject(EcmaRuntimeCallInfo *argv) @@ -1173,14 +1173,14 @@ JSTaggedValue global::PinObject(EcmaRuntimeCallInfo *argv) if (arg->IsHeapObject()) { auto *gc = vm->GetGC(); if (!gc->IsPinningSupported()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle err = vm->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Current GC does not support pinning"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } vm->GetHeapManager()->PinObject(arg->GetHeapObject()); } else { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(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()); } @@ -1196,7 +1196,7 @@ JSTaggedValue global::UnpinObject(EcmaRuntimeCallInfo *argv) if (arg->IsHeapObject()) { vm->GetHeapManager()->UnpinObject(arg->GetHeapObject()); } else { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(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()); } @@ -1207,22 +1207,22 @@ JSTaggedValue global::GetObjectAddress(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, GetObjectAddress); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - PandaStringStream addr_stream; - addr_stream << builtins_common::GetCallArg(argv, 0)->GetHeapObject(); - return thread->GetEcmaVM()->GetFactory()->NewFromString(addr_stream.str()).GetTaggedValue(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + PandaStringStream addrStream; + addrStream << builtins_common::GetCallArg(argv, 0)->GetHeapObject(); + return thread->GetEcmaVM()->GetFactory()->NewFromString(addrStream.str()).GetTaggedValue(); } JSTaggedValue global::CallJsBoundFunction(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, CallJsBoundFunction); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // argv contains jsfunc, this, arg1,... - JSHandle bound_func(builtins_common::GetConstructor(argv)); - JSHandle this_obj(thread, bound_func->GetBoundThis()); - argv->SetThis(this_obj.GetTaggedValue()); + JSHandle boundFunc(builtins_common::GetConstructor(argv)); + JSHandle thisObj(thread, boundFunc->GetBoundThis()); + argv->SetThis(thisObj.GetTaggedValue()); return SlowRuntimeHelper::CallBoundFunction(argv); } @@ -1230,7 +1230,7 @@ JSTaggedValue global::CallJsProxy(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, CallJsProxy); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // argv contains js_proxy, this, arg1,... JSHandle proxy(builtins_common::GetConstructor(argv)); if (!proxy->IsCallable()) { @@ -1245,7 +1245,7 @@ JSTaggedValue global::CallJsProxy(EcmaRuntimeCallInfo *argv) JSTaggedValue global::StartRuntimeStat(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // start vm runtime stat statistic thread->GetEcmaVM()->SetRuntimeStatEnable(true); return JSTaggedValue::Undefined(); @@ -1254,7 +1254,7 @@ JSTaggedValue global::StartRuntimeStat(EcmaRuntimeCallInfo *argv) JSTaggedValue global::StopRuntimeStat(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // start vm runtime stat statistic thread->GetEcmaVM()->SetRuntimeStatEnable(false); return JSTaggedValue::Undefined(); diff --git a/runtime/builtins/builtins_iterator.cpp b/runtime/builtins/builtins_iterator.cpp index 7f779303f44993764dbf6a642b238c91eec67c26..ce98e99b7b9fd2693cb813b51155bda3391567f6 100644 --- a/runtime/builtins/builtins_iterator.cpp +++ b/runtime/builtins/builtins_iterator.cpp @@ -34,10 +34,10 @@ JSTaggedValue iterator::proto::Return(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), IteratorPrototype, Return); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle value = builtins_common::GetCallArg(argv, 0); - JSHandle iter_result = JSIterator::CreateIterResultObject(thread, value, true); - return iter_result.GetTaggedValue(); + JSHandle iterResult = JSIterator::CreateIterResultObject(thread, value, true); + return iterResult.GetTaggedValue(); } JSTaggedValue iterator::proto::Iterator(EcmaRuntimeCallInfo *argv) diff --git a/runtime/builtins/builtins_json.cpp b/runtime/builtins/builtins_json.cpp index b074e3697b548fea73c3e9916f543028ab0b0a98..868893ddce61784b8b0de03b003d2f54b05272a2 100644 --- a/runtime/builtins/builtins_json.cpp +++ b/runtime/builtins/builtins_json.cpp @@ -31,27 +31,26 @@ JSTaggedValue json::Parse(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Json, Parse); ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); uint32_t argc = argv->GetArgsNumber(); if (argc == 0) { - 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 syntaxError = factory->GetJSError(ecmascript::base::ErrorType::SYNTAX_ERROR, "arg is empty"); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception()); } JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSHandle parse_string = JSTaggedValue::ToString(thread, msg); + JSHandle parseString = JSTaggedValue::ToString(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle result; - if (parse_string->IsUtf8()) { + if (parseString->IsUtf8()) { panda::ecmascript::base::JsonParser parser(thread); - result = parser.ParseUtf8(*parse_string); + result = parser.ParseUtf8(*parseString); } else { panda::ecmascript::base::JsonParser parser(thread); - result = parser.ParseUtf16(*parse_string); + result = parser.ParseUtf16(*parseString); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -59,17 +58,17 @@ JSTaggedValue json::Parse(EcmaRuntimeCallInfo *argv) if (argc == 2) { // 2: 2 args reviver = builtins_common::GetCallArg(argv, 1).GetTaggedValue(); if (reviver.IsCallable()) { - JSHandle callbackfn_handle(thread, reviver); + JSHandle callbackfnHandle(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 root_name(factory->GetEmptyString()); + JSHandle rootName(factory->GetEmptyString()); // Perform ! CreateDataPropertyOrThrow(root, rootName, unfiltered). - bool success = JSObject::CreateDataProperty(thread, root, root_name, result); + bool success = JSObject::CreateDataProperty(thread, root, rootName, result); if (success) { - result = base::Internalize::InternalizeJsonProperty(thread, root, root_name, callbackfn_handle); + result = base::Internalize::InternalizeJsonProperty(thread, root, rootName, callbackfnHandle); } } } @@ -82,7 +81,7 @@ JSTaggedValue json::Stringify(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Json, Parse); ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); uint32_t argc = argv->GetArgsNumber(); JSTaggedValue value = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); @@ -96,11 +95,11 @@ JSTaggedValue json::Stringify(EcmaRuntimeCallInfo *argv) gap = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD).GetTaggedValue(); } - JSHandle handle_value(thread, value); - JSHandle handle_replacer(thread, replacer); - JSHandle handle_gap(thread, gap); + JSHandle handleValue(thread, value); + JSHandle handleReplacer(thread, replacer); + JSHandle handleGap(thread, gap); panda::ecmascript::base::JsonStringifier stringifier(thread); - JSHandle result = stringifier.Stringify(handle_value, handle_replacer, handle_gap); + JSHandle result = stringifier.Stringify(handleValue, handleReplacer, handleGap); return result.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_locale.cpp b/runtime/builtins/builtins_locale.cpp index c5bbdb240dba5cea0579a4ce8def1e418b0f9ee9..456c73451232c12ecaa9425ed37fd6e1dc7d3849 100644 --- a/runtime/builtins/builtins_locale.cpp +++ b/runtime/builtins/builtins_locale.cpp @@ -26,19 +26,19 @@ JSTaggedValue locale::LocaleConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new_target is undefined", JSTaggedValue::Exception()); } // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, %LocalePrototype%, internalSlotsList). JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle locale = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. If Type(tag) is not String or Object, throw a TypeError exception. @@ -51,27 +51,27 @@ JSTaggedValue locale::LocaleConstructor(EcmaRuntimeCallInfo *argv) // a.Let tag be tag.[[Locale]]. // 9. Else, // a.Let tag be ? ToString(tag). - JSHandle locale_string = factory->GetEmptyString(); + JSHandle localeString = factory->GetEmptyString(); if (!tag->IsJSLocale()) { - locale_string = JSTaggedValue::ToString(thread, tag); + localeString = JSTaggedValue::ToString(thread, tag); } else { - icu::Locale *icu_locale = (JSHandle::Cast(tag))->GetIcuLocale(); - locale_string = JSLocale::ToLanguageTag(thread, *icu_locale); + icu::Locale *icuLocale = (JSHandle::Cast(tag))->GetIcuLocale(); + localeString = JSLocale::ToLanguageTag(thread, *icuLocale); } // 10. If options is undefined, then // a.Let options be ! ObjectCreate(null). // 11. Else // a.Let options be ? ToObject(options). JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle options_obj; + JSHandle optionsObj; if (options->IsUndefined()) { - options_obj = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); + optionsObj = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); } else { - options_obj = JSTaggedValue::ToObject(thread, options); + optionsObj = JSTaggedValue::ToObject(thread, options); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle result = JSLocale::InitializeLocale(thread, locale, locale_string, options_obj); + JSHandle result = JSLocale::InitializeLocale(thread, locale, localeString, optionsObj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -98,9 +98,9 @@ JSTaggedValue locale::proto::Maximize(EcmaRuntimeCallInfo *argv) ASSERT(!source.isBogus()); // 4. Return ! Construct(%Locale%, maximal). - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle ctor = env->GetLocaleFunction(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); @@ -133,9 +133,9 @@ JSTaggedValue locale::proto::Minimize(EcmaRuntimeCallInfo *argv) [[maybe_unused]] auto res = source.toLanguageTag(status); // 4. Return ! Construct(%Locale%, minimal). - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle ctor = env->GetLocaleFunction(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); @@ -173,9 +173,9 @@ JSTaggedValue locale::proto::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 icu_locale = icu::Locale::createFromName(locale->GetIcuLocale()->getBaseName()); - JSHandle base_name = JSLocale::ToLanguageTag(thread, icu_locale); - return base_name.GetTaggedValue(); + icu::Locale icuLocale = icu::Locale::createFromName(locale->GetIcuLocale()->getBaseName()); + JSHandle baseName = JSLocale::ToLanguageTag(thread, icuLocale); + return baseName.GetTaggedValue(); } // 10.3.7 get Intl.Locale.prototype.calendar @@ -209,8 +209,8 @@ JSTaggedValue locale::proto::GetCaseFirst(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[CaseFirst]]. JSHandle locale = JSHandle::Cast(loc); - JSHandle case_first = JSLocale::NormalizeKeywordValue(thread, locale, "kf"); - return case_first.GetTaggedValue(); + JSHandle caseFirst = JSLocale::NormalizeKeywordValue(thread, locale, "kf"); + return caseFirst.GetTaggedValue(); } // 10.3.9 get Intl.Locale.prototype.collation @@ -243,8 +243,8 @@ JSTaggedValue locale::proto::GetHourCycle(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[HourCycle]]. JSHandle locale = JSHandle::Cast(loc); - JSHandle hour_cycle = JSLocale::NormalizeKeywordValue(thread, locale, "hc"); - return hour_cycle.GetTaggedValue(); + JSHandle hourCycle = JSLocale::NormalizeKeywordValue(thread, locale, "hc"); + return hourCycle.GetTaggedValue(); } // 10.3.11 get Intl.Locale.prototype.numeric @@ -261,9 +261,9 @@ JSTaggedValue locale::proto::GetNumeric(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[Numeric]]. JSHandle locale = JSHandle::Cast(loc); - icu::Locale *icu_locale = locale->GetIcuLocale(); + icu::Locale *icuLocale = locale->GetIcuLocale(); UErrorCode status = U_ZERO_ERROR; - auto numeric = icu_locale->getUnicodeKeywordValue("kn", status); + auto numeric = icuLocale->getUnicodeKeywordValue("kn", status); JSTaggedValue result = (numeric == "true") ? JSTaggedValue::True() : JSTaggedValue::False(); return result; } @@ -281,8 +281,8 @@ JSTaggedValue locale::proto::GetNumberingSystem(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[NumberingSystem]]. JSHandle locale = JSHandle::Cast(loc); - JSHandle numbering_system = JSLocale::NormalizeKeywordValue(thread, locale, "nu"); - return numbering_system.GetTaggedValue(); + JSHandle numberingSystem = JSLocale::NormalizeKeywordValue(thread, locale, "nu"); + return numberingSystem.GetTaggedValue(); } // 10.3.13 get Intl.Locale.prototype.language @@ -345,9 +345,9 @@ JSTaggedValue locale::proto::GetRegion(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. Let loc be the this value. JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). @@ -363,7 +363,7 @@ JSTaggedValue locale::proto::GetRegion(EcmaRuntimeCallInfo *argv) // unicode_language_id. PandaString region = locale->GetIcuLocale()->getCountry(); if (region.empty()) { - return global_const->GetUndefined(); + return globalConst->GetUndefined(); } return factory->NewFromString(region).GetTaggedValue(); } diff --git a/runtime/builtins/builtins_map.cpp b/runtime/builtins/builtins_map.cpp index c4bd3e95623c3060d5677eae7b6200ccc8772b87..31043af5743d5551964709fc173bcf300b59d980 100644 --- a/runtime/builtins/builtins_map.cpp +++ b/runtime/builtins/builtins_map.cpp @@ -30,24 +30,24 @@ JSTaggedValue map::MapConstructor(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, MapConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let Map be OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", «‍[[MapData]]» ). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle map = JSHandle::Cast(obj); // 4.Set map’s [[MapData]] internal slot to a new empty List. - JSHandle linked_map = LinkedHashMap::Create(thread); - map->SetLinkedMap(thread, linked_map); + JSHandle linkedMap = LinkedHashMap::Create(thread); + map->SetLinkedMap(thread, linkedMap); // 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. @@ -60,8 +60,8 @@ JSTaggedValue map::MapConstructor(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "iterable is not object", JSTaggedValue::Exception()); } // Let adder be Get(map, "set"). - JSHandle adder_key(factory->NewFromCanBeCompressString("set")); - JSHandle adder = JSObject::GetProperty(thread, JSHandle(map), adder_key).GetValue(); + JSHandle adderKey(factory->NewFromCanBeCompressString("set")); + JSHandle adder = JSObject::GetProperty(thread, JSHandle(map), adderKey).GetValue(); // ReturnIfAbrupt(adder). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue()); JSTaggedValue result = @@ -75,7 +75,7 @@ JSTaggedValue map::proto::Set(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -97,7 +97,7 @@ JSTaggedValue map::proto::Clear(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Clear); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); @@ -116,7 +116,7 @@ JSTaggedValue map::proto::Delete(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. @@ -135,19 +135,19 @@ JSTaggedValue map::proto::Has(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } - JSHandle js_map(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle jsMap(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = builtins_common::GetCallArg(argv, 0); bool flag = false; if (JSMap::IsKey(key.GetTaggedValue())) { int hash = LinkedHash::Hash(key.GetTaggedValue()); - flag = js_map->Has(key.GetTaggedValue(), hash); + flag = jsMap->Has(key.GetTaggedValue(), hash); } return builtins_common::GetTaggedBoolean(flag); } @@ -157,19 +157,19 @@ JSTaggedValue map::proto::Get(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Get); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } - JSHandle js_map(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle jsMap(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = builtins_common::GetCallArg(argv, 0); JSTaggedValue value = JSTaggedValue::Undefined(); if (JSMap::IsKey(key.GetTaggedValue())) { int hash = LinkedHash::Hash(key.GetTaggedValue()); - value = js_map->Get(key.GetTaggedValue(), hash); + value = jsMap->Get(key.GetTaggedValue(), hash); } return value; } @@ -178,7 +178,7 @@ JSTaggedValue map::proto::Get(EcmaRuntimeCallInfo *argv) JSTaggedValue map::proto::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -194,21 +194,21 @@ JSTaggedValue map::proto::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 this_arg = builtins_common::GetCallArg(argv, 1); + JSHandle thisArg = builtins_common::GetCallArg(argv, 1); // composed arguments JSHandle iter(factory->NewJSMapIterator(map, IterationKind::KEY_AND_VALUE)); - JSHandle key_index(thread, JSTaggedValue(0)); - JSHandle value_index(thread, JSTaggedValue(1)); + JSHandle keyIndex(thread, JSTaggedValue(0)); + JSHandle valueIndex(thread, JSTaggedValue(1)); JSHandle result = JSIterator::IteratorStep(thread, iter); while (!result->IsFalse()) { RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result.GetTaggedValue()); - 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(); + JSHandle iterValue(JSIterator::IteratorValue(thread, result)); + JSHandle key = JSObject::GetProperty(thread, iterValue, keyIndex).GetValue(); + JSHandle value = JSObject::GetProperty(thread, iterValue, valueIndex).GetValue(); // Let funcResult be Call(callbackfn, T, «e, e, S»). - auto info = NewRuntimeCallInfo(thread, func, this_arg, JSTaggedValue::Undefined(), 3); + auto info = NewRuntimeCallInfo(thread, func, thisArg, JSTaggedValue::Undefined(), 3); info->SetCallArgs(value, key, JSHandle(map)); JSTaggedValue ret = JSFunction::Call(info.Get()); // 3: three args // returnIfAbrupt @@ -230,15 +230,15 @@ JSTaggedValue map::proto::GetSize(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, GetSize); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } - JSMap *js_map = JSMap::Cast(*JSTaggedValue::ToObject(thread, self)); - int count = js_map->GetSize(); + JSMap *jsMap = JSMap::Cast(*JSTaggedValue::ToObject(thread, self)); + int count = jsMap->GetSize(); return JSTaggedValue(count); } @@ -247,7 +247,7 @@ JSTaggedValue map::proto::Entries(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::KEY_AND_VALUE); return iter.GetTaggedValue(); @@ -258,7 +258,7 @@ JSTaggedValue map::proto::Keys(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::KEY); return iter.GetTaggedValue(); @@ -269,7 +269,7 @@ JSTaggedValue map::proto::Values(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), MapPrototype, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::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 5072f4f013c8e9d26fc5731f114fd26279a5eb73..3631f3aef59b5023c14294c89db951063bc060e1 100644 --- a/runtime/builtins/builtins_math.cpp +++ b/runtime/builtins/builtins_math.cpp @@ -29,16 +29,16 @@ JSTaggedValue math::Abs(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Abs); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - if (number_value.IsDouble()) { + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + if (numberValue.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 builtins_common::GetTaggedDouble(std::fabs(number_value.GetDouble())); + return builtins_common::GetTaggedDouble(std::fabs(numberValue.GetDouble())); } // if number_value is int,boolean,null, deal in this case - return builtins_common::GetTaggedInt(std::abs(number_value.GetInt())); + return builtins_common::GetTaggedInt(std::abs(numberValue.GetInt())); } // 20.2.2.2 @@ -47,10 +47,10 @@ JSTaggedValue math::Acos(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Acos); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Acosh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Acosh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (value >= 1) { result = std::acosh(value); @@ -82,10 +82,10 @@ JSTaggedValue math::Asin(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Asin); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (value >= -1 && value <= 1) { result = std::asin(value); @@ -99,10 +99,10 @@ JSTaggedValue math::Asinh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Asinh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; // value == -NaN, NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -117,10 +117,10 @@ JSTaggedValue math::Atan(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atan); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; // value == -NaN, NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -135,10 +135,10 @@ JSTaggedValue math::Atanh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atanh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (value >= -1 && value <= 1) { result = std::atanh(value); @@ -152,25 +152,25 @@ JSTaggedValue math::Atan2(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atan2); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg_y = builtins_common::GetCallArg(argv, 0); - JSHandle msg_x = builtins_common::GetCallArg(argv, 1); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle msgY = builtins_common::GetCallArg(argv, 0); + JSHandle msgX = builtins_common::GetCallArg(argv, 1); double result = ecmascript::base::NAN_VALUE; - JSTaggedNumber number_value_y = JSTaggedValue::ToNumber(thread, msg_y); - JSTaggedNumber number_value_x = JSTaggedValue::ToNumber(thread, msg_x); - double value_y = number_value_y.GetNumber(); - double value_x = number_value_x.GetNumber(); + JSTaggedNumber numberValueY = JSTaggedValue::ToNumber(thread, msgY); + JSTaggedNumber numberValueX = JSTaggedValue::ToNumber(thread, msgX); + double valueY = numberValueY.GetNumber(); + double valueX = numberValueX.GetNumber(); // y = +0 and x > +0, return +0 // y = -0 and x > +0, return -0 - if (value_y == 0 && value_x > 0) { - result = value_y; - } else if (std::isfinite(value_y) && value_x == std::numeric_limits::infinity()) { + if (valueY == 0 && valueX > 0) { + result = valueY; + } else if (std::isfinite(valueY) && valueX == 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 = value_y >= 0 ? 0 : -0.0; - } else if (!std::isnan(std::abs(value_y)) && !std::isnan(std::abs(value_x))) { + result = valueY >= 0 ? 0 : -0.0; + } else if (!std::isnan(std::abs(valueY)) && !std::isnan(std::abs(valueX))) { // If either x or y is NaN, the result is NaN - result = std::atan2(value_y, value_x); + result = std::atan2(valueY, valueX); } return builtins_common::GetTaggedDouble(result); } @@ -181,10 +181,10 @@ JSTaggedValue math::Cbrt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cbrt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Ceil(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Ceil); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, +infinite, -infinite,return value if (!std::isfinite(value)) { @@ -222,14 +222,14 @@ JSTaggedValue math::Clz32(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Clz32); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); constexpr int DEFAULT_VALUE = 32; JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); - auto tmp_value = std::abs(value); - auto result = number_value.ToUint32(); - if (!std::isfinite(tmp_value) || tmp_value == 0 || result == 0) { + 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) { // If value is NaN or -NaN, +infinite, -infinite, 0,return 32 return builtins_common::GetTaggedInt(DEFAULT_VALUE); } @@ -242,10 +242,10 @@ JSTaggedValue math::Cos(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cos); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Cosh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cosh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Exp(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Exp); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Expm1(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Expm1); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Floor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Floor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Fround(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Fround); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result; if (std::isnan(std::abs(value))) { // If result is NaN or -NaN, the result is NaN @@ -360,15 +360,15 @@ JSTaggedValue math::Hypot(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Hypot); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); double result = 0; double value = 0; - int arg_len = argv->GetArgsNumber(); - auto number_value = JSTaggedNumber(0); - for (int i = 0; i < arg_len; i++) { + int argLen = argv->GetArgsNumber(); + auto numberValue = JSTaggedNumber(0); + for (int i = 0; i < argLen; i++) { JSHandle msg = builtins_common::GetCallArg(argv, i); - number_value = JSTaggedValue::ToNumber(thread, msg); - value = number_value.GetNumber(); + numberValue = JSTaggedValue::ToNumber(thread, msg); + value = numberValue.GetNumber(); result = std::hypot(result, value); } return builtins_common::GetTaggedDouble(result); @@ -380,19 +380,19 @@ JSTaggedValue math::Imul(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Imul); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg1 = builtins_common::GetCallArg(argv, 0); JSHandle msg2 = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber number_value1 = JSTaggedValue::ToNumber(thread, msg1); - JSTaggedNumber number_value2 = JSTaggedValue::ToNumber(thread, msg2); - auto value1 = number_value1.GetNumber(); - auto value2 = number_value2.GetNumber(); + JSTaggedNumber numberValue1 = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber numberValue2 = JSTaggedValue::ToNumber(thread, msg2); + auto value1 = numberValue1.GetNumber(); + auto value2 = numberValue2.GetNumber(); if (!std::isfinite(value1) || !std::isfinite(value2)) { // If value is NaN or -NaN, +infinite, -infinite return builtins_common::GetTaggedInt(0); } - value1 = number_value1.ToInt32(); - value2 = number_value2.ToInt32(); + value1 = numberValue1.ToInt32(); + value2 = numberValue2.ToInt32(); // purposely ignoring overflow auto result = static_cast(static_cast(value1) * static_cast(value2)); return builtins_common::GetTaggedInt(result); @@ -404,10 +404,10 @@ JSTaggedValue math::Log(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Log1p(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log1p); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Log10(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log10); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Log2(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log2); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 math::Max(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Max); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - int arg_len = argv->GetArgsNumber(); - auto number_value = JSTaggedNumber(-ecmascript::base::POSITIVE_INFINITY); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + int argLen = argv->GetArgsNumber(); + auto numberValue = JSTaggedNumber(-ecmascript::base::POSITIVE_INFINITY); // If no arguments are given, the result is -inf auto result = JSTaggedNumber(-ecmascript::base::POSITIVE_INFINITY); - auto tmp_max = -ecmascript::base::POSITIVE_INFINITY; + auto tmpMax = -ecmascript::base::POSITIVE_INFINITY; auto value = -ecmascript::base::POSITIVE_INFINITY; - for (int i = 0; i < arg_len; i++) { + for (int i = 0; i < argLen; i++) { JSHandle msg = builtins_common::GetCallArg(argv, i); - number_value = JSTaggedValue::ToNumber(thread, msg); - value = number_value.GetNumber(); + numberValue = JSTaggedValue::ToNumber(thread, msg); + value = numberValue.GetNumber(); if (std::isnan(std::abs(value))) { // If any value is NaN, or -NaN, the max result is NaN - result = number_value; + result = numberValue; break; } - if (value > tmp_max) { - result = number_value; - tmp_max = value; - } else if (value == 0 && tmp_max == 0 && IsNegZero(tmp_max) && !IsNegZero(value)) { + if (value > tmpMax) { + result = numberValue; + tmpMax = value; + } else if (value == 0 && tmpMax == 0 && IsNegZero(tmpMax) && !IsNegZero(value)) { // if tmp_max is -0, value is 0, max is 0 - result = number_value; - tmp_max = value; + result = numberValue; + tmpMax = value; } } return result; @@ -516,29 +516,29 @@ JSTaggedValue math::Min(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Min); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - int arg_len = argv->GetArgsNumber(); - auto number_value = JSTaggedNumber(ecmascript::base::POSITIVE_INFINITY); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + int argLen = argv->GetArgsNumber(); + auto numberValue = JSTaggedNumber(ecmascript::base::POSITIVE_INFINITY); // If no arguments are given, the result is inf auto result = JSTaggedNumber(ecmascript::base::POSITIVE_INFINITY); - auto tmp_min = ecmascript::base::POSITIVE_INFINITY; + auto tmpMin = ecmascript::base::POSITIVE_INFINITY; auto value = ecmascript::base::POSITIVE_INFINITY; - for (int i = 0; i < arg_len; i++) { + for (int i = 0; i < argLen; i++) { JSHandle msg = builtins_common::GetCallArg(argv, i); - number_value = JSTaggedValue::ToNumber(thread, msg); - value = number_value.GetNumber(); + numberValue = JSTaggedValue::ToNumber(thread, msg); + value = numberValue.GetNumber(); if (std::isnan(std::abs(value))) { // If any value is NaN or -NaN, the min result is NaN - result = number_value; + result = numberValue; break; } - if (value < tmp_min) { - result = number_value; - tmp_min = value; - } else if (value == 0 && tmp_min == 0 && !IsNegZero(tmp_min) && IsNegZero(value)) { + if (value < tmpMin) { + result = numberValue; + tmpMin = value; + } else if (value == 0 && tmpMin == 0 && !IsNegZero(tmpMin) && IsNegZero(value)) { // if tmp_min is 0, value is -0, min is -0 - result = number_value; - tmp_min = value; + result = numberValue; + tmpMin = value; } } return result; @@ -550,14 +550,14 @@ JSTaggedValue math::Pow(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Pow); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg_x = builtins_common::GetCallArg(argv, 0); - JSHandle msg_y = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber number_value_x = JSTaggedValue::ToNumber(thread, msg_x); - JSTaggedNumber number_value_y = JSTaggedValue::ToNumber(thread, msg_y); - double value_x = number_value_x.GetNumber(); - double value_y = number_value_y.GetNumber(); - return base::NumberHelper::Pow(value_x, value_y); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle msgX = builtins_common::GetCallArg(argv, 0); + JSHandle msgY = builtins_common::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); } // 20.2.2.27 @@ -577,16 +577,16 @@ JSTaggedValue math::Round(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Round); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); auto result = ecmascript::base::NAN_VALUE; const double diff = 0.5; - double abs_value = std::abs(value); - if (!std::isfinite(abs_value) || abs_value == 0) { + double absValue = std::abs(value); + if (!std::isfinite(absValue) || absValue == 0) { // If value is NaN, +infinite, or -infinite, VRegisterTag is DOUBLE - if (!std::isnan(abs_value)) { + if (!std::isnan(absValue)) { // If value is NaN or -NaN, the result is default NaN, else is value result = value; } @@ -614,10 +614,10 @@ JSTaggedValue math::Sign(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sign); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); if (std::isnan(std::abs(value))) { return builtins_common::GetTaggedDouble(std::abs(value)); } @@ -636,10 +636,10 @@ JSTaggedValue math::Sin(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sin); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, the result is NaN if (std::isfinite(std::abs(value))) { @@ -654,10 +654,10 @@ JSTaggedValue math::Sinh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sinh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, the result is NaN if (!std::isnan(std::abs(value))) { @@ -672,10 +672,10 @@ JSTaggedValue math::Sqrt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sqrt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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) { @@ -690,10 +690,10 @@ JSTaggedValue math::Tan(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Tan); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, +infinite, -infinite, result is NaN if (std::isfinite(value)) { @@ -708,10 +708,10 @@ JSTaggedValue math::Tanh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Tanh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (!std::isnan(std::abs(value))) { result = std::tanh(value); @@ -725,10 +725,10 @@ JSTaggedValue math::Trunc(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Trunc); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); - double value = number_value.GetNumber(); + JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); + double value = numberValue.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 8d45d7e3cdbbe14a5194c80b900624a0dbf442cf..00e200ebd42121d93bf2d0c3ebf7ff2c35d45924 100644 --- a/runtime/builtins/builtins_number.cpp +++ b/runtime/builtins/builtins_number.cpp @@ -44,28 +44,28 @@ JSTaggedValue number::NumberConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, NumberConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = builtins_common::GetNewTarget(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle newTarget = builtins_common::GetNewTarget(argv); // 1. If no arguments were passed to this function invocation, let n be +0. - JSTaggedNumber number_value(0); + JSTaggedNumber numberValue(0); if (argv->GetArgsNumber() > 0) { // 2. Else, let n be ToNumber(value). - JSHandle number_input = builtins_common::GetCallArg(argv, 0); - number_value = JSTaggedValue::ToNumber(thread, number_input); + JSHandle numberInput = builtins_common::GetCallArg(argv, 0); + numberValue = JSTaggedValue::ToNumber(thread, numberInput); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 4. If NewTarget is undefined, return n. - if (new_target->IsUndefined()) { - return number_value; + if (newTarget->IsUndefined()) { + return numberValue; } // 5. Let O be OrdinaryCreateFromConstructor(NewTarget, "%NumberPrototype%", «[[NumberData]]» ). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle result = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor( - JSHandle::Cast(constructor), new_target); + JSHandle result = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(constructor), newTarget); // 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, number_value); + JSPrimitiveRef::Cast(*result)->SetValue(thread, numberValue); // 8. Return O. return result.GetTaggedValue(); } @@ -95,7 +95,7 @@ JSTaggedValue number::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 handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber(); // 3. Let integer be ToInteger(number). JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg); @@ -132,7 +132,7 @@ JSTaggedValue number::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 handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber(); // 3. Let integer be ToInteger(number). JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg); @@ -165,22 +165,22 @@ JSTaggedValue builtins::number::ParseFloat(EcmaRuntimeCallInfo *argv) if (msg->IsUndefined()) { return builtins_common::GetTaggedDouble(ecmascript::base::NAN_VALUE); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let inputString be ToString(string). - JSHandle number_string = JSTaggedValue::ToString(thread, msg); + JSHandle numberString = JSTaggedValue::ToString(thread, msg); // 2. ReturnIfAbrupt(inputString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (UNLIKELY(number_string->IsUtf16())) { - size_t len = utf::Utf16ToUtf8Size(number_string->GetDataUtf16(), number_string->GetLength()) - 1; + if (UNLIKELY(numberString->IsUtf16())) { + size_t len = utf::Utf16ToUtf8Size(numberString->GetDataUtf16(), numberString->GetLength()) - 1; PandaVector buf(len); - len = utf::ConvertRegionUtf16ToUtf8(number_string->GetDataUtf16(), buf.data(), number_string->GetLength(), len, - 0); + len = + utf::ConvertRegionUtf16ToUtf8(numberString->GetDataUtf16(), buf.data(), numberString->GetLength(), len, 0); auto str = Span(buf.data(), len); return ParseFloatStr(str); } - auto str = Span(number_string->GetDataUtf8(), number_string->GetUtf8Length() - 1); + auto str = Span(numberString->GetDataUtf8(), numberString->GetUtf8Length() - 1); return ParseFloatStr(str); } @@ -196,7 +196,7 @@ JSTaggedValue builtins::number::ParseInt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ParseInt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); JSHandle arg2 = builtins_common::GetCallArg(argv, 1); int32_t radix = 0; @@ -207,19 +207,19 @@ JSTaggedValue builtins::number::ParseInt(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 1. Let inputString be ToString(string). - JSHandle number_string = JSTaggedValue::ToString(thread, msg); + JSHandle numberString = JSTaggedValue::ToString(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (UNLIKELY(number_string->IsUtf16())) { - size_t len = utf::Utf16ToUtf8Size(number_string->GetDataUtf16(), number_string->GetLength()) - 1; + if (UNLIKELY(numberString->IsUtf16())) { + size_t len = utf::Utf16ToUtf8Size(numberString->GetDataUtf16(), numberString->GetLength()) - 1; PandaVector buf(len); - len = utf::ConvertRegionUtf16ToUtf8(number_string->GetDataUtf16(), buf.data(), number_string->GetLength(), len, - 0); + len = + utf::ConvertRegionUtf16ToUtf8(numberString->GetDataUtf16(), buf.data(), numberString->GetLength(), len, 0); auto str = Span(buf.data(), len); return ParseIntStr(str, radix); } - auto str = Span(number_string->GetDataUtf8(), number_string->GetUtf8Length() - 1); + auto str = Span(numberString->GetDataUtf8(), numberString->GetUtf8Length() - 1); return ParseIntStr(str, radix); } @@ -230,7 +230,7 @@ JSTaggedValue number::proto::ToExponential(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), NumberPrototype, ToExponential); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber value = ThisNumberValue(argv); // 2. ReturnIfAbrupt(x). @@ -238,7 +238,7 @@ JSTaggedValue number::proto::ToExponential(EcmaRuntimeCallInfo *argv) // 3. Let f be ToInteger(fractionDigits). JSHandle digits = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digits); + JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digits); // 5. ReturnIfAbrupt(f). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -261,7 +261,7 @@ JSTaggedValue number::proto::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 = digit_int.GetNumber(); + double fraction = digitInt.GetNumber(); if (digits->IsUndefined()) { fraction = -1; } else { @@ -278,38 +278,38 @@ JSTaggedValue number::proto::ToFixed(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), NumberPrototype, ToFixed); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(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 digit_argv = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digit_argv); - if (digit_argv->IsUndefined()) { - digit_int = JSTaggedNumber(0); + JSHandle digitArgv = builtins_common::GetCallArg(argv, 0); + JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digitArgv); + if (digitArgv->IsUndefined()) { + digitInt = JSTaggedNumber(0); } // 4. ReturnIfAbrupt(f). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double digit = digit_int.GetNumber(); + double digit = digitInt.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 value_number = value.GetNumber(); - if (std::isnan(value_number)) { + double valueNumber = value.GetNumber(); + if (std::isnan(valueNumber)) { return builtins_common::GetTaggedString(thread, "NaN"); } // 9. If x  1021, then // a. Let m = ToString(x). - const double first_no_fixed = 1e21; - if (value_number >= first_no_fixed) { + const double firstNoFixed = 1e21; + if (valueNumber >= firstNoFixed) { return value.ToString(thread).GetTaggedValue(); } - return NumberHelper::DoubleToFixed(thread, value_number, static_cast(digit)); + return NumberHelper::DoubleToFixed(thread, valueNumber, static_cast(digit)); } // 20.1.3.4 @@ -318,7 +318,7 @@ JSTaggedValue number::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, NumberPrototype, ToLocaleString); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber x = ThisNumberValue(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -326,14 +326,14 @@ JSTaggedValue number::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) JSHandle ctor = thread->GetEcmaVM()->GetGlobalEnv()->GetNumberFormatFunction(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); - JSHandle number_format = JSHandle::Cast(obj); + JSHandle numberFormat = JSHandle::Cast(obj); JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); + JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatNumeric(numberFormat, x). - JSHandle result = JSNumberFormat::FormatNumeric(thread, number_format, x); + JSHandle result = JSNumberFormat::FormatNumeric(thread, numberFormat, x); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -344,42 +344,42 @@ JSTaggedValue number::proto::ToPrecision(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), NumberPrototype, ToPrecision); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(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 digit_argv = builtins_common::GetCallArg(argv, 0); - if (digit_argv->IsUndefined()) { + JSHandle digitArgv = builtins_common::GetCallArg(argv, 0); + if (digitArgv->IsUndefined()) { return value.ToString(thread).GetTaggedValue(); } // 4. Let p be ToInteger(precision). - JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digit_argv); + JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digitArgv); // 5. ReturnIfAbrupt(p). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. If x is NaN, return the String "NaN". - double value_number = value.GetNumber(); - if (std::isnan(value_number)) { + double valueNumber = value.GetNumber(); + if (std::isnan(valueNumber)) { return builtins_common::GetTaggedString(thread, "NaN"); } // 9. If x = +infinity, then // a. Return the String that is the concatenation of s and "Infinity". - if (!std::isfinite(value_number)) { - if (value_number < 0) { + if (!std::isfinite(valueNumber)) { + if (valueNumber < 0) { return builtins_common::GetTaggedString(thread, "-Infinity"); } return builtins_common::GetTaggedString(thread, "Infinity"); } // If p < 1 or p > 21, throw a RangeError exception - double digit = digit_int.GetNumber(); + double digit = digitInt.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, value_number, static_cast(digit)); + return NumberHelper::DoubleToPrecision(thread, valueNumber, static_cast(digit)); } // 20.1.3.6 @@ -388,7 +388,7 @@ JSTaggedValue number::proto::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), NumberPrototype, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber value = ThisNumberValue(argv); // 2. ReturnIfAbrupt(x). @@ -397,13 +397,13 @@ JSTaggedValue number::proto::ToString(EcmaRuntimeCallInfo *argv) // 3. If radix is not present, let radixNumber be 10. // 4. Else if radix is undefined, let radixNumber be 10. double radix = ecmascript::base::DECIMAL; - JSHandle radix_value = builtins_common::GetCallArg(argv, 0); + JSHandle radixValue = builtins_common::GetCallArg(argv, 0); // 5. Else let radixNumber be ToInteger(radix). - if (!radix_value->IsUndefined()) { - JSTaggedNumber radix_number = JSTaggedValue::ToInteger(thread, radix_value); + if (!radixValue->IsUndefined()) { + JSTaggedNumber radixNumber = JSTaggedValue::ToInteger(thread, radixValue); // 6. ReturnIfAbrupt(x). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - radix = radix_number.GetNumber(); + radix = radixNumber.GetNumber(); } // 7. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception. @@ -415,20 +415,20 @@ JSTaggedValue number::proto::ToString(EcmaRuntimeCallInfo *argv) return value.ToString(thread).GetTaggedValue(); } - double value_number = value.GetNumber(); + double valueNumber = value.GetNumber(); // If x is NaN, return the String "NaN". - if (std::isnan(value_number)) { + if (std::isnan(valueNumber)) { return builtins_common::GetTaggedString(thread, "NaN"); } // If x = +infinity, then // Return the String that is the concatenation of s and "Infinity". - if (!std::isfinite(value_number)) { - if (value_number < 0) { + if (!std::isfinite(valueNumber)) { + if (valueNumber < 0) { return builtins_common::GetTaggedString(thread, "-Infinity"); } return builtins_common::GetTaggedString(thread, "Infinity"); } - return NumberHelper::DoubleToString(thread, value_number, static_cast(radix)); + return NumberHelper::DoubleToString(thread, valueNumber, static_cast(radix)); } // 20.1.3.7 diff --git a/runtime/builtins/builtins_number_format.cpp b/runtime/builtins/builtins_number_format.cpp index 603e57e9f9b68268040b6a9027a001c04140f00e..ab0a184f677cd62d047b89e2fce56e997bbbbc6c 100644 --- a/runtime/builtins/builtins_number_format.cpp +++ b/runtime/builtins/builtins_number_format.cpp @@ -32,15 +32,15 @@ JSTaggedValue number_format::NumberFormatConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { - new_target = constructor; + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { + newTarget = constructor; } // Let numberFormat be ? OrdinaryCreateFromConstructor(new_target, "%NumberFormatPrototype%", @@ -48,36 +48,36 @@ JSTaggedValue number_format::NumberFormatConstructor(EcmaRuntimeCallInfo *argv) // [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], // [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], // [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »). - JSHandle number_format = JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle numberFormat = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Perform ? InitializeNumberFormat(numberFormat, locales, options). JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); + JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let this be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::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 is_instance_of = JSObject::InstanceOf(thread, this_value, env->GetNumberFormatFunction()); + bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetNumberFormatFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (new_target->IsUndefined() && this_value->IsJSObject() && is_instance_of) { - PropertyDescriptor descriptor(thread, JSHandle::Cast(number_format), false, false, false); + if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { + PropertyDescriptor descriptor(thread, JSHandle::Cast(numberFormat), false, false, false); JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, this_value, key, descriptor); + JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return this_value.GetTaggedValue(); + return thisValue.GetTaggedValue(); } // 6. Return numberFormat. - return number_format.GetTaggedValue(); + return numberFormat.GetTaggedValue(); } // 13.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] ) @@ -86,16 +86,16 @@ JSTaggedValue number_format::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %NumberFormat%.[[AvailableLocales]]. - JSHandle available_locales = JSNumberFormat::GetAvailableLocales(thread); + JSHandle availableLocales = JSNumberFormat::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = builtins_common::GetCallArg(argv, 0); - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); + JSHandle result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -107,32 +107,32 @@ JSTaggedValue number_format::proto::GetFormat(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let nf be this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(nf) is not Object, throw a TypeError exception. - if (!this_value->IsJSObject()) { + if (!thisValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception()); } // 3. Let nf be ? UnwrapNumberFormat(nf). - JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, this_value); + JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (nf->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception()); } - JSHandle typped_nf = JSHandle::Cast(nf); - JSHandle bound_func(thread, typped_nf->GetBoundFormat()); + JSHandle typpedNf = JSHandle::Cast(nf); + JSHandle boundFunc(thread, typpedNf->GetBoundFormat()); // 4. If nf.[[BoundFormat]] is undefined, then // a. Let F be a new built-in function object as defined in Number Format Functions (12.1.4). // b. Set F.[[NumberFormat]] to nf. // c. Set nf.[[BoundFormat]] to F. - if (bound_func->IsUndefined()) { + if (boundFunc->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intl_bound_func = + JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction(reinterpret_cast(NumberFormatInternalFormatNumber)); - intl_bound_func->SetNumberFormat(thread, typped_nf); - typped_nf->SetBoundFormat(thread, intl_bound_func); + intlBoundFunc->SetNumberFormat(thread, typpedNf); + typpedNf->SetBoundFormat(thread, intlBoundFunc); } - return typped_nf->GetBoundFormat(); + return typpedNf->GetBoundFormat(); } // 13.4.4 Intl.NumberFormat.prototype.formatToParts ( date ) @@ -162,18 +162,18 @@ JSTaggedValue number_format::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let nf be this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(nf) is not Object, throw a TypeError exception. - if (!this_value->IsJSObject()) { + if (!thisValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. Let nf be ? UnwrapNumberFormat(nf). - JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, this_value); + JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let options be ! ObjectCreate(%ObjectPrototype%). - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); @@ -190,11 +190,11 @@ JSTaggedValue NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle intl_bound_func = + JSHandle intlBoundFunc = JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let nf be F.[[NumberFormat]]. - JSHandle nf(thread, intl_bound_func->GetNumberFormat()); + JSHandle nf(thread, intlBoundFunc->GetNumberFormat()); // 2. Assert: Type(nf) is Object and nf has an [[InitializedNumberFormat]] internal slot. ASSERT(nf->IsJSObject() && nf->IsJSNumberFormat()); // 3. If value is not provided, let value be undefined. diff --git a/runtime/builtins/builtins_object.cpp b/runtime/builtins/builtins_object.cpp index 10a3f218149cb5778dbb53e0198c9db80bc73d70..fe36604e722fc6d56d7875943f651021ada7abd8 100644 --- a/runtime/builtins/builtins_object.cpp +++ b/runtime/builtins/builtins_object.cpp @@ -44,24 +44,24 @@ JSTaggedValue object::ObjectConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ObjectConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); // 1.If NewTarget is neither undefined nor the active function, then // a.Return OrdinaryCreateFromConstructor(NewTarget, "%ObjectPrototype%"). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (!new_target->IsUndefined() && !(new_target.GetTaggedValue() == constructor.GetTaggedValue())) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (!newTarget->IsUndefined() && !(newTarget.GetTaggedValue() == constructor.GetTaggedValue())) { JSHandle obj = - ecma_vm->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), new_target); + ecmaVm->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), newTarget); return obj.GetTaggedValue(); } // 2.If value is null, undefined or not supplied, return ObjectCreate(%ObjectPrototype%). JSHandle value = builtins_common::GetCallArg(argv, 0); if (value->IsNull() || value->IsUndefined()) { - JSHandle obj = ecma_vm->GetFactory()->OrdinaryNewJSObjectCreate(env->GetObjectFunctionPrototype()); + JSHandle obj = ecmaVm->GetFactory()->OrdinaryNewJSObjectCreate(env->GetObjectFunctionPrototype()); return obj.GetTaggedValue(); } @@ -75,12 +75,12 @@ JSTaggedValue object::Assign(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Assign); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t num_args = argv->GetArgsNumber(); + uint32_t numArgs = argv->GetArgsNumber(); // 1.Let to be ToObject(target). JSHandle target = builtins_common::GetCallArg(argv, 0); - JSHandle to_assign = JSTaggedValue::ToObject(thread, target); + JSHandle toAssign = JSTaggedValue::ToObject(thread, target); // 2.ReturnIfAbrupt(to). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -94,7 +94,7 @@ JSTaggedValue object::Assign(EcmaRuntimeCallInfo *argv) // iii.ReturnIfAbrupt(keys). JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 1; i < num_args; i++) { + for (uint32_t i = 1; i < numArgs; i++) { JSHandle source = builtins_common::GetCallArg(argv, i); if (!source->IsNull() && !source->IsUndefined()) { JSHandle from = JSTaggedValue::ToObject(thread, source); @@ -112,8 +112,8 @@ JSTaggedValue object::Assign(EcmaRuntimeCallInfo *argv) // 2.ReturnIfAbrupt(propValue). // 3.Let status be Set(to, nextKey, propValue, true). // 4.ReturnIfAbrupt(status). - uint32_t keys_len = keys->GetLength(); - for (uint32_t j = 0; j < keys_len; j++) { + uint32_t keysLen = keys->GetLength(); + for (uint32_t j = 0; j < keysLen; j++) { PropertyDescriptor desc(thread); key.Update(keys->Get(j)); bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(from), key, desc); @@ -125,7 +125,7 @@ JSTaggedValue object::Assign(EcmaRuntimeCallInfo *argv) // ReturnIfAbrupt(prop_value) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(to_assign), key, value); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(toAssign), key, value); // ReturnIfAbrupt(status) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -134,7 +134,7 @@ JSTaggedValue object::Assign(EcmaRuntimeCallInfo *argv) } // 6.Return to. - return to_assign.GetTaggedValue(); + return toAssign.GetTaggedValue(); } // Runtime Semantics @@ -156,14 +156,14 @@ JSTaggedValue ObjectDefineProperties(JSThread *thread, const JSHandle handle_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(props)); + JSHandle handleKeys = 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 = handle_keys->GetLength(); + uint32_t length = handleKeys->GetLength(); [[maybe_unused]] JSHandle descriptors = factory->NewTaggedArray(2 * length); // 2: 2 means two element list @@ -176,24 +176,23 @@ JSTaggedValue ObjectDefineProperties(JSThread *thread, const JSHandle handle_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle handleKey(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; i++) { - PropertyDescriptor prop_desc(thread); - handle_key.Update(handle_keys->Get(i)); + PropertyDescriptor propDesc(thread); + handleKey.Update(handleKeys->Get(i)); - bool success = - JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(props), handle_key, prop_desc); + bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(props), handleKey, propDesc); // ReturnIfAbrupt(propDesc) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (success && prop_desc.IsEnumerable()) { - JSHandle desc_obj = - JSTaggedValue::GetProperty(thread, JSHandle::Cast(props), handle_key).GetValue(); + if (success && propDesc.IsEnumerable()) { + JSHandle descObj = + JSTaggedValue::GetProperty(thread, JSHandle::Cast(props), handleKey).GetValue(); // ReturnIfAbrupt(descObj) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); PropertyDescriptor desc(thread); - JSObject::ToPropertyDescriptor(thread, desc_obj, desc); + JSObject::ToPropertyDescriptor(thread, descObj, desc); // ReturnIfAbrupt(desc) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -203,7 +202,7 @@ JSTaggedValue ObjectDefineProperties(JSThread *thread, const JSHandleGetThread(), Object, Create); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.If Type(O) is neither Object nor Null, throw a TypeError exception. JSHandle obj = builtins_common::GetCallArg(argv, 0); if (!obj->IsECMAObject() && !obj->IsNull()) { @@ -231,16 +230,16 @@ JSTaggedValue object::Create(EcmaRuntimeCallInfo *argv) JSHandle properties = builtins_common::GetCallArg(argv, 1); // 2.Let obj be ObjectCreate(O). - JSHandle obj_create = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(obj); + JSHandle objCreate = 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(obj_create), properties); + return ObjectDefineProperties(thread, JSHandle::Cast(objCreate), properties); } // 4.Return obj. - return obj_create.GetTaggedValue(); + return objCreate.GetTaggedValue(); } // 19.1.2.3 Object.defineProperties ( O, Properties ) @@ -249,7 +248,7 @@ JSTaggedValue object::DefineProperties(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineProperties); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Return ObjectDefineProperties(O, Properties). return ObjectDefineProperties(thread, builtins_common::GetCallArg(argv, 0), builtins_common::GetCallArg(argv, 1)); } @@ -260,7 +259,7 @@ JSTaggedValue object::DefineProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.If Type(O) is not Object, throw a TypeError exception. JSHandle obj = builtins_common::GetCallArg(argv, 0); @@ -305,7 +304,7 @@ JSTaggedValue object::Freeze(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 2.Let status be SetIntegrityLevel( O, "frozen"). bool status = JSObject::SetIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::FROZEN); @@ -329,7 +328,7 @@ JSTaggedValue object::FromEntries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, SetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Perform ? RequireObjectCoercible(iterable). JSHandle iterable = builtins_common::GetCallArg(argv, 0); @@ -345,22 +344,22 @@ JSTaggedValue object::FromEntries(EcmaRuntimeCallInfo *argv) ASSERT(obj->IsExtensible()); // 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. - EcmaEntrypoint steps_define = base::ObjectHelper::CreateDataPropertyOnObject; + EcmaEntrypoint stepsDefine = base::ObjectHelper::CreateDataPropertyOnObject; // 5. Let lengthDefine be the number of non-optional parameters of the function definition in - size_t length_define = 2; + size_t lengthDefine = 2; // CreateDataPropertyOnObject Functions. // 6. Let adder be ! CreateBuiltinFunction(stepsDefine, lengthDefine, "", « »). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle adder = factory->CreateBuiltinFunction( - steps_define, length_define, JSHandle(factory->NewFromString("")), + stepsDefine, lengthDefine, JSHandle(factory->NewFromString("")), JSHandle(thread, JSTaggedValue::Undefined()), thread->GlobalConstants()->GetHandledUndefined()); // 7. Return ? AddEntriesFromIterable(obj, iterable, adder). - JSHandle adder_handler(thread, adder.GetTaggedValue()); + JSHandle adderHandler(thread, adder.GetTaggedValue()); JSTaggedValue result = - base::ObjectHelper::AddEntriesFromIterable(thread, JSHandle(obj), iterable, adder_handler); + base::ObjectHelper::AddEntriesFromIterable(thread, JSHandle(obj), iterable, adderHandler); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result); return result; } @@ -371,7 +370,7 @@ JSTaggedValue object::GetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDescriptor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let obj be ToObject(O). JSHandle func = builtins_common::GetCallArg(argv, 0); @@ -405,7 +404,7 @@ JSTaggedValue object::GetOwnPropertyDescriptors(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDescriptor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let obj be ? ToObject(O). JSHandle func = builtins_common::GetCallArg(argv, 0); @@ -413,7 +412,7 @@ JSTaggedValue object::GetOwnPropertyDescriptors(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let ownKeys be ? obj.[[OwnPropertyKeys]](). - JSHandle own_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(obj)); + JSHandle ownKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(obj)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let obj be ! OrdinaryObjectCreate(%Object.prototype%). @@ -422,9 +421,9 @@ JSTaggedValue object::GetOwnPropertyDescriptors(EcmaRuntimeCallInfo *argv) thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), constructor)); // 4. For each element key of ownKeys, do - for (ArraySizeT i = 0; i < own_keys->GetLength(); i++) { + for (ArraySizeT i = 0; i < ownKeys->GetLength(); i++) { // a. Let desc be ? obj.[[GetOwnProperty]](key). - JSHandle key(thread, own_keys->Get(i)); + JSHandle key(thread, ownKeys->Get(i)); PropertyDescriptor desc(thread); JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(obj), key, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -455,35 +454,35 @@ JSTaggedValue GetOwnPropertyKeys(JSThread *thread, const JSHandle RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3.Let keys be obj.[[OwnPropertyKeys]](). - JSHandle handle_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(obj)); + JSHandle handleKeys = 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 = handle_keys->GetLength(); - JSHandle name_list = factory->NewTaggedArray(length); + uint32_t length = handleKeys->GetLength(); + JSHandle nameList = factory->NewTaggedArray(length); // 6.Repeat for each element nextKey of keys in List order, - uint32_t copy_length = 0; + uint32_t copyLength = 0; switch (type) { case KeyType::STRING_TYPE: { for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = handle_keys->Get(i); + JSTaggedValue key = handleKeys->Get(i); if (key.IsString()) { - name_list->Set(thread, copy_length, key); - copy_length++; + nameList->Set(thread, copyLength, key); + copyLength++; } } break; } case KeyType::SYMBOL_TYPE: { for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = handle_keys->Get(i); + JSTaggedValue key = handleKeys->Get(i); if (key.IsSymbol()) { - name_list->Set(thread, copy_length, key); - copy_length++; + nameList->Set(thread, copyLength, key); + copyLength++; } } break; @@ -493,9 +492,9 @@ JSTaggedValue GetOwnPropertyKeys(JSThread *thread, const JSHandle } // 7.Return CreateArrayFromList(nameList). - JSHandle result_list = factory->CopyArray(name_list, length, copy_length); - JSHandle result_array = JSArray::CreateArrayFromList(thread, result_list); - return result_array.GetTaggedValue(); + JSHandle resultList = factory->CopyArray(nameList, length, copyLength); + JSHandle resultArray = JSArray::CreateArrayFromList(thread, resultList); + return resultArray.GetTaggedValue(); } // 19.1.2.7 Object.getOwnPropertyNames ( O ) @@ -503,7 +502,7 @@ JSTaggedValue object::GetOwnPropertyNames(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyNames); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); JSHandle obj = builtins_common::GetCallArg(argv, 0); KeyType type = KeyType::STRING_TYPE; @@ -516,7 +515,7 @@ JSTaggedValue object::GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertySymbols); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); JSHandle obj = builtins_common::GetCallArg(argv, 0); KeyType type = KeyType::SYMBOL_TYPE; @@ -530,7 +529,7 @@ JSTaggedValue object::GetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let obj be ToObject(O). JSHandle func = builtins_common::GetCallArg(argv, 0); @@ -565,7 +564,7 @@ JSTaggedValue object::IsExtensible(EcmaRuntimeCallInfo *argv) if (!obj.IsObject()) { return builtins_common::GetTaggedBoolean(false); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 2.Return IsExtensible(O). return builtins_common::GetTaggedBoolean(obj.IsExtensible(thread)); } @@ -581,7 +580,7 @@ JSTaggedValue object::IsFrozen(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 2.Return TestIntegrityLevel(O, "frozen"). bool status = JSObject::TestIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::FROZEN); @@ -600,7 +599,7 @@ JSTaggedValue object::IsSealed(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 2.Return TestIntegrityLevel(O, "sealed"). bool status = JSObject::TestIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::SEALED); @@ -613,7 +612,7 @@ JSTaggedValue object::Keys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let obj be ? ToObject(O). JSHandle msg = builtins_common::GetCallArg(argv, 0); @@ -623,11 +622,11 @@ JSTaggedValue object::Keys(EcmaRuntimeCallInfo *argv) // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key) ArraySizeT count = 0; - JSHandle name_list = JSObject::EnumerableOwnPropertyNames(thread, obj, PropertyKind::KEY, &count); + JSHandle nameList = JSObject::EnumerableOwnPropertyNames(thread, obj, PropertyKind::KEY, &count); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayFromList(nameList). - JSHandle result = JSArray::CreateArrayFromList(thread, name_list, count); + JSHandle result = JSArray::CreateArrayFromList(thread, nameList, count); return result.GetTaggedValue(); } @@ -641,7 +640,7 @@ JSTaggedValue object::PreventExtensions(EcmaRuntimeCallInfo *argv) if (!obj->IsECMAObject()) { return obj.GetTaggedValue(); } - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); // 2. Let status be O.[[PreventExtensions]](). bool status = JSTaggedValue::PreventExtensions(argv->GetThread(), obj); @@ -673,7 +672,7 @@ JSTaggedValue object::Seal(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 2. Let status be SetIntegrityLevel(O, "sealed"). JSHandle object = JSTaggedValue::ToObject(thread, msg); @@ -698,7 +697,7 @@ JSTaggedValue object::SetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, SetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be RequireObjectCoercible(O). JSHandle object = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetCallArg(argv, 0)); @@ -743,7 +742,7 @@ JSTaggedValue object::proto::HasOwnProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, HasOwnProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let P be ToPropertyKey(V). JSHandle prop = builtins_common::GetCallArg(argv, 0); JSHandle property = JSTaggedValue::ToPropertyKey(thread, prop); @@ -773,7 +772,7 @@ JSTaggedValue object::proto::IsPrototypeOf(EcmaRuntimeCallInfo *argv) if (!msg->IsECMAObject()) { return builtins_common::GetTaggedBoolean(false); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 2. Let O be ToObject(this value). JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); // 3. ReturnIfAbrupt(O). @@ -783,12 +782,12 @@ JSTaggedValue object::proto::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 msg_value = msg.GetTaggedValue(); - while (!msg_value.IsNull()) { - if (JSTaggedValue::SameValue(object.GetTaggedValue(), msg_value)) { + JSTaggedValue msgValue = msg.GetTaggedValue(); + while (!msgValue.IsNull()) { + if (JSTaggedValue::SameValue(object.GetTaggedValue(), msgValue)) { return builtins_common::GetTaggedBoolean(true); } - msg_value = JSObject::Cast(msg_value)->GetPrototype(thread); + msgValue = JSObject::Cast(msgValue)->GetPrototype(thread); } return builtins_common::GetTaggedBoolean(false); } @@ -799,7 +798,7 @@ JSTaggedValue object::proto::PropertyIsEnumerable(EcmaRuntimeCallInfo *argv) ASSERT(argv); // 1. Let P be ToPropertyKey(V). JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg = builtins_common::GetCallArg(argv, 0); JSHandle property = JSTaggedValue::ToPropertyKey(thread, msg); @@ -833,13 +832,13 @@ JSTaggedValue object::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, ToLocaleString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. JSHandle object = builtins_common::GetThis(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); // 2. Return Invoke(O, "toString"). - JSHandle callee_key = thread->GlobalConstants()->GetHandledToStringString(); + JSHandle calleeKey = thread->GlobalConstants()->GetHandledToStringString(); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), object, JSTaggedValue::Undefined(), argv->GetArgsNumber()); @@ -847,47 +846,47 @@ JSTaggedValue object::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) info->SetCallArg(argv->GetArgsNumber(), reinterpret_cast(argv->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS))); } - return JSFunction::Invoke(info.Get(), callee_key); + return JSFunction::Invoke(info.Get(), calleeKey); } JSTaggedValue GetBuiltinTag(JSThread *thread, const JSHandle &object) { BUILTINS_API_TRACE(thread, Object, GetBuiltinTag); // 4. Let isArray be IsArray(O). - bool is_array = object->IsJSArray(); + bool isArray = object->IsJSArray(); // 5. ReturnIfAbrupt(isArray). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle builtin_tag = factory->NewFromCanBeCompressString("Object"); + JSHandle builtinTag = factory->NewFromCanBeCompressString("Object"); // 6. If isArray is true, let builtinTag be "Array". - if (is_array) { - builtin_tag = factory->NewFromCanBeCompressString("Array"); + if (isArray) { + builtinTag = factory->NewFromCanBeCompressString("Array"); } else if (object->IsJSPrimitiveRef()) { // 7. Else, if O is an exotic String object, let builtinTag be "String". - JSPrimitiveRef *primitive_ref = JSPrimitiveRef::Cast(*object); - if (primitive_ref->IsString()) { - builtin_tag = factory->NewFromCanBeCompressString("String"); - } else if (primitive_ref->IsBoolean()) { + JSPrimitiveRef *primitiveRef = JSPrimitiveRef::Cast(*object); + if (primitiveRef->IsString()) { + builtinTag = factory->NewFromCanBeCompressString("String"); + } else if (primitiveRef->IsBoolean()) { // 11. Else, if O has a [[BooleanData]] internal slot, let builtinTag be "Boolean". - builtin_tag = factory->NewFromCanBeCompressString("Boolean"); - } else if (primitive_ref->IsNumber()) { + builtinTag = factory->NewFromCanBeCompressString("Boolean"); + } else if (primitiveRef->IsNumber()) { // 12. Else, if O has a [[NumberData]] internal slot, let builtinTag be "Number". - builtin_tag = factory->NewFromCanBeCompressString("Number"); + builtinTag = factory->NewFromCanBeCompressString("Number"); } } else if (object->IsArguments()) { - builtin_tag = factory->NewFromCanBeCompressString("Arguments"); + builtinTag = factory->NewFromCanBeCompressString("Arguments"); } else if (object->IsCallable()) { - builtin_tag = factory->NewFromCanBeCompressString("Function"); + builtinTag = factory->NewFromCanBeCompressString("Function"); } else if (object->IsJSError()) { - builtin_tag = factory->NewFromCanBeCompressString("Error"); + builtinTag = factory->NewFromCanBeCompressString("Error"); } else if (object->IsDate()) { - builtin_tag = factory->NewFromCanBeCompressString("Date"); + builtinTag = factory->NewFromCanBeCompressString("Date"); } else if (object->IsJSRegExp()) { - builtin_tag = factory->NewFromCanBeCompressString("RegExp"); + builtinTag = factory->NewFromCanBeCompressString("RegExp"); } // 15. Else, let builtinTag be "Object". - return builtin_tag.GetTaggedValue(); + return builtinTag.GetTaggedValue(); } // 19.1.3.6 Object.prototype.toString() @@ -896,7 +895,7 @@ JSTaggedValue object::proto::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If the this value is undefined, return "[object Undefined]". JSHandle msg = builtins_common::GetThis(argv); @@ -911,12 +910,12 @@ JSTaggedValue object::proto::ToString(EcmaRuntimeCallInfo *argv) // 3. Let O be ToObject(this value). JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle builtin_tag(thread, GetBuiltinTag(thread, object)); + JSHandle builtinTag(thread, GetBuiltinTag(thread, object)); // 16. Let tag be Get (O, @@toStringTag). - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - auto factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + auto factory = ecmaVm->GetFactory(); JSHandle tag = JSTaggedValue::GetProperty(thread, msg, env->GetToStringTagSymbol()).GetValue(); @@ -925,16 +924,16 @@ JSTaggedValue object::proto::ToString(EcmaRuntimeCallInfo *argv) // 18. If Type(tag) is not String, let tag be builtinTag. if (!tag->IsString()) { - tag = builtin_tag; + tag = builtinTag; } // 19. Return the String that is the result of concatenating "[object ", tag, and "]". - JSHandle left_string(factory->NewFromCanBeCompressString("[object ")); - JSHandle right_string(factory->NewFromCanBeCompressString("]")); + JSHandle leftString(factory->NewFromCanBeCompressString("[object ")); + JSHandle rightString(factory->NewFromCanBeCompressString("]")); - JSHandle new_left_string_handle = - factory->ConcatFromString(left_string, JSTaggedValue::ToString(thread, tag)); - auto result = factory->ConcatFromString(new_left_string_handle, right_string); + JSHandle newLeftStringHandle = + factory->ConcatFromString(leftString, JSTaggedValue::ToString(thread, tag)); + auto result = factory->ConcatFromString(newLeftStringHandle, rightString); return result.GetTaggedValue(); } @@ -944,7 +943,7 @@ JSTaggedValue object::proto::ValueOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, ValueOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Return ToObject(this value). JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); @@ -958,7 +957,7 @@ JSTaggedValue object::proto::Get__proto__(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, Get__proto__); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let obj be ToObject(this value). JSHandle obj = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); @@ -976,7 +975,7 @@ JSTaggedValue object::proto::Set__proto__(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, Set__proto__); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be RequireObjectCoercible(this value). JSHandle obj = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); @@ -1017,7 +1016,7 @@ JSTaggedValue object::proto::__defineGetter__(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, __defineGetter__); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ? ToObject(this value). JSHandle obj = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); @@ -1054,7 +1053,7 @@ JSTaggedValue object::proto::__defineSetter__(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ObjectPrototype, __defineSetter__); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ? ToObject(this value). JSHandle obj = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); @@ -1085,12 +1084,12 @@ JSTaggedValue object::proto::__defineSetter__(EcmaRuntimeCallInfo *argv) } static JSTaggedValue LookupDesc(EcmaRuntimeCallInfo *argv, - const std::function &get_desc) + const std::function &getDesc) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, LookupDesc); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ? ToObject(this value). JSHandle obj = JSTaggedValue::ToObject(thread, ecmascript::builtins_common::GetThis(argv)); @@ -1115,7 +1114,7 @@ static JSTaggedValue LookupDesc(EcmaRuntimeCallInfo *argv, RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!desc.IsEmpty()) { - return get_desc(desc); + return getDesc(desc); } objval.Update(JSObject::Cast(objval.GetTaggedValue())->GetPrototype(thread)); @@ -1154,7 +1153,7 @@ JSTaggedValue object::proto::CreateRealm(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle realm = factory->NewJSRealm(); return realm.GetTaggedValue(); @@ -1166,7 +1165,7 @@ JSTaggedValue object::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let obj be ? ToObject(O). JSHandle obj = builtins_common::GetCallArg(argv, 0); @@ -1174,11 +1173,11 @@ JSTaggedValue object::Entries(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key+value). ArraySizeT length = 0; - JSHandle name_list = + JSHandle nameList = JSObject::EnumerableOwnPropertyNames(thread, object, PropertyKind::KEY_VALUE, &length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayFromList(nameList). - return JSArray::CreateArrayFromList(thread, name_list, length).GetTaggedValue(); + return JSArray::CreateArrayFromList(thread, nameList, length).GetTaggedValue(); } // ES2021 20.1.2.22 @@ -1187,7 +1186,7 @@ JSTaggedValue object::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let obj be ? ToObject(O). JSHandle obj = builtins_common::GetCallArg(argv, 0); @@ -1195,10 +1194,9 @@ JSTaggedValue object::Values(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, value). ArraySizeT length = 0; - JSHandle name_list = - JSObject::EnumerableOwnPropertyNames(thread, object, PropertyKind::VALUE, &length); + JSHandle nameList = JSObject::EnumerableOwnPropertyNames(thread, object, PropertyKind::VALUE, &length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayFromList(nameList). - return JSArray::CreateArrayFromList(thread, name_list, length).GetTaggedValue(); + return JSArray::CreateArrayFromList(thread, nameList, length).GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_plural_rules.cpp b/runtime/builtins/builtins_plural_rules.cpp index 29162be4852ea4dce0eca8cd89f761f28d3d491e..ccd05da1c9c488bdf4056946b8649f6a5b157a9e 100644 --- a/runtime/builtins/builtins_plural_rules.cpp +++ b/runtime/builtins/builtins_plural_rules.cpp @@ -27,30 +27,30 @@ JSTaggedValue plural_rules::PluralRulesConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new_target is undefined", JSTaggedValue::Exception()); } // 2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRulesPrototype%", // « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], // [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »). - JSHandle plural_rules = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle pluralRules = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? InitializePluralRules(pluralRules, locales, options). JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSPluralRules::InitializePluralRules(thread, plural_rules, locales, options); + JSPluralRules::InitializePluralRules(thread, pluralRules, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return plural_rules.GetTaggedValue(); + return pluralRules.GetTaggedValue(); } // 15.3.2 Intl.PluralRules.supportedLocalesOf ( locales [, options ] ) @@ -60,16 +60,16 @@ JSTaggedValue plural_rules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %PluralRules%.[[AvailableLocales]]. - JSHandle available_locales = JSPluralRules::GetAvailableLocales(thread); + JSHandle availableLocales = JSPluralRules::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = builtins_common::GetCallArg(argv, 0); - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); + JSHandle result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -81,10 +81,10 @@ JSTaggedValue plural_rules::proto::Select(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let pr be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). - if (!this_value->IsJSPluralRules()) { + if (!thisValue->IsJSPluralRules()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception()); } @@ -96,8 +96,8 @@ JSTaggedValue plural_rules::proto::Select(EcmaRuntimeCallInfo *argv) x = temp.GetNumber(); // 4. Return ? ResolvePlural(pr, n). - JSHandle plural_rules = JSHandle::Cast(this_value); - JSHandle result = JSPluralRules::ResolvePlural(thread, plural_rules, x); + JSHandle pluralRules = JSHandle::Cast(thisValue); + JSHandle result = JSPluralRules::ResolvePlural(thread, pluralRules, x); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -109,23 +109,23 @@ JSTaggedValue plural_rules::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let thisValue be the this value; - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). - if (!this_value->IsJSPluralRules()) { + if (!thisValue->IsJSPluralRules()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception()); } // 3. Let options be ! ObjectCreate(%ObjectPrototype%). - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); // 4. Perform resolvedOptions - JSHandle plural_rules = JSHandle::Cast(this_value); - JSPluralRules::ResolvedOptions(thread, plural_rules, options); + JSHandle pluralRules = JSHandle::Cast(thisValue); + JSPluralRules::ResolvedOptions(thread, pluralRules, 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 68ca7b6855c8bbcd63a34f78439e8ac5e84e135a..d0265d238e131a0b7f460706c75ae31ae9084c6c 100644 --- a/runtime/builtins/builtins_promise.cpp +++ b/runtime/builtins/builtins_promise.cpp @@ -31,12 +31,12 @@ namespace panda::ecmascript::builtins { -static JSHandle PerformPromiseAll(JSThread *thread, const JSHandle &it_record, +static JSHandle PerformPromiseAll(JSThread *thread, const JSHandle &itRecord, const JSHandle &ctor, const JSHandle &capa); static JSHandle PerformPromiseRace(JSThread *thread, - const JSHandle &iterator_record, + const JSHandle &iteratorRecord, const JSHandle &capability, const JSHandle &constructor); @@ -46,13 +46,13 @@ JSTaggedValue promise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCallInfo * ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, PromiseConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "PromiseConstructor: NewTarget is undefined", JSTaggedValue::Exception()); } // 2. If IsCallable(executor) is false, throw a TypeError exception. @@ -65,44 +65,43 @@ JSTaggedValue promise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCallInfo * // «[[PromiseState]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]]» ). // 4. ReturnIfAbrupt(promise). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle instance_promise = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle instancePromise = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Set promise's [[PromiseState]] internal slot to "pending". // 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 resolving_function = - JSPromise::CreateResolvingFunctions(thread, instance_promise); + JSHandle resolvingFunction = JSPromise::CreateResolvingFunctions(thread, instancePromise); // 9. Let completion be Call(executor, undefined, «resolvingFunctions.[[Resolve]], resolvingFunctions.[[reject]]) - auto resolve_func = resolving_function->GetResolveFunction(); - auto reject_func = resolving_function->GetRejectFunction(); + auto resolveFunc = resolvingFunction->GetResolveFunction(); + auto rejectFunc = resolvingFunction->GetRejectFunction(); - JSTaggedValue tagged_value; - JSHandle this_value = global_const->GetHandledUndefined(); + JSTaggedValue taggedValue; + JSHandle thisValue = globalConst->GetHandledUndefined(); { - 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 + auto info = NewRuntimeCallInfo(thread, executor, thisValue, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(resolveFunc, rejectFunc); + taggedValue = JSFunction::Call(info.Get()); // 2: two args } - JSHandle completion_value(thread, tagged_value); + JSHandle completionValue(thread, taggedValue); // 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())) { - completion_value = JSPromise::IfThrowGetThrowValue(thread); + completionValue = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - JSHandle reject(thread, resolving_function->GetRejectFunction()); - auto info = NewRuntimeCallInfo(thread, reject, this_value, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(completion_value); + JSHandle reject(thread, resolvingFunction->GetRejectFunction()); + auto info = NewRuntimeCallInfo(thread, reject, thisValue, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(completionValue); JSFunction::Call(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 11. Return promise. - return instance_promise.GetTaggedValue(); + return instancePromise.GetTaggedValue(); } // 25.4.4.1 Promise.all ( iterable ) @@ -111,10 +110,10 @@ JSTaggedValue promise::All(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, All); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. Let C be the this value. JSHandle ctor = builtins_common::GetThis(argv); @@ -124,8 +123,8 @@ JSTaggedValue promise::All(EcmaRuntimeCallInfo *argv) } // 3. Let S be Get(C, @@species). // 4. ReturnIfAbrupt(S). - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle sctor = JSObject::GetProperty(thread, ctor, species_symbol).GetValue(); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + JSHandle sctor = JSObject::GetProperty(thread, ctor, speciesSymbol).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, sctor.GetTaggedValue()); // 5. If S is neither undefined nor null, let C be S. @@ -146,19 +145,19 @@ JSTaggedValue promise::All(EcmaRuntimeCallInfo *argv) // 10. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. JSHandle done(thread, JSTaggedValue::False()); - JSHandle it_record = factory->NewPromiseIteratorRecord(itor, done); + JSHandle itRecord = factory->NewPromiseIteratorRecord(itor, done); // 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability). - JSHandle result = PerformPromiseAll(thread, it_record, ctor, capa); + JSHandle result = PerformPromiseAll(thread, itRecord, 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 (it_record->GetDone().IsFalse()) { - JSHandle close_val = + if (itRecord->GetDone().IsFalse()) { + JSHandle closeVal = JSIterator::IteratorClose(thread, itor, JSHandle::Cast(result)); - if (close_val.GetTaggedValue().IsRecord()) { - result = JSHandle::Cast(close_val); + if (closeVal.GetTaggedValue().IsRecord()) { + result = JSHandle::Cast(closeVal); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, capa); return result->GetValue(); } @@ -176,29 +175,29 @@ JSTaggedValue promise::Race(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Race); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle env = ecma_vm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle env = ecmaVm->GetGlobalEnv(); // 1. Let C be the this value. // 2. If Type(C) is not Object, throw a TypeError exception. - JSHandle this_value = builtins_common::GetThis(argv); - if (!this_value->IsECMAObject()) { + JSHandle thisValue = builtins_common::GetThis(argv); + if (!thisValue->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 species_symbol = env->GetSpeciesSymbol(); - JSHandle species_constructor = JSObject::GetProperty(thread, this_value, species_symbol).GetValue(); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + JSHandle speciesConstructor = JSObject::GetProperty(thread, thisValue, speciesSymbol).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!(species_constructor->IsUndefined() || species_constructor->IsNull())) { - this_value = species_constructor; + if (!(speciesConstructor->IsUndefined() || speciesConstructor->IsNull())) { + thisValue = speciesConstructor; } // 6. Let promiseCapability be NewPromiseCapability(C). // 7. ReturnIfAbrupt(promiseCapability). - JSHandle promise_capability = JSPromise::NewPromiseCapability(thread, this_value); + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Let iterator be GetIterator(iterable). @@ -208,30 +207,30 @@ JSTaggedValue promise::Race(EcmaRuntimeCallInfo *argv) if (UNLIKELY(thread->HasPendingException())) { iterator = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, iterator, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, iterator, promiseCapability); // 10. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. JSHandle done(thread, JSTaggedValue::False()); - JSHandle iterator_record = factory->NewPromiseIteratorRecord(iterator, done); + JSHandle iteratorRecord = 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, iterator_record, promise_capability, this_value); + JSHandle result = PerformPromiseRace(thread, iteratorRecord, promiseCapability, thisValue); if (result->IsThrow()) { thread->ClearException(); - if (iterator_record->GetDone().IsFalse()) { + if (iteratorRecord->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, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); return result->GetValue(); } } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); return result->GetValue(); } return result->GetValue(); @@ -243,17 +242,17 @@ JSTaggedValue promise::Resolve(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Resolve); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let C be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(C) is not Object, throw a TypeError exception. - if (!this_value->IsECMAObject()) { + if (!thisValue->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Resolve: this value is not object", JSTaggedValue::Exception()); } - JSHandle x_value = builtins_common::GetCallArg(argv, 0); - return JSPromise::PromiseResolve(thread, this_value, x_value); + JSHandle xValue = builtins_common::GetCallArg(argv, 0); + return JSPromise::PromiseResolve(thread, thisValue, xValue); } // 25.4.4.4 Promise.reject ( r ) @@ -262,26 +261,26 @@ JSTaggedValue promise::Reject(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Reject); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let C be the this value. // 2. If Type(C) is not Object, throw a TypeError exception. - JSHandle this_value = builtins_common::GetThis(argv); - if (!this_value->IsECMAObject()) { + JSHandle thisValue = builtins_common::GetThis(argv); + if (!thisValue->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 promise_capability = JSPromise::NewPromiseCapability(thread, this_value); + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let rejectResult be Call(promiseCapability.[[Reject]], undefined, «r»). // 6. ReturnIfAbrupt(rejectResult). JSHandle reason = builtins_common::GetCallArg(argv, 0); - JSHandle reject(thread, promise_capability->GetReject()); - JSHandle undefined = global_const->GetHandledUndefined(); + JSHandle reject(thread, promiseCapability->GetReject()); + JSHandle undefined = globalConst->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, reject, undefined, JSTaggedValue::Undefined(), 1); info->SetCallArgs(reason); @@ -289,7 +288,7 @@ JSTaggedValue promise::Reject(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Return promiseCapability.[[Promise]]. - JSHandle promise(thread, promise_capability->GetPromise()); + JSHandle promise(thread, promiseCapability->GetPromise()); return promise.GetTaggedValue(); } @@ -308,15 +307,15 @@ JSTaggedValue promise::proto::Catch(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromisePrototype, Catch); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle promise = builtins_common::GetThis(argv); - JSHandle then_key = global_const->GetHandledPromiseThenString(); + JSHandle thenKey = globalConst->GetHandledPromiseThenString(); JSHandle reject = builtins_common::GetCallArg(argv, 0); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), promise, JSTaggedValue::Undefined(), 2); info->SetCallArgs(JSTaggedValue::Undefined(), reject); - return JSFunction::Invoke(info.Get(), then_key); // 2: two args + return JSFunction::Invoke(info.Get(), thenKey); // 2: two args } // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected ) @@ -325,84 +324,84 @@ JSTaggedValue promise::proto::Then(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromisePrototype, Then); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); // 1. Let promise be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If IsPromise(promise) is false, throw a TypeError exception. - if (!this_value->IsJSPromise()) { + if (!thisValue->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(this_value); - JSHandle default_func = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle constructor = JSObject::SpeciesConstructor(thread, promise, default_func); + JSHandle promise = JSHandle::Cast(thisValue); + JSHandle defaultFunc = JSHandle::Cast(env->GetPromiseFunction()); + JSHandle constructor = JSObject::SpeciesConstructor(thread, promise, defaultFunc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let resultCapability be NewPromiseCapability(C). // 6. ReturnIfAbrupt(resultCapability). - JSHandle result_capability = JSPromise::NewPromiseCapability(thread, constructor); + JSHandle resultCapability = JSPromise::NewPromiseCapability(thread, constructor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle on_fulfilled = builtins_common::GetCallArg(argv, 0); - JSHandle on_rejected = builtins_common::GetCallArg(argv, 1); + JSHandle onFulfilled = builtins_common::GetCallArg(argv, 0); + JSHandle onRejected = builtins_common::GetCallArg(argv, 1); // 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability). - return promise::PerformPromiseThen(thread, JSHandle::Cast(promise), on_fulfilled, on_rejected, - JSHandle::Cast(result_capability)); + return promise::PerformPromiseThen(thread, JSHandle::Cast(promise), onFulfilled, onRejected, + JSHandle::Cast(resultCapability)); } JSTaggedValue promise::PerformPromiseThen(JSThread *thread, const JSHandle &promise, - const JSHandle &on_fulfilled, - const JSHandle &on_rejected, + const JSHandle &onFulfilled, + const JSHandle &onRejected, const JSHandle &capability) { - 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(); + 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(); if (!fulfilled->IsCallable()) { - fulfilled.Update(global_const->GetIdentityString()); + fulfilled.Update(globalConst->GetIdentityString()); } - JSMutableHandle rejected(thread, on_rejected.GetTaggedValue()); + JSMutableHandle rejected(thread, onRejected.GetTaggedValue()); if (!rejected->IsCallable()) { - rejected.Update(global_const->GetThrowerString()); + rejected.Update(globalConst->GetThrowerString()); } - JSHandle fulfill_reaction = factory->NewPromiseReaction(); - fulfill_reaction->SetPromiseCapability(thread, capability.GetTaggedValue()); - fulfill_reaction->SetHandler(thread, fulfilled.GetTaggedValue()); + JSHandle fulfillReaction = factory->NewPromiseReaction(); + fulfillReaction->SetPromiseCapability(thread, capability.GetTaggedValue()); + fulfillReaction->SetHandler(thread, fulfilled.GetTaggedValue()); - JSHandle reject_reaction = factory->NewPromiseReaction(); - reject_reaction->SetPromiseCapability(thread, capability.GetTaggedValue()); - reject_reaction->SetHandler(thread, rejected.GetTaggedValue()); + JSHandle rejectReaction = factory->NewPromiseReaction(); + rejectReaction->SetPromiseCapability(thread, capability.GetTaggedValue()); + rejectReaction->SetHandler(thread, rejected.GetTaggedValue()); if (JSTaggedValue::SameValue(promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING)))) { - 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)); + 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)); } 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, fulfill_reaction.GetTaggedValue()); + argv->Set(thread, 0, fulfillReaction.GetTaggedValue()); argv->Set(thread, 1, promise->GetPromiseResult()); - JSHandle promise_reactions_job(env->GetPromiseReactionJob()); - job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promise_reactions_job, argv); + JSHandle promiseReactionsJob(env->GetPromiseReactionJob()); + job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, 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, reject_reaction.GetTaggedValue()); + argv->Set(thread, 0, rejectReaction.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". @@ -410,8 +409,8 @@ JSTaggedValue promise::PerformPromiseThen(JSThread *thread, const JSHandle reason(thread, JSTaggedValue::Null()); thread->GetEcmaVM()->PromiseRejectionTracker(promise, reason, ecmascript::PromiseRejectionEvent::HANDLE); } - JSHandle promise_reactions_job(env->GetPromiseReactionJob()); - job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promise_reactions_job, argv); + JSHandle promiseReactionsJob(env->GetPromiseReactionJob()); + job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, argv); } promise->SetPromiseIsHandled(thread, JSTaggedValue::True()); @@ -423,34 +422,34 @@ JSTaggedValue promise::PerformPromiseThen(JSThread *thread, const JSHandleGetHeapObject())->GetPromise(); } -JSHandle PerformPromiseAll(JSThread *thread, const JSHandle &it_record, +JSHandle PerformPromiseAll(JSThread *thread, const JSHandle &itRecord, const JSHandle &ctor, const JSHandle &capa) { - auto ecma_vm = thread->GetEcmaVM(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = ecmaVm->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 empty_array = factory->EmptyArray(); - values->SetValue(thread, empty_array); + JSHandle emptyArray = factory->EmptyArray(); + values->SetValue(thread, emptyArray); // 4. Let remainingElementsCount be a new Record { [[value]]: 1 }. - JSHandle remain_cnt = factory->NewPromiseRecord(); - remain_cnt->SetValue(thread, JSTaggedNumber(1)); + JSHandle remainCnt = factory->NewPromiseRecord(); + remainCnt->SetValue(thread, JSTaggedNumber(1)); // 5. Let index be 0. uint32_t index = 0; // 6. Repeat - JSHandle itor(thread, it_record->GetIterator()); - JSMutableHandle next(thread, global_const->GetUndefined()); + JSHandle itor(thread, itRecord->GetIterator()); + JSMutableHandle next(thread, globalConst->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())) { - it_record->SetDone(thread, JSTaggedValue::True()); + itRecord->SetDone(thread, JSTaggedValue::True()); next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); } // c. ReturnIfAbrupt(next). @@ -458,92 +457,92 @@ JSHandle PerformPromiseAll(JSThread *thread, const JSHandleIsFalse()) { // i. Set iteratorRecord.[[done]] to true. - it_record->SetDone(thread, JSTaggedValue::True()); + itRecord->SetDone(thread, JSTaggedValue::True()); // ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1. - remain_cnt->SetValue(thread, --JSTaggedNumber(remain_cnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); // iii. If remainingElementsCount.[[value]] is 0, - if (remain_cnt->GetValue().IsZero()) { + if (remainCnt->GetValue().IsZero()) { // 1. Let valuesArray be CreateArrayFromList(values). - JSHandle js_array_values = + JSHandle jsArrayValues = JSArray::CreateArrayFromList(thread, JSHandle(thread, values->GetValue())); // 2. Let resolveResult be Call(resultCapability.[[Resolve]], undefined, «valuesArray»). - JSHandle res_capa_func(thread, capa->GetResolve()); + JSHandle resCapaFunc(thread, capa->GetResolve()); - auto info = NewRuntimeCallInfo(thread, res_capa_func, global_const->GetHandledUndefined(), + auto info = NewRuntimeCallInfo(thread, resCapaFunc, globalConst->GetHandledUndefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(js_array_values.GetTaggedValue()); - JSTaggedValue resolve_res = JSFunction::Call(info.Get()); + info->SetCallArgs(jsArrayValues.GetTaggedValue()); + JSTaggedValue resolveRes = JSFunction::Call(info.Get()); // 3. ReturnIfAbrupt(resolveResult) - JSHandle resolve_abrupt(thread, resolve_res); - RETURN_COMPLETION_IF_ABRUPT(thread, resolve_abrupt); + JSHandle resolveAbrupt(thread, resolveRes); + RETURN_COMPLETION_IF_ABRUPT(thread, resolveAbrupt); } // iv. Return resultCapability.[[Promise]]. - JSHandle res_record = factory->NewCompletionRecord( + JSHandle resRecord = factory->NewCompletionRecord( CompletionRecord::NORMAL, JSHandle(thread, capa->GetPromise())); - return res_record; + return resRecord; } // e. Let nextValue be IteratorValue(next). - JSHandle next_val = JSIterator::IteratorValue(thread, next); + JSHandle nextVal = JSIterator::IteratorValue(thread, next); // f. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to true. if (UNLIKELY(thread->HasPendingException())) { - it_record->SetDone(thread, JSTaggedValue::True()); + itRecord->SetDone(thread, JSTaggedValue::True()); if (thread->GetException().IsObjectWrapper()) { - JSHandle wrapper_val(thread, thread->GetException()); - JSHandle throw_val(thread, wrapper_val->GetValue()); - next_val = throw_val; + JSHandle wrapperVal(thread, thread->GetException()); + JSHandle throwVal(thread, wrapperVal->GetValue()); + nextVal = throwVal; } else { - next_val = JSHandle(thread, thread->GetException()); + nextVal = JSHandle(thread, thread->GetException()); } } // g. ReturnIfAbrupt(nextValue). - RETURN_COMPLETION_IF_ABRUPT(thread, next_val); + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); // h. Append undefined to values. - JSHandle values_array = + JSHandle valuesArray = JSHandle::Cast(JSHandle(thread, values->GetValue())); - values_array = TaggedArray::SetCapacity(thread, values_array, index + 1); - values_array->Set(thread, index, JSTaggedValue::Undefined()); - values->SetValue(thread, values_array); + valuesArray = TaggedArray::SetCapacity(thread, valuesArray, index + 1); + valuesArray->Set(thread, index, JSTaggedValue::Undefined()); + values->SetValue(thread, valuesArray); // i. Let nextPromise be Invoke(constructor, "resolve", «‍nextValue»). - JSHandle resolve_key = global_const->GetHandledPromiseResolveString(); - JSTaggedValue tagged_next_promise; + JSHandle resolveKey = globalConst->GetHandledPromiseResolveString(); + JSTaggedValue taggedNextPromise; { auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), ctor, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(next_val); - tagged_next_promise = JSFunction::Invoke(info.Get(), resolve_key); + info->SetCallArgs(nextVal); + taggedNextPromise = JSFunction::Invoke(info.Get(), resolveKey); } // j. ReturnIfAbrupt(nextPromise). - JSHandle next_promise(thread, tagged_next_promise); - RETURN_COMPLETION_IF_ABRUPT(thread, next_promise); + JSHandle nextPromise(thread, taggedNextPromise); + RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); // k. Let resolveElement be a new built-in function object as defined in Promise.all // Resolve Element Functions. - JSHandle resoleve_element = factory->NewJSPromiseAllResolveElementFunction( + JSHandle resoleveElement = factory->NewJSPromiseAllResolveElementFunction( reinterpret_cast(promise_handler::ResolveElementFunction)); // l. Set the [[AlreadyCalled]] internal slot of resolveElement to a new Record {[[value]]: false }. - JSHandle false_record = factory->NewPromiseRecord(); - false_record->SetValue(thread, JSTaggedValue::False()); - resoleve_element->SetAlreadyCalled(thread, false_record); + JSHandle falseRecord = factory->NewPromiseRecord(); + falseRecord->SetValue(thread, JSTaggedValue::False()); + resoleveElement->SetAlreadyCalled(thread, falseRecord); // m. Set the [[Index]] internal slot of resolveElement to index. - resoleve_element->SetIndex(thread, JSTaggedValue(index)); + resoleveElement->SetIndex(thread, JSTaggedValue(index)); // n. Set the [[Values]] internal slot of resolveElement to values. - resoleve_element->SetValues(thread, values); + resoleveElement->SetValues(thread, values); // o. Set the [[Capabilities]] internal slot of resolveElement to resultCapability. - resoleve_element->SetCapabilities(thread, capa); + resoleveElement->SetCapabilities(thread, capa); // p. Set the [[RemainingElements]] internal slot of resolveElement to remainingElementsCount. - resoleve_element->SetRemainingElements(thread, remain_cnt); + resoleveElement->SetRemainingElements(thread, remainCnt); // q. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] + 1. - remain_cnt->SetValue(thread, ++JSTaggedNumber(remain_cnt->GetValue())); + remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); // r. Let result be Invoke(nextPromise, "then", «‍resolveElement, resultCapability.[[Reject]]»). - JSTaggedValue tagged_result; + JSTaggedValue taggedResult; { - JSHandle then_key = global_const->GetHandledPromiseThenString(); + JSHandle thenKey = globalConst->GetHandledPromiseThenString(); auto info = - NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), next_promise, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(resoleve_element, capa->GetReject()); - tagged_result = JSFunction::Invoke(info.Get(), then_key); + NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), nextPromise, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(resoleveElement, capa->GetReject()); + taggedResult = JSFunction::Invoke(info.Get(), thenKey); } - JSHandle result(thread, tagged_result); + JSHandle result(thread, taggedResult); // s. ReturnIfAbrupt(result). RETURN_COMPLETION_IF_ABRUPT(thread, result); // t. Set index to index + 1. @@ -551,7 +550,7 @@ JSHandle PerformPromiseAll(JSThread *thread, const JSHandle PerformPromiseRace(JSThread *thread, const JSHandle &iterator_record, +JSHandle PerformPromiseRace(JSThread *thread, const JSHandle &iteratorRecord, const JSHandle &capability, const JSHandle &constructor) { @@ -569,60 +568,60 @@ JSHandle PerformPromiseRace(JSThread *thread, const JSHandle

GetEcmaVM(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle iterator(thread, iterator_record->GetIterator()); - JSMutableHandle next(thread, global_const->GetUndefined()); + auto ecmaVm = thread->GetEcmaVM(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle iterator(thread, iteratorRecord->GetIterator()); + JSMutableHandle next(thread, globalConst->GetUndefined()); while (true) { next.Update(JSIterator::IteratorStep(thread, iterator).GetTaggedValue()); if (UNLIKELY(thread->HasPendingException())) { - iterator_record->SetDone(thread, JSTaggedValue::True()); + iteratorRecord->SetDone(thread, JSTaggedValue::True()); next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); } RETURN_COMPLETION_IF_ABRUPT(thread, next); if (next->IsFalse()) { - iterator_record->SetDone(thread, JSTaggedValue::True()); + iteratorRecord->SetDone(thread, JSTaggedValue::True()); JSHandle promise(thread, capability->GetPromise()); - JSHandle completion_record = + JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::NORMAL, promise); - return completion_record; + return completionRecord; } - JSHandle next_value = JSIterator::IteratorValue(thread, next); + JSHandle nextValue = JSIterator::IteratorValue(thread, next); if (UNLIKELY(thread->HasPendingException())) { - iterator_record->SetDone(thread, JSTaggedValue::True()); - next_value = JSPromise::IfThrowGetThrowValue(thread); + iteratorRecord->SetDone(thread, JSTaggedValue::True()); + nextValue = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_COMPLETION_IF_ABRUPT(thread, next_value); - JSHandle resolve_str = global_const->GetHandledPromiseResolveString(); + RETURN_COMPLETION_IF_ABRUPT(thread, nextValue); + JSHandle resolveStr = globalConst->GetHandledPromiseResolveString(); JSTaggedValue result; { auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), constructor, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(next_value); - result = JSFunction::Invoke(info.Get(), resolve_str); + info->SetCallArgs(nextValue); + result = JSFunction::Invoke(info.Get(), resolveStr); } - JSHandle next_promise(thread, result); + JSHandle nextPromise(thread, result); if (UNLIKELY(thread->HasPendingException())) { - next_promise = JSPromise::IfThrowGetThrowValue(thread); + nextPromise = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_COMPLETION_IF_ABRUPT(thread, next_promise); + RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); { - JSHandle then_str = global_const->GetHandledPromiseThenString(); + JSHandle thenStr = globalConst->GetHandledPromiseThenString(); auto info = - NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), next_promise, JSTaggedValue::Undefined(), 2); + NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), nextPromise, JSTaggedValue::Undefined(), 2); info->SetCallArgs(capability->GetResolve(), capability->GetReject()); - result = JSFunction::Invoke(info.Get(), then_str); // 2: two args + result = JSFunction::Invoke(info.Get(), thenStr); // 2: two args } - JSHandle handle_result(thread, result); + JSHandle handleResult(thread, result); if (UNLIKELY(thread->HasPendingException())) { - handle_result = JSPromise::IfThrowGetThrowValue(thread); + handleResult = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_COMPLETION_IF_ABRUPT(thread, handle_result); + RETURN_COMPLETION_IF_ABRUPT(thread, handleResult); } } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_promise_handler.cpp b/runtime/builtins/builtins_promise_handler.cpp index ac7a11537df6e07065d5b9c4831b45ed5f9254d1..fccb2cf1465fd8fb0fdabb366d8768df683a62e4 100644 --- a/runtime/builtins/builtins_promise_handler.cpp +++ b/runtime/builtins/builtins_promise_handler.cpp @@ -31,10 +31,10 @@ JSTaggedValue promise_handler::Resolve(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Resolve); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); // 1. Assert: F has a [[Promise]] internal slot whose value is an Object. JSHandle resolve = @@ -45,63 +45,63 @@ JSTaggedValue promise_handler::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 resolve_promise(thread, resolve->GetPromise()); - JSHandle already_resolved(thread, resolve->GetAlreadyResolved()); - if (already_resolved->GetValue().IsTrue()) { + JSHandle resolvePromise(thread, resolve->GetPromise()); + JSHandle alreadyResolved(thread, resolve->GetAlreadyResolved()); + if (alreadyResolved->GetValue().IsTrue()) { return JSTaggedValue::Undefined(); } - already_resolved->SetValue(thread, JSTaggedValue::True()); + alreadyResolved->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 = builtins_common::GetCallArg(argv, 0); - if (JSTaggedValue::SameValue(resolution.GetTaggedValue(), resolve_promise.GetTaggedValue())) { - JSHandle resolution_error = + if (JSTaggedValue::SameValue(resolution.GetTaggedValue(), resolvePromise.GetTaggedValue())) { + JSHandle resolutionError = factory->GetJSError(ErrorType::TYPE_ERROR, "Resolve: The promise and resolution cannot be the same."); - JSPromise::RejectPromise(thread, resolve_promise, JSHandle::Cast(resolution_error)); + JSPromise::RejectPromise(thread, resolvePromise, JSHandle::Cast(resolutionError)); return JSTaggedValue::Undefined(); } // 7. If Type(resolution) is not Object, then // a. Return FulfillPromise(promise, resolution). if (!resolution.GetTaggedValue().IsECMAObject()) { - JSPromise::FulfillPromise(thread, resolve_promise, resolution); + JSPromise::FulfillPromise(thread, resolvePromise, 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 then_key(thread->GlobalConstants()->GetHandledPromiseThenString()); - JSHandle then_value = JSObject::GetProperty(thread, resolution, then_key).GetValue(); + JSHandle thenKey(thread->GlobalConstants()->GetHandledPromiseThenString()); + JSHandle thenValue = JSObject::GetProperty(thread, resolution, thenKey).GetValue(); if (UNLIKELY(thread->HasPendingException())) { - if (!then_value->IsJSError()) { + if (!thenValue->IsJSError()) { if (thread->GetException().IsObjectWrapper()) { - JSHandle wrapper_value(thread, thread->GetException()); - JSHandle throw_value(thread, wrapper_value->GetValue()); - then_value = throw_value; + JSHandle wrapperValue(thread, thread->GetException()); + JSHandle throwValue(thread, wrapperValue->GetValue()); + thenValue = throwValue; } else { - then_value = JSHandle(thread, thread->GetException()); + thenValue = JSHandle(thread, thread->GetException()); } } thread->ClearException(); - return JSPromise::RejectPromise(thread, resolve_promise, then_value); + return JSPromise::RejectPromise(thread, resolvePromise, thenValue); } // 10. Let thenAction be then.[[value]]. // 11. If IsCallable(thenAction) is false, then // a. Return FulfillPromise(promise, resolution). - if (!then_value->IsCallable()) { - JSPromise::FulfillPromise(thread, resolve_promise, resolution); + if (!thenValue->IsCallable()) { + JSPromise::FulfillPromise(thread, resolvePromise, 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, resolve_promise); + arguments->Set(thread, 0, resolvePromise); arguments->Set(thread, 1, resolution); - arguments->Set(thread, 2, then_value); // 2: 2 means index of array is 2 + arguments->Set(thread, 2, thenValue); // 2: 2 means index of array is 2 - JSHandle promise_resolve_thenable_job(env->GetPromiseResolveThenableJob()); + JSHandle promiseResolveThenableJob(env->GetPromiseResolveThenableJob()); JSHandle job = thread->GetEcmaVM()->GetMicroJobQueue(); - job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promise_resolve_thenable_job, arguments); + job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseResolveThenableJob, arguments); // 13. Return undefined. return JSTaggedValue::Undefined(); @@ -113,7 +113,7 @@ JSTaggedValue promise_handler::Reject(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Reject); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Assert: F has a [[Promise]] internal slot whose value is an Object. JSHandle reject = @@ -124,16 +124,16 @@ JSTaggedValue promise_handler::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 reject_promise(thread, reject->GetPromise()); - JSHandle already_resolved(thread, reject->GetAlreadyResolved()); - if (already_resolved->GetValue().IsTrue()) { + JSHandle rejectPromise(thread, reject->GetPromise()); + JSHandle alreadyResolved(thread, reject->GetAlreadyResolved()); + if (alreadyResolved->GetValue().IsTrue()) { return JSTaggedValue::Undefined(); } - already_resolved->SetValue(thread, JSTaggedValue::True()); + alreadyResolved->SetValue(thread, JSTaggedValue::True()); // 6. Return RejectPromise(promise, reason). JSHandle reason = builtins_common::GetCallArg(argv, 0); - JSHandle result(thread, JSPromise::RejectPromise(thread, reject_promise, reason)); + JSHandle result(thread, JSPromise::RejectPromise(thread, rejectPromise, reason)); return result.GetTaggedValue(); } @@ -143,7 +143,7 @@ JSTaggedValue promise_handler::Executor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Executor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Assert: F has a [[Capability]] internal slot whose value is a PromiseCapability Record. JSHandle executor = @@ -153,20 +153,20 @@ JSTaggedValue promise_handler::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 promise_capability(thread, executor->GetCapability()); - if (!promise_capability->GetResolve().IsUndefined()) { + JSHandle promiseCapability(thread, executor->GetCapability()); + if (!promiseCapability->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 (!promise_capability->GetReject().IsUndefined()) { + if (!promiseCapability->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 = builtins_common::GetCallArg(argv, 0); JSHandle reject = builtins_common::GetCallArg(argv, 1); - promise_capability->SetResolve(thread, resolve); - promise_capability->SetReject(thread, reject); + promiseCapability->SetResolve(thread, resolve); + promiseCapability->SetReject(thread, reject); // 7. Return undefined. return JSTaggedValue::Undefined(); } @@ -177,19 +177,19 @@ JSTaggedValue promise_handler::ResolveElementFunction(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, ResolveElementFunction); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle func = JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot. - JSHandle already_called = + JSHandle alreadyCalled = JSHandle::Cast(JSHandle(thread, func->GetAlreadyCalled())); // 2. If alreadyCalled.[[value]] is true, return undefined. - if (already_called->GetValue().IsTrue()) { + if (alreadyCalled->GetValue().IsTrue()) { return JSTaggedValue::Undefined(); } // 3. Set alreadyCalled.[[value]] to true. - already_called->SetValue(thread, JSTaggedValue::True()); + alreadyCalled->SetValue(thread, JSTaggedValue::True()); // 4. Let index be the value of F's [[Index]] internal slot. // 5. Let values be the value of F's [[Values]] internal slot. JSHandle values = JSHandle::Cast(JSHandle(thread, func->GetValues())); @@ -197,25 +197,25 @@ JSTaggedValue promise_handler::ResolveElementFunction(EcmaRuntimeCallInfo *argv) JSHandle capa = JSHandle::Cast(JSHandle(thread, func->GetCapabilities())); // 7. Let remainingElementsCount be the value of F's [[RemainingElements]] internal slot. - JSHandle remain_cnt = + JSHandle remainCnt = JSHandle::Cast(JSHandle(thread, func->GetRemainingElements())); // 8. Set values[index] to x. - JSHandle array_values = + JSHandle arrayValues = JSHandle::Cast(JSHandle(thread, values->GetValue())); auto index = JSTaggedValue::ToUint32(thread, JSHandle(thread, func->GetIndex())); - array_values->Set(thread, index, builtins_common::GetCallArg(argv, 0).GetTaggedValue()); + arrayValues->Set(thread, index, builtins_common::GetCallArg(argv, 0).GetTaggedValue()); // 9. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] - 1. - remain_cnt->SetValue(thread, --JSTaggedNumber(remain_cnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); // 10. If remainingElementsCount.[[value]] is 0, - if (remain_cnt->GetValue().IsZero()) { + if (remainCnt->GetValue().IsZero()) { // a. Let valuesArray be CreateArrayFromList(values). - JSHandle js_array_values = JSArray::CreateArrayFromList(thread, array_values); + JSHandle jsArrayValues = JSArray::CreateArrayFromList(thread, arrayValues); // b. Return Call(promiseCapability.[[Resolve]], undefined, «valuesArray»). - JSHandle capa_resolve(thread, capa->GetResolve()); - JSHandle undefine = global_const->GetHandledUndefined(); + JSHandle capaResolve(thread, capa->GetResolve()); + JSHandle undefine = globalConst->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, capa_resolve, undefine, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(js_array_values); + auto info = NewRuntimeCallInfo(thread, capaResolve, undefine, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(jsArrayValues); return JSFunction::Call(info.Get()); } // 11. Return undefined. @@ -227,7 +227,7 @@ JSTaggedValue promise_handler::AsyncAwaitFulfilled(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, AsyncAwaitFulfilled); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); JSHandle value = builtins_common::GetCallArg(argv, 0); JSHandle func(builtins_common::GetConstructor(argv)); @@ -239,7 +239,7 @@ JSTaggedValue promise_handler::AsyncAwaitRejected(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, AsyncAwaitRejected); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); JSHandle reason = builtins_common::GetCallArg(argv, 0); JSHandle func(builtins_common::GetConstructor(argv)); diff --git a/runtime/builtins/builtins_promise_job.cpp b/runtime/builtins/builtins_promise_job.cpp index b67490a99b97d1523f37b3c2666a44455d7a196c..96e62e0ce69b5ca094be516923e9b01bcc7f9001 100644 --- a/runtime/builtins/builtins_promise_job.cpp +++ b/runtime/builtins/builtins_promise_job.cpp @@ -29,28 +29,28 @@ JSTaggedValue promise_job::PromiseReactionJob(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseJob, PromiseReactionJob); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Assert: reaction is a PromiseReaction Record. JSHandle value = builtins_common::GetCallArg(argv, 0); ASSERT(value->IsPromiseReaction()); JSHandle reaction = JSHandle::Cast(value); JSHandle argument = builtins_common::GetCallArg(argv, 1); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 2. Let promiseCapability be reaction.[[Capabilities]]. - JSTaggedValue capabilities_value = reaction->GetPromiseCapability(); + JSTaggedValue capabilitiesValue = reaction->GetPromiseCapability(); // 3. Let handler be reaction.[[Handler]]. JSHandle handler(thread, reaction->GetHandler()); - JSHandle this_value = global_const->GetHandledUndefined(); + JSHandle thisValue = globalConst->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, handler, this_value, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread, handler, thisValue, JSTaggedValue::Undefined(), 1); info->SetCallArgs(argument); - if (capabilities_value.IsUndefined()) { + if (capabilitiesValue.IsUndefined()) { [[maybe_unused]] JSTaggedValue val = JSFunction::Call(info.Get()); return JSTaggedValue::Undefined(); } - JSHandle capability(thread, capabilities_value); + JSHandle capability(thread, capabilitiesValue); JSMutableHandle call(thread, capability->GetResolve()); if (handler->IsString()) { @@ -59,20 +59,20 @@ JSTaggedValue promise_job::PromiseReactionJob(EcmaRuntimeCallInfo *argv) // [[target]]: empty}. if (EcmaString::StringsAreEqual(handler.GetObject(), - global_const->GetHandledThrowerString().GetObject())) { + globalConst->GetHandledThrowerString().GetObject())) { call.Update(capability->GetReject()); } } else { // 6. Else, let handlerResult be Call(handler, undefined, «argument»). - JSTaggedValue tagged_value = JSFunction::Call(info.Get()); - info->SetCallArgs(tagged_value); + JSTaggedValue taggedValue = JSFunction::Call(info.Get()); + info->SetCallArgs(taggedValue); // 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 throw_value = JSPromise::IfThrowGetThrowValue(thread); + JSHandle throwValue = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - info->SetCallArgs(throw_value); + info->SetCallArgs(throwValue); call.Update(capability->GetReject()); } } @@ -86,12 +86,12 @@ JSTaggedValue promise_job::PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseJob, PromiseResolveThenableJob); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle promise = builtins_common::GetCallArg(argv, 0); ASSERT(promise->IsJSPromise()); // 1. Let resolvingFunctions be CreateResolvingFunctions(promiseToResolve). - JSHandle resolving_functions = + JSHandle resolvingFunctions = JSPromise::CreateResolvingFunctions(thread, JSHandle::Cast(promise)); JSHandle thenable = builtins_common::GetCallArg(argv, 1); JSHandle then = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); @@ -101,20 +101,20 @@ JSTaggedValue promise_job::PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) JSTaggedValue result; { auto info = NewRuntimeCallInfo(thread, then, thenable, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(resolving_functions->GetResolveFunction(), resolving_functions->GetRejectFunction()); + info->SetCallArgs(resolvingFunctions->GetResolveFunction(), resolvingFunctions->GetRejectFunction()); result = JSFunction::Call(info.Get()); // 2: two args } - JSHandle then_result(thread, result); + JSHandle thenResult(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())) { - then_result = JSPromise::IfThrowGetThrowValue(thread); + thenResult = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - JSHandle reject(thread, resolving_functions->GetRejectFunction()); - JSHandle undefined = global_const->GetHandledUndefined(); + JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); + JSHandle undefined = globalConst->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, reject, undefined, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(then_result); + info->SetCallArgs(thenResult); return JSFunction::Call(info.Get()); } // 4. NextJob Completion(thenCallResult). diff --git a/runtime/builtins/builtins_proxy.cpp b/runtime/builtins/builtins_proxy.cpp index 1b5cbb8be0ce493e9c4f8e756a7c6d23f8666d35..322373eeea4cd0ec12c995016fe5d70366e4765d 100644 --- a/runtime/builtins/builtins_proxy.cpp +++ b/runtime/builtins/builtins_proxy.cpp @@ -29,11 +29,11 @@ JSTaggedValue proxy::ProxyConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, ProxyConstructor); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); // 1.If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "ProxyConstructor: NewTarget is undefined", JSTaggedValue::Exception()); } @@ -51,7 +51,7 @@ JSTaggedValue proxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, Revocable); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let p be ProxyCreate(target, handler). JSHandle proxy = @@ -70,13 +70,13 @@ JSTaggedValue proxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSHandle result = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(proto); // 6.Perform CreateDataProperty(result, "proxy", p). - auto global_const = thread->GlobalConstants(); - JSHandle proxy_key = global_const->GetHandledProxyString(); - JSObject::CreateDataProperty(thread, result, proxy_key, JSHandle(proxy)); + auto globalConst = thread->GlobalConstants(); + JSHandle proxyKey = globalConst->GetHandledProxyString(); + JSObject::CreateDataProperty(thread, result, proxyKey, JSHandle(proxy)); // 7.Perform CreateDataProperty(result, "revoke", revoker). - JSHandle revoke_key = global_const->GetHandledRevokeString(); - JSObject::CreateDataProperty(thread, result, revoke_key, JSHandle(revoker)); + JSHandle revokeKey = globalConst->GetHandledRevokeString(); + JSObject::CreateDataProperty(thread, result, revokeKey, JSHandle(revoker)); // 8.Return result. return result.GetTaggedValue(); @@ -88,13 +88,13 @@ JSTaggedValue InvalidateProxyFunction(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, InvalidateProxyFunction); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle revoke_obj(builtins_common::GetThis(argv)); - JSHandle revoke_key = thread->GlobalConstants()->GetHandledRevokeString(); + JSHandle revokeObj(builtins_common::GetThis(argv)); + JSHandle revokeKey = thread->GlobalConstants()->GetHandledRevokeString(); PropertyDescriptor desc(thread); - JSObject::GetOwnProperty(thread, revoke_obj, revoke_key, desc); + JSObject::GetOwnProperty(thread, revokeObj, revokeKey, 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 4e3bc418d6244b807fbc42b35d073e0c671b6357..375583499e4c65140cc1ec86bcafc84b13944a15 100644 --- a/runtime/builtins/builtins_reflect.cpp +++ b/runtime/builtins/builtins_reflect.cpp @@ -25,26 +25,26 @@ JSTaggedValue reflect::Apply(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Apply); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If IsCallable(target) is false, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.apply target is not callable", JSTaggedValue::Exception()); } // 2. Let args be ? CreateListFromArrayLike(argumentsList). - JSHandle this_argument = builtins_common::GetCallArg(argv, 1); - JSHandle arguments_list = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); - JSHandle arg_or_abrupt = JSObject::CreateListFromArrayLike(thread, arguments_list); + JSHandle thisArgument = builtins_common::GetCallArg(argv, 1); + JSHandle argumentsList = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); + JSHandle argOrAbrupt = JSObject::CreateListFromArrayLike(thread, argumentsList); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle args = JSHandle::Cast(arg_or_abrupt); + JSHandle args = JSHandle::Cast(argOrAbrupt); // 3. Perform PrepareForTailCall(). // 4. Return ? Call(target, thisArgument, args). - const auto args_length = args->GetLength(); + const auto argsLength = args->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, target, this_argument, undefined, args_length); + auto info = NewRuntimeCallInfo(thread, target, thisArgument, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info->SetCallArg(args_length, args->GetData()); + info->SetCallArg(argsLength, args->GetData()); return JSFunction::Call(info.Get()); } @@ -54,31 +54,31 @@ JSTaggedValue reflect::Construct(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Construct); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If IsConstructor(target) is false, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.construct target is not constructor", JSTaggedValue::Exception()); } // 2. If new_target is not present, set new_target to target. - JSHandle new_target = argv->GetArgsNumber() > 2 - ? builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD) - : target; // 2: num args + JSHandle newTarget = argv->GetArgsNumber() > 2 + ? builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD) + : target; // 2: num args // 3. Else if IsConstructor(new_target) is false, throw a TypeError exception. - if (!new_target->IsConstructor()) { + if (!newTarget->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.construct new_target is present, but not constructor", JSTaggedValue::Exception()); } // 4. Let args be ? CreateListFromArrayLike(argumentsList). - JSHandle arguments_list = builtins_common::GetCallArg(argv, 1); - JSHandle arg_or_abrupt = JSObject::CreateListFromArrayLike(thread, arguments_list); + JSHandle argumentsList = builtins_common::GetCallArg(argv, 1); + JSHandle argOrAbrupt = JSObject::CreateListFromArrayLike(thread, argumentsList); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle args = JSHandle::Cast(arg_or_abrupt); + JSHandle args = JSHandle::Cast(argOrAbrupt); // 5. Return ? Construct(target, args, new_target). - const auto args_length = args->GetLength(); - auto info = NewRuntimeCallInfo(thread, target, JSTaggedValue::Undefined(), new_target, args_length); + const auto argsLength = args->GetLength(); + auto info = NewRuntimeCallInfo(thread, target, JSTaggedValue::Undefined(), newTarget, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info->SetCallArg(args_length, args->GetData()); + info->SetCallArg(argsLength, args->GetData()); return JSFunction::Construct(info.Get()); } @@ -88,7 +88,7 @@ JSTaggedValue reflect::DefineProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, DefineProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -112,7 +112,7 @@ JSTaggedValue reflect::DeleteProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, DeleteProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -131,7 +131,7 @@ JSTaggedValue reflect::Get(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Get); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle val = builtins_common::GetCallArg(argv, 0); if (!val->IsECMAObject()) { @@ -157,7 +157,7 @@ JSTaggedValue reflect::GetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, GetOwnPropertyDescriptor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -183,7 +183,7 @@ JSTaggedValue reflect::GetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, GetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle val = builtins_common::GetCallArg(argv, 0); if (!val->IsECMAObject()) { @@ -200,7 +200,7 @@ JSTaggedValue reflect::Has(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -218,7 +218,7 @@ JSTaggedValue reflect::IsExtensible(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -234,7 +234,7 @@ JSTaggedValue reflect::OwnKeys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, OwnKeys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -254,7 +254,7 @@ JSTaggedValue reflect::PreventExtensions(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, PreventExtensions); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -271,10 +271,10 @@ JSTaggedValue reflect::Set(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target_val = builtins_common::GetCallArg(argv, 0); - if (!target_val->IsECMAObject()) { + JSHandle targetVal = builtins_common::GetCallArg(argv, 0); + if (!targetVal->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.get target is not object", JSTaggedValue::Exception()); } // 2. Let key be ? ToPropertyKey(propertyKey). @@ -285,10 +285,10 @@ JSTaggedValue reflect::Set(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 builtins_common::GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::SetProperty(thread, targetVal, key, value)); } JSHandle receiver = builtins_common::GetCallArg(argv, 3); // 3: 3 means the third arg - return builtins_common::GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value, receiver)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::SetProperty(thread, targetVal, key, value, receiver)); } // ecma 26.1.13 Reflect.setPrototypeOf (target, proto) @@ -297,7 +297,7 @@ JSTaggedValue reflect::SetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, SetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { diff --git a/runtime/builtins/builtins_regexp.cpp b/runtime/builtins/builtins_regexp.cpp index 1fcc04dd715db2aa551fb256aa4e7d59db88c8df..749f0b4be617a8bfe48cdf27695eba43cc41d826 100644 --- a/runtime/builtins/builtins_regexp.cpp +++ b/runtime/builtins/builtins_regexp.cpp @@ -37,17 +37,17 @@ namespace panda::ecmascript::builtins { constexpr uint32_t MIN_REPLACE_STRING_LENGTH = 1000; constexpr uint32_t MAX_SPLIT_LIMIT = 0xFFFFFFFFU; static MatchResult Matcher(JSThread *thread, const JSHandle ®exp, const uint8_t *buffer, - size_t length, int32_t last_index, bool is_utf16); + size_t length, int32_t lastIndex, bool isUtf16); static bool GetFlagsInternal(JSThread *thread, const JSHandle &obj, uint8_t mask); // 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) static JSTaggedValue RegExpBuiltinExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &input_str, bool use_cache); + const JSHandle &inputStr, bool useCache); // 21.2.3.2.1 Runtime Semantics: RegExpAlloc ( new_target ) -static JSTaggedValue RegExpAlloc(JSThread *thread, const JSHandle &new_target); +static JSTaggedValue RegExpAlloc(JSThread *thread, const JSHandle &newTarget); -static uint32_t UpdateExpressionFlags(JSThread *thread, const PandaString &check_str); +static uint32_t UpdateExpressionFlags(JSThread *thread, const PandaString &checkStr); // 21.2.3.2.2 Runtime Semantics: RegExpInitialize ( obj, pattern, flags ) static JSTaggedValue RegExpInitialize(JSThread *thread, const JSHandle &obj, @@ -56,7 +56,7 @@ static JSTaggedValue RegExpInitialize(JSThread *thread, const JSHandle &src, const JSHandle &flags); static JSTaggedValue RegExpReplaceFast(JSThread *thread, JSHandle ®exp, - JSHandle input_string, uint32_t input_length); + JSHandle inputString, uint32_t inputLength); // 21.2.3.1 JSTaggedValue reg_exp::RegExpConstructor(EcmaRuntimeCallInfo *argv) @@ -64,116 +64,116 @@ JSTaggedValue reg_exp::RegExpConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, RegExpConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target_temp = builtins_common::GetNewTarget(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle newTargetTemp = builtins_common::GetNewTarget(argv); JSHandle pattern = builtins_common::GetCallArg(argv, 0); JSHandle flags = builtins_common::GetCallArg(argv, 1); // 1. Let patternIsRegExp be IsRegExp(pattern). - bool pattern_is_reg_exp = JSObject::IsRegExp(thread, pattern); + bool patternIsRegExp = 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 *global_const = thread->GlobalConstants(); - if (!new_target_temp->IsUndefined()) { - new_target = new_target_temp; + JSHandle newTarget; + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + if (!newTargetTemp->IsUndefined()) { + newTarget = newTargetTemp; } else { - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); // disable gc - [[maybe_unused]] DisallowGarbageCollection no_gc; + [[maybe_unused]] DisallowGarbageCollection noGc; // 4.a Let new_target be the active function object. - new_target = env->GetRegExpFunction(); - JSHandle constructor_string = global_const->GetHandledConstructorString(); + newTarget = env->GetRegExpFunction(); + JSHandle constructorString = globalConst->GetHandledConstructorString(); // 4.b If patternIsRegExp is true and flags is undefined - if (pattern_is_reg_exp && flags->IsUndefined()) { + if (patternIsRegExp && flags->IsUndefined()) { // 4.b.i Let patternConstructor be Get(pattern, "constructor"). - JSTaggedValue pattern_constructor = - FastRuntimeStub::FastGetPropertyByValue(thread, pattern, constructor_string); + JSTaggedValue patternConstructor = + FastRuntimeStub::FastGetPropertyByValue(thread, pattern, constructorString); // 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(), pattern_constructor)) { + if (JSTaggedValue::SameValue(newTarget.GetTaggedValue(), patternConstructor)) { return pattern.GetTaggedValue(); } } } // 5. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal slot - bool is_js_reg = false; + bool isJsReg = false; if (pattern->IsECMAObject()) { - JSHandle pattern_obj = JSHandle::Cast(pattern); - is_js_reg = pattern_obj->IsJSRegExp(); + JSHandle patternObj = JSHandle::Cast(pattern); + isJsReg = patternObj->IsJSRegExp(); } - JSHandle pattern_temp; - JSHandle flags_temp; - if (is_js_reg) { - JSHandle pattern_reg(thread, JSRegExp::Cast(pattern->GetTaggedObject())); + JSHandle patternTemp; + JSHandle flagsTemp; + if (isJsReg) { + JSHandle patternReg(thread, JSRegExp::Cast(pattern->GetTaggedObject())); // 5.a Let P be the value of pattern’s [[OriginalSource]] internal slot. - pattern_temp = JSHandle(thread, pattern_reg->GetOriginalSource()); + patternTemp = JSHandle(thread, patternReg->GetOriginalSource()); if (flags->IsUndefined()) { // 5.b If flags is undefined, let F be the value of pattern’s [[OriginalFlags]] internal slot. - flags_temp = JSHandle(thread, pattern_reg->GetOriginalFlags()); + flagsTemp = JSHandle(thread, patternReg->GetOriginalFlags()); } else { // 5.c Else, let F be flags. - flags_temp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); + flagsTemp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); } // 6. Else if patternIsRegExp is true - } else if (pattern_is_reg_exp) { - JSHandle source_string(global_const->GetHandledSourceString()); - JSHandle flags_string(global_const->GetHandledFlagsString()); + } else if (patternIsRegExp) { + JSHandle sourceString(globalConst->GetHandledSourceString()); + JSHandle flagsString(globalConst->GetHandledFlagsString()); // disable gc - [[maybe_unused]] DisallowGarbageCollection no_gc; + [[maybe_unused]] DisallowGarbageCollection noGc; // 6.a Let P be Get(pattern, "source"). - pattern_temp = JSObject::GetProperty(thread, pattern, source_string).GetValue(); + patternTemp = JSObject::GetProperty(thread, pattern, sourceString).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"). - flags_temp = JSObject::GetProperty(thread, pattern, flags_string).GetValue(); + flagsTemp = JSObject::GetProperty(thread, pattern, flagsString).GetValue(); // 6.c.ii ReturnIfAbrupt(F). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { // 6.d Else, let F be flags. - flags_temp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); + flagsTemp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); } } else { // 7.a Let P be pattern. - pattern_temp = pattern; + patternTemp = pattern; // 7.b Let F be flags. if (flags->IsUndefined()) { - flags_temp = flags; + flagsTemp = flags; } else { - flags_temp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); + flagsTemp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); } } // 8. Let O be RegExpAlloc(new_target). - JSHandle object(thread, RegExpAlloc(thread, new_target)); + JSHandle object(thread, RegExpAlloc(thread, newTarget)); // 9. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. Return RegExpInitialize(O, P, F). - JSTaggedValue result = RegExpInitialize(thread, object, pattern_temp, flags_temp); + JSTaggedValue result = RegExpInitialize(thread, object, patternTemp, flagsTemp); return JSTaggedValue(result); } -static bool ExecCachingAllowed(JSThread *thread, JSHandle &this_val) +static bool ExecCachingAllowed(JSThread *thread, JSHandle &thisVal) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - if (!this_val->IsJSObject()) { + if (!thisVal->IsJSObject()) { return false; } - JSObject *this_obj = JSObject::Cast(this_val->GetTaggedObject()); - JSHClass *this_class = this_obj->GetJSHClass(); + JSObject *thisObj = JSObject::Cast(thisVal->GetTaggedObject()); + JSHClass *thisClass = thisObj->GetJSHClass(); - JSHandle regex_fn(thread->GetEcmaVM()->GetGlobalEnv()->GetRegExpFunction()); - if (JSTaggedValue(this_class) != regex_fn->GetProtoOrDynClass()) { + JSHandle regexFn(thread->GetEcmaVM()->GetGlobalEnv()->GetRegExpFunction()); + if (JSTaggedValue(thisClass) != regexFn->GetProtoOrDynClass()) { return false; } - JSTaggedValue regex_proto = - JSHClass::Cast(global_const->GetHandledJSRegExpClass()->GetTaggedObject())->GetPrototype(); - return this_class->GetPrototype() == regex_proto; + JSTaggedValue regexProto = + JSHClass::Cast(globalConst->GetHandledJSRegExpClass()->GetTaggedObject())->GetPrototype(); + return thisClass->GetPrototype() == regexProto; } // prototype @@ -183,34 +183,34 @@ JSTaggedValue reg_exp::proto::Exec(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, Exec); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let R be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); + JSHandle thisObj = builtins_common::GetThis(argv); // 4. Let S be ToString(string). - JSHandle input_str = builtins_common::GetCallArg(argv, 0); - JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); + JSHandle inputStr = builtins_common::GetCallArg(argv, 0); + JSHandle stringHandle = JSTaggedValue::ToString(thread, inputStr); // 5. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(string_handle); + JSHandle string = JSHandle::Cast(stringHandle); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!this_obj->IsECMAObject()) { + if (!thisObj->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 (!this_obj->IsJSRegExp()) { + if (!thisObj->IsJSRegExp()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this does not have [[RegExpMatcher]]", JSTaggedValue::Exception()); } - 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; + bool useCache = ExecCachingAllowed(thread, thisObj); + JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); + if (cacheTable->GetLargeStrCount() == 0 || cacheTable->GetConflictCount() == 0) { + useCache = false; } // 6. Return RegExpBuiltinExec(R, S). - JSTaggedValue result = RegExpBuiltinExec(thread, this_obj, string, use_cache); + JSTaggedValue result = RegExpBuiltinExec(thread, thisObj, string, useCache); return JSTaggedValue(result); } @@ -220,27 +220,27 @@ JSTaggedValue reg_exp::proto::Test(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, Test); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let R be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); - JSHandle input_str = builtins_common::GetCallArg(argv, 0); + JSHandle thisObj = builtins_common::GetThis(argv); + JSHandle inputStr = builtins_common::GetCallArg(argv, 0); // 3. Let string be ToString(S). // 4. ReturnIfAbrupt(string). - JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); + JSHandle stringHandle = JSTaggedValue::ToString(thread, inputStr); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(string_handle); + JSHandle string = JSHandle::Cast(stringHandle); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!this_obj->IsECMAObject()) { + if (!thisObj->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 match_result = reg_exp::RegExpExec(thread, this_obj, string, false); + JSTaggedValue matchResult = reg_exp::RegExpExec(thread, thisObj, string, false); // 6. ReturnIfAbrupt(match). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. If match is not null, return true; else return false. - return builtins_common::GetTaggedBoolean(!match_result.IsNull()); + return builtins_common::GetTaggedBoolean(!matchResult.IsNull()); } // 20.2.5.14 @@ -249,33 +249,33 @@ JSTaggedValue reg_exp::proto::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let R be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); - auto ecma_vm = thread->GetEcmaVM(); + JSHandle thisObj = builtins_common::GetThis(argv); + auto ecmaVm = thread->GetEcmaVM(); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!this_obj->IsECMAObject()) { + if (!thisObj->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } - ObjectFactory *factory = ecma_vm->GetFactory(); - const GlobalEnvConstants *global_constants = thread->GlobalConstants(); - JSHandle source_string(global_constants->GetHandledSourceString()); - JSHandle flags_string(global_constants->GetHandledFlagsString()); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); + JSHandle sourceString(globalConstants->GetHandledSourceString()); + JSHandle flagsString(globalConstants->GetHandledFlagsString()); // 3. Let pattern be ToString(Get(R, "source")). - 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); + JSHandle getSource(JSObject::GetProperty(thread, thisObj, sourceString).GetValue()); + JSHandle getFlags(JSObject::GetProperty(thread, thisObj, flagsString).GetValue()); + JSHandle sourceStrHandle = JSTaggedValue::ToString(thread, getSource); // 4. ReturnIfAbrupt(pattern). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let flags be ToString(Get(R, "flags")). - JSHandle flags_str_handle = JSTaggedValue::ToString(thread, get_flags); + JSHandle flagsStrHandle = JSTaggedValue::ToString(thread, getFlags); // 4. ReturnIfAbrupt(flags). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle slash_str = JSHandle::Cast(global_constants->GetHandledBackslashString()); + JSHandle slashStr = JSHandle::Cast(globalConstants->GetHandledBackslashString()); // 7. Let result be the String value formed by concatenating "/", pattern, and "/", and flags. - 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(); + JSHandle tempStr = factory->ConcatFromString(slashStr, sourceStrHandle); + JSHandle resultTemp = factory->ConcatFromString(tempStr, slashStr); + return factory->ConcatFromString(resultTemp, flagsStrHandle).GetTaggedValue(); } // 20.2.5.3 @@ -284,48 +284,48 @@ JSTaggedValue reg_exp::proto::GetFlags(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, GetFlags); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let R be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); + JSHandle thisObj = builtins_common::GetThis(argv); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!this_obj->IsECMAObject()) { + if (!thisObj->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(this_obj)->IsJSRegExp()) { - uint8_t flags_bits = - static_cast(JSRegExp::Cast(this_obj->GetTaggedObject())->GetOriginalFlags().GetInt()); - return reg_exp::FlagsBitsToString(thread, flags_bits); + if (JSHandle::Cast(thisObj)->IsJSRegExp()) { + uint8_t flagsBits = + static_cast(JSRegExp::Cast(thisObj->GetTaggedObject())->GetOriginalFlags().GetInt()); + return reg_exp::FlagsBitsToString(thread, flagsBits); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) - std::array flags_str; // six flags + \0 + std::array flagsStr; // six flags + \0 { - char *flags_cur = flags_str.data(); + char *flagsCur = flagsStr.data(); - 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()) { + auto addFlagVal = [&](char const *propStr, char const flagChar) { + JSHandle prop(factory->NewFromString(propStr)); + JSHandle getResult(JSObject::GetProperty(thread, thisObj, prop).GetValue()); + if (getResult->ToBoolean()) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *flags_cur++ = flag_char; + *flagsCur++ = flagChar; } }; - 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'); + addFlagVal("global", 'g'); + addFlagVal("ignoreCase", 'i'); + addFlagVal("multiline", 'm'); + addFlagVal("dotAll", 's'); + addFlagVal("unicode", 'u'); + addFlagVal("sticky", 'y'); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *flags_cur = '\0'; + *flagsCur = '\0'; } - return factory->NewFromString(flags_str.data()).GetTaggedValue(); + return factory->NewFromString(flagsStr.data()).GetTaggedValue(); } // 20.2.5.4 @@ -333,9 +333,9 @@ JSTaggedValue reg_exp::proto::GetGlobal(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = builtins_common::GetThis(argv); - bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_GLOBAL); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisObj = builtins_common::GetThis(argv); + bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_GLOBAL); return builtins_common::GetTaggedBoolean(result); } @@ -344,9 +344,9 @@ JSTaggedValue reg_exp::proto::GetIgnoreCase(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = builtins_common::GetThis(argv); - bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_IGNORECASE); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisObj = builtins_common::GetThis(argv); + bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_IGNORECASE); return builtins_common::GetTaggedBoolean(result); } @@ -355,9 +355,9 @@ JSTaggedValue reg_exp::proto::GetMultiline(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = builtins_common::GetThis(argv); - bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_MULTILINE); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisObj = builtins_common::GetThis(argv); + bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_MULTILINE); return builtins_common::GetTaggedBoolean(result); } @@ -365,9 +365,9 @@ JSTaggedValue reg_exp::proto::GetDotAll(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = builtins_common::GetThis(argv); - bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_DOTALL); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisObj = builtins_common::GetThis(argv); + bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_DOTALL); return builtins_common::GetTaggedBoolean(result); } @@ -376,26 +376,26 @@ JSTaggedValue reg_exp::proto::GetSource(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let R be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); + JSHandle thisObj = builtins_common::GetThis(argv); // 2. If Type(R) is not Object, throw a TypeError exception. // 3. If R does not have an [[OriginalSource]] internal slot, throw a TypeError exception. // 4. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError exception. - if (!this_obj->IsECMAObject()) { + if (!thisObj->IsECMAObject()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } - if (!this_obj->IsJSRegExp()) { + if (!thisObj->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 regexp_obj(thread, JSRegExp::Cast(this_obj->GetTaggedObject())); - JSHandle source(thread, regexp_obj->GetOriginalSource()); + JSHandle regexpObj(thread, JSRegExp::Cast(thisObj->GetTaggedObject())); + JSHandle source(thread, regexpObj->GetOriginalSource()); // 6. Let flags be the value of R’s [[OriginalFlags]] internal slot. - uint8_t flags_bits = static_cast(regexp_obj->GetOriginalFlags().GetInt()); - JSHandle flags(thread, reg_exp::FlagsBitsToString(thread, flags_bits)); + uint8_t flagsBits = static_cast(regexpObj->GetOriginalFlags().GetInt()); + JSHandle flags(thread, reg_exp::FlagsBitsToString(thread, flagsBits)); // 7. Return EscapeRegExpPattern(src, flags). return JSTaggedValue(EscapeRegExpPattern(thread, source, flags)); } @@ -405,9 +405,9 @@ JSTaggedValue reg_exp::proto::GetSticky(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = builtins_common::GetThis(argv); - bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_STICKY); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisObj = builtins_common::GetThis(argv); + bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_STICKY); return builtins_common::GetTaggedBoolean(result); } @@ -416,9 +416,9 @@ JSTaggedValue reg_exp::proto::GetUnicode(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = builtins_common::GetThis(argv); - bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_UTF16); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisObj = builtins_common::GetThis(argv); + bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_UTF16); return builtins_common::GetTaggedBoolean(result); } @@ -435,98 +435,98 @@ JSTaggedValue reg_exp::proto::Match(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, Match); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let rx be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); + JSHandle thisObj = builtins_common::GetThis(argv); // 3. Let S be ToString(string) - JSHandle input_string = builtins_common::GetCallArg(argv, 0); - JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); - bool use_cache = true; - JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); - if (cache_table->GetLargeStrCount() == 0 || cache_table->GetConflictCount() == 0) { - use_cache = false; + JSHandle inputString = builtins_common::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; } // 4. ReturnIfAbrupt(string). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(string_handle); - if (!this_obj->IsECMAObject()) { + JSHandle string = JSHandle::Cast(stringHandle); + if (!thisObj->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 *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - use_cache &= ExecCachingAllowed(thread, this_obj); + useCache &= ExecCachingAllowed(thread, thisObj); // 5. Let global be ToBoolean(Get(rx, "global")). - JSHandle global = global_const->GetHandledGlobalString(); - JSTaggedValue global_value = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, global); + JSHandle global = globalConst->GetHandledGlobalString(); + JSTaggedValue globalValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, global); // 6. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle regexp_obj(this_obj); + JSHandle regexpObj(thisObj); JSMutableHandle pattern(thread, JSTaggedValue::Undefined()); JSMutableHandle flags(thread, JSTaggedValue::Undefined()); - if (this_obj->IsJSRegExp()) { - pattern.Update(regexp_obj->GetOriginalSource()); - flags.Update(regexp_obj->GetOriginalFlags()); + if (thisObj->IsJSRegExp()) { + pattern.Update(regexpObj->GetOriginalSource()); + flags.Update(regexpObj->GetOriginalFlags()); } - bool is_global = global_value.ToBoolean(); + bool isGlobal = globalValue.ToBoolean(); // 7. If global is false, then - if (!is_global) { + if (!isGlobal) { // a. Return RegExpExec(rx, S). - 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; + if (useCache) { + JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, pattern, flags, inputString, + RegExpExecResultCache::EXEC_TYPE, thisObj); + if (cacheResult != JSTaggedValue::Undefined()) { + return cacheResult; } } - JSTaggedValue result = reg_exp::RegExpExec(thread, this_obj, string, use_cache); + JSTaggedValue result = reg_exp::RegExpExec(thread, thisObj, string, useCache); return JSTaggedValue(result); } - 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; + if (useCache) { + JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, pattern, flags, inputString, + RegExpExecResultCache::MATCH_TYPE, thisObj); + if (cacheResult != JSTaggedValue::Undefined()) { + return cacheResult; } } // 8. Else global is true // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). - JSHandle unicode = global_const->GetHandledUnicodeString(); - JSTaggedValue uincode_value = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, unicode); + JSHandle unicode = globalConst->GetHandledUnicodeString(); + JSTaggedValue uincodeValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, unicode); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool full_unicode = uincode_value.ToBoolean(); + bool fullUnicode = uincodeValue.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). - JSHandle last_index_string(global_const->GetHandledLastIndexString()); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(this_obj), last_index_string, + JSHandle lastIndexString(globalConst->GetHandledLastIndexString()); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(thisObj), lastIndexString, 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 result_num = 0; + int resultNum = 0; JSMutableHandle result(thread, JSTaggedValue(0)); // g. Repeat, while (true) { // i. Let result be RegExpExec(rx, S). - result.Update(reg_exp::RegExpExec(thread, this_obj, string, use_cache)); + result.Update(reg_exp::RegExpExec(thread, thisObj, string, useCache)); // 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 (result_num == 0) { + if (resultNum == 0) { return JSTaggedValue::Null(); } - if (use_cache) { - RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags, input_string, + if (useCache) { + RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flags, inputString, JSHandle(array), RegExpExecResultCache::MATCH_TYPE, 0); } @@ -535,33 +535,33 @@ JSTaggedValue reg_exp::proto::Match(EcmaRuntimeCallInfo *argv) } // iv. Else result is not null, // 1. Let matchStr be ToString(Get(result, "0")). - 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); + JSHandle zeroString = globalConst->GetHandledZeroString(); + JSTaggedValue matchVal = FastRuntimeStub::FastGetPropertyByValue(thread, result, zeroString); + JSHandle matchStr(thread, matchVal); + JSHandle matchString = JSTaggedValue::ToString(thread, matchStr); // 2. ReturnIfAbrupt(matchStr). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle match_value = JSHandle::Cast(match_string); + JSHandle matchValue = JSHandle::Cast(matchString); // 3. Let status be CreateDataProperty(A, ToString(n), matchStr). - JSObject::CreateDataProperty(thread, array, result_num, match_value); + JSObject::CreateDataProperty(thread, array, resultNum, matchValue); // 5. If matchStr is the empty String, then - if (JSTaggedValue::ToString(thread, match_value)->GetLength() == 0) { + if (JSTaggedValue::ToString(thread, matchValue)->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - 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); + JSTaggedValue lastIndex = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, lastIndexString); + JSHandle lastIndexHandle(thread, lastIndex); + JSTaggedNumber thisIndex = JSTaggedValue::ToLength(thread, lastIndexHandle); // 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 next_index = JSTaggedValue(AdvanceStringIndex(string, this_index.GetNumber(), full_unicode)); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(this_obj), last_index_string, - HandleFromLocal(&next_index)); + auto nextIndex = JSTaggedValue(AdvanceStringIndex(string, thisIndex.GetNumber(), fullUnicode)); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(thisObj), lastIndexString, + HandleFromLocal(&nextIndex)); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 6. Increase n. - result_num++; + resultNum++; } } @@ -570,195 +570,194 @@ JSTaggedValue reg_exp::proto::MatchAll(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RegExpPrototype, MatchAll); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. - JSHandle this_obj = builtins_common::GetThis(argv); - auto ecma_vm = thread->GetEcmaVM(); - if (!this_obj->IsECMAObject()) { + JSHandle thisObj = builtins_common::GetThis(argv); + auto ecmaVm = thread->GetEcmaVM(); + if (!thisObj->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } // 3. Let S be ? ToString(string). - JSHandle input_string = builtins_common::GetCallArg(argv, 0); - JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); + JSHandle inputString = builtins_common::GetCallArg(argv, 0); + JSHandle stringHandle = JSTaggedValue::ToString(thread, inputString); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let C be ? SpeciesConstructor(R, %RegExp%). - JSHandle default_constructor = ecma_vm->GetGlobalEnv()->GetRegExpFunction(); - JSHandle obj_handle(this_obj); - JSHandle constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); + JSHandle defaultConstructor = ecmaVm->GetGlobalEnv()->GetRegExpFunction(); + JSHandle objHandle(thisObj); + JSHandle constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - const GlobalEnvConstants *global_constants = thread->GlobalConstants(); + const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); // 5. Let flags be ? ToString(? Get(R, "flags")). - 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); + JSHandle flagsString(globalConstants->GetHandledFlagsString()); + JSHandle getFlags(JSObject::GetProperty(thread, thisObj, flagsString).GetValue()); + JSHandle flagsStrHandle = JSTaggedValue::ToString(thread, getFlags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Let matcher be ? Construct(C, « R, flags »). - JSHandle undefined = global_constants->GetHandledUndefined(); + JSHandle undefined = globalConstants->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), undefined, 2); - info->SetCallArgs(this_obj.GetTaggedValue(), flags_str_handle.GetTaggedValue()); - JSTaggedValue tagged_matcher = JSFunction::Construct(info.Get()); - JSHandle matcher_handle(thread, tagged_matcher); + info->SetCallArgs(thisObj.GetTaggedValue(), flagsStrHandle.GetTaggedValue()); + JSTaggedValue taggedMatcher = JSFunction::Construct(info.Get()); + JSHandle matcherHandle(thread, taggedMatcher); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let lastIndex be ? ToLength(? Get(R, "lastIndex")). - 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); + JSHandle lastIndexString(globalConstants->GetHandledLastIndexString()); + JSHandle getLastIndex(JSObject::GetProperty(thread, thisObj, lastIndexString).GetValue()); + JSTaggedNumber thisLastIndex = JSTaggedValue::ToLength(thread, getLastIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Perform ? Set(matcher, "lastIndex", lastIndex, true). - FastRuntimeStub::FastSetPropertyByValue(thread, matcher_handle, last_index_string, - HandleFromLocal(&this_last_index)); + FastRuntimeStub::FastSetPropertyByValue(thread, matcherHandle, lastIndexString, HandleFromLocal(&thisLastIndex)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. If flags contains "g", let global be true. // 10. Else, let global be false. - JSHandle g_string(global_constants->GetHandledGString()); + JSHandle gString(globalConstants->GetHandledGString()); bool global = false; - if (base::StringHelper::Contains(*flags_str_handle, *g_string)) { + if (base::StringHelper::Contains(*flagsStrHandle, *gString)) { global = true; } // 11. If flags contains "u", let fullUnicode be true. // 12. Else, let fullUnicode be false. - JSHandle u_string(global_constants->GetHandledUString()); - bool full_unicode = false; - if (base::StringHelper::Contains(*flags_str_handle, *u_string)) { - full_unicode = true; + JSHandle uString(globalConstants->GetHandledUString()); + bool fullUnicode = false; + if (base::StringHelper::Contains(*flagsStrHandle, *uString)) { + fullUnicode = true; } // 13. Return ! CreateRegExpStringIterator(matcher, S, global, fullUnicode). - return JSRegExpIterator::CreateRegExpStringIterator(thread, matcher_handle, string_handle, global, full_unicode) + return JSRegExpIterator::CreateRegExpStringIterator(thread, matcherHandle, stringHandle, global, fullUnicode) .GetTaggedValue(); } -JSTaggedValue RegExpReplaceFast(JSThread *thread, JSHandle ®exp, JSHandle input_string, - uint32_t input_length) +JSTaggedValue RegExpReplaceFast(JSThread *thread, JSHandle ®exp, JSHandle inputString, + uint32_t inputLength) { ASSERT(regexp->IsJSRegExp()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // get bytecode - JSTaggedValue buffer_data = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); - void *dyn_buf = JSNativePointer::Cast(buffer_data.GetTaggedObject())->GetExternalPointer(); + JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); + void *dynBuf = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); // get flags - auto bytecode_buffer = reinterpret_cast(dyn_buf); + auto bytecodeBuffer = reinterpret_cast(dynBuf); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - 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; + uint32_t flags = *reinterpret_cast(bytecodeBuffer + RegExpParser::FLAGS_OFFSET); + JSHandle lastIndexHandle(thread->GlobalConstants()->GetHandledLastIndexString()); + uint32_t lastIndex; + JSHandle regexpHandle(regexp); + bool useCache = false; if ((flags & (RegExpParser::FLAG_STICKY | RegExpParser::FLAG_GLOBAL)) == 0) { - last_index = 0; + lastIndex = 0; } else { - JSTaggedValue this_index = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, last_index_handle); - if (this_index.IsInt()) { - last_index = static_cast(this_index.GetInt()); + JSTaggedValue thisIndex = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, lastIndexHandle); + if (thisIndex.IsInt()) { + lastIndex = static_cast(thisIndex.GetInt()); } else { - JSHandle this_index_handle(thread, this_index); - last_index = JSTaggedValue::ToLength(thread, this_index_handle).GetNumber(); + JSHandle thisIndexHandle(thread, thisIndex); + lastIndex = JSTaggedValue::ToLength(thread, thisIndexHandle).GetNumber(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } - 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()); + auto globalConst = thread->GlobalConstants(); + JSHandle tagInputString = JSHandle::Cast(inputString); + JSHandle pattern(thread, regexpHandle->GetOriginalSource()); + JSHandle flagsBits(thread, regexpHandle->GetOriginalFlags()); - 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) { + JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); + uint32_t length = inputString->GetLength(); + uint32_t largeStrCount = cacheTable->GetLargeStrCount(); + if (largeStrCount != 0) { if (length > MIN_REPLACE_STRING_LENGTH) { - cache_table->SetLargeStrCount(thread, --large_str_count); + cacheTable->SetLargeStrCount(thread, --largeStrCount); } } else { - cache_table->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); + cacheTable->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); } - if (length > cache_table->GetStrLenThreshold()) { - use_cache = ExecCachingAllowed(thread, regexp); + if (length > cacheTable->GetStrLenThreshold()) { + useCache = ExecCachingAllowed(thread, regexp); } - 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; + if (useCache) { + JSTaggedValue cacheResult = + cacheTable->FindCachedResult(thread, pattern, flagsBits, tagInputString, + RegExpExecResultCache::REPLACE_TYPE, regexp, globalConst->GetEmptyString()); + if (cacheResult != JSTaggedValue::Undefined()) { + return cacheResult; } } - std::string result_string; - uint32_t next_position = 0; + std::string resultString; + uint32_t nextPosition = 0; // 12. Let done be false. // 13. Repeat, while done is false for (;;) { - if (last_index > input_length) { + if (lastIndex > inputLength) { break; } - 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()); + 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()); } else { - u8_buffer = PandaVector(input_length + 1); - input_string->CopyDataUtf8(u8_buffer.data(), input_length + 1); - str_buffer = u8_buffer.data(); + u8Buffer = PandaVector(inputLength + 1); + inputString->CopyDataUtf8(u8Buffer.data(), inputLength + 1); + strBuffer = u8Buffer.data(); } - MatchResult match_result = Matcher(thread, regexp, str_buffer, input_length, last_index, is_utf16); - if (!match_result.is_success) { + MatchResult matchResult = Matcher(thread, regexp, strBuffer, inputLength, lastIndex, isUtf16); + if (!matchResult.isSuccess) { if ((flags & (RegExpParser::FLAG_STICKY | RegExpParser::FLAG_GLOBAL)) != 0) { - last_index = 0; - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), last_index_handle, + lastIndex = 0; + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), lastIndexHandle, thread->GlobalConstants()->GetHandledZero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } break; } - 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); + uint32_t startIndex = matchResult.index; + uint32_t endIndex = matchResult.endIndex; + lastIndex = endIndex; + if (nextPosition < startIndex) { + resultString += base::StringHelper::SubString(inputString, nextPosition, startIndex - nextPosition); } - next_position = end_index; + nextPosition = endIndex; if ((flags & RegExpParser::FLAG_GLOBAL) == 0) { // a. Let setStatus be Set(R, "lastIndex", e, true). - JSTaggedValue last_index_value(last_index); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), last_index_handle, - HandleFromLocal(&last_index_value)); + JSTaggedValue lastIndexValue(lastIndex); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), lastIndexHandle, + HandleFromLocal(&lastIndexValue)); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); break; } - if (end_index == start_index) { - bool unicode = input_string->IsUtf16() && ((flags & RegExpParser::FLAG_UTF16) != 0); - end_index = reg_exp::AdvanceStringIndex(tag_input_string, end_index, unicode); + if (endIndex == startIndex) { + bool unicode = inputString->IsUtf16() && ((flags & RegExpParser::FLAG_UTF16) != 0); + endIndex = reg_exp::AdvanceStringIndex(tagInputString, endIndex, unicode); } - last_index = end_index; + lastIndex = endIndex; } - result_string += base::StringHelper::SubString(input_string, next_position, input_length - next_position); - auto result_value = factory->NewFromStdString(result_string); - if (use_cache) { + resultString += base::StringHelper::SubString(inputString, nextPosition, inputLength - nextPosition); + auto resultValue = factory->NewFromStdString(resultString); + if (useCache) { RegExpExecResultCache::AddResultInCache( - thread, cache_table, pattern, flags_bits, tag_input_string, JSHandle(result_value), - RegExpExecResultCache::REPLACE_TYPE, last_index, global_const->GetEmptyString()); + thread, cacheTable, pattern, flagsBits, tagInputString, JSHandle(resultValue), + RegExpExecResultCache::REPLACE_TYPE, lastIndex, globalConst->GetEmptyString()); } - return result_value.GetTaggedValue(); + return resultValue.GetTaggedValue(); } // 21.2.5.8 @@ -768,184 +767,184 @@ JSTaggedValue reg_exp::proto::Replace(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, Replace); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let rx be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); - if (!this_obj->IsECMAObject()) { + JSHandle thisObj = builtins_common::GetThis(argv); + if (!thisObj->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 = builtins_common::GetCallArg(argv, 0); - JSHandle input_replace_value = builtins_common::GetCallArg(argv, 1); - JSHandle sr_panda_string = JSTaggedValue::ToString(thread, string); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + JSHandle inputReplaceValue = builtins_common::GetCallArg(argv, 1); + JSHandle srPandaString = JSTaggedValue::ToString(thread, string); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 4. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle input_str = JSHandle::Cast(sr_panda_string); + JSHandle inputStr = JSHandle::Cast(srPandaString); // 5. Let lengthS be the number of code unit elements in S. - uint32_t length = sr_panda_string->GetLength(); + uint32_t length = srPandaString->GetLength(); // 6. Let functionalReplace be IsCallable(replaceValue). - bool functional_replace = input_replace_value->IsCallable(); - JSHandle replace_value_handle; - if (!functional_replace) { - replace_value_handle = JSTaggedValue::ToString(thread, input_replace_value); + bool functionalReplace = inputReplaceValue->IsCallable(); + JSHandle replaceValueHandle; + if (!functionalReplace) { + replaceValueHandle = JSTaggedValue::ToString(thread, inputReplaceValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - JSHandle last_index = global_const->GetHandledLastIndexString(); + JSHandle lastIndex = globalConst->GetHandledLastIndexString(); // 8. Let global be ToBoolean(Get(rx, "global")). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle global = global_const->GetHandledGlobalString(); - JSTaggedValue global_value = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, global); + JSHandle global = globalConst->GetHandledGlobalString(); + JSTaggedValue globalValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, global); // 9. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool is_global = global_value.ToBoolean(); + bool isGlobal = globalValue.ToBoolean(); // 10. If global is true, then - bool full_unicode = false; - if (is_global) { + bool fullUnicode = false; + if (isGlobal) { // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). - JSHandle unicode = global_const->GetHandledUnicodeString(); - JSTaggedValue full_unicode_tag = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, unicode); + JSHandle unicode = globalConst->GetHandledUnicodeString(); + JSTaggedValue fullUnicodeTag = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, unicode); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - full_unicode = full_unicode_tag.ToBoolean(); + fullUnicode = fullUnicodeTag.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). - FastRuntimeStub::FastSetPropertyByValue(thread, this_obj, last_index, + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj, lastIndex, thread->GlobalConstants()->GetHandledZero()); // d. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // Add cache for regexp replace - bool use_cache = false; + bool useCache = false; JSMutableHandle pattern(thread, JSTaggedValue::Undefined()); - 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); + 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); } - JSHandle regexp_handle(this_obj); - if (regexp_handle->IsJSRegExp()) { - pattern.Update(regexp_handle->GetOriginalSource()); - flags_bits.Update(regexp_handle->GetOriginalFlags()); + JSHandle regexpHandle(thisObj); + if (regexpHandle->IsJSRegExp()) { + pattern.Update(regexpHandle->GetOriginalSource()); + flagsBits.Update(regexpHandle->GetOriginalFlags()); } - 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); + uint32_t strLength = replaceValueHandle->GetLength(); + uint32_t largeStrCount = cacheTable->GetLargeStrCount(); + if (largeStrCount != 0) { + if (strLength > MIN_REPLACE_STRING_LENGTH) { + cacheTable->SetLargeStrCount(thread, --largeStrCount); } } else { - cache_table->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); + cacheTable->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); } - 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; + 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; } } } } - JSHandle matched_str = global_const->GetHandledZeroString(); + JSHandle matchedStr = globalConst->GetHandledZeroString(); // 11. Let results be a new empty List. - JSHandle results_list(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); - int results_index = 0; + JSHandle resultsList(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); + int resultsIndex = 0; // 12. Let done be false. // 13. Repeat, while done is false - JSMutableHandle next_index_handle(thread, JSTaggedValue(0)); - JSMutableHandle exec_result(thread, JSTaggedValue(0)); + JSMutableHandle nextIndexHandle(thread, JSTaggedValue(0)); + JSMutableHandle execResult(thread, JSTaggedValue(0)); for (;;) { // a. Let result be RegExpExec(rx, S). - exec_result.Update(RegExpExec(thread, this_obj, input_str, use_cache)); + execResult.Update(RegExpExec(thread, thisObj, inputStr, useCache)); // b. ReturnIfAbrupt(result). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If result is null, set done to true. - if (exec_result->IsNull()) { + if (execResult->IsNull()) { break; } // d. Else result is not null, i. Append result to the end of results. - JSObject::CreateDataProperty(thread, results_list, results_index, exec_result); - results_index++; + JSObject::CreateDataProperty(thread, resultsList, resultsIndex, execResult); + resultsIndex++; // ii. If global is false, set done to true. - if (!is_global) { + if (!isGlobal) { break; } // iii. Else, 1. Let matchStr be ToString(Get(result, "0")). - 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); + JSTaggedValue getMatchVal = FastRuntimeStub::FastGetPropertyByValue(thread, execResult, matchedStr); + JSHandle getMatch(thread, getMatchVal); + JSHandle matchString = JSTaggedValue::ToString(thread, getMatch); // 2. ReturnIfAbrupt(matchStr). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If matchStr is the empty String, then - if (match_string->GetLength() == 0) { + if (matchString->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - 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()); + JSTaggedValue thisIndexVal = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, lastIndex); + JSHandle thisIndexHandle(thread, thisIndexVal); + uint32_t thisIndex = 0; + if (thisIndexHandle->IsInt()) { + thisIndex = static_cast(thisIndexHandle->GetInt()); } else { - this_index_val = JSTaggedValue::ToLength(thread, this_index_handle); + thisIndexVal = JSTaggedValue::ToLength(thread, thisIndexHandle); // b. ReturnIfAbrupt(thisIndex). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - this_index = this_index_val.GetNumber(); + thisIndex = thisIndexVal.GetNumber(); } // c. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode). - uint32_t next_index = AdvanceStringIndex(input_str, this_index, full_unicode); - next_index_handle.Update(JSTaggedValue(next_index)); + uint32_t nextIndex = AdvanceStringIndex(inputStr, thisIndex, fullUnicode); + nextIndexHandle.Update(JSTaggedValue(nextIndex)); // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). - FastRuntimeStub::FastSetPropertyByValue(thread, this_obj, last_index, next_index_handle); + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj, lastIndex, nextIndexHandle); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } // 14. Let accumulatedResult be the empty String value. - std::string accumulated_result; + std::string accumulatedResult; // 15. Let nextSourcePosition be 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)); + uint32_t nextSourcePosition = 0; + JSHandle getMatchString; + JSMutableHandle resultValues(thread, JSTaggedValue(0)); + JSMutableHandle ncapturesHandle(thread, JSTaggedValue(0)); + JSMutableHandle capN(thread, JSTaggedValue(0)); // 16. Repeat, for each result in results, - for (int i = 0; i < results_index; i++) { - result_values.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, results_list.GetTaggedValue(), i)); + for (int i = 0; i < resultsIndex; i++) { + resultValues.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultsList.GetTaggedValue(), i)); // a. Let nCaptures be ToLength(Get(result, "length")). - JSHandle length_handle = global_const->GetHandledLengthString(); - ncaptures_handle.Update(FastRuntimeStub::FastGetPropertyByValue(thread, result_values, length_handle)); - uint32_t ncaptures = JSTaggedValue::ToUint32(thread, ncaptures_handle); + JSHandle lengthHandle = globalConst->GetHandledLengthString(); + ncapturesHandle.Update(FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, lengthHandle)); + uint32_t ncaptures = JSTaggedValue::ToUint32(thread, ncapturesHandle); // 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, result_values.GetTaggedValue(), 0); - get_match_string = JSHandle(thread, value); - JSHandle match_string = JSTaggedValue::ToString(thread, get_match_string); + JSTaggedValue value = FastRuntimeStub::GetPropertyByIndex(thread, resultValues.GetTaggedValue(), 0); + getMatchString = JSHandle(thread, value); + JSHandle matchString = JSTaggedValue::ToString(thread, getMatchString); // e. ReturnIfAbrupt(matched). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // f. Let matchLength be the number of code units in matched. - uint32_t match_length = match_string->GetLength(); + uint32_t matchLength = matchString->GetLength(); // g. Let position be ToInteger(Get(result, "index")). - JSHandle result_index = global_const->GetHandledIndexString(); - JSTaggedValue position_tag = FastRuntimeStub::FastGetPropertyByValue(thread, result_values, result_index); - JSHandle position_handle(thread, position_tag); + JSHandle resultIndex = globalConst->GetHandledIndexString(); + JSTaggedValue positionTag = FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, resultIndex); + JSHandle positionHandle(thread, positionTag); uint32_t position = 0; - if (position_handle->IsInt()) { - position = static_cast(position_handle->GetInt()); + if (positionHandle->IsInt()) { + position = static_cast(positionHandle->GetInt()); } else { - position = JSTaggedValue::ToUint32(thread, position_handle); + position = JSTaggedValue::ToUint32(thread, positionHandle); // h. ReturnIfAbrupt(position). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -954,117 +953,117 @@ JSTaggedValue reg_exp::proto::Replace(EcmaRuntimeCallInfo *argv) // j. Let n be 1. uint32_t index = 1; // k. Let captures be an empty List. - JSHandle captures_list = factory->NewTaggedArray(ncaptures); + JSHandle capturesList = factory->NewTaggedArray(ncaptures); // l. Repeat while n ≤ nCaptures while (index <= ncaptures) { // i. Let capN be Get(result, ToString(n)). - cap_n.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, result_values.GetTaggedValue(), index)); + capN.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultValues.GetTaggedValue(), index)); // ii. ReturnIfAbrupt(capN). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iii. If capN is not undefined, then - if (!cap_n->IsUndefined()) { + if (!capN->IsUndefined()) { // 1. Let capN be ToString(capN). - JSHandle cap_n_str = JSTaggedValue::ToString(thread, cap_n); + JSHandle capNStr = JSTaggedValue::ToString(thread, capN); // 2. ReturnIfAbrupt(capN). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle capn_str = JSHandle::Cast(cap_n_str); - captures_list->Set(thread, index - 1, capn_str); + JSHandle capnStr = JSHandle::Cast(capNStr); + capturesList->Set(thread, index - 1, capnStr); } else { // iv. Append capN as the last element of captures. - captures_list->Set(thread, index - 1, cap_n); + capturesList->Set(thread, index - 1, capN); } // v. Let n be n+1 ++index; } // j. Let namedCaptures be ? Get(result, "groups"). - JSHandle groups_key = global_const->GetHandledGroupsString(); - JSTaggedValue named = FastRuntimeStub::FastGetPropertyByValue(thread, result_values, groups_key); - JSHandle named_captures(thread, named); + JSHandle groupsKey = globalConst->GetHandledGroupsString(); + JSTaggedValue named = FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, groupsKey); + JSHandle namedCaptures(thread, named); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // m. If functionalReplace is true, then PandaString replacement; - int empty_arr_length = 0; - if (named_captures->IsUndefined()) { - empty_arr_length = 3; // 3: «matched, pos, and string» + int emptyArrLength = 0; + if (namedCaptures->IsUndefined()) { + emptyArrLength = 3; // 3: «matched, pos, and string» } else { - empty_arr_length = 4; // 4: «matched, pos, string, and groups» + emptyArrLength = 4; // 4: «matched, pos, string, and groups» } - JSHandle replacer_args = factory->NewTaggedArray(empty_arr_length + captures_list->GetLength()); - if (functional_replace) { + JSHandle replacerArgs = factory->NewTaggedArray(emptyArrLength + capturesList->GetLength()); + if (functionalReplace) { // i. Let replacerArgs be «matched». - replacer_args->Set(thread, 0, get_match_string.GetTaggedValue()); + replacerArgs->Set(thread, 0, getMatchString.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 < captures_list->GetLength()) { - replacer_args->Set(thread, index + 1, captures_list->Get(index)); + while (index < capturesList->GetLength()) { + replacerArgs->Set(thread, index + 1, capturesList->Get(index)); ++index; } - 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 + 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 } // iv. Let replValue be Call(replaceValue, undefined, replacerArgs). - const int32_t args_length = replacer_args->GetLength(); - auto info = NewRuntimeCallInfo(thread, input_replace_value, JSTaggedValue::Undefined(), - JSTaggedValue::Undefined(), args_length); + const int32_t argsLength = replacerArgs->GetLength(); + auto info = NewRuntimeCallInfo(thread, inputReplaceValue, JSTaggedValue::Undefined(), + JSTaggedValue::Undefined(), argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info->SetCallArg(args_length, replacer_args->GetData()); - JSTaggedValue replace_result = JSFunction::Call(info.Get()); - JSHandle repl_value(thread, replace_result); + info->SetCallArg(argsLength, replacerArgs->GetData()); + JSTaggedValue replaceResult = JSFunction::Call(info.Get()); + JSHandle replValue(thread, replaceResult); // v. Let replacement be ToString(replValue). - JSHandle replacement_string = JSTaggedValue::ToString(thread, repl_value); + JSHandle replacementString = JSTaggedValue::ToString(thread, replValue); // o. ReturnIfAbrupt(replacement). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - replacement = ConvertToPandaString(*replacement_string, StringConvertedUsage::LOGICOPERATION); + replacement = ConvertToPandaString(*replacementString, StringConvertedUsage::LOGICOPERATION); } else { // n. Else, - if (!named_captures->IsUndefined()) { - JSHandle named_captures_obj = JSTaggedValue::ToObject(thread, named_captures); + if (!namedCaptures->IsUndefined()) { + JSHandle namedCapturesObj = JSTaggedValue::ToObject(thread, namedCaptures); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - named_captures = JSHandle::Cast(named_captures_obj); + namedCaptures = JSHandle::Cast(namedCapturesObj); } - JSHandle replacement_handle( - thread, string::GetSubstitution(thread, match_string, sr_panda_string, position, captures_list, - named_captures, replace_value_handle)); - replacement = ConvertToPandaString(EcmaString::Cast(replacement_handle->GetTaggedObject()), + JSHandle replacementHandle( + thread, string::GetSubstitution(thread, matchString, srPandaString, position, capturesList, + namedCaptures, replaceValueHandle)); + replacement = ConvertToPandaString(EcmaString::Cast(replacementHandle->GetTaggedObject()), StringConvertedUsage::LOGICOPERATION); } // p. If position ≥ nextSourcePosition, then - if (position >= next_source_position) { + if (position >= nextSourcePosition) { // 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. - accumulated_result += base::StringHelper::SubString( - JSHandle::Cast(input_str), next_source_position, (position - next_source_position)); - accumulated_result += replacement; + accumulatedResult += base::StringHelper::SubString(JSHandle::Cast(inputStr), nextSourcePosition, + (position - nextSourcePosition)); + accumulatedResult += replacement; // iii. Let nextSourcePosition be position + matchLength. - next_source_position = position + match_length; + nextSourcePosition = position + matchLength; } } // 17. If nextSourcePosition ≥ lengthS, return accumulatedResult. - if (next_source_position >= length) { - JSHandle result_value = factory->NewFromStdString(accumulated_result); - if (use_cache) { + if (nextSourcePosition >= length) { + JSHandle resultValue = factory->NewFromStdString(accumulatedResult); + if (useCache) { RegExpExecResultCache::AddResultInCache( - thread, cache_table, pattern, flags_bits, string, JSHandle(result_value), - RegExpExecResultCache::REPLACE_TYPE, next_index_handle->GetInt(), input_replace_value.GetTaggedValue()); + thread, cacheTable, pattern, flagsBits, string, JSHandle(resultValue), + RegExpExecResultCache::REPLACE_TYPE, nextIndexHandle->GetInt(), inputReplaceValue.GetTaggedValue()); } - return result_value.GetTaggedValue(); + return resultValue.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). - 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) { + accumulatedResult += base::StringHelper::SubString(JSHandle::Cast(inputStr), nextSourcePosition, + (length - nextSourcePosition)); + JSHandle resultValue = factory->NewFromStdString(accumulatedResult); + if (useCache) { RegExpExecResultCache::AddResultInCache( - thread, cache_table, pattern, flags_bits, string, JSHandle(result_value), - RegExpExecResultCache::REPLACE_TYPE, next_index_handle->GetInt(), input_replace_value.GetTaggedValue()); + thread, cacheTable, pattern, flagsBits, string, JSHandle(resultValue), + RegExpExecResultCache::REPLACE_TYPE, nextIndexHandle->GetInt(), inputReplaceValue.GetTaggedValue()); } - return result_value.GetTaggedValue(); + return resultValue.GetTaggedValue(); } // 21.2.5.9 @@ -1073,40 +1072,40 @@ JSTaggedValue reg_exp::proto::Search(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, Search); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let rx be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); + JSHandle thisObj = builtins_common::GetThis(argv); // 3. Let S be ToString(string). - JSHandle input_str = builtins_common::GetCallArg(argv, 0); - JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); + JSHandle inputStr = builtins_common::GetCallArg(argv, 0); + JSHandle stringHandle = JSTaggedValue::ToString(thread, inputStr); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(string_handle); - if (!this_obj->IsECMAObject()) { + JSHandle string = JSHandle::Cast(stringHandle); + if (!thisObj->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 last_index_string(thread->GlobalConstants()->GetHandledLastIndexString()); - JSHandle previous_last_index = JSObject::GetProperty(thread, this_obj, last_index_string).GetValue(); + JSHandle lastIndexString(thread->GlobalConstants()->GetHandledLastIndexString()); + JSHandle previousLastIndex = JSObject::GetProperty(thread, thisObj, lastIndexString).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If SameValue(previousLastIndex, 0) is false, then // Perform ? Set(rx, "lastIndex", 0, true). - if (!JSTaggedValue::SameValue(previous_last_index.GetTaggedValue(), JSTaggedValue(0))) { + if (!JSTaggedValue::SameValue(previousLastIndex.GetTaggedValue(), JSTaggedValue(0))) { JSHandle value(thread, JSTaggedValue(0)); - JSObject::SetProperty(thread, this_obj, last_index_string, value, true); + JSObject::SetProperty(thread, thisObj, lastIndexString, value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 6. Let result be ? RegExpExec(rx, S). - JSHandle result(thread, RegExpExec(thread, this_obj, string, false)); + JSHandle result(thread, RegExpExec(thread, thisObj, string, false)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let currentLastIndex be ? Get(rx, "lastIndex"). - JSHandle current_last_index = JSObject::GetProperty(thread, this_obj, last_index_string).GetValue(); + JSHandle currentLastIndex = JSObject::GetProperty(thread, thisObj, lastIndexString).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. If SameValue(currentLastIndex, previousLastIndex) is false, then // Perform ? Set(rx, "lastIndex", 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); + if (!JSTaggedValue::SameValue(previousLastIndex.GetTaggedValue(), currentLastIndex.GetTaggedValue())) { + JSObject::SetProperty(thread, thisObj, lastIndexString, previousLastIndex, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 9. If result is null, return -1. @@ -1125,56 +1124,56 @@ JSTaggedValue reg_exp::proto::Split(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExpPrototype, Split); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - bool use_cache = false; + [[maybe_unused]] EcmaHandleScope handleScope(thread); + bool useCache = false; // 1. Let rx be the this value. - JSHandle this_obj = builtins_common::GetThis(argv); - auto ecma_vm = thread->GetEcmaVM(); + JSHandle thisObj = builtins_common::GetThis(argv); + auto ecmaVm = thread->GetEcmaVM(); // 3. Let S be ToString(string). - JSHandle input_string = builtins_common::GetCallArg(argv, 0); + JSHandle inputString = builtins_common::GetCallArg(argv, 0); JSHandle limit = builtins_common::GetCallArg(argv, 1); - JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); + JSHandle stringHandle = JSTaggedValue::ToString(thread, inputString); // 4. ReturnIfAbrupt(string). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle js_string = JSHandle::Cast(string_handle); - if (!this_obj->IsECMAObject()) { + JSHandle jsString = JSHandle::Cast(stringHandle); + if (!thisObj->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 default_constructor = ecma_vm->GetGlobalEnv()->GetRegExpFunction(); - JSHandle obj_handle(this_obj); - JSHandle constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); + JSHandle defaultConstructor = ecmaVm->GetGlobalEnv()->GetRegExpFunction(); + JSHandle objHandle(thisObj); + JSHandle constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); // 6. ReturnIfAbrupt(C). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let flags be ToString(Get(rx, "flags")). - 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(); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); + JSHandle flagsString(globalConstants->GetHandledFlagsString()); + JSHandle taggedFlags = JSObject::GetProperty(thread, thisObj, flagsString).GetValue(); JSHandle flags; - if (tagged_flags->IsUndefined()) { + if (taggedFlags->IsUndefined()) { flags = factory->GetEmptyString(); } else { - flags = JSTaggedValue::ToString(thread, tagged_flags); + flags = JSTaggedValue::ToString(thread, taggedFlags); } // 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 u_string_handle(global_constants->GetHandledUString()); - bool unicode_matching = base::StringHelper::Contains(*flags, *u_string_handle); + JSHandle uStringHandle(globalConstants->GetHandledUString()); + bool unicodeMatching = base::StringHelper::Contains(*flags, *uStringHandle); // 11. If flags contains "y", let newFlags be 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; + JSHandle newFlagsHandle; + JSHandle yStringHandle = JSHandle::Cast(globalConstants->GetHandledYString()); + if (base::StringHelper::Contains(*flags, *yStringHandle)) { + newFlagsHandle = flags; } else { // 12. Else, let newFlags be the string that is the concatenation of flags and "y". - JSHandle y_str = JSHandle::Cast(global_constants->GetHandledYString()); - new_flags_handle = factory->ConcatFromString(flags, y_str); + JSHandle yStr = JSHandle::Cast(globalConstants->GetHandledYString()); + newFlagsHandle = factory->ConcatFromString(flags, yStr); } // 17. If limit is undefined, let lim be 2^32–1; else let lim be ToUint32(limit). @@ -1188,45 +1187,45 @@ JSTaggedValue reg_exp::proto::Split(EcmaRuntimeCallInfo *argv) } if (lim == MAX_SPLIT_LIMIT) { - use_cache = ExecCachingAllowed(thread, this_obj); + useCache = ExecCachingAllowed(thread, thisObj); } - JSHandle regexp_handle(this_obj); + JSHandle regexpHandle(thisObj); JSMutableHandle pattern(thread, JSTaggedValue::Undefined()); - 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; + 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; } } // 13. Let splitter be Construct(C, «rx, newFlags»). - JSHandle global_object(thread, thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject()); - JSHandle undefined = global_constants->GetHandledUndefined(); + JSHandle globalObject(thread, thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject()); + JSHandle undefined = globalConstants->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), undefined, 2); - info->SetCallArgs(this_obj.GetTaggedValue(), new_flags_handle.GetTaggedValue()); - JSTaggedValue tagged_splitter = JSFunction::Construct(info.Get()); + info->SetCallArgs(thisObj.GetTaggedValue(), newFlagsHandle.GetTaggedValue()); + JSTaggedValue taggedSplitter = JSFunction::Construct(info.Get()); // 14. ReturnIfAbrupt(splitter). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle splitter(thread, tagged_splitter); + JSHandle splitter(thread, taggedSplitter); // 15. Let A be ArrayCreate(0). JSHandle array(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); // 16. Let lengthA be 0. - uint32_t a_length = 0; + uint32_t aLength = 0; // 19. Let size be the number of elements in S. - uint32_t size = static_cast(js_string->GetTaggedObject())->GetLength(); + uint32_t size = static_cast(jsString->GetTaggedObject())->GetLength(); // 20. Let p be 0. - uint32_t start_index = 0; + uint32_t startIndex = 0; // 21. If lim = 0, return A. if (lim == 0) { return JSTaggedValue(static_cast(array.GetTaggedValue().GetTaggedObject())); @@ -1234,122 +1233,122 @@ JSTaggedValue reg_exp::proto::Split(EcmaRuntimeCallInfo *argv) // 22. If size = 0, then if (size == 0) { // a. Let z be RegExpExec(splitter, S). - JSHandle exec_result(thread, RegExpExec(thread, splitter, js_string, use_cache)); + JSHandle execResult(thread, RegExpExec(thread, splitter, jsString, useCache)); // b. ReturnIfAbrupt(z). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If z is not null, return A. - if (!exec_result->IsNull()) { + if (!execResult->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, js_string); + JSObject::CreateDataProperty(thread, array, 0, jsString); // f. Return A. return JSTaggedValue(static_cast(array.GetTaggedValue().GetTaggedObject())); } // 23. Let q be p. - uint32_t end_index = start_index; - JSMutableHandle last_indexvalue(thread, JSTaggedValue(end_index)); + uint32_t endIndex = startIndex; + JSMutableHandle lastIndexvalue(thread, JSTaggedValue(endIndex)); // 24. Repeat, while q < size - JSHandle last_index_string = global_constants->GetHandledLastIndexString(); - while (end_index < size) { + JSHandle lastIndexString = globalConstants->GetHandledLastIndexString(); + while (endIndex < size) { // a. Let setStatus be Set(splitter, "lastIndex", q, true). - last_indexvalue.Update(JSTaggedValue(end_index)); - JSObject::SetProperty(thread, splitter, last_index_string, last_indexvalue, true); + lastIndexvalue.Update(JSTaggedValue(endIndex)); + JSObject::SetProperty(thread, splitter, lastIndexString, lastIndexvalue, true); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle exec_result(thread, RegExpExec(thread, splitter, js_string, use_cache)); + JSHandle execResult(thread, RegExpExec(thread, splitter, jsString, useCache)); // d. ReturnIfAbrupt(z). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // e. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). - if (exec_result->IsNull()) { - end_index = AdvanceStringIndex(js_string, end_index, unicode_matching); + if (execResult->IsNull()) { + endIndex = AdvanceStringIndex(jsString, endIndex, unicodeMatching); } else { // f. Else z is not null, // i. Let e be ToLength(Get(splitter, "lastIndex")). - JSHandle last_index_handle = - JSObject::GetProperty(thread, splitter, last_index_string).GetValue(); - JSTaggedNumber last_index_number = JSTaggedValue::ToLength(thread, last_index_handle); + JSHandle lastIndexHandle = + JSObject::GetProperty(thread, splitter, lastIndexString).GetValue(); + JSTaggedNumber lastIndexNumber = JSTaggedValue::ToLength(thread, lastIndexHandle); // ii. ReturnIfAbrupt(e). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t last_index = last_index_number.GetNumber(); + uint32_t lastIndex = lastIndexNumber.GetNumber(); // iii. If e = p, let q be AdvanceStringIndex(S, q, unicodeMatching). - if (last_index == start_index) { - end_index = AdvanceStringIndex(js_string, end_index, unicode_matching); + if (lastIndex == startIndex) { + endIndex = AdvanceStringIndex(jsString, endIndex, unicodeMatching); } 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 std_str_t = base::StringHelper::SubString(JSHandle::Cast(js_string), - start_index, (end_index - start_index)); + std::string stdStrT = base::StringHelper::SubString(JSHandle::Cast(jsString), startIndex, + (endIndex - startIndex)); // 2. Assert: The following call will never result in an abrupt completion. // 3. Perform CreateDataProperty(A, ToString(lengthA), T). - JSHandle t_value(factory->NewFromStdString(std_str_t)); - JSObject::CreateDataProperty(thread, array, a_length, t_value); + JSHandle tValue(factory->NewFromStdString(stdStrT)); + JSObject::CreateDataProperty(thread, array, aLength, tValue); // 4. Let lengthA be lengthA +1. - ++a_length; + ++aLength; // 5. If lengthA = lim, return A. - if (a_length == lim) { - if (use_cache) { - RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags_bits, input_string, + if (aLength == lim) { + if (useCache) { + RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flagsBits, inputString, JSHandle(array), - RegExpExecResultCache::SPLIT_TYPE, last_index); + RegExpExecResultCache::SPLIT_TYPE, lastIndex); } return array.GetTaggedValue(); } // 6. Let p be e. - start_index = last_index; + startIndex = lastIndex; // 7. Let numberOfCaptures be ToLength(Get(z, "length")). - 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); + JSHandle lengthString(thread->GlobalConstants()->GetHandledLengthString()); + JSHandle capturesHandle = + JSObject::GetProperty(thread, execResult, lengthString).GetValue(); + JSTaggedNumber numberOfCapturesNumber = JSTaggedValue::ToLength(thread, capturesHandle); // 8. ReturnIfAbrupt(numberOfCaptures). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t number_of_captures = number_of_captures_number.GetNumber(); + uint32_t numberOfCaptures = numberOfCapturesNumber.GetNumber(); // 9. Let numberOfCaptures be max(numberOfCaptures-1, 0). - number_of_captures = (number_of_captures == 0) ? 0 : number_of_captures - 1; + numberOfCaptures = (numberOfCaptures == 0) ? 0 : numberOfCaptures - 1; // 10. Let i be 1. uint32_t i = 1; // 11. Repeat, while i ≤ numberOfCaptures. - while (i <= number_of_captures) { + while (i <= numberOfCaptures) { // a. Let nextCapture be Get(z, ToString(i)). - JSHandle next_capture = JSObject::GetProperty(thread, exec_result, i).GetValue(); + JSHandle nextCapture = JSObject::GetProperty(thread, execResult, i).GetValue(); // b. ReturnIfAbrupt(nextCapture). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Perform CreateDataProperty(A, ToString(lengthA), nextCapture). - JSObject::CreateDataProperty(thread, array, a_length, next_capture); + JSObject::CreateDataProperty(thread, array, aLength, nextCapture); // d. Let i be i + 1. ++i; // e. Let lengthA be lengthA +1. - ++a_length; + ++aLength; // f. If lengthA = lim, return A. - if (a_length == lim) { - if (use_cache) { - RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags_bits, - input_string, JSHandle(array), - RegExpExecResultCache::SPLIT_TYPE, last_index); + if (aLength == lim) { + if (useCache) { + RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flagsBits, inputString, + JSHandle(array), + RegExpExecResultCache::SPLIT_TYPE, lastIndex); } return array.GetTaggedValue(); } } // 12. Let q be p. - end_index = start_index; + endIndex = startIndex; } } } // 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 std_str_t = - base::StringHelper::SubString(JSHandle::Cast(js_string), start_index, (size - start_index)); + std::string stdStrT = + base::StringHelper::SubString(JSHandle::Cast(jsString), startIndex, (size - startIndex)); // 26. Assert: The following call will never result in an abrupt completion. // 27. Perform CreateDataProperty(A, ToString(lengthA), t). - JSHandle t_value(factory->NewFromStdString(std_str_t)); - JSObject::CreateDataProperty(thread, array, a_length, t_value); + JSHandle tValue(factory->NewFromStdString(stdStrT)); + JSObject::CreateDataProperty(thread, array, aLength, tValue); if (lim == MAX_SPLIT_LIMIT) { - RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags_bits, input_string, + RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flagsBits, inputString, JSHandle(array), RegExpExecResultCache::SPLIT_TYPE, - end_index); + endIndex); } // 28. Return A. return array.GetTaggedValue(); @@ -1357,26 +1356,26 @@ JSTaggedValue reg_exp::proto::Split(EcmaRuntimeCallInfo *argv) // NOLINTNEXTLINE(readability-non-const-parameter) MatchResult Matcher(JSThread *thread, const JSHandle ®exp, const uint8_t *buffer, size_t length, - int32_t last_index, bool is_utf16) + int32_t lastIndex, bool isUtf16) { // get bytecode - JSTaggedValue buffer_data = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); - void *dyn_buf = JSNativePointer::Cast(buffer_data.GetTaggedObject())->GetExternalPointer(); - auto bytecode_buffer = reinterpret_cast(dyn_buf); + JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); + void *dynBuf = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); + auto bytecodeBuffer = reinterpret_cast(dynBuf); // execute RegExpExecutor executor = RegExpExecutor(); - if (last_index < 0) { - last_index = 0; + if (lastIndex < 0) { + lastIndex = 0; } - bool ret = executor.Execute(buffer, last_index, static_cast(length), bytecode_buffer, is_utf16); + bool ret = executor.Execute(buffer, lastIndex, static_cast(length), bytecodeBuffer, isUtf16); MatchResult result = executor.GetResult(thread, ret); return result; } -uint32_t reg_exp::AdvanceStringIndex(const JSHandle &input_str, uint32_t index, bool unicode) +uint32_t reg_exp::AdvanceStringIndex(const JSHandle &inputStr, uint32_t index, bool unicode) { // 1. Assert: Type(S) is String. - ASSERT(input_str->IsString()); + ASSERT(inputStr->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. @@ -1385,19 +1384,19 @@ uint32_t reg_exp::AdvanceStringIndex(const JSHandle &input_str, u return index + 1; } // 5. Let length be the number of code units in S. - uint32_t length = static_cast(input_str->GetTaggedObject())->GetLength(); + uint32_t length = static_cast(inputStr->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(input_str->GetTaggedObject())->At(index); + uint16_t first = static_cast(inputStr->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(input_str->GetTaggedObject())->At(index + 1); + uint16_t second = static_cast(inputStr->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; @@ -1415,144 +1414,144 @@ bool GetFlagsInternal(JSThread *thread, const JSHandle &obj, cons THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", false); } // 3. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError exception. - JSHandle pattern_obj = JSHandle::Cast(obj); - if (!pattern_obj->IsJSRegExp()) { + JSHandle patternObj = JSHandle::Cast(obj); + if (!patternObj->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 regexp_obj(thread, JSRegExp::Cast(obj->GetTaggedObject())); + JSHandle regexpObj(thread, JSRegExp::Cast(obj->GetTaggedObject())); // 5. If flags contains the code unit "[flag]", return true. // 6. Return false. - uint8_t flags = static_cast(regexp_obj->GetOriginalFlags().GetInt()); + uint8_t flags = static_cast(regexpObj->GetOriginalFlags().GetInt()); return (flags & mask) != 0; } // 21.2.5.2.2 JSTaggedValue RegExpBuiltinExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &input_str, bool use_cache) + const JSHandle &inputStr, bool useCache) { ASSERT(JSObject::IsRegExp(thread, regexp)); - ASSERT(input_str->IsString()); + ASSERT(inputStr->IsString()); - 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; + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle lastIndexHandle = globalConst->GetHandledLastIndexString(); + JSTaggedValue result = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, lastIndexHandle); + int32_t lastIndex = 0; if (result.IsInt()) { - last_index = result.GetInt(); + lastIndex = result.GetInt(); } else { - JSHandle last_index_result(thread, result); - JSTaggedNumber last_index_number = JSTaggedValue::ToLength(thread, last_index_result); + JSHandle lastIndexResult(thread, result); + JSTaggedNumber lastIndexNumber = JSTaggedValue::ToLength(thread, lastIndexResult); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - last_index = last_index_number.GetNumber(); + lastIndex = lastIndexNumber.GetNumber(); } - JSHandle global_handle = global_const->GetHandledGlobalString(); - bool global = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, global_handle).ToBoolean(); + JSHandle globalHandle = globalConst->GetHandledGlobalString(); + bool global = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, globalHandle).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle sticky_handle = global_const->GetHandledStickyString(); - bool sticky = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, sticky_handle).ToBoolean(); + JSHandle stickyHandle = globalConst->GetHandledStickyString(); + bool sticky = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, stickyHandle).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!global && !sticky) { - last_index = 0; + lastIndex = 0; } - JSHandle regexp_obj(regexp); - JSMutableHandle pattern(thread, regexp_obj->GetOriginalSource()); - JSMutableHandle flags(thread, regexp_obj->GetOriginalFlags()); + JSHandle regexpObj(regexp); + JSMutableHandle pattern(thread, regexpObj->GetOriginalSource()); + JSMutableHandle flags(thread, regexpObj->GetOriginalFlags()); - 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, + JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); + uint32_t length = static_cast(inputStr->GetTaggedObject())->GetLength(); + if (lastIndex > static_cast(length)) { + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, thread->GlobalConstants()->GetHandledZero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Null(); } - 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()); + 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()); } else { - u8_buffer = PandaVector(string_length + 1); - input_string->CopyDataUtf8(u8_buffer.data(), string_length + 1); - str_buffer = u8_buffer.data(); + u8Buffer = PandaVector(stringLength + 1); + inputString->CopyDataUtf8(u8Buffer.data(), stringLength + 1); + strBuffer = u8Buffer.data(); } - MatchResult match_result = Matcher(thread, regexp, str_buffer, string_length, last_index, is_utf16); - if (!match_result.is_success) { + MatchResult matchResult = Matcher(thread, regexp, strBuffer, stringLength, lastIndex, isUtf16); + if (!matchResult.isSuccess) { if (global || sticky) { - JSHandle last_index_value(thread, JSTaggedValue(0)); - FastRuntimeStub::FastSetPropertyByValue(thread, regexp, last_index_handle, + JSHandle lastIndexValue(thread, JSTaggedValue(0)); + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, thread->GlobalConstants()->GetHandledZero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } return JSTaggedValue::Null(); } - uint32_t end_index = match_result.end_index; + uint32_t endIndex = matchResult.endIndex; if (global || sticky) { // a. Let setStatus be Set(R, "lastIndex", e, true). - JSTaggedValue end_index_val(end_index); - FastRuntimeStub::FastSetPropertyByValue(thread, regexp, last_index_handle, HandleFromLocal(&end_index_val)); + JSTaggedValue endIndexVal(endIndex); + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, HandleFromLocal(&endIndexVal)); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - uint32_t captures_size = match_result.captures.size(); - JSHandle results(JSArray::ArrayCreate(thread, JSTaggedNumber(captures_size))); - uint32_t match_index = match_result.index; + uint32_t capturesSize = matchResult.captures.size(); + JSHandle results(JSArray::ArrayCreate(thread, JSTaggedNumber(capturesSize))); + uint32_t matchIndex = matchResult.index; // 24. Perform CreateDataProperty(A, "index", matchIndex). - JSHandle index_key = global_const->GetHandledIndexString(); - JSHandle index_value(thread, JSTaggedValue(match_index)); - JSObject::CreateDataProperty(thread, results, index_key, index_value); + JSHandle indexKey = globalConst->GetHandledIndexString(); + JSHandle indexValue(thread, JSTaggedValue(matchIndex)); + JSObject::CreateDataProperty(thread, results, indexKey, indexValue); // 25. Perform CreateDataProperty(A, "input", S). - JSHandle input_key = global_const->GetHandledInputString(); + JSHandle inputKey = globalConst->GetHandledInputString(); - JSHandle input_value(thread, static_cast(input_str->GetTaggedObject())); - JSObject::CreateDataProperty(thread, results, input_key, input_value); + JSHandle inputValue(thread, static_cast(inputStr->GetTaggedObject())); + JSObject::CreateDataProperty(thread, results, inputKey, inputValue); // 27. Perform CreateDataProperty(A, "0", matched_substr). - JSHandle zero_value(match_result.captures[0].second); - JSObject::CreateDataProperty(thread, results, 0, zero_value); + JSHandle zeroValue(matchResult.captures[0].second); + JSObject::CreateDataProperty(thread, results, 0, zeroValue); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle group_name(thread, regexp_obj->GetGroupName()); + JSHandle groupName(thread, regexpObj->GetGroupName()); JSMutableHandle groups(thread, JSTaggedValue::Undefined()); - if (!group_name->IsUndefined()) { - JSHandle null_handle(thread, JSTaggedValue::Null()); - JSHandle null_obj = factory->OrdinaryNewJSObjectCreate(null_handle); - groups.Update(null_obj.GetTaggedValue()); + if (!groupName->IsUndefined()) { + JSHandle nullHandle(thread, JSTaggedValue::Null()); + JSHandle nullObj = factory->OrdinaryNewJSObjectCreate(nullHandle); + groups.Update(nullObj.GetTaggedValue()); } - JSHandle groups_key = global_const->GetHandledGroupsString(); - JSObject::CreateDataProperty(thread, results, groups_key, groups); + JSHandle groupsKey = globalConst->GetHandledGroupsString(); + JSObject::CreateDataProperty(thread, results, groupsKey, groups); // 28. For each integer i such that i > 0 and i <= n - for (uint32_t i = 1; i < captures_size; i++) { + for (uint32_t i = 1; i < capturesSize; i++) { // a. Let capture_i be ith element of r's captures List - JSTaggedValue captured_value; - if (match_result.captures[i].first) { - captured_value = JSTaggedValue::Undefined(); + JSTaggedValue capturedValue; + if (matchResult.captures[i].first) { + capturedValue = JSTaggedValue::Undefined(); } else { - captured_value = match_result.captures[i].second.GetTaggedValue(); + capturedValue = matchResult.captures[i].second.GetTaggedValue(); } - 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); + 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); } } } - if (last_index == 0 && use_cache) { - RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags, input_str, + if (lastIndex == 0 && useCache) { + RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flags, inputStr, JSHandle(results), RegExpExecResultCache::EXEC_TYPE, - end_index); + endIndex); } // 29. Return A. return results.GetTaggedValue(); @@ -1560,25 +1559,25 @@ JSTaggedValue RegExpBuiltinExec(JSThread *thread, const JSHandle // 21.2.5.2.1 JSTaggedValue reg_exp::RegExpExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &input_string, bool use_cache) + const JSHandle &inputString, bool useCache) { // 1. Assert: Type(R) is Object. ASSERT(regexp->IsECMAObject()); // 2. Assert: Type(S) is String. - ASSERT(input_string->IsString()); + ASSERT(inputString->IsString()); // 3. Let exec be Get(R, "exec"). - JSHandle input_str = JSTaggedValue::ToString(thread, input_string); + JSHandle inputStr = JSTaggedValue::ToString(thread, inputString); - 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); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle execHandle = globalConst->GetHandledExecString(); + JSTaggedValue execVal = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, execHandle); + JSHandle exec(thread, execVal); // 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(input_str.GetTaggedValue()); + info->SetCallArgs(inputStr.GetTaggedValue()); JSTaggedValue result = JSFunction::Call(info.Get()); // b. ReturnIfAbrupt(result). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1594,11 +1593,11 @@ JSTaggedValue reg_exp::RegExpExec(JSThread *thread, const JSHandle &new_target) +JSTaggedValue RegExpAlloc(JSThread *thread, const JSHandle &newTarget) { /** * 1. Let obj be OrdinaryCreateFromConstructor(new_target, "%RegExpPrototype%", @@ -1607,53 +1606,53 @@ JSTaggedValue RegExpAlloc(JSThread *thread, const JSHandle &new_t ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle func = env->GetRegExpFunction(); - JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(func), new_target)); + JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(func), newTarget)); // 2. ReturnIfAbrupt(obj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return obj. return obj.GetTaggedValue(); } -uint32_t UpdateExpressionFlags(JSThread *thread, const PandaString &check_str) +uint32_t UpdateExpressionFlags(JSThread *thread, const PandaString &checkStr) { - uint32_t flags_bits = 0; - uint32_t flags_bits_temp = 0; - for (char i : check_str) { + uint32_t flagsBits = 0; + uint32_t flagsBitsTemp = 0; + for (char i : checkStr) { switch (i) { case 'g': - flags_bits_temp = RegExpParser::FLAG_GLOBAL; + flagsBitsTemp = RegExpParser::FLAG_GLOBAL; break; case 'i': - flags_bits_temp = RegExpParser::FLAG_IGNORECASE; + flagsBitsTemp = RegExpParser::FLAG_IGNORECASE; break; case 'm': - flags_bits_temp = RegExpParser::FLAG_MULTILINE; + flagsBitsTemp = RegExpParser::FLAG_MULTILINE; break; case 's': - flags_bits_temp = RegExpParser::FLAG_DOTALL; + flagsBitsTemp = RegExpParser::FLAG_DOTALL; break; case 'u': - flags_bits_temp = RegExpParser::FLAG_UTF16; + flagsBitsTemp = RegExpParser::FLAG_UTF16; break; case 'y': - flags_bits_temp = RegExpParser::FLAG_STICKY; + flagsBitsTemp = RegExpParser::FLAG_STICKY; break; default: { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle syntax_error = + JSHandle syntaxError = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, "invalid regular expression flags"); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), 0); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), 0); } } - if ((flags_bits & flags_bits_temp) != 0) { + if ((flagsBits & flagsBitsTemp) != 0) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle syntax_error = + JSHandle syntaxError = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, "invalid regular expression flags"); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), 0); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), 0); } - flags_bits |= flags_bits_temp; + flagsBits |= flagsBitsTemp; } - return flags_bits; + return flagsBits; } JSTaggedValue reg_exp::FlagsBitsToString(JSThread *thread, uint8_t flags) @@ -1661,36 +1660,36 @@ JSTaggedValue reg_exp::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 flags_str; // 7: maximum 6 flags + '\0' - size_t flags_len = 0; + std::array flagsStr; // 7: maximum 6 flags + '\0' + size_t flagsLen = 0; if ((flags & RegExpParser::FLAG_GLOBAL) != 0) { - flags_str[flags_len] = 'g'; - flags_len++; + flagsStr[flagsLen] = 'g'; + flagsLen++; } if ((flags & RegExpParser::FLAG_IGNORECASE) != 0) { - flags_str[flags_len] = 'i'; - flags_len++; + flagsStr[flagsLen] = 'i'; + flagsLen++; } if ((flags & RegExpParser::FLAG_MULTILINE) != 0) { - flags_str[flags_len] = 'm'; - flags_len++; + flagsStr[flagsLen] = 'm'; + flagsLen++; } if ((flags & RegExpParser::FLAG_DOTALL) != 0) { - flags_str[flags_len] = 's'; - flags_len++; + flagsStr[flagsLen] = 's'; + flagsLen++; } if ((flags & RegExpParser::FLAG_UTF16) != 0) { - flags_str[flags_len] = 'u'; - flags_len++; + flagsStr[flagsLen] = 'u'; + flagsLen++; } if ((flags & RegExpParser::FLAG_STICKY) != 0) { - flags_str[flags_len] = 'y'; - flags_len++; + flagsStr[flagsLen] = 'y'; + flagsLen++; } - flags_str[flags_len] = '\0'; - JSHandle flags_string = thread->GetEcmaVM()->GetFactory()->NewFromUtf8(flags_str.data(), flags_len); + flagsStr[flagsLen] = '\0'; + JSHandle flagsString = thread->GetEcmaVM()->GetFactory()->NewFromUtf8(flagsStr.data(), flagsLen); - return flags_string.GetTaggedValue(); + return flagsString.GetTaggedValue(); } // 21.2.3.2.2 @@ -1698,81 +1697,80 @@ JSTaggedValue RegExpInitialize(JSThread *thread, const JSHandle & const JSHandle &pattern, const JSHandle &flags) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle pattern_str_handle; - uint8_t flags_bits = 0; + JSHandle patternStrHandle; + uint8_t flagsBits = 0; // 1. If pattern is undefined, let P be the empty String. if (pattern->IsUndefined()) { - pattern_str_handle = factory->GetEmptyString(); + patternStrHandle = factory->GetEmptyString(); } else { // 2. Else, let P be ToString(pattern). - pattern_str_handle = JSTaggedValue::ToString(thread, pattern); + patternStrHandle = 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()) { - flags_bits = 0; + flagsBits = 0; } else if (flags->IsInt()) { - flags_bits = static_cast(flags->GetInt()); + flagsBits = static_cast(flags->GetInt()); } else { // 5. Else, let F be ToString(flags). - JSHandle flags_str_handle = JSTaggedValue::ToString(thread, flags); + JSHandle flagsStrHandle = 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 check_str = ConvertToPandaString(*flags_str_handle, StringConvertedUsage::LOGICOPERATION); - flags_bits = static_cast(UpdateExpressionFlags(thread, check_str)); + PandaString checkStr = ConvertToPandaString(*flagsStrHandle, StringConvertedUsage::LOGICOPERATION); + flagsBits = static_cast(UpdateExpressionFlags(thread, checkStr)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // String -> PandaString - PandaString pattern_std_str = ConvertToPandaString(*pattern_str_handle, StringConvertedUsage::LOGICOPERATION); + PandaString patternStdStr = ConvertToPandaString(*patternStrHandle, StringConvertedUsage::LOGICOPERATION); // 9. 10. RegExpParser parser = RegExpParser(); - 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); + 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); parser.Parse(); if (parser.IsError()) { - JSHandle syntax_error = + JSHandle syntaxError = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, parser.GetErrorMsg().c_str()); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), JSTaggedValue::Exception()); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception()); } - group_name = parser.GetGroupNames(); + groupName = parser.GetGroupNames(); } JSHandle regexp(thread, JSRegExp::Cast(obj->GetTaggedObject())); // 11. Set the value of obj’s [[OriginalSource]] internal slot to P. - regexp->SetOriginalSource(thread, pattern_str_handle.GetTaggedValue()); + regexp->SetOriginalSource(thread, patternStrHandle.GetTaggedValue()); // 12. Set the value of obj’s [[OriginalFlags]] internal slot to F. - 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->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->SetGroupName(thread, tagged_array); + regexp->SetGroupName(thread, taggedArray); } // 13. Set obj’s [[RegExpMatcher]] internal slot. - if (get_cache.first == JSTaggedValue::Hole()) { - auto buffer_size = parser.GetOriginBufferSize(); + if (getCache.first == JSTaggedValue::Hole()) { + auto bufferSize = parser.GetOriginBufferSize(); auto buffer = parser.GetOriginBuffer(); - factory->NewJSRegExpByteCodeData(regexp, buffer, buffer_size); - reg_exp_parser_cache->SetCache(*pattern_str_handle, flags_bits, regexp->GetByteCodeBuffer(), buffer_size, - std::move(group_name)); + factory->NewJSRegExpByteCodeData(regexp, buffer, bufferSize); + regExpParserCache->SetCache(*patternStrHandle, flagsBits, regexp->GetByteCodeBuffer(), bufferSize, + std::move(groupName)); } else { - regexp->SetByteCodeBuffer(thread, get_cache.first); - regexp->SetLength(thread, JSTaggedValue(static_cast(get_cache.second))); + regexp->SetByteCodeBuffer(thread, getCache.first); + regexp->SetLength(thread, JSTaggedValue(static_cast(getCache.second))); } // 14. Let setStatus be Set(obj, "lastIndex", 0, true). - JSHandle last_index_string = thread->GlobalConstants()->GetHandledLastIndexString(); - FastRuntimeStub::FastSetPropertyByValue(thread, obj, last_index_string, - thread->GlobalConstants()->GetHandledZero()); + JSHandle lastIndexString = thread->GlobalConstants()->GetHandledLastIndexString(); + FastRuntimeStub::FastSetPropertyByValue(thread, obj, lastIndexString, thread->GlobalConstants()->GetHandledZero()); // 15. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. Return obj. @@ -1783,11 +1781,11 @@ JSTaggedValue reg_exp::RegExpCreate(JSThread *thread, const JSHandle &flags) { BUILTINS_API_TRACE(thread, RegExp, RegExpCreate); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - JSHandle new_target = env->GetRegExpFunction(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + JSHandle newTarget = env->GetRegExpFunction(); // 1. Let obj be RegExpAlloc(%RegExp%). - JSHandle object(thread, RegExpAlloc(thread, new_target)); + JSHandle object(thread, RegExpAlloc(thread, newTarget)); // 2. ReturnIfAbrupt(obj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return RegExpInitialize(obj, P, F). @@ -1799,20 +1797,20 @@ EcmaString *EscapeRegExpPattern(JSThread *thread, const JSHandle const JSHandle &flags) { // String -> PandaString - 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); + JSHandle srcStr(thread, static_cast(src->GetTaggedObject())); + JSHandle flagsStr(thread, static_cast(flags->GetTaggedObject())); + PandaString srcStdStr = ConvertToPandaString(*srcStr, StringConvertedUsage::LOGICOPERATION); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // "" -> (?:) - if (src_std_str.empty()) { - src_std_str = "(?:)"; + if (srcStdStr.empty()) { + srcStdStr = "(?:)"; } // "/" -> "\/" - src_std_str = base::StringHelper::RepalceAll(src_std_str, "/", "\\/"); + srcStdStr = base::StringHelper::RepalceAll(srcStdStr, "/", "\\/"); // "\\" -> "\" - src_std_str = base::StringHelper::RepalceAll(src_std_str, "\\", "\\"); + srcStdStr = base::StringHelper::RepalceAll(srcStdStr, "\\", "\\"); - return *factory->NewFromString(src_std_str); + return *factory->NewFromString(srcStdStr); } JSTaggedValue RegExpExecResultCache::CreateCacheTable(JSThread *thread) @@ -1835,9 +1833,9 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, const JS const JSHandle &input, CacheType type, const JSHandle ®exp, JSTaggedValue extend) { - JSTaggedValue pattern_value = pattern.GetTaggedValue(); - JSTaggedValue flags_value = flags.GetTaggedValue(); - JSTaggedValue input_value = input.GetTaggedValue(); + JSTaggedValue patternValue = pattern.GetTaggedValue(); + JSTaggedValue flagsValue = flags.GetTaggedValue(); + JSTaggedValue inputValue = input.GetTaggedValue(); if (!pattern->IsString() || !flags->IsInt() || !input->IsString()) { return JSTaggedValue::Undefined(); @@ -1845,9 +1843,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, pattern_value, flags_value, input_value, extend)) { + if (!Match(entry, patternValue, flagsValue, inputValue, extend)) { uint32_t entry2 = (entry + 1) & static_cast(GetCacheLength() - 1); - if (!Match(entry2, pattern_value, flags_value, input_value, extend)) { + if (!Match(entry2, patternValue, flagsValue, inputValue, extend)) { return JSTaggedValue::Undefined(); } entry = entry2; @@ -1872,65 +1870,65 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, const JS break; } SetHitCount(thread, GetHitCount() + 1); - 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)); + JSHandle lastIndexHandle = thread->GlobalConstants()->GetHandledLastIndexString(); + JSTaggedValue lastIndex = Get(index + LAST_INDEX_INDEX); // must be primitive + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, HandleFromLocal(&lastIndex)); return result; } void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle cache, const JSHandle &pattern, const JSHandle &flags, const JSHandle &input, - const JSHandle &result_array, CacheType type, - uint32_t last_index, JSTaggedValue extend) + const JSHandle &resultArray, CacheType type, + uint32_t lastIndex, JSTaggedValue extend) { if (!pattern->IsString() || !flags->IsInt() || !input->IsString()) { return; } - JSTaggedValue pattern_value = pattern.GetTaggedValue(); - JSTaggedValue flags_value = flags.GetTaggedValue(); - JSTaggedValue input_value = input.GetTaggedValue(); - JSTaggedValue last_index_value(last_index); + JSTaggedValue patternValue = pattern.GetTaggedValue(); + JSTaggedValue flagsValue = flags.GetTaggedValue(); + JSTaggedValue inputValue = input.GetTaggedValue(); + JSTaggedValue lastIndexValue(lastIndex); uint32_t hash = - pattern_value.GetKeyHashCode() + static_cast(flags_value.GetInt()) + input_value.GetKeyHashCode(); + patternValue.GetKeyHashCode() + static_cast(flagsValue.GetInt()) + inputValue.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, 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); + 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); } else { uint32_t entry2 = (entry + 1) & static_cast(cache->GetCacheLength() - 1); uint32_t index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE; - JSHandle extend_handle(thread, extend); + JSHandle extendHandle(thread, extend); if (cache->GetCacheLength() < DEFAULT_CACHE_NUMBER) { GrowRegexpCache(thread, cache); // update value after gc. - pattern_value = pattern.GetTaggedValue(); - flags_value = flags.GetTaggedValue(); - input_value = input.GetTaggedValue(); + patternValue = pattern.GetTaggedValue(); + flagsValue = flags.GetTaggedValue(); + inputValue = input.GetTaggedValue(); cache->SetCacheLength(thread, DEFAULT_CACHE_NUMBER); entry2 = hash & static_cast(cache->GetCacheLength() - 1); index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE; } - JSTaggedValue extend_value = extend_handle.GetTaggedValue(); + JSTaggedValue extendValue = extendHandle.GetTaggedValue(); if (cache->Get(index2) == JSTaggedValue::Undefined()) { cache->SetCacheCount(thread, cache->GetCacheCount() + 1); - 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); + 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); } 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, pattern_value, flags_value, input_value, last_index_value, extend_value); - cache->UpdateResultArray(thread, entry, result_array.GetTaggedValue(), type); + cache->SetEntry(thread, entry, patternValue, flagsValue, inputValue, lastIndexValue, extendValue); + cache->UpdateResultArray(thread, entry, resultArray.GetTaggedValue(), type); } } } @@ -1939,37 +1937,37 @@ void RegExpExecResultCache::GrowRegexpCache(JSThread *thread, JSHandleGetEcmaVM()->GetFactory(); - auto new_cache = factory->ExtendArray(JSHandle(cache), length, JSTaggedValue::Undefined()); - thread->GetEcmaVM()->SetRegExpCache(new_cache.GetTaggedValue()); + auto newCache = factory->ExtendArray(JSHandle(cache), length, JSTaggedValue::Undefined()); + thread->GetEcmaVM()->SetRegExpCache(newCache.GetTaggedValue()); } void RegExpExecResultCache::SetEntry(JSThread *thread, int entry, JSTaggedValue &pattern, JSTaggedValue &flags, - JSTaggedValue &input, JSTaggedValue &last_index_value, JSTaggedValue &extend_value) + JSTaggedValue &input, JSTaggedValue &lastIndexValue, JSTaggedValue &extendValue) { 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, last_index_value); - Set(thread, index + EXTEND_INDEX, extend_value); + Set(thread, index + LAST_INDEX_INDEX, lastIndexValue); + Set(thread, index + EXTEND_INDEX, extendValue); } -void RegExpExecResultCache::UpdateResultArray(JSThread *thread, int entry, JSTaggedValue result_array, CacheType type) +void RegExpExecResultCache::UpdateResultArray(JSThread *thread, int entry, JSTaggedValue resultArray, CacheType type) { int index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; switch (type) { break; case REPLACE_TYPE: - Set(thread, index + RESULT_REPLACE_INDEX, result_array); + Set(thread, index + RESULT_REPLACE_INDEX, resultArray); break; case SPLIT_TYPE: - Set(thread, index + RESULT_SPLIT_INDEX, result_array); + Set(thread, index + RESULT_SPLIT_INDEX, resultArray); break; case MATCH_TYPE: - Set(thread, index + RESULT_MATCH_INDEX, result_array); + Set(thread, index + RESULT_MATCH_INDEX, resultArray); break; case EXEC_TYPE: - Set(thread, index + RESULT_EXEC_INDEX, result_array); + Set(thread, index + RESULT_EXEC_INDEX, resultArray); break; default: UNREACHABLE(); @@ -1989,32 +1987,32 @@ bool RegExpExecResultCache::Match(int entry, JSTaggedValue &pattern, JSTaggedVal JSTaggedValue &extend) { int index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; - 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); + 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); - if (key_pattern == JSTaggedValue::Undefined()) { + if (keyPattern == JSTaggedValue::Undefined()) { return false; } - 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; + 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; } else { return false; } - return EcmaString::StringsAreEqual(pattern_str, key_pattern_str) && flags_bits == key_flags_bits && - EcmaString::StringsAreEqual(input_str, key_input_str) && extend_equal; + return EcmaString::StringsAreEqual(patternStr, keyPatternStr) && flagsBits == keyFlagsBits && + EcmaString::StringsAreEqual(inputStr, keyInputStr) && extendEqual; } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_regexp.h b/runtime/builtins/builtins_regexp.h index ac8d4de7281d3cd4ff4a02833ee8e38e0507fc62..f2dcb60b36e0e66735a2b75bb269e2f20caffeea 100644 --- a/runtime/builtins/builtins_regexp.h +++ b/runtime/builtins/builtins_regexp.h @@ -42,21 +42,20 @@ 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 &result_array, - CacheType type, uint32_t last_index, - JSTaggedValue extend = JSTaggedValue::Undefined()); + const JSHandle &input, const JSHandle &resultArray, + CacheType type, uint32_t lastIndex, 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 &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 &lastIndexValue, JSTaggedValue &extendValue); + void UpdateResultArray(JSThread *thread, int entry, JSTaggedValue resultArray, CacheType type); + bool Match(int entry, JSTaggedValue &patternStr, JSTaggedValue &flagsStr, JSTaggedValue &inputStr, JSTaggedValue &extend); - inline void SetHitCount(JSThread *thread, int hit_count) + inline void SetHitCount(JSThread *thread, int hitCount) { - Set(thread, CACHE_HIT_COUNT_INDEX, JSTaggedValue(hit_count)); + Set(thread, CACHE_HIT_COUNT_INDEX, JSTaggedValue(hitCount)); } inline int GetHitCount() @@ -64,9 +63,9 @@ public: return Get(CACHE_HIT_COUNT_INDEX).GetInt(); } - inline void SetCacheCount(JSThread *thread, int hit_count) + inline void SetCacheCount(JSThread *thread, int hitCount) { - Set(thread, CACHE_COUNT_INDEX, JSTaggedValue(hit_count)); + Set(thread, CACHE_COUNT_INDEX, JSTaggedValue(hitCount)); } inline int GetCacheCount() @@ -80,19 +79,19 @@ public: std::cout << "cache hit count: " << GetHitCount() << std::endl; } - inline void SetLargeStrCount(JSThread *thread, uint32_t new_count) + inline void SetLargeStrCount(JSThread *thread, uint32_t newCount) { - Set(thread, LARGE_STRING_COUNT_INDEX, JSTaggedValue(new_count)); + Set(thread, LARGE_STRING_COUNT_INDEX, JSTaggedValue(newCount)); } - inline void SetConflictCount(JSThread *thread, uint32_t new_count) + inline void SetConflictCount(JSThread *thread, uint32_t newCount) { - Set(thread, CONFLICT_COUNT_INDEX, JSTaggedValue(new_count)); + Set(thread, CONFLICT_COUNT_INDEX, JSTaggedValue(newCount)); } - inline void SetStrLenThreshold(JSThread *thread, uint32_t new_threshold) + inline void SetStrLenThreshold(JSThread *thread, uint32_t newThreshold) { - Set(thread, STRING_LENGTH_THRESHOLD_INDEX, JSTaggedValue(new_threshold)); + Set(thread, STRING_LENGTH_THRESHOLD_INDEX, JSTaggedValue(newThreshold)); } inline uint32_t GetLargeStrCount() diff --git a/runtime/builtins/builtins_relative_time_format.cpp b/runtime/builtins/builtins_relative_time_format.cpp index 7eb8842da1f3f34a332b159924473aa264e08dce..4587170f43184b13ac06bb1f5e79d7f783233db8 100644 --- a/runtime/builtins/builtins_relative_time_format.cpp +++ b/runtime/builtins/builtins_relative_time_format.cpp @@ -22,13 +22,13 @@ JSTaggedValue relative_time_format::RelativeTimeFormatConstructor(EcmaRuntimeCal { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new_target is undefined", JSTaggedValue::Exception()); } @@ -36,30 +36,30 @@ JSTaggedValue relative_time_format::RelativeTimeFormatConstructor(EcmaRuntimeCal // (NewTarget, "%RelativeTimeFormatPrototype%", « [[InitializedRelativeTimeFormat]], // [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle relative_time_format = JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); + JSHandle relativeTimeFormat = JSHandle::Cast( + factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Perform ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options). JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle options = builtins_common::GetCallArg(argv, 1); - JSRelativeTimeFormat::InitializeRelativeTimeFormat(thread, relative_time_format, locales, options); + JSRelativeTimeFormat::InitializeRelativeTimeFormat(thread, relativeTimeFormat, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Intl.RelativeTimeFormat.prototype[ @@toStringTag ] // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. - JSHandle this_value = builtins_common::GetThis(argv); - bool is_instance_of = JSObject::InstanceOf(thread, this_value, env->GetRelativeTimeFormatFunction()); + JSHandle thisValue = builtins_common::GetThis(argv); + bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetRelativeTimeFormatFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (new_target->IsUndefined() && this_value->IsJSObject() && is_instance_of) { - PropertyDescriptor descriptor(thread, JSHandle::Cast(relative_time_format), false, false, true); + if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { + PropertyDescriptor descriptor(thread, JSHandle::Cast(relativeTimeFormat), false, false, true); JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, this_value, key, descriptor); + JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return this_value.GetTaggedValue(); + return thisValue.GetTaggedValue(); } - return relative_time_format.GetTaggedValue(); + return relativeTimeFormat.GetTaggedValue(); } // 14.3.1 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] ) @@ -69,16 +69,16 @@ JSTaggedValue relative_time_format::SupportedLocalesOf(EcmaRuntimeCallInfo *argv [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %RelativeTimeFormat%.[[AvailableLocales]]. - JSHandle available_locales = JSLocale::GetAvailableLocales(thread, "calendar", nullptr); + JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, "calendar", nullptr); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = builtins_common::GetCallArg(argv, 0); - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSHandle options = builtins_common::GetCallArg(argv, 1); - JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); + JSHandle result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -90,10 +90,10 @@ JSTaggedValue relative_time_format::proto::Format(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - if (!this_value->IsJSRelativeTimeFormat()) { + if (!thisValue->IsJSRelativeTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception()); } @@ -105,13 +105,13 @@ JSTaggedValue relative_time_format::proto::Format(EcmaRuntimeCallInfo *argv) x = temp.GetNumber(); // 4. Let unit be ? ToString(unit). - JSHandle unit_value = builtins_common::GetCallArg(argv, 1); - JSHandle unit = JSTaggedValue::ToString(thread, unit_value); + JSHandle unitValue = builtins_common::GetCallArg(argv, 1); + JSHandle unit = JSTaggedValue::ToString(thread, unitValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit). - JSHandle relative_time_format = JSHandle::Cast(this_value); - JSHandle result = JSRelativeTimeFormat::Format(thread, x, unit, relative_time_format); + JSHandle relativeTimeFormat = JSHandle::Cast(thisValue); + JSHandle result = JSRelativeTimeFormat::Format(thread, x, unit, relativeTimeFormat); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -123,10 +123,10 @@ JSTaggedValue relative_time_format::proto::FormatToParts(EcmaRuntimeCallInfo *ar [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - if (!this_value->IsJSRelativeTimeFormat()) { + if (!thisValue->IsJSRelativeTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception()); } @@ -138,13 +138,13 @@ JSTaggedValue relative_time_format::proto::FormatToParts(EcmaRuntimeCallInfo *ar x = temp.GetNumber(); // 4. Let unit be ? ToString(unit). - JSHandle unit_value = builtins_common::GetCallArg(argv, 1); - JSHandle unit = JSTaggedValue::ToString(thread, unit_value); + JSHandle unitValue = builtins_common::GetCallArg(argv, 1); + JSHandle unit = JSTaggedValue::ToString(thread, unitValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit). - JSHandle relative_time_format = JSHandle::Cast(this_value); - JSHandle result = JSRelativeTimeFormat::FormatToParts(thread, x, unit, relative_time_format); + JSHandle relativeTimeFormat = JSHandle::Cast(thisValue); + JSHandle result = JSRelativeTimeFormat::FormatToParts(thread, x, unit, relativeTimeFormat); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -156,23 +156,23 @@ JSTaggedValue relative_time_format::proto::ResolvedOptions(EcmaRuntimeCallInfo * [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - if (!this_value->IsJSRelativeTimeFormat()) { + if (!thisValue->IsJSRelativeTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception()); } // 3. Let options be ! ObjectCreate(%ObjectPrototype%). - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); // 4. perform resolvedOptions - JSHandle relative_time_format = JSHandle::Cast(this_value); - JSRelativeTimeFormat::ResolvedOptions(thread, relative_time_format, options); + JSHandle relativeTimeFormat = JSHandle::Cast(thisValue); + JSRelativeTimeFormat::ResolvedOptions(thread, relativeTimeFormat, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return options. return options.GetTaggedValue(); diff --git a/runtime/builtins/builtins_runtime_testing.cpp b/runtime/builtins/builtins_runtime_testing.cpp index 29e839918c3e8460dc047bbcd23f51c16497ed79..406b56aee1a5fe704ecef843dfd6e7d48ebdd991 100644 --- a/runtime/builtins/builtins_runtime_testing.cpp +++ b/runtime/builtins/builtins_runtime_testing.cpp @@ -44,25 +44,25 @@ JSTaggedValue runtime_testing::GetOptimizationStatus(EcmaRuntimeCallInfo *argv) ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, GetOptimizationStatus); - JSHandle arg_tagged = builtins_common::GetCallArg(argv, 0); + JSHandle argTagged = builtins_common::GetCallArg(argv, 0); uint32_t status = 0; const auto &opts = Runtime::GetCurrent()->GetOptions(); - bool no_async_jit = Runtime::GetCurrent()->GetPandaVM()->GetCompiler()->IsNoAsyncJit(); + bool noAsyncJit = Runtime::GetCurrent()->GetPandaVM()->GetCompiler()->IsNoAsyncJit(); if (!opts.IsCompilerEnableJit()) { status |= static_cast(OptimizationStatus::LITE_MODE); status |= static_cast(OptimizationStatus::NEVER_OPTIMIZE); - } else if ((opts.GetCompilerHotnessThreshold() == 0) && no_async_jit) { + } else if ((opts.GetCompilerHotnessThreshold() == 0) && noAsyncJit) { status |= static_cast(OptimizationStatus::ALWAYS_OPTIMIZE); } - if (arg_tagged->IsCallable()) { + if (argTagged->IsCallable()) { return JSTaggedValue(status); } - ASSERT(arg_tagged->IsCallable()); - const auto *method = JSHandle::Cast(arg_tagged)->GetCallTarget(); + ASSERT(argTagged->IsCallable()); + const auto *method = JSHandle::Cast(argTagged)->GetCallTarget(); status |= static_cast(OptimizationStatus::IS_FUNCTION); switch (method->GetCompilationStatus()) { @@ -74,7 +74,7 @@ JSTaggedValue runtime_testing::GetOptimizationStatus(EcmaRuntimeCallInfo *argv) break; } case Method::WAITING: { - if (no_async_jit) { + if (noAsyncJit) { status |= static_cast(OptimizationStatus::MARKED_FOR_OPTIMIZATION); } else { status |= static_cast(OptimizationStatus::MARKED_FOR_CONCURRENT_OPTIMIZATION); @@ -117,14 +117,14 @@ JSTaggedValue runtime_testing::PrepareFunctionForOptimization(EcmaRuntimeCallInf ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, PrepareFunctionForOptimization); - JSHandle arg_tagged = builtins_common::GetCallArg(argv, 0); - - ASSERT(arg_tagged->IsCallable()); - auto *js_method = JSHandle::Cast(arg_tagged)->GetCallTarget(); - ASSERT(!js_method->IsNative()); - if (js_method->GetProfilingVector() == nullptr) { - js_method->InitProfileVector(); - ASSERT(js_method->GetProfilingVector() != nullptr); + JSHandle argTagged = builtins_common::GetCallArg(argv, 0); + + ASSERT(argTagged->IsCallable()); + auto *jsMethod = JSHandle::Cast(argTagged)->GetCallTarget(); + ASSERT(!jsMethod->IsNative()); + if (jsMethod->GetProfilingVector() == nullptr) { + jsMethod->InitProfileVector(); + ASSERT(jsMethod->GetProfilingVector() != nullptr); } return JSTaggedValue::Undefined(); } @@ -134,35 +134,35 @@ JSTaggedValue runtime_testing::OptimizeFunctionOnNextCall(EcmaRuntimeCallInfo *a ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, OptimizeFunctionOnNextCall); - JSHandle arg_tagged_0 = builtins_common::GetCallArg(argv, 0); - JSHandle arg_tagged_1 = builtins_common::GetCallArg(argv, 1); + JSHandle argTagged0 = builtins_common::GetCallArg(argv, 0); + JSHandle argTagged1 = builtins_common::GetCallArg(argv, 1); - ASSERT(arg_tagged_0->IsCallable()); - auto *js_method = JSHandle::Cast(arg_tagged_0)->GetCallTarget(); - ASSERT(js_method->GetProfilingVector() != nullptr); + ASSERT(argTagged0->IsCallable()); + auto *jsMethod = JSHandle::Cast(argTagged0)->GetCallTarget(); + ASSERT(jsMethod->GetProfilingVector() != nullptr); - bool is_async = false; - if (!arg_tagged_1->IsUndefined()) { - ASSERT(arg_tagged_1->IsString()); + bool isAsync = false; + if (!argTagged1->IsUndefined()) { + ASSERT(argTagged1->IsString()); constexpr size_t STR_LEN = 10; - std::array mode_concurrent = {'c', 'o', 'n', 'c', 'u', 'r', 'r', 'e', 'n', 't', '\0'}; - if (EcmaString::StringsAreEqualUtf8(EcmaString::ConstCast(arg_tagged_1->GetTaggedObject()), - mode_concurrent.data(), STR_LEN, true)) { - is_async = true; + std::array modeConcurrent = {'c', 'o', 'n', 'c', 'u', 'r', 'r', 'e', 'n', 't', '\0'}; + if (EcmaString::StringsAreEqualUtf8(EcmaString::ConstCast(argTagged1->GetTaggedObject()), modeConcurrent.data(), + STR_LEN, true)) { + isAsync = true; } else { THROW_TYPE_ERROR_AND_RETURN(thread, "mode is expected to be 'concurrent' or undefined", JSTaggedValue::Exception()); } } auto *compiler = Runtime::GetCurrent()->GetPandaVM()->GetCompiler(); - if (js_method->HasCompiledCode()) { + if (jsMethod->HasCompiledCode()) { return JSTaggedValue::Undefined(); } - bool saved_async_flag = compiler->IsNoAsyncJit(); - compiler->SetNoAsyncJit(!is_async); - compiler->CompileMethod(js_method, 0, false, arg_tagged_0.GetTaggedValue()); - ASSERT(is_async || js_method->HasCompiledCode()); - compiler->SetNoAsyncJit(saved_async_flag); + bool savedAsyncFlag = compiler->IsNoAsyncJit(); + compiler->SetNoAsyncJit(!isAsync); + compiler->CompileMethod(jsMethod, 0, false, argTagged0.GetTaggedValue()); + ASSERT(isAsync || jsMethod->HasCompiledCode()); + compiler->SetNoAsyncJit(savedAsyncFlag); return JSTaggedValue::Undefined(); } @@ -171,10 +171,10 @@ JSTaggedValue runtime_testing::Exit(EcmaRuntimeCallInfo *argv) ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, Exit); - JSHandle arg_tagged = builtins_common::GetCallArg(argv, 0); + JSHandle argTagged = builtins_common::GetCallArg(argv, 0); - ASSERT(arg_tagged->IsInt()); - Runtime::Halt(arg_tagged->GetInt()); + ASSERT(argTagged->IsInt()); + Runtime::Halt(argTagged->GetInt()); UNREACHABLE(); } diff --git a/runtime/builtins/builtins_set.cpp b/runtime/builtins/builtins_set.cpp index a7abc9a6f85c9cf60ffb6bb686da036b3596de21..69130acfb0ae209b815d673bfd38c4ae891b5cc7 100644 --- a/runtime/builtins/builtins_set.cpp +++ b/runtime/builtins/builtins_set.cpp @@ -30,24 +30,24 @@ JSTaggedValue set::SetConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, SetConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let set be OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", «‍[[SetData]]» ). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle set = JSHandle::Cast(obj); // 3.ReturnIfAbrupt(set). // 4.Set set’s [[SetData]] internal slot to a new empty List. - JSHandle linked_set = LinkedHashSet::Create(thread); - set->SetLinkedSet(thread, linked_set); + JSHandle linkedSet = LinkedHashSet::Create(thread); + set->SetLinkedSet(thread, linkedSet); // add data into set from iterable // 5.If iterable is not present, let iterable be undefined. @@ -58,9 +58,9 @@ JSTaggedValue set::SetConstructor(EcmaRuntimeCallInfo *argv) return set.GetTaggedValue(); } // Let adder be Get(set, "add"). - JSHandle adder_key(factory->NewFromCanBeCompressString("add")); - JSHandle set_handle(set); - JSHandle adder = JSObject::GetProperty(thread, set_handle, adder_key).GetValue(); + JSHandle adderKey(factory->NewFromCanBeCompressString("add")); + JSHandle setHandle(set); + JSHandle adder = JSObject::GetProperty(thread, setHandle, adderKey).GetValue(); // ReturnIfAbrupt(adder). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue()); // If IsCallable(adder) is false, throw a TypeError exception @@ -73,22 +73,22 @@ JSTaggedValue set::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 value_index(thread, JSTaggedValue(1)); + JSHandle valueIndex(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 next_value(JSIterator::IteratorValue(thread, next)); + JSHandle nextValue(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next_value.GetTaggedValue()); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); auto info = NewRuntimeCallInfo(thread, adder, set, JSTaggedValue::Undefined(), 1); - if (next_value->IsArray(thread)) { - auto prop = JSObject::GetProperty(thread, next_value, value_index).GetValue(); + if (nextValue->IsArray(thread)) { + auto prop = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); info->SetCallArgs(prop); } else { - info->SetCallArgs(next_value); + info->SetCallArgs(nextValue); } JSTaggedValue ret = JSFunction::Call(info.Get()); // Let status be Call(adder, set, «nextValue.[[value]]»). @@ -108,7 +108,7 @@ JSTaggedValue set::proto::Add(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SetPrototype, Add); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -129,7 +129,7 @@ JSTaggedValue set::proto::Clear(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SetPrototype, Clear); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -147,7 +147,7 @@ JSTaggedValue set::proto::Delete(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SetPrototype, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. @@ -166,19 +166,19 @@ JSTaggedValue set::proto::Has(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SetPrototype, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSSet()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception()); } - JSHandle js_set(thread, JSSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle jsSet(thread, JSSet::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle value = builtins_common::GetCallArg(argv, 0); bool flag = false; if (JSSet::IsKey(value.GetTaggedValue())) { int hash = LinkedHash::Hash(value.GetTaggedValue()); - flag = js_set->Has(value.GetTaggedValue(), hash); + flag = jsSet->Has(value.GetTaggedValue(), hash); } return builtins_common::GetTaggedBoolean(flag); } @@ -186,7 +186,7 @@ JSTaggedValue set::proto::Has(EcmaRuntimeCallInfo *argv) JSTaggedValue set::proto::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -203,7 +203,7 @@ JSTaggedValue set::proto::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) } // 5.If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg = builtins_common::GetCallArg(argv, 1); + JSHandle thisArg = builtins_common::GetCallArg(argv, 1); // composed arguments JSHandle iter(factory->NewJSSetIterator(set, IterationKind::KEY)); @@ -213,7 +213,7 @@ JSTaggedValue set::proto::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, this_arg, JSTaggedValue::Undefined(), 3); + auto info = NewRuntimeCallInfo(thread, func, thisArg, JSTaggedValue::Undefined(), 3); info->SetCallArgs(value, value, JSHandle(set)); JSTaggedValue ret = JSFunction::Call(info.Get()); // 3: three args // returnIfAbrupt @@ -233,15 +233,15 @@ JSTaggedValue set::proto::GetSize(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SetPrototype, GetSize); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSSet()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception()); } - JSSet *js_set = JSSet::Cast(*JSTaggedValue::ToObject(thread, self)); - int count = js_set->GetSize(); + JSSet *jsSet = JSSet::Cast(*JSTaggedValue::ToObject(thread, self)); + int count = jsSet->GetSize(); return JSTaggedValue(count); } @@ -250,7 +250,7 @@ JSTaggedValue set::proto::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SetPrototype, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSSetIterator::CreateSetIterator(thread, self, IterationKind::KEY_AND_VALUE); return iter.GetTaggedValue(); @@ -261,7 +261,7 @@ JSTaggedValue set::proto::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SetPrototype, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::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 ff50a410ac04627fa38c19e6379736cb6f2bedec..6182f1bfa9339b33c9768bcab1bda3134ff2ecb1 100644 --- a/runtime/builtins/builtins_string.cpp +++ b/runtime/builtins/builtins_string.cpp @@ -61,28 +61,28 @@ JSTaggedValue string::StringConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, StringConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_target = builtins_common::GetNewTarget(argv); + JSHandle newTarget = builtins_common::GetNewTarget(argv); if (argv->GetArgsNumber() > 0) { - JSHandle val_tag_new = builtins_common::GetCallArg(argv, 0); - if (new_target->IsUndefined() && val_tag_new->IsSymbol()) { - return symbol::SymbolDescriptiveString(thread, val_tag_new.GetTaggedValue()); + JSHandle valTagNew = builtins_common::GetCallArg(argv, 0); + if (newTarget->IsUndefined() && valTagNew->IsSymbol()) { + return symbol::SymbolDescriptiveString(thread, valTagNew.GetTaggedValue()); } - JSHandle str = JSTaggedValue::ToString(thread, val_tag_new); + JSHandle str = JSTaggedValue::ToString(thread, valTagNew); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (new_target->IsUndefined()) { + if (newTarget->IsUndefined()) { return str.GetTaggedValue(); } - JSHandle str_tag(str); - return JSPrimitiveRef::StringCreate(thread, str_tag).GetTaggedValue(); + JSHandle strTag(str); + return JSPrimitiveRef::StringCreate(thread, strTag).GetTaggedValue(); } JSHandle val = factory->GetEmptyString(); - JSHandle val_tag(val); - if (new_target->IsUndefined()) { + JSHandle valTag(val); + if (newTarget->IsUndefined()) { return factory->GetEmptyString().GetTaggedValue(); } - return JSPrimitiveRef::StringCreate(thread, val_tag).GetTaggedValue(); + return JSPrimitiveRef::StringCreate(thread, valTag).GetTaggedValue(); } // 21.1.2.1 @@ -91,35 +91,35 @@ JSTaggedValue string::FromCharCode(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, FromCharCode); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - int32_t arg_length = argv->GetArgsNumber(); - if (arg_length == 0) { + int32_t argLength = argv->GetArgsNumber(); + if (argLength == 0) { return factory->GetEmptyString().GetTaggedValue(); } - JSHandle code_point_tag = builtins_common::GetCallArg(argv, 0); - uint16_t code_point_value = JSTaggedValue::ToUint16(thread, code_point_tag); + JSHandle codePointTag = builtins_common::GetCallArg(argv, 0); + uint16_t codePointValue = JSTaggedValue::ToUint16(thread, codePointTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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 = builtins_common::GetCallArg(argv, i); - uint16_t next_cv = JSTaggedValue::ToUint16(thread, next_cp); - value_table.emplace_back(next_cv); + 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 = builtins_common::GetCallArg(argv, i); + uint16_t nextCv = JSTaggedValue::ToUint16(thread, nextCp); + valueTable.emplace_back(nextCv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - 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(); + 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(); } // 21.1.2.2 @@ -128,22 +128,22 @@ JSTaggedValue string::FromCodePoint(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, FromCodePoint); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - int32_t arg_length = argv->GetArgsNumber(); - if (arg_length == 0) { + int32_t argLength = argv->GetArgsNumber(); + if (argLength == 0) { return factory->GetEmptyString().GetTaggedValue(); } std::u16string u16str; - int32_t u16str_size = arg_length; - for (int i = 0; i < arg_length; i++) { - JSHandle next_cp_tag = builtins_common::GetCallArg(argv, i); - JSTaggedNumber next_cp_val = JSTaggedValue::ToNumber(thread, next_cp_tag); + int32_t u16strSize = argLength; + for (int i = 0; i < argLength; i++) { + JSHandle nextCpTag = builtins_common::GetCallArg(argv, i); + JSTaggedNumber nextCpVal = JSTaggedValue::ToNumber(thread, nextCpTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!next_cp_val.IsInteger()) { + if (!nextCpVal.IsInteger()) { THROW_RANGE_ERROR_AND_RETURN(thread, "is not integer", JSTaggedValue::Exception()); } - int32_t cp = next_cp_val.ToInt32(); + int32_t cp = nextCpVal.ToInt32(); if (cp < 0 || cp > ENCODE_MAX_UTF16) { THROW_RANGE_ERROR_AND_RETURN(thread, "CodePoint < 0 or CodePoint > 0x10FFFF", JSTaggedValue::Exception()); } @@ -154,21 +154,21 @@ JSTaggedValue string::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 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++; + 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++; } else { - 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); + auto u16tCp = static_cast(cp); + std::u16string nextU16str = ecmascript::base::StringHelper::Utf16ToU16String(&u16tCp, 1); + u16str = ecmascript::base::StringHelper::Append(u16str, nextU16str); } } - 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(); + const char16_t *constChar16tData = u16str.data(); + auto *char16tData = const_cast(constChar16tData); + auto *uint16tData = reinterpret_cast(char16tData); + return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); } // 21.1.2.4 @@ -177,66 +177,65 @@ JSTaggedValue string::Raw(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Raw); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Let cooked be ToObject(template). JSHandle cooked = JSTaggedValue::ToObject(thread, builtins_common::GetCallArg(argv, 0)); // ReturnIfAbrupt(cooked). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let raw be ToObject(Get(cooked, "raw")). - 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); + JSHandle rawKey(factory->NewFromCanBeCompressString("raw")); + JSHandle rawTag = + JSObject::GetProperty(thread, JSHandle::Cast(cooked), rawKey).GetValue(); + JSHandle rawObj = JSTaggedValue::ToObject(thread, rawTag); // ReturnIfAbrupt(rawObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle raw_len = - JSObject::GetProperty(thread, JSHandle::Cast(raw_obj), length_key).GetValue(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle rawLen = + JSObject::GetProperty(thread, JSHandle::Cast(rawObj), lengthKey).GetValue(); // ReturnIfAbrupt(rawLen). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedNumber length_number = JSTaggedValue::ToLength(thread, raw_len); + JSTaggedNumber lengthNumber = JSTaggedValue::ToLength(thread, rawLen); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int length = length_number.ToUint32(); + int length = lengthNumber.ToUint32(); if (length <= 0) { return factory->GetEmptyString().GetTaggedValue(); } std::u16string u16str; int argc = static_cast(argv->GetArgsNumber()) - 1; - bool can_be_compress = true; - for (int i = 0, args_i = 1; i < length; ++i, ++args_i) { + bool canBeCompress = true; + for (int i = 0, argsI = 1; i < length; ++i, ++argsI) { // Let nextSeg be ToString(Get(raw, nextKey)). - JSHandle element_string = - JSObject::GetProperty(thread, JSHandle::Cast(raw_obj), i).GetValue(); + JSHandle elementString = + JSObject::GetProperty(thread, JSHandle::Cast(rawObj), i).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *next_seg = *JSTaggedValue::ToString(thread, element_string); + EcmaString *nextSeg = *JSTaggedValue::ToString(thread, elementString); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (next_seg->IsUtf16()) { - u16str += ecmascript::base::StringHelper::Utf16ToU16String(next_seg->GetDataUtf16(), next_seg->GetLength()); - can_be_compress = false; + if (nextSeg->IsUtf16()) { + u16str += ecmascript::base::StringHelper::Utf16ToU16String(nextSeg->GetDataUtf16(), nextSeg->GetLength()); + canBeCompress = false; } else { - u16str += ecmascript::base::StringHelper::Utf8ToU16String(next_seg->GetDataUtf8(), next_seg->GetLength()); + u16str += ecmascript::base::StringHelper::Utf8ToU16String(nextSeg->GetDataUtf8(), nextSeg->GetLength()); } if (i + 1 == length) { break; } - if (args_i <= argc) { - EcmaString *next_sub = *JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, args_i)); + if (argsI <= argc) { + EcmaString *nextSub = *JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, argsI)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (next_sub->IsUtf16()) { + if (nextSub->IsUtf16()) { u16str += - ecmascript::base::StringHelper::Utf16ToU16String(next_sub->GetDataUtf16(), next_sub->GetLength()); - can_be_compress = false; + ecmascript::base::StringHelper::Utf16ToU16String(nextSub->GetDataUtf16(), nextSub->GetLength()); + canBeCompress = false; } else { - u16str += - ecmascript::base::StringHelper::Utf8ToU16String(next_sub->GetDataUtf8(), next_sub->GetLength()); + u16str += ecmascript::base::StringHelper::Utf8ToU16String(nextSub->GetDataUtf8(), nextSub->GetLength()); } } } // return the result string - auto *uint16t_data = reinterpret_cast(const_cast(u16str.data())); - return factory->NewFromUtf16LiteralUnCheck(uint16t_data, u16str.size(), can_be_compress).GetTaggedValue(); + auto *uint16tData = reinterpret_cast(const_cast(u16str.data())); + return factory->NewFromUtf16LiteralUnCheck(uint16tData, u16str.size(), canBeCompress).GetTaggedValue(); } // 21.1.3.1 @@ -245,25 +244,25 @@ JSTaggedValue string::proto::CharAt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, CharAt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - JSHandle pos_tag = builtins_common::GetCallArg(argv, 0); + int32_t thisLen = thisHandle->GetLength(); + JSHandle posTag = builtins_common::GetCallArg(argv, 0); int32_t pos; - if (pos_tag->IsUndefined()) { + if (posTag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); + JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = pos_val.ToInt32(); + pos = posVal.ToInt32(); } - if (pos < 0 || pos >= this_len) { + if (pos < 0 || pos >= thisLen) { return factory->GetEmptyString().GetTaggedValue(); } - uint16_t res = this_handle->At(pos); + uint16_t res = thisHandle->At(pos); return factory->NewFromUtf16Literal(&res, 1).GetTaggedValue(); } @@ -273,24 +272,24 @@ JSTaggedValue string::proto::CharCodeAt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, CharCodeAt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - JSHandle pos_tag = builtins_common::GetCallArg(argv, 0); + int32_t thisLen = thisHandle->GetLength(); + JSHandle posTag = builtins_common::GetCallArg(argv, 0); int32_t pos; - if (pos_tag->IsUndefined()) { + if (posTag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); + JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = pos_val.ToInt32(); + pos = posVal.ToInt32(); } - if (pos < 0 || pos >= this_len) { + if (pos < 0 || pos >= thisLen) { return builtins_common::GetTaggedDouble(ecmascript::base::NAN_VALUE); } - uint16_t ret = this_handle->At(pos); + uint16_t ret = thisHandle->At(pos); return builtins_common::GetTaggedInt(ret); } @@ -300,24 +299,24 @@ JSTaggedValue string::proto::CodePointAt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, CodePointAt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle pos_tag = builtins_common::GetCallArg(argv, 0); + JSHandle posTag = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber pos_val = JSTaggedValue::ToNumber(thread, pos_tag); + JSTaggedNumber posVal = JSTaggedValue::ToNumber(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(pos_val.GetNumber()); - int32_t this_len = this_handle->GetLength(); - if (pos < 0 || pos >= this_len) { + int32_t pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber()); + int32_t thisLen = thisHandle->GetLength(); + if (pos < 0 || pos >= thisLen) { return JSTaggedValue::Undefined(); } - uint16_t first = this_handle->At(pos); - if (first < utf::DECODE_LEAD_LOW || first > utf::DECODE_LEAD_HIGH || pos + 1 == this_len) { + uint16_t first = thisHandle->At(pos); + if (first < utf::DECODE_LEAD_LOW || first > utf::DECODE_LEAD_HIGH || pos + 1 == thisLen) { return builtins_common::GetTaggedInt(first); } - uint16_t second = this_handle->At(pos + 1); + uint16_t second = thisHandle->At(pos + 1); if (second < utf::DECODE_TRAIL_LOW || second > utf::DECODE_TRAIL_HIGH) { return builtins_common::GetTaggedInt(first); } @@ -331,42 +330,42 @@ JSTaggedValue string::proto::Concat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Concat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - int32_t arg_length = argv->GetArgsNumber(); - if (arg_length == 0) { - return this_handle.GetTaggedValue(); - } - std::u16string u16str_this; - std::u16string u16str_next; - bool can_be_compress = true; - if (this_handle->IsUtf16()) { - u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); - can_be_compress = false; + int32_t thisLen = thisHandle->GetLength(); + int32_t argLength = argv->GetArgsNumber(); + if (argLength == 0) { + return thisHandle.GetTaggedValue(); + } + std::u16string u16strThis; + std::u16string u16strNext; + bool canBeCompress = true; + if (thisHandle->IsUtf16()) { + u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + canBeCompress = false; } else { - u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(this_handle->GetDataUtf8(), this_len); - } - for (int i = 0; i < arg_length; i++) { - JSHandle next_tag = builtins_common::GetCallArg(argv, i); - JSHandle next_handle = JSTaggedValue::ToString(thread, next_tag); - int32_t next_len = next_handle->GetLength(); - if (next_handle->IsUtf16()) { - u16str_next = ecmascript::base::StringHelper::Utf16ToU16String(next_handle->GetDataUtf16(), next_len); - can_be_compress = false; + u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(thisHandle->GetDataUtf8(), thisLen); + } + for (int i = 0; i < argLength; i++) { + JSHandle nextTag = builtins_common::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); + canBeCompress = false; } else { - u16str_next = ecmascript::base::StringHelper::Utf8ToU16String(next_handle->GetDataUtf8(), next_len); + u16strNext = ecmascript::base::StringHelper::Utf8ToU16String(nextHandle->GetDataUtf8(), nextLen); } - u16str_this = ecmascript::base::StringHelper::Append(u16str_this, u16str_next); + u16strThis = ecmascript::base::StringHelper::Append(u16strThis, u16strNext); } - 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(); + 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, canBeCompress).GetTaggedValue(); } // 21.1.3.5 String.prototype.constructor @@ -376,48 +375,48 @@ JSTaggedValue string::proto::EndsWith(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, EndsWith); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle search_tag = builtins_common::GetCallArg(argv, 0); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle searchTag = builtins_common::GetCallArg(argv, 0); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool is_regexp = JSObject::IsRegExp(thread, search_tag); - if (is_regexp) { + bool isRegexp = JSObject::IsRegExp(thread, searchTag); + if (isRegexp) { THROW_TYPE_ERROR_AND_RETURN(thread, "is regexp", JSTaggedValue::Exception()); } - JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); + JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - int32_t search_len = search_handle->GetLength(); + int32_t thisLen = thisHandle->GetLength(); + int32_t searchLen = searchHandle->GetLength(); int32_t pos; - JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); - if (pos_tag->IsUndefined()) { - pos = this_len; + JSHandle posTag = builtins_common::GetCallArg(argv, 1); + if (posTag->IsUndefined()) { + pos = thisLen; } else { - JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); + JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = pos_val.ToInt32(); + pos = posVal.ToInt32(); } - int32_t end = std::min(std::max(pos, 0), this_len); - int32_t start = end - search_len; + int32_t end = std::min(std::max(pos, 0), thisLen); + int32_t start = end - searchLen; if (start < 0) { return builtins_common::GetTaggedBoolean(false); } - std::u16string u16str_this; - std::u16string u16str_search; - if (this_handle->IsUtf16()) { - u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); + std::u16string u16strThis; + std::u16string u16strSearch; + if (thisHandle->IsUtf16()) { + u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); } else { - const uint8_t *uint8_this = this_handle->GetDataUtf8(); - u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); + const uint8_t *uint8This = thisHandle->GetDataUtf8(); + u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); } - if (search_handle->IsUtf16()) { - u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); + if (searchHandle->IsUtf16()) { + u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); } else { - const uint8_t *uint8_search = search_handle->GetDataUtf8(); - u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); + const uint8_t *uint8Search = searchHandle->GetDataUtf8(); + u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, start); + int32_t idx = ecmascript::base::StringHelper::Find(u16strThis, u16strSearch, start); if (idx == start) { return builtins_common::GetTaggedBoolean(true); } @@ -430,45 +429,45 @@ JSTaggedValue string::proto::Includes(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Includes); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = builtins_common::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle searchTag = builtins_common::GetCallArg(argv, 0); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool is_regexp = JSObject::IsRegExp(thread, search_tag); - if (is_regexp) { + bool isRegexp = JSObject::IsRegExp(thread, searchTag); + if (isRegexp) { THROW_TYPE_ERROR_AND_RETURN(thread, "is regexp", JSTaggedValue::Exception()); } - JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); + JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - int32_t search_len = search_handle->GetLength(); + int32_t thisLen = thisHandle->GetLength(); + int32_t searchLen = searchHandle->GetLength(); int32_t pos = 0; - JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); + JSHandle posTag = builtins_common::GetCallArg(argv, 1); if (argv->GetArgsNumber() == 1) { pos = 0; } else { - JSTaggedNumber pos_val = JSTaggedValue::ToNumber(thread, pos_tag); + JSTaggedNumber posVal = JSTaggedValue::ToNumber(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(pos_val.GetNumber()); + pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber()); } - 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); + 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); } else { - const uint8_t *uint8_this = this_handle->GetDataUtf8(); - u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); + const uint8_t *uint8This = thisHandle->GetDataUtf8(); + u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); } - if (search_handle->IsUtf16()) { - u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); + if (searchHandle->IsUtf16()) { + u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); } else { - const uint8_t *uint8_search = search_handle->GetDataUtf8(); - u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); + const uint8_t *uint8Search = searchHandle->GetDataUtf8(); + u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, start); - if (idx < 0 || idx > this_len) { + int32_t idx = ecmascript::base::StringHelper::Find(u16strThis, u16strSearch, start); + if (idx < 0 || idx > thisLen) { return builtins_common::GetTaggedBoolean(false); } return builtins_common::GetTaggedBoolean(true); @@ -480,28 +479,28 @@ JSTaggedValue string::proto::IndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, IndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = builtins_common::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle searchTag = builtins_common::GetCallArg(argv, 0); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t this_len = this_handle->GetLength(); - JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); + uint32_t thisLen = thisHandle->GetLength(); + JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); + JSHandle posTag = builtins_common::GetCallArg(argv, 1); int32_t pos; - if (pos_tag->IsInt()) { - pos = pos_tag->GetInt(); - } else if (pos_tag->IsUndefined()) { + if (posTag->IsInt()) { + pos = posTag->GetInt(); + } else if (posTag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); + JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = pos_val.ToInt32(); + pos = posVal.ToInt32(); } - 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)) { + pos = std::min(std::max(pos, 0), static_cast(thisLen)); + int32_t res = thisHandle->IndexOf(*searchHandle, pos); + if (res >= 0 && res < static_cast(thisLen)) { return builtins_common::GetTaggedInt(res); } return builtins_common::GetTaggedInt(-1); @@ -513,45 +512,45 @@ JSTaggedValue string::proto::LastIndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, LastIndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = builtins_common::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle searchTag = builtins_common::GetCallArg(argv, 0); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); + int32_t thisLen = thisHandle->GetLength(); + JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t search_len = search_handle->GetLength(); + int32_t searchLen = searchHandle->GetLength(); int32_t pos; if (argv->GetArgsNumber() == 1) { - pos = this_len; + pos = thisLen; } else { - JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); + JSHandle posTag = builtins_common::GetCallArg(argv, 1); + JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (std::isnan(JSTaggedValue::ToNumber(thread, pos_tag).GetNumber())) { - pos = this_len; + if (std::isnan(JSTaggedValue::ToNumber(thread, posTag).GetNumber())) { + pos = thisLen; } else { - pos = pos_val.ToInt32(); + pos = posVal.ToInt32(); } } - 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); + 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); } else { - const uint8_t *uint8_this = this_handle->GetDataUtf8(); - u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); + const uint8_t *uint8This = thisHandle->GetDataUtf8(); + u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); } - if (search_handle->IsUtf16()) { - u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); + if (searchHandle->IsUtf16()) { + u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); } else { - const uint8_t *uint8_search = search_handle->GetDataUtf8(); - u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); + const uint8_t *uint8Search = searchHandle->GetDataUtf8(); + u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t res = ecmascript::base::StringHelper::RFind(u16str_this, u16str_search, pos); - if (res >= 0 && res < this_len) { + int32_t res = ecmascript::base::StringHelper::RFind(u16strThis, u16strSearch, pos); + if (res >= 0 && res < thisLen) { return builtins_common::GetTaggedInt(res); } res = -1; @@ -564,14 +563,14 @@ JSTaggedValue string::proto::LocaleCompare(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, LocaleCompare); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle that_tag = builtins_common::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thatTag = builtins_common::GetCallArg(argv, 0); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle that_handle = JSTaggedValue::ToString(thread, that_tag); + JSHandle thatHandle = JSTaggedValue::ToString(thread, thatTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t res = this_handle->Compare(*that_handle); + int32_t res = thisHandle->Compare(*thatHandle); return builtins_common::GetTaggedInt(res); } @@ -581,44 +580,44 @@ JSTaggedValue string::proto::Match(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Match); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle regexp = builtins_common::GetCallArg(argv, 0); - JSHandle match_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchSymbol(); + JSHandle matchTag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchSymbol(); if (regexp->IsJSRegExp()) { - JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); JSHandle re(regexp); JSHandle pattern(thread, re->GetOriginalSource()); JSHandle flags(thread, re->GetOriginalFlags()); - JSTaggedValue cache_result = - cache_table->FindCachedResult(thread, pattern, flags, this_tag, RegExpExecResultCache::MATCH_TYPE, regexp); - if (cache_result != JSTaggedValue::Undefined()) { - return cache_result; + JSTaggedValue cacheResult = + cacheTable->FindCachedResult(thread, pattern, flags, thisTag, RegExpExecResultCache::MATCH_TYPE, regexp); + if (cacheResult != JSTaggedValue::Undefined()) { + return cacheResult; } } if (!regexp->IsUndefined() && !regexp->IsNull()) { if (regexp->IsECMAObject()) { - JSHandle matcher = JSObject::GetMethod(thread, regexp, match_tag); + JSHandle matcher = JSObject::GetMethod(thread, regexp, matchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!matcher->IsUndefined()) { ASSERT(matcher->IsJSFunction()); auto info = NewRuntimeCallInfo(thread, matcher, regexp, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(this_tag); + info->SetCallArgs(thisTag); return JSFunction::Call(info.Get()); } } } - JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisVal = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle undifined_handle = global_const->GetHandledUndefined(); - JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, undifined_handle)); + JSHandle undifinedHandle = globalConst->GetHandledUndefined(); + JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, undifinedHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(this_val.GetTaggedValue()); - return JSFunction::Invoke(info.Get(), match_tag); + info->SetCallArgs(thisVal.GetTaggedValue()); + return JSFunction::Invoke(info.Get(), matchTag); } JSTaggedValue string::proto::MatchAll(EcmaRuntimeCallInfo *argv) @@ -626,32 +625,32 @@ JSTaggedValue string::proto::MatchAll(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, MatchAll); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let O be ? RequireObjectCoercible(this value). - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle regexp = builtins_common::GetCallArg(argv, 0); - JSHandle match_all_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchAllSymbol(); - JSHandle gvalue(global_const->GetHandledGString()); + JSHandle matchAllTag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchAllSymbol(); + JSHandle gvalue(globalConst->GetHandledGString()); // 2. If regexp is neither undefined nor null, then if (!regexp->IsUndefined() && !regexp->IsNull()) { // a. Let isRegExp be ? IsRegExp(searchValue). - bool is_js_reg_exp = JSObject::IsRegExp(thread, regexp); + bool isJsRegExp = JSObject::IsRegExp(thread, regexp); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If isRegExp is true, then - if (is_js_reg_exp) { + if (isJsRegExp) { // i. Let flags be ? Get(searchValue, "flags"). - JSHandle flags_string(global_const->GetHandledFlagsString()); - JSHandle flags = JSObject::GetProperty(thread, regexp, flags_string).GetValue(); + JSHandle flagsString(globalConst->GetHandledFlagsString()); + JSHandle flags = JSObject::GetProperty(thread, regexp, flagsString).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 flag_string = JSTaggedValue::ToString(thread, flags); + JSHandle flagString = JSTaggedValue::ToString(thread, flags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t pos = flag_string->IndexOf(static_cast(gvalue->GetTaggedObject())); + int32_t pos = flagString->IndexOf(static_cast(gvalue->GetTaggedObject())); if (pos == -1) { THROW_TYPE_ERROR_AND_RETURN(thread, "matchAll called with a non-global RegExp argument", JSTaggedValue::Exception()); @@ -661,27 +660,27 @@ JSTaggedValue string::proto::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, match_all_tag); + JSHandle matcher = JSObject::GetMethod(thread, regexp, matchAllTag); 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(this_tag.GetTaggedValue()); + info->SetCallArgs(thisTag.GetTaggedValue()); return JSFunction::Call(info.Get()); } } } // 3. Let S be ? ToString(O). - JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisVal = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let rx be ? RegExpCreate(regexp, "g"). JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, gvalue)); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(this_val.GetTaggedValue()); - return JSFunction::Invoke(info.Get(), match_all_tag); + info->SetCallArgs(thisVal.GetTaggedValue()); + return JSFunction::Invoke(info.Get(), matchAllTag); } // 21.1.3.12 @@ -690,20 +689,20 @@ JSTaggedValue string::proto::Normalize(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Normalize); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - JSHandle form_value; + JSHandle formValue; if (argv->GetArgsNumber() == 0) { - form_value = factory->NewFromString("NFC"); + formValue = factory->NewFromString("NFC"); } else { - JSHandle form_tag = builtins_common::GetCallArg(argv, 0); - if (form_tag->IsUndefined()) { - form_value = factory->NewFromString("NFC"); + JSHandle formTag = builtins_common::GetCallArg(argv, 0); + if (formTag->IsUndefined()) { + formValue = factory->NewFromString("NFC"); } else { - form_value = JSTaggedValue::ToString(thread, form_tag); + formValue = JSTaggedValue::ToString(thread, formTag); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); } } @@ -711,37 +710,37 @@ JSTaggedValue string::proto::Normalize(EcmaRuntimeCallInfo *argv) JSHandle nfd = factory->NewFromString("NFD"); JSHandle nfkc = factory->NewFromString("NFKC"); JSHandle nfkd = factory->NewFromString("NFKD"); - if (form_value->Compare(*nfc) != 0 && form_value->Compare(*nfd) != 0 && form_value->Compare(*nfkc) != 0 && - form_value->Compare(*nfkd) != 0) { + if (formValue->Compare(*nfc) != 0 && formValue->Compare(*nfd) != 0 && formValue->Compare(*nfkc) != 0 && + formValue->Compare(*nfkd) != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "compare not equal", JSTaggedValue::Exception()); } - std::u16string u16str_this; - if (this_handle->IsUtf16()) { - u16str_this = - ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_handle->GetLength()); + std::u16string u16strThis; + if (thisHandle->IsUtf16()) { + u16strThis = + ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisHandle->GetLength()); } else { - const uint8_t *uint8_this = this_handle->GetDataUtf8(); - u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_handle->GetLength()); + const uint8_t *uint8This = thisHandle->GetDataUtf8(); + u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisHandle->GetLength()); } - const char16_t *const_char16t_data = u16str_this.data(); - icu::UnicodeString src(const_char16t_data); + const char16_t *constChar16tData = u16strThis.data(); + icu::UnicodeString src(constChar16tData); icu::UnicodeString res; - UErrorCode error_code = U_ZERO_ERROR; - UNormalizationMode u_form; + UErrorCode errorCode = U_ZERO_ERROR; + UNormalizationMode uForm; int32_t option = 0; - 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; + 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; } else { UNREACHABLE(); } - icu::Normalizer::normalize(src, u_form, option, res, error_code); + icu::Normalizer::normalize(src, uForm, option, res, errorCode); JSHandle str = JSLocale::IcuToString(thread, res); return JSTaggedValue(*str); } @@ -751,11 +750,11 @@ JSTaggedValue string::proto::PadEnd(EcmaRuntimeCallInfo *argv) { // 1. Let O be ? RequireObjectCoercible(this value). JSThread *thread = argv->GetThread(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Return ? StringPad(O, maxLength, fillString, start). - return base::StringHelper::StringPad(thread, this_tag, builtins_common::GetCallArg(argv, 0), + return base::StringHelper::StringPad(thread, thisTag, builtins_common::GetCallArg(argv, 0), builtins_common::GetCallArg(argv, 1), base::PadPlacement::END); } @@ -764,11 +763,11 @@ JSTaggedValue string::proto::PadStart(EcmaRuntimeCallInfo *argv) { // 1. Let O be ? RequireObjectCoercible(this value). JSThread *thread = argv->GetThread(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Return ? StringPad(O, maxLength, fillString, start). - return base::StringHelper::StringPad(thread, this_tag, builtins_common::GetCallArg(argv, 0), + return base::StringHelper::StringPad(thread, thisTag, builtins_common::GetCallArg(argv, 0), builtins_common::GetCallArg(argv, 1), base::PadPlacement::START); } @@ -778,13 +777,13 @@ JSTaggedValue string::proto::Repeat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Repeat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - JSHandle count_tag = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber num = JSTaggedValue::ToInteger(thread, count_tag); + int32_t thisLen = thisHandle->GetLength(); + JSHandle countTag = builtins_common::GetCallArg(argv, 0); + JSTaggedNumber num = JSTaggedValue::ToInteger(thread, countTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double d = num.GetNumber(); if (d < 0) { @@ -794,20 +793,20 @@ JSTaggedValue string::proto::Repeat(EcmaRuntimeCallInfo *argv) THROW_RANGE_ERROR_AND_RETURN(thread, "is infinity", JSTaggedValue::Exception()); } int32_t count = ecmascript::base::NumberHelper::DoubleInRangeInt32(d); - std::u16string u16str_this; - bool can_be_compress = true; - if (this_handle->IsUtf16()) { - u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); - can_be_compress = false; + std::u16string u16strThis; + bool canBeCompress = true; + if (thisHandle->IsUtf16()) { + u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + canBeCompress = false; } else { - const uint8_t *uint8_this = this_handle->GetDataUtf8(); - u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); + const uint8_t *uint8This = thisHandle->GetDataUtf8(); + u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); } - if (this_len == 0) { - return this_handle.GetTaggedValue(); + if (thisLen == 0) { + return thisHandle.GetTaggedValue(); } - EcmaString *res = ecmascript::base::StringHelper::Repeat(thread, u16str_this, count, can_be_compress); + EcmaString *res = ecmascript::base::StringHelper::Repeat(thread, u16strThis, count, canBeCompress); return JSTaggedValue(res); } @@ -817,102 +816,102 @@ JSTaggedValue string::proto::Replace(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Replace); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle search_tag = builtins_common::GetCallArg(argv, 0); - JSHandle replace_tag = builtins_common::GetCallArg(argv, 1); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle searchTag = builtins_common::GetCallArg(argv, 0); + JSHandle replaceTag = builtins_common::GetCallArg(argv, 1); - ObjectFactory *factory = ecma_vm->GetFactory(); + ObjectFactory *factory = ecmaVm->GetFactory(); - if (search_tag->IsJSRegExp() && replace_tag->IsString()) { - JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); - JSHandle re(search_tag); + if (searchTag->IsJSRegExp() && replaceTag->IsString()) { + JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); + JSHandle re(searchTag); JSHandle pattern(thread, re->GetOriginalSource()); JSHandle flags(thread, re->GetOriginalFlags()); - 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; + JSTaggedValue cacheResult = + cacheTable->FindCachedResult(thread, pattern, flags, thisTag, RegExpExecResultCache::REPLACE_TYPE, + searchTag, replaceTag.GetTaggedValue()); + if (cacheResult != JSTaggedValue::Undefined()) { + return cacheResult; } } // If searchValue is neither undefined nor null, then - if (search_tag->IsECMAObject()) { - JSHandle replace_key = env->GetReplaceSymbol(); + if (searchTag->IsECMAObject()) { + JSHandle replaceKey = env->GetReplaceSymbol(); // Let replacer be GetMethod(searchValue, @@replace). - JSHandle replace_method = JSObject::GetMethod(thread, search_tag, replace_key); + JSHandle replaceMethod = JSObject::GetMethod(thread, searchTag, replaceKey); // ReturnIfAbrupt(replacer). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If replacer is not undefined, then - if (!replace_method->IsUndefined()) { + if (!replaceMethod->IsUndefined()) { // Return Call(replacer, searchValue, «O, replaceValue»). - auto info = NewRuntimeCallInfo(thread, replace_method, search_tag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(this_tag, replace_tag); + auto info = NewRuntimeCallInfo(thread, replaceMethod, searchTag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(thisTag, replaceTag); return JSFunction::Call(info.Get()); // 2: two args } } // Let string be ToString(O). - JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); // ReturnIfAbrupt(string). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let searchString be ToString(searchValue). - JSHandle search_string = JSTaggedValue::ToString(thread, search_tag); + JSHandle searchString = JSTaggedValue::ToString(thread, searchTag); // ReturnIfAbrupt(searchString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let functionalReplace be IsCallable(replaceValue). - if (!replace_tag->IsCallable()) { + if (!replaceTag->IsCallable()) { // If functionalReplace is false, then // Let replaceValue be ToString(replaceValue). // ReturnIfAbrupt(replaceValue) - replace_tag = JSHandle(JSTaggedValue::ToString(thread, replace_tag)); + replaceTag = JSHandle(JSTaggedValue::ToString(thread, replaceTag)); 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 = this_string->IndexOf(*search_string); + int32_t pos = thisString->IndexOf(*searchString); if (pos == -1) { - return this_string.GetTaggedValue(); + return thisString.GetTaggedValue(); } - JSMutableHandle repl_handle(thread, factory->GetEmptyString().GetTaggedValue()); + JSMutableHandle replHandle(thread, factory->GetEmptyString().GetTaggedValue()); // If functionalReplace is true, then - if (replace_tag->IsCallable()) { + if (replaceTag->IsCallable()) { // Let replValue be Call(replaceValue, undefined,«matched, pos, and string»). - 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); + 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); } else { - JSHandle undefined = global_const->GetHandledUndefined(); + JSHandle undefined = globalConst->GetHandledUndefined(); // Let captures be an empty List. - JSHandle captures_list = factory->EmptyArray(); - ASSERT_PRINT(replace_tag->IsString(), "replace must be string"); - JSHandle replacement(thread, replace_tag->GetTaggedObject()); + JSHandle capturesList = factory->EmptyArray(); + ASSERT_PRINT(replaceTag->IsString(), "replace must be string"); + JSHandle replacement(thread, replaceTag->GetTaggedObject()); // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) - repl_handle.Update( - string::GetSubstitution(thread, search_string, this_string, pos, captures_list, undefined, replacement)); + replHandle.Update( + string::GetSubstitution(thread, searchString, thisString, pos, capturesList, undefined, replacement)); } - JSHandle real_replace_str = JSTaggedValue::ToString(thread, repl_handle); + JSHandle realReplaceStr = JSTaggedValue::ToString(thread, replHandle); // Let tailPos be pos + the number of code units in matched. - int32_t tail_pos = pos + search_string->GetLength(); + int32_t tailPos = pos + searchString->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 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)); + 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)); } // ES2021 22.1.3.18 @@ -922,36 +921,36 @@ JSTaggedValue string::proto::ReplaceAll(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, StringPrototype, ReplaceAll); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle search_tag = builtins_common::GetCallArg(argv, 0); - JSHandle replace_tag = builtins_common::GetCallArg(argv, 1); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle searchTag = builtins_common::GetCallArg(argv, 0); + JSHandle replaceTag = builtins_common::GetCallArg(argv, 1); - ObjectFactory *factory = ecma_vm->GetFactory(); + ObjectFactory *factory = ecmaVm->GetFactory(); - if (!search_tag->IsUndefined() && !search_tag->IsNull()) { + if (!searchTag->IsUndefined() && !searchTag->IsNull()) { // a. Let isRegExp be ? IsRegExp(searchValue). - bool is_js_reg_exp = JSObject::IsRegExp(thread, search_tag); + bool isJsRegExp = JSObject::IsRegExp(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If isRegExp is true, then - if (is_js_reg_exp) { + if (isJsRegExp) { // i. Let flags be ? Get(searchValue, "flags"). - JSHandle flags_string(global_const->GetHandledFlagsString()); - JSHandle flags = JSObject::GetProperty(thread, search_tag, flags_string).GetValue(); + JSHandle flagsString(globalConst->GetHandledFlagsString()); + JSHandle flags = JSObject::GetProperty(thread, searchTag, flagsString).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 flag_string = JSTaggedValue::ToString(thread, flags); + JSHandle flagString = JSTaggedValue::ToString(thread, flags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle g_string(global_const->GetHandledGString()); - int32_t pos = flag_string->IndexOf(*g_string); + JSHandle gString(globalConst->GetHandledGString()); + int32_t pos = flagString->IndexOf(*gString); if (pos == -1) { THROW_TYPE_ERROR_AND_RETURN(thread, "string.prototype.replaceAll called with a non-global RegExp argument", @@ -959,207 +958,205 @@ JSTaggedValue string::proto::ReplaceAll(EcmaRuntimeCallInfo *argv) } } // c. Let replacer be ? GetMethod(searchValue, @@replace). - JSHandle replace_key = env->GetReplaceSymbol(); - JSHandle replace_method = JSObject::GetMethod(thread, search_tag, replace_key); + JSHandle replaceKey = env->GetReplaceSymbol(); + JSHandle replaceMethod = JSObject::GetMethod(thread, searchTag, replaceKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. If replacer is not undefined, then - if (!replace_method->IsUndefined()) { + if (!replaceMethod->IsUndefined()) { // i. Return ? Call(replacer, searchValue, «O, replaceValue»). - auto info = NewRuntimeCallInfo(thread, replace_method, search_tag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(this_tag.GetTaggedValue(), replace_tag.GetTaggedValue()); + auto info = NewRuntimeCallInfo(thread, replaceMethod, searchTag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(thisTag.GetTaggedValue(), replaceTag.GetTaggedValue()); return JSFunction::Call(info.Get()); } } // 3. Let string be ? ToString(O). - JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let searchString be ? ToString(searchValue). - JSHandle search_string = JSTaggedValue::ToString(thread, search_tag); + JSHandle searchString = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let functionalReplace be IsCallable(replaceValue). // 6. If functionalReplace is false, then - if (!replace_tag->IsCallable()) { + if (!replaceTag->IsCallable()) { // a. Set replaceValue to ? ToString(replaceValue). - replace_tag = JSHandle(JSTaggedValue::ToString(thread, replace_tag)); + replaceTag = JSHandle(JSTaggedValue::ToString(thread, replaceTag)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 7. Let searchLength be the length of searchString. // 8. Let advanceBy be max(1, searchLength). - int32_t search_length = search_string->GetLength(); - int32_t advance_by = std::max(1, search_length); + int32_t searchLength = searchString->GetLength(); + int32_t advanceBy = std::max(1, searchLength); // 9. Let matchPositions be a new empty List. - std::u16string string_builder; - std::u16string string_prefix_string; - std::u16string string_real_replace_str; - std::u16string string_suffix_string; + std::u16string stringBuilder; + std::u16string stringPrefixString; + std::u16string stringRealReplaceStr; + std::u16string stringSuffixString; // 10. Let position be ! StringIndexOf(string, searchString, 0). - int32_t pos = this_string->IndexOf(*search_string); - int32_t end_of_last_match = 0; - bool can_be_compress = true; - JSHandle undefined = global_const->GetHandledUndefined(); - JSMutableHandle repl_handle(thread, factory->GetEmptyString().GetTaggedValue()); + int32_t pos = thisString->IndexOf(*searchString); + int32_t endOfLastMatch = 0; + bool canBeCompress = true; + JSHandle undefined = globalConst->GetHandledUndefined(); + JSMutableHandle replHandle(thread, factory->GetEmptyString().GetTaggedValue()); while (pos != -1) { // If functionalReplace is true, then - if (replace_tag->IsCallable()) { + if (replaceTag->IsCallable()) { // Let replValue be Call(replaceValue, undefined, «matched, pos, and string»). - 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); + 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); } else { // Let captures be an empty List. - JSHandle captures_list = factory->NewTaggedArray(0); - ASSERT_PRINT(replace_tag->IsString(), "replace must be string"); - JSHandle replacement(thread, replace_tag->GetTaggedObject()); + JSHandle capturesList = factory->NewTaggedArray(0); + ASSERT_PRINT(replaceTag->IsString(), "replace must be string"); + JSHandle replacement(thread, replaceTag->GetTaggedObject()); // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) - repl_handle.Update(string::GetSubstitution(thread, search_string, this_string, pos, captures_list, - undefined, replacement)); + replHandle.Update( + string::GetSubstitution(thread, searchString, thisString, pos, capturesList, undefined, replacement)); } - JSHandle real_replace_str = JSTaggedValue::ToString(thread, repl_handle); + JSHandle realReplaceStr = JSTaggedValue::ToString(thread, replHandle); // 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 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; + 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()); + canBeCompress = false; } else { - const uint8_t *data = prefix_string->GetDataUtf8(); - string_prefix_string = base::StringHelper::Utf8ToU16String(data, prefix_string->GetLength()); + const uint8_t *data = prefixString->GetDataUtf8(); + stringPrefixString = base::StringHelper::Utf8ToU16String(data, prefixString->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; + if (realReplaceStr->IsUtf16()) { + const uint16_t *data = realReplaceStr->GetDataUtf16(); + stringRealReplaceStr = base::StringHelper::Utf16ToU16String(data, realReplaceStr->GetLength()); + canBeCompress = false; } else { - const uint8_t *data = real_replace_str->GetDataUtf8(); - string_real_replace_str = base::StringHelper::Utf8ToU16String(data, real_replace_str->GetLength()); + const uint8_t *data = realReplaceStr->GetDataUtf8(); + stringRealReplaceStr = base::StringHelper::Utf8ToU16String(data, realReplaceStr->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; + 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()); + canBeCompress = false; } else { - const uint8_t *data = suffix_string->GetDataUtf8(); - string_suffix_string = base::StringHelper::Utf8ToU16String(data, suffix_string->GetLength()); + const uint8_t *data = suffixString->GetDataUtf8(); + stringSuffixString = base::StringHelper::Utf8ToU16String(data, suffixString->GetLength()); } - string_builder = string_builder + string_suffix_string; + stringBuilder = stringBuilder + stringSuffixString; } - 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(); + auto *char16tData = const_cast(stringBuilder.c_str()); + auto *uint16tData = reinterpret_cast(char16tData); + return factory->NewFromUtf16LiteralUnCheck(uint16tData, stringBuilder.length(), canBeCompress).GetTaggedValue(); } // 21.1.3.14.1 Runtime Semantics: GetSubstitution() // NOLINTNEXTLINE(readability-function-size) JSTaggedValue string::GetSubstitution(JSThread *thread, const JSHandle &matched, - const JSHandle &src_string, int position, - const JSHandle &capture_list, - const JSHandle &named_captures, + const JSHandle &srcString, int position, + const JSHandle &captureList, + const JSHandle &namedCaptures, const JSHandle &replacement) { BUILTINS_API_TRACE(thread, String, GetSubstitution); - 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) { + 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) { return replacement.GetTaggedValue(); } - std::u16string string_builder; - bool can_be_compress = true; - if (next_dollar_index > 0) { + std::u16string stringBuilder; + bool canBeCompress = true; + if (nextDollarIndex > 0) { if (replacement->IsUtf16()) { const uint16_t *data = replacement->GetDataUtf16(); - string_builder += base::StringHelper::Utf16ToU16String(data, next_dollar_index); - can_be_compress = false; + stringBuilder += base::StringHelper::Utf16ToU16String(data, nextDollarIndex); + canBeCompress = false; } else { const uint8_t *data = replacement->GetDataUtf8(); - string_builder += base::StringHelper::Utf8ToU16String(data, next_dollar_index); + stringBuilder += base::StringHelper::Utf8ToU16String(data, nextDollarIndex); } } while (true) { - 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) + 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(), canBeCompress) .GetTaggedValue(); } - int continue_from_index = -1; - uint16_t peek = replacement->At(peek_index); + int continueFromIndex = -1; + uint16_t peek = replacement->At(peekIndex); switch (peek) { case '$': // $$ - string_builder += '$'; - continue_from_index = peek_index + 1; + stringBuilder += '$'; + continueFromIndex = peekIndex + 1; break; case '&': // $& - match if (matched->IsUtf16()) { const uint16_t *data = matched->GetDataUtf16(); - string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, matched->GetLength()); - can_be_compress = false; + stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, matched->GetLength()); + canBeCompress = false; } else { const uint8_t *data = matched->GetDataUtf8(); - string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, matched->GetLength()); + stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, matched->GetLength()); } - continue_from_index = peek_index + 1; + continueFromIndex = peekIndex + 1; break; case '`': // $` - prefix if (position > 0) { - EcmaString *prefix = EcmaString::FastSubString(src_string, 0, position, ecma_vm); + EcmaString *prefix = EcmaString::FastSubString(srcString, 0, position, ecmaVm); if (prefix->IsUtf16()) { const uint16_t *data = prefix->GetDataUtf16(); - string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, prefix->GetLength()); - can_be_compress = false; + stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, prefix->GetLength()); + canBeCompress = false; } else { const uint8_t *data = prefix->GetDataUtf8(); - string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, prefix->GetLength()); + stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, prefix->GetLength()); } } - continue_from_index = peek_index + 1; + continueFromIndex = peekIndex + 1; break; case '\'': { // $' - suffix - 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); + int32_t srcLength = srcString->GetLength(); + if (tailPos < srcLength) { + EcmaString *sufffix = EcmaString::FastSubString(srcString, tailPos, srcLength - tailPos, ecmaVm); if (sufffix->IsUtf16()) { const uint16_t *data = sufffix->GetDataUtf16(); - string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, sufffix->GetLength()); - can_be_compress = false; + stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, sufffix->GetLength()); + canBeCompress = false; } else { const uint8_t *data = sufffix->GetDataUtf8(); - string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, sufffix->GetLength()); + stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, sufffix->GetLength()); } } - continue_from_index = peek_index + 1; + continueFromIndex = peekIndex + 1; break; } case '0': @@ -1172,114 +1169,114 @@ JSTaggedValue string::GetSubstitution(JSThread *thread, const JSHandleGetLength(); + int capturesLength = captureList->GetLength(); // Valid indices are $1 .. $9, $01 .. $09 and $10 .. $99 - int32_t scaled_index = (peek - '0'); + int32_t scaledIndex = (peek - '0'); int32_t advance = 1; - if (peek_index + 1 < replace_length) { - uint16_t next_peek = replacement->At(peek_index + 1); - if (next_peek >= '0' && next_peek <= '9') { + if (peekIndex + 1 < replaceLength) { + uint16_t nextPeek = replacement->At(peekIndex + 1); + if (nextPeek >= '0' && nextPeek <= '9') { constexpr int32_t TEN_BASE = 10; - int32_t new_scaled_index = scaled_index * TEN_BASE + (next_peek - '0'); - if (new_scaled_index <= captures_length) { - scaled_index = new_scaled_index; + int32_t newScaledIndex = scaledIndex * TEN_BASE + (nextPeek - '0'); + if (newScaledIndex <= capturesLength) { + scaledIndex = newScaledIndex; advance = 2; // 2: 2 means from index needs to add two. } } } - if (scaled_index == 0 || scaled_index > captures_length) { - string_builder += '$'; - continue_from_index = peek_index; + if (scaledIndex == 0 || scaledIndex > capturesLength) { + stringBuilder += '$'; + continueFromIndex = peekIndex; break; } - 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; + 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()); + canBeCompress = false; } else { - const uint8_t *data = capture_string->GetDataUtf8(); - string_builder += - ecmascript::base::StringHelper::Utf8ToU16String(data, capture_string->GetLength()); + const uint8_t *data = captureString->GetDataUtf8(); + stringBuilder += + ecmascript::base::StringHelper::Utf8ToU16String(data, captureString->GetLength()); } } - continue_from_index = peek_index + advance; + continueFromIndex = peekIndex + advance; break; } case '<': { - if (named_captures->IsUndefined()) { - string_builder += '$'; - continue_from_index = peek_index; + if (namedCaptures->IsUndefined()) { + stringBuilder += '$'; + continueFromIndex = peekIndex; break; } - JSHandle greater_sym_string = factory->NewFromStdString(">"); - int pos = replacement->IndexOf(*greater_sym_string, peek_index); + JSHandle greaterSymString = factory->NewFromStdString(">"); + int pos = replacement->IndexOf(*greaterSymString, peekIndex); if (pos == -1) { - string_builder += '$'; - continue_from_index = peek_index; + stringBuilder += '$'; + continueFromIndex = peekIndex; break; } - 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(); + JSHandle groupName( + thread, EcmaString::FastSubString(replacement, peekIndex + 1, pos - peekIndex - 1, ecmaVm)); + JSHandle names(groupName); + JSHandle capture = JSObject::GetProperty(thread, namedCaptures, names).GetValue(); if (capture->IsUndefined()) { - continue_from_index = pos + 1; + continueFromIndex = pos + 1; break; } - 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; + JSHandle captureName(capture); + if (captureName->IsUtf16()) { + const uint16_t *data = captureName->GetDataUtf16(); + stringBuilder += base::StringHelper::Utf16ToU16String(data, captureName->GetLength()); + canBeCompress = false; } else { - const uint8_t *data = capture_name->GetDataUtf8(); - string_builder += base::StringHelper::Utf8ToU16String(data, capture_name->GetLength()); + const uint8_t *data = captureName->GetDataUtf8(); + stringBuilder += base::StringHelper::Utf8ToU16String(data, captureName->GetLength()); } - continue_from_index = pos + 1; + continueFromIndex = pos + 1; break; } default: - string_builder += '$'; - continue_from_index = peek_index; + stringBuilder += '$'; + continueFromIndex = peekIndex; break; } // Go the the next $ in the replacement. - 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; + 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()); + canBeCompress = false; } else { - const uint8_t *data = next_append->GetDataUtf8(); - string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, next_append->GetLength()); + const uint8_t *data = nextAppend->GetDataUtf8(); + stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, nextAppend->GetLength()); } } - 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) + auto *char16tData = const_cast(stringBuilder.c_str()); + auto *uint16tData = reinterpret_cast(char16tData); + return factory->NewFromUtf16LiteralUnCheck(uint16tData, stringBuilder.length(), canBeCompress) .GetTaggedValue(); } // Append substring between the previous and the next $ character. - 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; + 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()); + canBeCompress = false; } else { - const uint8_t *data = next_append->GetDataUtf8(); - string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, next_append->GetLength()); + const uint8_t *data = nextAppend->GetDataUtf8(); + stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, nextAppend->GetLength()); } } } @@ -1292,33 +1289,33 @@ JSTaggedValue string::proto::Search(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Search); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle regexp = builtins_common::GetCallArg(argv, 0); - JSHandle search_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetSearchSymbol(); + JSHandle searchTag = thread->GetEcmaVM()->GetGlobalEnv()->GetSearchSymbol(); if (!regexp->IsUndefined() && !regexp->IsNull()) { if (regexp->IsECMAObject()) { - JSHandle searcher = JSObject::GetMethod(thread, regexp, search_tag); + JSHandle searcher = JSObject::GetMethod(thread, regexp, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!searcher->IsUndefined()) { ASSERT(searcher->IsJSFunction()); auto info = NewRuntimeCallInfo(thread, searcher, regexp, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(this_tag); + info->SetCallArgs(thisTag); return JSFunction::Call(info.Get()); } } } - JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisVal = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle undifined_handle = global_const->GetHandledUndefined(); - JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, undifined_handle)); + JSHandle undifinedHandle = globalConst->GetHandledUndefined(); + JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, undifinedHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(this_val.GetTaggedValue()); - return JSFunction::Invoke(info.Get(), search_tag); + info->SetCallArgs(thisVal.GetTaggedValue()); + return JSFunction::Invoke(info.Get(), searchTag); } // 21.1.3.16 @@ -1327,39 +1324,39 @@ JSTaggedValue string::proto::Slice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Slice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - JSHandle start_tag = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber start_val = JSTaggedValue::ToInteger(thread, start_tag); + int32_t thisLen = thisHandle->GetLength(); + JSHandle startTag = builtins_common::GetCallArg(argv, 0); + JSTaggedNumber startVal = JSTaggedValue::ToInteger(thread, startTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t start = ConvertDoubleToInt(start_val.GetNumber()); + int32_t start = ConvertDoubleToInt(startVal.GetNumber()); int32_t end; - JSHandle end_tag = builtins_common::GetCallArg(argv, 1); - if (end_tag->IsUndefined()) { - end = this_len; + JSHandle endTag = builtins_common::GetCallArg(argv, 1); + if (endTag->IsUndefined()) { + end = thisLen; } else { - JSTaggedNumber end_val = JSTaggedValue::ToInteger(thread, end_tag); + JSTaggedNumber endVal = JSTaggedValue::ToInteger(thread, endTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = ConvertDoubleToInt(end_val.GetNumber()); + end = ConvertDoubleToInt(endVal.GetNumber()); } int32_t from; int32_t to; if (start < 0) { - from = std::max(start + this_len, 0); + from = std::max(start + thisLen, 0); } else { - from = std::min(start, this_len); + from = std::min(start, thisLen); } if (end < 0) { - to = std::max(end + this_len, 0); + to = std::max(end + thisLen, 0); } else { - to = std::min(end, this_len); + to = std::min(end, thisLen); } int32_t len = std::max(to - from, 0); - return JSTaggedValue(EcmaString::FastSubString(this_handle, from, len, thread->GetEcmaVM())); + return JSTaggedValue(EcmaString::FastSubString(thisHandle, from, len, thread->GetEcmaVM())); } // 21.1.3.17 @@ -1368,104 +1365,104 @@ JSTaggedValue string::proto::Split(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Split); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); // Let O be RequireObjectCoercible(this value). - JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); - JSHandle this_obj(this_tag); + JSHandle thisTag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); + JSHandle thisObj(thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle seperator_tag = builtins_common::GetCallArg(argv, 0); - JSHandle limit_tag = builtins_common::GetCallArg(argv, 1); + JSHandle seperatorTag = builtins_common::GetCallArg(argv, 0); + JSHandle limitTag = builtins_common::GetCallArg(argv, 1); // If separator is neither undefined nor null, then - if (seperator_tag->IsECMAObject()) { - JSHandle split_key = env->GetSplitSymbol(); + if (seperatorTag->IsECMAObject()) { + JSHandle splitKey = env->GetSplitSymbol(); // Let splitter be GetMethod(separator, @@split). - JSHandle splitter = JSObject::GetMethod(thread, seperator_tag, split_key); + JSHandle splitter = JSObject::GetMethod(thread, seperatorTag, splitKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!splitter->IsUndefined()) { // Return Call(splitter, separator, «‍O, limit»). - auto info = NewRuntimeCallInfo(thread, splitter, seperator_tag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(this_tag, limit_tag); + auto info = NewRuntimeCallInfo(thread, splitter, seperatorTag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(thisTag, limitTag); return JSFunction::Call(info.Get()); // 2: two args } } // Let S be ToString(O). - JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let A be ArrayCreate(0). - JSHandle result_array(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); - uint32_t array_length = 0; + JSHandle resultArray(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); + uint32_t arrayLength = 0; // If limit is undefined, let lim = 2^53–1; else let lim = ToLength(limit). uint32_t lim; - if (limit_tag->IsUndefined()) { + if (limitTag->IsUndefined()) { lim = UINT32_MAX - 1; } else { - JSTaggedNumber lim_val = JSTaggedValue::ToInteger(thread, limit_tag); + JSTaggedNumber limVal = JSTaggedValue::ToInteger(thread, limitTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - lim = lim_val.ToUint32(); + lim = limVal.ToUint32(); } // ReturnIfAbrupt(lim). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If lim = 0, return A. if (lim == 0) { - return result_array.GetTaggedValue(); + return resultArray.GetTaggedValue(); } // Let s be the number of elements in S. - int32_t this_length = this_string->GetLength(); - JSHandle seperator_string = JSTaggedValue::ToString(thread, seperator_tag); + int32_t thisLength = thisString->GetLength(); + JSHandle seperatorString = JSTaggedValue::ToString(thread, seperatorTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (seperator_tag->IsUndefined()) { + if (seperatorTag->IsUndefined()) { // Perform CreateDataProperty(A, "0", S). - JSObject::CreateDataProperty(thread, result_array, 0, JSHandle(this_string)); + JSObject::CreateDataProperty(thread, resultArray, 0, JSHandle(thisString)); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty(A, \"0\", S) can't throw exception"); - return result_array.GetTaggedValue(); + return resultArray.GetTaggedValue(); } // If S.length = 0, then - if (this_length == 0) { - if (this_string->IndexOf(*seperator_string, 0) != -1) { - return result_array.GetTaggedValue(); + if (thisLength == 0) { + if (thisString->IndexOf(*seperatorString, 0) != -1) { + return resultArray.GetTaggedValue(); } - JSObject::CreateDataProperty(thread, result_array, 0, JSHandle(this_string)); + JSObject::CreateDataProperty(thread, resultArray, 0, JSHandle(thisString)); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty(A, \"0\", S) can't throw exception"); - return result_array.GetTaggedValue(); + return resultArray.GetTaggedValue(); } - 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); + 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); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty can't throw exception"); - ++array_length; - if (array_length == lim) { - return result_array.GetTaggedValue(); + ++arrayLength; + if (arrayLength == lim) { + return resultArray.GetTaggedValue(); } } - return result_array.GetTaggedValue(); + return resultArray.GetTaggedValue(); } int32_t index = 0; - int32_t pos = this_string->IndexOf(*seperator_string); + int32_t pos = thisString->IndexOf(*seperatorString); while (pos != -1) { - 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); + EcmaString *elementString = EcmaString::FastSubString(thisString, index, pos - index, ecmaVm); + JSHandle elementTag(thread, elementString); + JSObject::CreateDataProperty(thread, resultArray, arrayLength, elementTag); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty can't throw exception"); - ++array_length; - if (array_length == lim) { - return result_array.GetTaggedValue(); + ++arrayLength; + if (arrayLength == lim) { + return resultArray.GetTaggedValue(); } - index = pos + seperator_length; - pos = this_string->IndexOf(*seperator_string, index); + index = pos + seperatorLength; + pos = thisString->IndexOf(*seperatorString, index); } - 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); + EcmaString *elementString = EcmaString::FastSubString(thisString, index, thisLength - index, ecmaVm); + JSHandle elementTag(thread, elementString); + JSObject::CreateDataProperty(thread, resultArray, arrayLength, elementTag); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty can't throw exception"); - return result_array.GetTaggedValue(); + return resultArray.GetTaggedValue(); } // 21.1.3.18 @@ -1474,49 +1471,49 @@ JSTaggedValue string::proto::StartsWith(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, StartsWith); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = builtins_common::GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle searchTag = builtins_common::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool is_regexp = JSObject::IsRegExp(thread, search_tag); - if (is_regexp) { + bool isRegexp = JSObject::IsRegExp(thread, searchTag); + if (isRegexp) { THROW_TYPE_ERROR_AND_RETURN(thread, "is regexp", JSTaggedValue::Exception()); } - JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); + JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - int32_t search_len = search_handle->GetLength(); + int32_t thisLen = thisHandle->GetLength(); + int32_t searchLen = searchHandle->GetLength(); int32_t pos; - JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); - if (pos_tag->IsUndefined()) { + JSHandle posTag = builtins_common::GetCallArg(argv, 1); + if (posTag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); + JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = pos_val.ToInt32(); + pos = posVal.ToInt32(); } - pos = std::min(std::max(pos, 0), this_len); - if (pos + search_len > this_len) { + pos = std::min(std::max(pos, 0), thisLen); + if (pos + searchLen > thisLen) { return builtins_common::GetTaggedBoolean(false); } - std::u16string u16str_this; - std::u16string u16str_search; - if (this_handle->IsUtf16()) { - u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); + std::u16string u16strThis; + std::u16string u16strSearch; + if (thisHandle->IsUtf16()) { + u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); } else { - const uint8_t *uint8_this = this_handle->GetDataUtf8(); - u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); + const uint8_t *uint8This = thisHandle->GetDataUtf8(); + u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); } - if (search_handle->IsUtf16()) { - u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); + if (searchHandle->IsUtf16()) { + u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); } else { - const uint8_t *uint8_search = search_handle->GetDataUtf8(); - u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); + const uint8_t *uint8Search = searchHandle->GetDataUtf8(); + u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, pos); + int32_t idx = ecmascript::base::StringHelper::Find(u16strThis, u16strSearch, pos); if (idx == pos) { return builtins_common::GetTaggedBoolean(true); } @@ -1529,31 +1526,31 @@ JSTaggedValue string::proto::Substring(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Substring); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t this_len = this_handle->GetLength(); - JSHandle start_tag = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber start_val = JSTaggedValue::ToInteger(thread, start_tag); + int32_t thisLen = thisHandle->GetLength(); + JSHandle startTag = builtins_common::GetCallArg(argv, 0); + JSTaggedNumber startVal = JSTaggedValue::ToInteger(thread, startTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t start = ConvertDoubleToInt(start_val.GetNumber()); + int32_t start = ConvertDoubleToInt(startVal.GetNumber()); int32_t end; - JSHandle end_tag = builtins_common::GetCallArg(argv, 1); - if (end_tag->IsUndefined()) { - end = this_len; + JSHandle endTag = builtins_common::GetCallArg(argv, 1); + if (endTag->IsUndefined()) { + end = thisLen; } else { - JSTaggedNumber end_val = JSTaggedValue::ToInteger(thread, end_tag); + JSTaggedNumber endVal = JSTaggedValue::ToInteger(thread, endTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = ConvertDoubleToInt(end_val.GetNumber()); + end = ConvertDoubleToInt(endVal.GetNumber()); } - start = std::min(std::max(start, 0), this_len); - end = std::min(std::max(end, 0), this_len); + start = std::min(std::max(start, 0), thisLen); + end = std::min(std::max(end, 0), thisLen); int32_t from = std::min(start, end); int32_t to = std::max(start, end); int32_t len = to - from; - return JSTaggedValue(EcmaString::FastSubString(this_handle, from, len, thread->GetEcmaVM())); + return JSTaggedValue(EcmaString::FastSubString(thisHandle, from, len, thread->GetEcmaVM())); } // 21.1.3.20 @@ -1562,9 +1559,9 @@ JSTaggedValue string::proto::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, ToLocaleLowerCase); JSThread *thread = argv->GetThread(); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // Let O be RequireObjectCoercible(this value). JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); @@ -1575,29 +1572,29 @@ JSTaggedValue string::proto::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) // Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = builtins_common::GetCallArg(argv, 0); - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = 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 requested_locale = JSLocale::DefaultLocale(thread); - if (requested_locales->GetLength() != 0) { - requested_locale = JSHandle(thread, requested_locales->Get(0)); + JSHandle requestedLocale = JSLocale::DefaultLocale(thread); + if (requestedLocales->GetLength() != 0) { + requestedLocale = JSHandle(thread, requestedLocales->Get(0)); } // Let noExtensionsLocale be the String value that is requestedLocale with all Unicode locale extension sequences // removed. - JSLocale::ParsedLocale no_extensions_locale = JSLocale::HandleLocale(requested_locale); + JSLocale::ParsedLocale noExtensionsLocale = JSLocale::HandleLocale(requestedLocale); 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 available_locales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); + JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let locale be BestAvailableLocale(availableLocales, noExtensionsLocale). - std::string locale = JSLocale::BestAvailableLocale(thread, available_locales, no_extensions_locale.base); + std::string locale = JSLocale::BestAvailableLocale(thread, availableLocales, noExtensionsLocale.base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If locale is undefined, let locale be "und". @@ -1608,20 +1605,20 @@ JSTaggedValue string::proto::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 icu_locale = icu::Locale::createFromName(locale.c_str()); - std::u16string utf16_string; + icu::Locale icuLocale = icu::Locale::createFromName(locale.c_str()); + std::u16string utf16String; if (string->IsUtf16()) { - utf16_string = + utf16String = ecmascript::base::StringHelper::Utf16ToU16String(string->GetDataUtf16(), string->GetUtf16Length()); } else { - 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); + 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); return result.GetTaggedValue(); } @@ -1631,9 +1628,9 @@ JSTaggedValue string::proto::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, ToLocaleUpperCase); JSThread *thread = argv->GetThread(); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // Let O be RequireObjectCoercible(this value). JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); @@ -1644,29 +1641,29 @@ JSTaggedValue string::proto::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) // Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = builtins_common::GetCallArg(argv, 0); - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = 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 requested_locale = JSLocale::DefaultLocale(thread); - if (requested_locales->GetLength() != 0) { - requested_locale = JSHandle(thread, requested_locales->Get(0)); + JSHandle requestedLocale = JSLocale::DefaultLocale(thread); + if (requestedLocales->GetLength() != 0) { + requestedLocale = JSHandle(thread, requestedLocales->Get(0)); } // Let noExtensionsLocale be the String value that is requestedLocale with all Unicode locale extension sequences // removed. - JSLocale::ParsedLocale no_extensions_locale = JSLocale::HandleLocale(requested_locale); + JSLocale::ParsedLocale noExtensionsLocale = JSLocale::HandleLocale(requestedLocale); 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 available_locales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); + JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let locale be BestAvailableLocale(availableLocales, noExtensionsLocale). - std::string locale = JSLocale::BestAvailableLocale(thread, available_locales, no_extensions_locale.base); + std::string locale = JSLocale::BestAvailableLocale(thread, availableLocales, noExtensionsLocale.base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If locale is undefined, let locale be "und". @@ -1677,41 +1674,41 @@ JSTaggedValue string::proto::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 icu_locale = icu::Locale::createFromName(locale.c_str()); - std::u16string utf16_string; + icu::Locale icuLocale = icu::Locale::createFromName(locale.c_str()); + std::u16string utf16String; if (string->IsUtf16()) { - utf16_string = + utf16String = ecmascript::base::StringHelper::Utf16ToU16String(string->GetDataUtf16(), string->GetUtf16Length()); } else { - 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); + 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); return result.GetTaggedValue(); } static std::u16string ToU16String(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag( + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag( JSTaggedValue::RequireObjectCoercible(thread, ecmascript::builtins_common::GetThis(argv))); - JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); if (UNLIKELY(thread->HasPendingException())) { return std::u16string(); } - int32_t this_len = this_handle->GetLength(); - if (this_handle->IsUtf16()) { - return ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); + int32_t thisLen = thisHandle->GetLength(); + if (thisHandle->IsUtf16()) { + return ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); } - const uint8_t *uint8_this = this_handle->GetDataUtf8(); - return ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); + const uint8_t *uint8This = thisHandle->GetDataUtf8(); + return ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); } // 21.1.3.22 @@ -1720,10 +1717,10 @@ JSTaggedValue string::proto::ToLowerCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, ToLowerCase); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - std::u16string u16str_this = ToU16String(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + std::u16string u16strThis = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return JSTaggedValue(ecmascript::base::StringHelper::ToLower(thread, u16str_this)); + return JSTaggedValue(ecmascript::base::StringHelper::ToLower(thread, u16strThis)); } // 21.1.3.23 @@ -1739,10 +1736,10 @@ JSTaggedValue string::proto::ToUpperCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, ToUpperCase); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - std::u16string u16str_this = ToU16String(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + std::u16string u16strThis = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return JSTaggedValue(ecmascript::base::StringHelper::ToUpper(thread, u16str_this)); + return JSTaggedValue(ecmascript::base::StringHelper::ToUpper(thread, u16strThis)); } // 21.1.3.25 @@ -1751,9 +1748,9 @@ JSTaggedValue string::proto::Trim(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Trim); JSThread *thread = argv->GetThread(); - std::u16string u16str_this = ToU16String(argv); + std::u16string u16strThis = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16str_this, base::TrimKind::TRIM_START_END); + EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16strThis, base::TrimKind::TRIM_START_END); return JSTaggedValue(str); } @@ -1763,9 +1760,9 @@ JSTaggedValue string::proto::TrimEnd(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, TrimEnd); JSThread *thread = argv->GetThread(); - std::u16string u16str_this = ToU16String(argv); + std::u16string u16strThis = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16str_this, base::TrimKind::TRIM_END); + EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16strThis, base::TrimKind::TRIM_END); return JSTaggedValue(str); } @@ -1775,9 +1772,9 @@ JSTaggedValue string::proto::TrimStart(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, TrimStart); JSThread *thread = argv->GetThread(); - std::u16string u16str_this = ToU16String(argv); + std::u16string u16strThis = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16str_this, base::TrimKind::TRIM_START); + EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16strThis, base::TrimKind::TRIM_START); return JSTaggedValue(str); } @@ -1794,7 +1791,7 @@ JSTaggedValue string::proto::Iterator(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Iterator); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be RequireObjectCoercible(this value). JSHandle current(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); // Let S be ToString(O). @@ -1812,58 +1809,58 @@ JSTaggedValue string::proto::Substr(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), StringPrototype, Substr); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be RequireObjectCoercible(this value). // 2. Let S be ToString(O). - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); - JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); + JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); // 3. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle int_start = builtins_common::GetCallArg(argv, 0); + JSHandle intStart = builtins_common::GetCallArg(argv, 0); // 4. Let intStart be ToInteger(start). - JSTaggedNumber num_start = JSTaggedValue::ToInteger(thread, int_start); + JSTaggedNumber numStart = JSTaggedValue::ToInteger(thread, intStart); // 5. ReturnIfAbrupt(intStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t start = num_start.ToInt32(); - JSHandle length_tag = builtins_common::GetCallArg(argv, 1); + int32_t start = numStart.ToInt32(); + JSHandle lengthTag = builtins_common::GetCallArg(argv, 1); // 6. If length is undefined, let end be +; otherwise let end be ToInteger(length). int32_t end; - if (length_tag->IsUndefined()) { + if (lengthTag->IsUndefined()) { end = INT_MAX; } else { - JSTaggedNumber length_number = JSTaggedValue::ToInteger(thread, length_tag); + JSTaggedNumber lengthNumber = JSTaggedValue::ToInteger(thread, lengthTag); // 7. ReturnIfAbrupt(end). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = length_number.ToInt32(); + end = lengthNumber.ToInt32(); } // 8. Let size be the number of code units in S. - int32_t size = this_string->GetLength(); + int32_t size = thisString->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 result_length = std::min(std::max(end, 0), size - start); + int32_t resultLength = std::min(std::max(end, 0), size - start); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 11. If resultLength  0, return the empty String "". - if (result_length <= 0) { + if (resultLength <= 0) { return factory->GetEmptyString().GetTaggedValue(); } - return JSTaggedValue(EcmaString::FastSubString(this_string, start, result_length, thread->GetEcmaVM())); + return JSTaggedValue(EcmaString::FastSubString(thisString, start, resultLength, thread->GetEcmaVM())); } JSTaggedValue string::proto::GetLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = builtins_common::GetThis(argv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisHandle = builtins_common::GetThis(argv); - JSHandle this_string = JSTaggedValue::ToString(thread, this_handle); - return builtins_common::GetTaggedInt(this_string->GetLength()); + JSHandle thisString = JSTaggedValue::ToString(thread, thisHandle); + return builtins_common::GetTaggedInt(thisString->GetLength()); } // 21.1.3 @@ -1873,8 +1870,8 @@ JSTaggedValue ThisStringValue(JSThread *thread, JSTaggedValue value) return value; } if (value.IsECMAObject()) { - auto jsh_class = value.GetTaggedObject()->GetClass(); - if (jsh_class->GetObjectType() == JSType::JS_PRIMITIVE_REF) { + auto jshClass = value.GetTaggedObject()->GetClass(); + if (jshClass->GetObjectType() == JSType::JS_PRIMITIVE_REF) { JSTaggedValue primitive = JSPrimitiveRef::Cast(value.GetTaggedObject())->GetValue(); if (primitive.IsString()) { return primitive; diff --git a/runtime/builtins/builtins_string_iterator.cpp b/runtime/builtins/builtins_string_iterator.cpp index d439d574eb7dc0778b72e7e4085a82774733c04e..b1119df2796043409e2b1f3bd316dbbce66dab6e 100644 --- a/runtime/builtins/builtins_string_iterator.cpp +++ b/runtime/builtins/builtins_string_iterator.cpp @@ -29,24 +29,23 @@ JSTaggedValue string_iterator::proto::Next(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringIteratorPrototype, Next); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. // 3. If O does not have all of the internal slots of an String Iterator Instance (21.1.5.3), // throw a TypeError exception. - if (!this_value->IsStringIterator()) { + if (!thisValue->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, this_value.GetObject()->GetIteratedString()); + JSHandle string(thread, thisValue.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(this_value.GetObject()->GetStringIteratorNextIndex()).GetNumber(); + double position = JSTaggedNumber(thisValue.GetObject()->GetStringIteratorNextIndex()).GetNumber(); // 7. Let len be the number of elements in s. uint32_t len = string.GetObject()->GetLength(); @@ -54,7 +53,7 @@ JSTaggedValue string_iterator::proto::Next(EcmaRuntimeCallInfo *argv) // a. Set the value of the [[IteratedString]] internal slot of O to // b. Return CreateIterResultObject(undefined, true). if (position >= len) { - this_value.GetObject()->SetIteratedString(thread, JSTaggedValue::Undefined()); + thisValue.GetObject()->SetIteratedString(thread, JSTaggedValue::Undefined()); JSHandle result(thread, JSTaggedValue::Undefined()); return JSIterator::CreateIterResultObject(thread, result, true).GetTaggedValue(); } @@ -62,13 +61,13 @@ JSTaggedValue string_iterator::proto::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 result_size = 1; + uint32_t resultSize = 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 result_string {first, 0x0}; - result.Update(factory->NewFromUtf16UnCheck(result_string.data(), 1, true).GetTaggedValue()); + std::vector resultString {first, 0x0}; + result.Update(factory->NewFromUtf16UnCheck(resultString.data(), 1, true).GetTaggedValue()); } else { // 11. Else, // a. Let second be the code unit value at index position+1 in the String S. @@ -77,18 +76,18 @@ JSTaggedValue string_iterator::proto::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 result_string {first, 0x0}; - result.Update(factory->NewFromUtf16UnCheck(result_string.data(), 1, false).GetTaggedValue()); + std::vector resultString {first, 0x0}; + result.Update(factory->NewFromUtf16UnCheck(resultString.data(), 1, false).GetTaggedValue()); } else { - std::vector result_string {first, second, 0x0}; + std::vector resultString {first, second, 0x0}; result.Update( - factory->NewFromUtf16UnCheck(result_string.data(), 2, false).GetTaggedValue()); // 2: two bytes - result_size = 2; // 2: 2 means that two bytes represent a character string + factory->NewFromUtf16UnCheck(resultString.data(), 2, false).GetTaggedValue()); // 2: two bytes + resultSize = 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. - this_value.GetObject()->SetStringIteratorNextIndex(thread, JSTaggedValue(position + result_size)); + thisValue.GetObject()->SetStringIteratorNextIndex(thread, JSTaggedValue(position + resultSize)); // 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 c40ff8b7155b78f85c4af527581db90f9d4e7db9..3181efa6fee2b4253c0b32e1a011dc6a17512509 100644 --- a/runtime/builtins/builtins_symbol.cpp +++ b/runtime/builtins/builtins_symbol.cpp @@ -36,27 +36,27 @@ JSTaggedValue symbol::SymbolConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, SymbolConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.If NewTarget is not undefined, throw a TypeError exception. JSHandle key = builtins_common::GetCallArg(argv, 0); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (!new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (!newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "SymbolConstructor: NewTarget is not undefined", JSTaggedValue::Exception()); } // 2.If description is undefined, let descString be undefined. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (key->IsUndefined()) { - JSHandle js_symbol = factory->NewJSSymbol(); - return js_symbol.GetTaggedValue(); + JSHandle jsSymbol = factory->NewJSSymbol(); + return jsSymbol.GetTaggedValue(); } // 3.Else, let descString be ToString(description). - JSHandle desc_handle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); + JSHandle descHandle = 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 js_symbol = factory->NewPublicSymbol(desc_handle); - return js_symbol.GetTaggedValue(); + JSHandle jsSymbol = factory->NewPublicSymbol(descHandle); + return jsSymbol.GetTaggedValue(); } // 19.4.3.2 Symbol.prototype.toString() @@ -65,20 +65,20 @@ JSTaggedValue symbol::proto::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SymbolPrototype, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let s be the this value. - JSHandle value_handle = builtins_common::GetThis(argv); + JSHandle valueHandle = builtins_common::GetThis(argv); // 2.If Type(s) is Symbol, let sym be s. - JSTaggedValue sym = value_handle.GetTaggedValue(); + JSTaggedValue sym = valueHandle.GetTaggedValue(); // 3.Else - if (!value_handle->IsSymbol()) { - if (value_handle->IsObject()) { - if (!value_handle->IsJSPrimitiveRef()) { + if (!valueHandle->IsSymbol()) { + if (valueHandle->IsObject()) { + if (!valueHandle->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(value_handle->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(); ASSERT(primitive.IsSymbol()); sym = primitive; } else { @@ -98,25 +98,25 @@ JSTaggedValue symbol::SymbolDescriptiveString(JSThread *thread, JSTaggedValue sy ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Let desc be sym’s [[Description]] value. - auto symbol_object = reinterpret_cast(sym.GetTaggedObject()); - JSHandle desc_handle(thread, symbol_object->GetDescription()); + auto symbolObject = reinterpret_cast(sym.GetTaggedObject()); + JSHandle descHandle(thread, symbolObject->GetDescription()); // If desc is undefined, let desc be the empty string. - if (desc_handle->IsUndefined()) { - JSHandle left_handle(factory->NewFromCanBeCompressString("Symbol(")); - JSHandle right_handle(factory->NewFromCanBeCompressString(")")); - JSHandle str = factory->ConcatFromString(left_handle, right_handle); + if (descHandle->IsUndefined()) { + JSHandle leftHandle(factory->NewFromCanBeCompressString("Symbol(")); + JSHandle rightHandle(factory->NewFromCanBeCompressString(")")); + JSHandle str = factory->ConcatFromString(leftHandle, rightHandle); return str.GetTaggedValue(); } // Assert: Type(desc) is String. - ASSERT(desc_handle->IsString()); + ASSERT(descHandle->IsString()); // Return the result of concatenating the strings "Symbol(", desc, and ")". - 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); + JSHandle leftHandle(factory->NewFromCanBeCompressString("Symbol(")); + JSHandle rightHandle(factory->NewFromCanBeCompressString(")")); + JSHandle stringLeft = + factory->ConcatFromString(leftHandle, JSTaggedValue::ToString(thread, descHandle)); + JSHandle str = factory->ConcatFromString(stringLeft, rightHandle); return str.GetTaggedValue(); } @@ -126,24 +126,24 @@ JSTaggedValue symbol::proto::ValueOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SymbolPrototype, ValueOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // Let s be the this value. - JSHandle value_handle = builtins_common::GetThis(argv); + JSHandle valueHandle = builtins_common::GetThis(argv); // If Type(s) is Symbol, return s. - if (value_handle->IsSymbol()) { - return value_handle.GetTaggedValue(); + if (valueHandle->IsSymbol()) { + return valueHandle.GetTaggedValue(); } // If Type(s) is not Object, throw a TypeError exception. - if (!value_handle->IsObject()) { + if (!valueHandle->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 (!value_handle->IsJSPrimitiveRef()) { + if (!valueHandle->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(value_handle->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(); ASSERT(primitive.IsSymbol()); // Return the value of s's [[SymbolData]] internal slot. return primitive; @@ -155,10 +155,10 @@ JSTaggedValue symbol::For(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, For); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let stringKey be ToString(key). JSHandle key = builtins_common::GetCallArg(argv, 0); - JSHandle string_handle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); + JSHandle stringHandle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); // 2.ReturnIfAbrupt RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -169,7 +169,7 @@ JSTaggedValue symbol::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(string_handle); + JSHandle symbol = factory->NewSymbolWithTable(stringHandle); return symbol.GetTaggedValue(); } @@ -179,7 +179,7 @@ JSTaggedValue symbol::KeyFor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, KeyFor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.If Type(sym) is not Symbol, throw a TypeError exception. JSHandle sym = builtins_common::GetCallArg(argv, 0); if (!sym->IsSymbol()) { @@ -206,7 +206,7 @@ JSTaggedValue symbol::proto::ToPrimitive(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), SymbolPrototype, ToPrimitive); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let s be the this value. JSHandle sym = builtins_common::GetThis(argv); // 2.If Type(s) is Symbol, return s. @@ -238,7 +238,7 @@ JSTaggedValue symbol::proto::GetDescription(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), SymbolPrototype, GetDescription); // 1.Let s be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle s = builtins_common::GetThis(argv); // 2.Let sym be ? thisSymbolValue(s). // 3.Return sym.[[Description]]. @@ -249,8 +249,8 @@ JSTaggedValue ThisSymbolValue(JSThread *thread, const JSHandle &v { BUILTINS_API_TRACE(thread, Symbol, ThisSymbolValue); if (value->IsSymbol()) { - JSTaggedValue des_value = JSSymbol::Cast(value->GetTaggedObject())->GetDescription(); - return des_value; + JSTaggedValue desValue = JSSymbol::Cast(value->GetTaggedObject())->GetDescription(); + return desValue; } // If s does not have a [[SymbolData]] internal slot, throw a TypeError exception. @@ -260,7 +260,7 @@ JSTaggedValue ThisSymbolValue(JSThread *thread, const JSHandle &v JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(); ASSERT(primitive.IsSymbol()); // Return the value of s's [[SymbolData]] internal slot. - JSTaggedValue primitive_des_value = JSSymbol::Cast(primitive.GetTaggedObject())->GetDescription(); - return primitive_des_value; + JSTaggedValue primitiveDesValue = JSSymbol::Cast(primitive.GetTaggedObject())->GetDescription(); + return primitiveDesValue; } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_typedarray.cpp b/runtime/builtins/builtins_typedarray.cpp index aab1b377bdee19b314706a1abee1b08df9fcb700..0d6a1cdbbcbb79ced056b2cf759580945ca867b3 100644 --- a/runtime/builtins/builtins_typedarray.cpp +++ b/runtime/builtins/builtins_typedarray.cpp @@ -127,16 +127,16 @@ JSTaggedValue typed_array::From(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, From); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 1. Let C be the this value. // 2. If IsConstructor(C) is false, throw a TypeError exception. - JSHandle this_handle = builtins_common::GetThis(argv); - if (!this_handle->IsConstructor()) { + JSHandle thisHandle = builtins_common::GetThis(argv); + if (!thisHandle->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the this value is not a Constructor.", JSTaggedValue::Exception()); } - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); // 3. If mapfn is undefined, let mapping be false. // 4. Else, // a. If IsCallable(mapfn) is false, throw a TypeError exception. @@ -154,34 +154,33 @@ JSTaggedValue typed_array::From(EcmaRuntimeCallInfo *argv) if (!source->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the source is not an object.", JSTaggedValue::Exception()); } - JSHandle source_obj(source); - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSHandle using_iterator = - JSObject::GetMethod(thread, JSHandle::Cast(source_obj), iterator_symbol); + JSHandle sourceObj(source); + JSHandle iteratorSymbol = env->GetIteratorSymbol(); + JSHandle usingIterator = + JSObject::GetMethod(thread, JSHandle::Cast(sourceObj), iteratorSymbol); 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 (!using_iterator->IsUndefined()) { + if (!usingIterator->IsUndefined()) { PandaVector> vec; - JSHandle iterator = JSIterator::GetIterator(thread, source, using_iterator); + JSHandle iterator = JSIterator::GetIterator(thread, source, usingIterator); 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 next_value = JSIterator::IteratorValue(thread, next); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next_value.GetTaggedValue()); - vec.push_back(next_value); + JSHandle nextValue = JSIterator::IteratorValue(thread, next); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); + vec.push_back(nextValue); } } uint32_t len = vec.size(); std::array args = {JSTaggedValue(len).GetRawData()}; - JSHandle target_obj = - TypedArrayHelper::TypedArrayCreate(thread, this_handle, args.size(), args.data()); + JSHandle targetObj = TypedArrayHelper::TypedArrayCreate(thread, thisHandle, args.size(), args.data()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. Let k be 0. // e. Repeat, while k < len @@ -192,49 +191,49 @@ JSTaggedValue typed_array::From(EcmaRuntimeCallInfo *argv) // iv. Else, let mappedValue be kValue. // v. Perform ? Set(targetObj, Pk, mappedValue, true). // vi. Set k to k + 1. - JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle map_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - t_key.Update(JSTaggedValue(k)); - JSHandle k_value = vec[k]; + tKey.Update(JSTaggedValue(k)); + JSHandle kValue = vec[k]; if (mapping) { - 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 + auto info = NewRuntimeCallInfo(thread, mapfn, thisArgHandle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(kValue, tKey); + JSTaggedValue callResult = JSFunction::Call(info.Get()); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - map_value.Update(call_result); + mapValue.Update(callResult); } else { - map_value.Update(k_value.GetTaggedValue()); + mapValue.Update(kValue.GetTaggedValue()); } - JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(target_obj), k_key, map_value, true); + JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(targetObj), kKey, mapValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // f. Assert: values is now an empty List. // g. Return targetObj. - return target_obj.GetTaggedValue(); + return targetObj.GetTaggedValue(); } // 7. NOTE: source is not an Iterable so assume it is already an array-like object. // 8. Let arrayLike be ! ToObject(source). - JSHandle array_like_obj = JSTaggedValue::ToObject(thread, source); + JSHandle arrayLikeObj = JSTaggedValue::ToObject(thread, source); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle array_like(array_like_obj); + JSHandle arrayLike(arrayLikeObj); // 9. Let len be ? LengthOfArrayLike(arrayLike). - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle len_result = JSTaggedValue::GetProperty(thread, array_like, length_key).GetValue(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lenResult = JSTaggedValue::GetProperty(thread, arrayLike, lengthKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedNumber t_len = JSTaggedValue::ToLength(thread, len_result); + JSTaggedNumber tLen = JSTaggedValue::ToLength(thread, lenResult); // 6. ReturnIfAbrupt(relativeTarget). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double len = t_len.GetNumber(); + double len = tLen.GetNumber(); // 10. Let targetObj be ? TypedArrayCreate(C, « len »). std::array args = {JSTaggedValue(len).GetRawData()}; - JSHandle target_obj = TypedArrayHelper::TypedArrayCreate(thread, this_handle, args.size(), args.data()); + JSHandle targetObj = TypedArrayHelper::TypedArrayCreate(thread, thisHandle, args.size(), args.data()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Let k be 0. // 12. Repeat, while k < len @@ -245,29 +244,29 @@ JSTaggedValue typed_array::From(EcmaRuntimeCallInfo *argv) // d. Else, let mappedValue be kValue. // e. Perform ? Set(targetObj, Pk, mappedValue, true). // f. Set k to k + 1. - JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - t_key.Update(JSTaggedValue(k)); - JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); - JSHandle k_value = JSTaggedValue::GetProperty(thread, array_like, k_key).GetValue(); + tKey.Update(JSTaggedValue(k)); + JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); + JSHandle kValue = JSTaggedValue::GetProperty(thread, arrayLike, kKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle map_value; + JSHandle mapValue; if (mapping) { - 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 + auto info = NewRuntimeCallInfo(thread, mapfn, thisArgHandle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(kValue, tKey); + JSTaggedValue callResult = JSFunction::Call(info.Get()); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - map_value = JSHandle(thread, call_result); + mapValue = JSHandle(thread, callResult); } else { - map_value = k_value; + mapValue = kValue; } - JSTaggedValue::SetProperty(thread, JSHandle::Cast(target_obj), k_key, map_value, true); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(targetObj), kKey, mapValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 13. Return targetObj. - return target_obj.GetTaggedValue(); + return targetObj.GetTaggedValue(); } // 22.2.2.2 %TypedArray%.of ( ...items ) @@ -276,20 +275,20 @@ JSTaggedValue typed_array::Of(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Of); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(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 this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 4. If IsConstructor(C) is false, throw a TypeError exception. - if (!this_handle->IsConstructor()) { + if (!thisHandle->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 new_obj = TypedArrayHelper::TypedArrayCreate(thread, this_handle, args.size(), args.data()); + JSHandle newObj = TypedArrayHelper::TypedArrayCreate(thread, thisHandle, args.size(), args.data()); // 6. ReturnIfAbrupt(newObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let k be 0. @@ -299,18 +298,18 @@ JSTaggedValue typed_array::Of(EcmaRuntimeCallInfo *argv) // c. Perform ? Set(newObj, Pk, kValue, true). // d. ReturnIfAbrupt(status). // e. Set k to k + 1. - JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - t_key.Update(JSTaggedValue(k)); - JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); - JSHandle k_value = builtins_common::GetCallArg(argv, k); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_obj), k_key, k_value, true); + tKey.Update(JSTaggedValue(k)); + JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); + JSHandle kValue = builtins_common::GetCallArg(argv, k); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newObj), kKey, kValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 9. Return newObj. - return new_obj.GetTaggedValue(); + return newObj.GetTaggedValue(); } // 22.2.2.4 @@ -328,20 +327,20 @@ JSTaggedValue typed_array::proto::GetBuffer(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, GetBuffer); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsTypedArray()) { + if (!thisHandle->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(this_handle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); // 5. Return buffer. return buffer; } @@ -352,27 +351,27 @@ JSTaggedValue typed_array::proto::GetByteLength(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, GetByteLength); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsTypedArray()) { + if (!thisHandle->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(this_handle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, return 0. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. // 7. Return size. - return JSHandle(this_handle)->GetByteLength(); + return JSHandle(thisHandle)->GetByteLength(); } // 22.2.3.3 @@ -381,26 +380,26 @@ JSTaggedValue typed_array::proto::GetByteOffset(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, GetByteOffset); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsTypedArray()) { + if (!thisHandle->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(this_handle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, return 0. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. - int32_t offset = TypedArrayHelper::GetByteOffset(thread, JSHandle(this_handle)); + int32_t offset = TypedArrayHelper::GetByteOffset(thread, JSHandle(thisHandle)); // 7. Return offset. return JSTaggedValue(offset); } @@ -422,14 +421,14 @@ JSTaggedValue typed_array::proto::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, this_handle); + TypedArrayHelper::ValidateTypedArray(thread, thisHandle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); - JSHandle self(this_handle); + JSHandle self(thisHandle); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 4. Return CreateArrayIterator(O, "key+value"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::KEY_AND_VALUE)); @@ -442,31 +441,31 @@ JSTaggedValue typed_array::proto::Every(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Every); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - if (!this_handle->IsTypedArray()) { + JSHandle thisHandle = builtins_common::GetThis(argv); + if (!thisHandle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj_handle); + int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObjHandle); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -485,15 +484,15 @@ JSTaggedValue typed_array::proto::Every(EcmaRuntimeCallInfo *argv) int32_t k = 0; while (k < len) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle k_value = JSTaggedValue::GetProperty(thread, this_obj_val, k).GetValue(); + JSHandle kValue = JSTaggedValue::GetProperty(thread, thisObjVal, k).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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 + auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(kValue, key, thisObjVal); + JSTaggedValue callResult = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool bool_result = call_result.ToBoolean(); - if (!bool_result) { + bool boolResult = callResult.ToBoolean(); + if (!boolResult) { return builtins_common::GetTaggedBoolean(false); } k++; @@ -519,25 +518,25 @@ JSTaggedValue typed_array::proto::Filter(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Filter); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, this_handle); + TypedArrayHelper::ValidateTypedArray(thread, thisHandle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj(this_handle); + JSHandle thisObj(thisHandle); // 4. Let len be the value of O’s [[ArrayLength]] internal slot. - int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); + int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 10. Let kept be a new empty List. JSHandle kept(factory->NewTaggedArray(len)); @@ -555,27 +554,26 @@ JSTaggedValue typed_array::proto::Filter(EcmaRuntimeCallInfo *argv) // ii. Increase captured by 1. // g. Increase k by 1. int32_t captured = 0; - JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); for (int32_t k = 0; k < len; k++) { - t_key.Update(JSTaggedValue(k)); - JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); - JSHandle k_value = JSTaggedValue::GetProperty(thread, this_handle, k_key).GetValue(); + tKey.Update(JSTaggedValue(k)); + JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); + JSHandle kValue = JSTaggedValue::GetProperty(thread, thisHandle, kKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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(); + 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(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (test_result) { - kept->Set(thread, captured, k_value); + if (testResult) { + kept->Set(thread, captured, kValue); captured++; } } // es11 9. Let A be ? TypedArraySpeciesCreate(O, « captured »). std::array args = {JSTaggedValue(captured).GetRawData()}; - JSHandle new_arr_obj = - TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); + JSHandle newArrObj = TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, args.size(), args.data()); // 15. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. Let n be 0. @@ -583,17 +581,17 @@ JSTaggedValue typed_array::proto::Filter(EcmaRuntimeCallInfo *argv) // a. Let status be Set(A, ToString(n), e, true ). // b. ReturnIfAbrupt(status). // c. Increment n by 1. - JSMutableHandle value_handle(thread, JSTaggedValue::Undefined()); - JSMutableHandle nt_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); + JSMutableHandle ntKey(thread, JSTaggedValue::Undefined()); for (int32_t n = 0; n < captured; n++) { - 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); + valueHandle.Update(kept->Get(n)); + ntKey.Update(JSTaggedValue(n)); + JSHandle nKey(JSTaggedValue::ToString(thread, ntKey)); + JSTaggedValue::SetProperty(thread, JSHandle(newArrObj), nKey, valueHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 18. Return A. - return new_arr_obj.GetTaggedValue(); + return newArrObj.GetTaggedValue(); } // 22.2.3.10 @@ -622,31 +620,31 @@ JSTaggedValue typed_array::proto::ForEach(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, ForEach); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - if (!this_handle->IsTypedArray()) { + JSHandle thisHandle = builtins_common::GetThis(argv); + if (!thisHandle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); // 3. Let len be ToLength(Get(O, "length")). - int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj_handle); + int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObjHandle); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); - if (!callback_fn_handle->IsCallable()) { + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -663,13 +661,13 @@ JSTaggedValue typed_array::proto::ForEach(EcmaRuntimeCallInfo *argv) int32_t k = 0; while (k < len) { - JSHandle k_value = JSTaggedValue::GetProperty(thread, this_obj_val, k).GetValue(); + JSHandle kValue = JSTaggedValue::GetProperty(thread, thisObjVal, k).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - 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); + 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); k++; } @@ -683,18 +681,18 @@ JSTaggedValue typed_array::proto::Includes(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Includes); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. Perform ? ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, this_handle); + TypedArrayHelper::ValidateTypedArray(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let len be ToLength(Get(O, "length")). - JSHandle this_obj(this_handle); - int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); + JSHandle thisObj(thisHandle); + int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If len is 0, return false. @@ -703,15 +701,15 @@ JSTaggedValue typed_array::proto::Includes(EcmaRuntimeCallInfo *argv) } ArraySizeT argc = argv->GetArgsNumber(); - double from_index = 0; + double fromIndex = 0; if (argc > 1) { // 4-5. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0. JSHandle msg1 = builtins_common::GetCallArg(argv, 1); - JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); + fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber()); // 6. If n is positiveInfinity, return false. if (JSTaggedValue::Equal(thread, msg1, @@ -722,7 +720,7 @@ JSTaggedValue typed_array::proto::Includes(EcmaRuntimeCallInfo *argv) // 7. Else if n is negativeInfinity, set n to 0. if (JSTaggedValue::Equal(thread, msg1, JSHandle(thread, JSTaggedValue(-base::POSITIVE_INFINITY)))) { - from_index = 0; + fromIndex = 0; } } @@ -731,19 +729,19 @@ JSTaggedValue typed_array::proto::Includes(EcmaRuntimeCallInfo *argv) // 9. Else, // a. Let k be len + n. // b. If k < 0, set k to 0. - double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); + double from = (fromIndex >= 0) ? fromIndex : ((len + fromIndex) >= 0 ? len + fromIndex : 0); // 10. - const JSHandle search_element = builtins_common::GetCallArg(argv, 0); + const JSHandle searchElement = builtins_common::GetCallArg(argv, 0); while (from < len) { // a) - JSHandle index_handle(thread, JSTaggedValue(from)); + JSHandle indexHandle(thread, JSTaggedValue(from)); JSHandle handle = - JSHandle(thread, JSTaggedValue::ToString(thread, index_handle).GetTaggedValue()); - JSHandle element = JSTaggedValue::GetProperty(thread, this_handle, handle).GetValue(); + JSHandle(thread, JSTaggedValue::ToString(thread, indexHandle).GetTaggedValue()); + JSHandle element = JSTaggedValue::GetProperty(thread, thisHandle, handle).GetValue(); // b) - if (JSTaggedValue::SameValueZero(search_element.GetTaggedValue(), element.GetTaggedValue())) { + if (JSTaggedValue::SameValueZero(searchElement.GetTaggedValue(), element.GetTaggedValue())) { return builtins_common::GetTaggedBoolean(true); } @@ -779,14 +777,14 @@ JSTaggedValue typed_array::proto::Keys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, this_handle); + TypedArrayHelper::ValidateTypedArray(thread, thisHandle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); - JSHandle self(this_handle); + JSHandle self(thisHandle); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 4. Return CreateArrayIterator(O, "key"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::KEY)); @@ -809,27 +807,27 @@ JSTaggedValue typed_array::proto::GetLength(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, GetLength); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->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 (!this_handle->IsTypedArray()) { + if (!thisHandle->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(this_handle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); // 6. If IsDetachedBuffer(buffer) is true, return 0. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 7. Let length be the value of O’s [[ArrayLength]] internal slot. - int32_t length = TypedArrayHelper::GetArrayLength(thread, JSHandle(this_handle)); + int32_t length = TypedArrayHelper::GetArrayLength(thread, JSHandle(thisHandle)); // 8. Return length. return JSTaggedValue(length); } @@ -840,29 +838,28 @@ JSTaggedValue typed_array::proto::Map(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Map); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, this_handle); + TypedArrayHelper::ValidateTypedArray(thread, thisHandle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj(this_handle); + JSHandle thisObj(thisHandle); // 4. Let len be the value of O’s [[ArrayLength]] internal slot. - int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); + int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackfn_handle = builtins_common::GetCallArg(argv, 0); - if (!callbackfn_handle->IsCallable()) { + JSHandle callbackfnHandle = builtins_common::GetCallArg(argv, 0); + if (!callbackfnHandle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); + JSHandle thisArgHandle = builtins_common::GetCallArg(argv, 1); // es11 5. Let A be ? TypedArraySpeciesCreate(O, « len »). std::array args = {JSTaggedValue(len).GetRawData()}; - JSHandle new_arr_obj = - TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); + JSHandle newArrObj = TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, args.size(), args.data()); // 11. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -877,22 +874,22 @@ JSTaggedValue typed_array::proto::Map(EcmaRuntimeCallInfo *argv) // g. ReturnIfAbrupt(status). // h. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle map_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); for (int32_t k = 0; k < len; k++) { key.Update(JSTaggedValue(k)); - JSHandle k_value = JSTaggedValue::GetProperty(thread, this_handle, key).GetValue(); + JSHandle kValue = JSTaggedValue::GetProperty(thread, thisHandle, key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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); + 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); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, JSHandle(new_arr_obj), key, map_value, true); + JSTaggedValue::SetProperty(thread, JSHandle(newArrObj), key, mapValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 14. Return A. - return new_arr_obj.GetTaggedValue(); + return newArrObj.GetTaggedValue(); } // 22.2.3.19 @@ -932,7 +929,7 @@ JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(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. @@ -942,7 +939,7 @@ JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } - JSHandle target_obj(target); + JSHandle targetObj(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.", @@ -951,19 +948,19 @@ JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) // 5. Assert: target has a [[ViewedArrayBuffer]] internal slot. // 6. Let targetOffset be ToInteger (offset). - JSTaggedNumber t_target_offset = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 1)); + JSTaggedNumber tTargetOffset = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 1)); // 7. ReturnIfAbrupt(targetOffset). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double target_offset = t_target_offset.GetNumber(); + double targetOffset = tTargetOffset.GetNumber(); // 8. If targetOffset < 0, throw a RangeError exception. - if (target_offset < 0) { + if (targetOffset < 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 target_buffer(thread, JSTypedArray::Cast(*target_obj)->GetViewedArrayBuffer()); + JSHandle targetBuffer(thread, JSTypedArray::Cast(*targetObj)->GetViewedArrayBuffer()); // 10. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. - if (builtins::array_buffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -972,40 +969,40 @@ JSTaggedValue typed_array::proto::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 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); + 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); - JSHandle arg_array = builtins_common::GetCallArg(argv, 0); + JSHandle argArray = builtins_common::GetCallArg(argv, 0); // 22.2.3.22.1 %TypedArray%.prototype.set (array [ , offset ] ) - if (!arg_array->IsTypedArray()) { + if (!argArray->IsTypedArray()) { // 16. Let src be ToObject(array). - JSHandle src = JSTaggedValue::ToObject(thread, arg_array); + JSHandle src = JSTaggedValue::ToObject(thread, argArray); // 17. ReturnIfAbrupt(src). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 18. Let srcLength be ToLength(Get(src, "length")). - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle len_result = - JSTaggedValue::GetProperty(thread, JSHandle::Cast(src), length_key).GetValue(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lenResult = + JSTaggedValue::GetProperty(thread, JSHandle::Cast(src), lengthKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedNumber t_src_len = JSTaggedValue::ToLength(thread, len_result); + JSTaggedNumber tSrcLen = JSTaggedValue::ToLength(thread, lenResult); // 19. ReturnIfAbrupt(srcLength). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double src_len = t_src_len.GetNumber(); + double srcLen = tSrcLen.GetNumber(); // 20. If srcLength + targetOffset > targetLength, throw a RangeError exception. - if (src_len + target_offset > target_length) { + if (srcLen + targetOffset > targetLength) { 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 target_byte_index = target_offset * target_element_size + target_byte_offset; + int32_t targetByteIndex = targetOffset * targetElementSize + targetByteOffset; // 22. Let k be 0. // 23. Let limit be targetByteIndex + targetElementSize × srcLength. int32_t k = 0; - int32_t limit = target_byte_index + target_element_size * src_len; + int32_t limit = targetByteIndex + targetElementSize * srcLen; // 24. Repeat, while targetByteIndex < limit // a. Let Pk be ToString(k). // b. Let kNumber be ToNumber(Get(src, Pk)). @@ -1014,42 +1011,42 @@ JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) // e. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, kNumber). // f. Set k to k + 1. // g. Set targetByteIndex to targetByteIndex + targetElementSize. - 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(); + 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(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (builtins::array_buffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } - ContentType content_type = JSHandle::Cast(target)->GetContentType(); - if (content_type == ContentType::BIG_INT) { - k_number_handle.Update(JSTaggedValue::ToBigInt(thread, k_value)); + ContentType contentType = JSHandle::Cast(target)->GetContentType(); + if (contentType == ContentType::BIG_INT) { + kNumberHandle.Update(JSTaggedValue::ToBigInt(thread, kValue)); } else { - k_number_handle.Update(JSTaggedValue::ToNumber(thread, k_value)); + kNumberHandle.Update(JSTaggedValue::ToNumber(thread, kValue)); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, target_type, - k_number_handle, true); + builtins::array_buffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, targetType, kNumberHandle, + true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; - target_byte_index = target_byte_index + target_element_size; + targetByteIndex = targetByteIndex + targetElementSize; } // 25. Return undefined. return JSTaggedValue::Undefined(); } // 22.2.3.22.2 %TypedArray%.prototype.set(typedArray [, offset ] ) - JSHandle typed_array(arg_array); + JSHandle typedArray(argArray); // 12. Let srcBuffer be the value of typedArray’s [[ViewedArrayBuffer]] internal slot. // 13. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - JSMutableHandle src_buffer(thread, JSTypedArray::Cast(*typed_array)->GetViewedArrayBuffer()); - if (builtins::array_buffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { + JSMutableHandle srcBuffer(thread, JSTypedArray::Cast(*typedArray)->GetViewedArrayBuffer()); + if (builtins::array_buffer::IsDetachedBuffer(srcBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of typedArray is detached buffer.", JSTaggedValue::Exception()); } @@ -1058,13 +1055,13 @@ JSTaggedValue typed_array::proto::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 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); + 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); // 23. If srcLength + targetOffset > targetLength, throw a RangeError exception. - if (src_length + target_offset > target_length) { + if (srcLength + targetOffset > targetLength) { THROW_RANGE_ERROR_AND_RETURN(thread, "The sum of srcLength and targetOffset is greater than targetLength.", JSTaggedValue::Exception()); } @@ -1075,19 +1072,19 @@ JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) // c. ReturnIfAbrupt(srcBuffer). // d. Let srcByteIndex be 0. // 25. Else, let srcByteIndex be srcByteOffset. - int32_t src_byte_index; - if (JSTaggedValue::SameValue(src_buffer.GetTaggedValue(), target_buffer.GetTaggedValue())) { - src_buffer.Update(builtins::array_buffer::CloneArrayBuffer(thread, target_buffer, src_byte_offset, - env->GetArrayBufferFunction())); + int32_t srcByteIndex; + if (JSTaggedValue::SameValue(srcBuffer.GetTaggedValue(), targetBuffer.GetTaggedValue())) { + srcBuffer.Update(builtins::array_buffer::CloneArrayBuffer(thread, targetBuffer, srcByteOffset, + env->GetArrayBufferFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - src_byte_index = 0; + srcByteIndex = 0; } else { - src_byte_index = src_byte_offset; + srcByteIndex = srcByteOffset; } // 26. Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset. - int32_t target_byte_index = target_offset * target_element_size + target_byte_offset; + int32_t targetByteIndex = targetOffset * targetElementSize + targetByteOffset; // 27. Let limit be targetByteIndex + targetElementSize × srcLength. - int32_t limit = target_byte_index + target_element_size * src_length; + int32_t limit = targetByteIndex + targetElementSize * srcLength; // 28. If SameValue(srcType, targetType) is false, then // a. Repeat, while targetByteIndex < limit // i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). @@ -1095,16 +1092,15 @@ JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) // iii. Set srcByteIndex to srcByteIndex + srcElementSize. // iv. Set targetByteIndex to targetByteIndex + targetElementSize. JSMutableHandle value(thread, JSTaggedValue::Undefined()); - if (src_type != target_type) { - while (target_byte_index < limit) { - JSTaggedValue tagged_data = - builtins::array_buffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, src_type, true); - value.Update(tagged_data); - builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, target_type, value, - true); + if (srcType != targetType) { + while (targetByteIndex < limit) { + JSTaggedValue taggedData = + builtins::array_buffer::GetValueFromBuffer(thread, srcBuffer, srcByteIndex, srcType, true); + value.Update(taggedData); + builtins::array_buffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, targetType, value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - src_byte_index = src_byte_index + src_element_size; - target_byte_index = target_byte_index + target_element_size; + srcByteIndex = srcByteIndex + srcElementSize; + targetByteIndex = targetByteIndex + targetElementSize; } } else { // 29. Else, @@ -1115,19 +1111,18 @@ JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) // ii. Perform SetValueInBuffer (targetBuffer, targetByteIndex, "Uint8", value). // iii. Set srcByteIndex to srcByteIndex + 1. // iv. Set targetByteIndex to targetByteIndex + 1. - while (target_byte_index < limit) { - JSTaggedValue tagged_data = + while (targetByteIndex < limit) { + JSTaggedValue taggedData = // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue // (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - builtins::array_buffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, DataViewType::UINT8, - true); - value.Update(tagged_data); - builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, DataViewType::UINT8, - value, true); + builtins::array_buffer::GetValueFromBuffer(thread, srcBuffer, srcByteIndex, DataViewType::UINT8, true); + value.Update(taggedData); + builtins::array_buffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, DataViewType::UINT8, value, + true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - src_byte_index = src_byte_index + 1; - target_byte_index = target_byte_index + 1; + srcByteIndex = srcByteIndex + 1; + targetByteIndex = targetByteIndex + 1; } } // 30. Return undefined. @@ -1140,63 +1135,62 @@ JSTaggedValue typed_array::proto::Slice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Slice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, this_handle); + TypedArrayHelper::ValidateTypedArray(thread, thisHandle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj(this_handle); + JSHandle thisObj(thisHandle); // 4. Let len be the value of O’s [[ArrayLength]] internal slot. - int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); + int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); double k; // 5. Let relativeStart be ToInteger(start). - JSTaggedNumber t_relative_start = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); + JSTaggedNumber tRelativeStart = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double relative_start = t_relative_start.GetNumber(); + double relativeStart = tRelativeStart.GetNumber(); // 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be min(relativeStart, len). - if (relative_start < 0) { - k = relative_start + len > 0 ? relative_start + len : 0; + if (relativeStart < 0) { + k = relativeStart + len > 0 ? relativeStart + len : 0; } else { - k = relative_start < len ? relative_start : len; + k = relativeStart < len ? relativeStart : len; } // 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). - double relative_end = len; + double relativeEnd = len; JSHandle end = builtins_common::GetCallArg(argv, 1); if (!end->IsUndefined()) { - JSTaggedNumber t_relative_end = JSTaggedValue::ToInteger(thread, end); + JSTaggedNumber tRelativeEnd = JSTaggedValue::ToInteger(thread, end); // 9. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - relative_end = t_relative_end.GetNumber(); + relativeEnd = tRelativeEnd.GetNumber(); } // 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). double final = 0; - if (relative_end < 0) { - final = relative_end + len > 0 ? relative_end + len : 0; + if (relativeEnd < 0) { + final = relativeEnd + len > 0 ? relativeEnd + len : 0; } else { - final = relative_end < len ? relative_end : len; + final = relativeEnd < len ? relativeEnd : 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 new_arr_obj = - TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); + JSHandle newArrObj = TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, 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 src_name(thread, JSTypedArray::Cast(*this_obj)->GetTypedArrayName()); - DataViewType src_type = TypedArrayHelper::GetTypeFromName(thread, src_name); + JSHandle srcName(thread, JSTypedArray::Cast(*thisObj)->GetTypedArrayName()); + DataViewType srcType = TypedArrayHelper::GetTypeFromName(thread, srcName); // 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 target_name(thread, JSTypedArray::Cast(*new_arr_obj)->GetTypedArrayName()); - DataViewType target_type = TypedArrayHelper::GetTypeFromName(thread, target_name); + JSHandle targetName(thread, JSTypedArray::Cast(*newArrObj)->GetTypedArrayName()); + DataViewType targetType = TypedArrayHelper::GetTypeFromName(thread, targetName); // 21. If SameValue(srcType, targetType) is false, then // a. Let n be 0. // b. Repeat, while k < final @@ -1207,19 +1201,19 @@ JSTaggedValue typed_array::proto::Slice(EcmaRuntimeCallInfo *argv) // v. ReturnIfAbrupt(status). // vi. Increase k by 1. // vii. Increase n by 1. - JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle k_value(thread, JSTaggedValue::Undefined()); - JSMutableHandle nt_key(thread, JSTaggedValue::Undefined()); - if (src_type != target_type) { + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle kValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle ntKey(thread, JSTaggedValue::Undefined()); + if (srcType != targetType) { double n = 0; while (k < final) { - 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()); + tKey.Update(JSTaggedValue(k)); + JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); + kValue.Update(JSTaggedValue::GetProperty(thread, thisHandle, kKey).GetValue().GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - 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); + ntKey.Update(JSTaggedValue(n)); + JSHandle nKey(JSTaggedValue::ToString(thread, ntKey)); + JSTaggedValue::SetProperty(thread, JSHandle(newArrObj), nKey, kValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); n++; k++; @@ -1228,40 +1222,39 @@ JSTaggedValue typed_array::proto::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 src_buffer(thread, JSTypedArray::Cast(*this_obj)->GetViewedArrayBuffer()); - if (builtins::array_buffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { + JSHandle srcBuffer(thread, JSTypedArray::Cast(*thisObj)->GetViewedArrayBuffer()); + if (builtins::array_buffer::IsDetachedBuffer(srcBuffer.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 target_buffer(thread, JSTypedArray::Cast(*new_arr_obj)->GetViewedArrayBuffer()); + JSHandle targetBuffer(thread, JSTypedArray::Cast(*newArrObj)->GetViewedArrayBuffer()); // d. Let elementSize be the Number value of the Element Size value specified in Table 49 for srcType. - int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, src_name); + int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, srcName); // 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 src_byte_offset = TypedArrayHelper::GetByteOffset(thread, this_obj); + int32_t srcByteOffset = TypedArrayHelper::GetByteOffset(thread, thisObj); // g. Let targetByteIndex be 0. // h. Let srcByteIndex be (k × elementSize) + srcByteOffset. - int32_t src_byte_index = k * element_size + src_byte_offset; + int32_t srcByteIndex = k * elementSize + srcByteOffset; // 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 target_byte_index = 0; target_byte_index < count * element_size; - src_byte_index++, target_byte_index++) { - JSTaggedValue tagged_data = builtins::array_buffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, - DataViewType::UINT8, true); - value.Update(tagged_data); - builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, DataViewType::UINT8, - value, true); + for (int32_t targetByteIndex = 0; targetByteIndex < count * elementSize; srcByteIndex++, targetByteIndex++) { + JSTaggedValue taggedData = + builtins::array_buffer::GetValueFromBuffer(thread, srcBuffer, srcByteIndex, DataViewType::UINT8, true); + value.Update(taggedData); + builtins::array_buffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, DataViewType::UINT8, value, + true); } } // 23. Return A. - return new_arr_obj.GetTaggedValue(); + return newArrObj.GetTaggedValue(); } // 22.2.3.24 @@ -1280,47 +1273,47 @@ JSTaggedValue typed_array::proto::Sort(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Sort); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let obj be ToObject(this value). - JSHandle this_handle = builtins_common::GetThis(argv); - if (!this_handle->IsTypedArray()) { + JSHandle thisHandle = builtins_common::GetThis(argv); + if (!thisHandle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle this_obj_val(this_obj_handle); + JSHandle thisObjVal(thisObjHandle); JSHandle buffer; - buffer = JSHandle(thread, TypedArrayHelper::ValidateTypedArray(thread, this_handle)); + buffer = JSHandle(thread, TypedArrayHelper::ValidateTypedArray(thread, thisHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double len = TypedArrayHelper::GetArrayLength(thread, this_obj_handle); + double len = TypedArrayHelper::GetArrayLength(thread, thisObjHandle); - JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); + JSHandle callbackFnHandle = builtins_common::GetCallArg(argv, 0); uint32_t i = 0; while (i < len - 1) { uint32_t j = len - 1; while (j > i) { - JSHandle x_value = JSTaggedValue::GetProperty(thread, this_obj_val, j - 1).GetValue(); + JSHandle xValue = JSTaggedValue::GetProperty(thread, thisObjVal, j - 1).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle y_value = JSTaggedValue::GetProperty(thread, this_obj_val, j).GetValue(); + JSHandle yValue = JSTaggedValue::GetProperty(thread, thisObjVal, j).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t compare_result; - compare_result = TypedArrayHelper::SortCompare(thread, callback_fn_handle, buffer, x_value, y_value); + int32_t compareResult; + compareResult = TypedArrayHelper::SortCompare(thread, callbackFnHandle, buffer, xValue, yValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (compare_result > 0) { - JSTaggedValue::SetProperty(thread, this_obj_val, j - 1, y_value, true); + if (compareResult > 0) { + JSTaggedValue::SetProperty(thread, thisObjVal, j - 1, yValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, this_obj_val, j, x_value, true); + JSTaggedValue::SetProperty(thread, thisObjVal, j, xValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } j--; } i++; } - return JSTaggedValue::ToObject(thread, this_handle).GetTaggedValue(); + return JSTaggedValue::ToObject(thread, thisHandle).GetTaggedValue(); } // 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) @@ -1329,75 +1322,75 @@ JSTaggedValue typed_array::proto::Subarray(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Subarray); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } - JSHandle this_obj(this_handle); + JSHandle thisObj(thisHandle); // 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception. - if (!this_handle->IsTypedArray()) { + if (!thisHandle->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 src_length = TypedArrayHelper::GetArrayLength(thread, this_obj); + int32_t srcLength = TypedArrayHelper::GetArrayLength(thread, thisObj); // 7. Let relativeBegin be ToInteger(begin). - JSTaggedNumber t_relative_begin = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); + JSTaggedNumber tRelativeBegin = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); // 8. ReturnIfAbrupt(relativeBegin). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double relative_begin = t_relative_begin.GetNumber(); + double relativeBegin = tRelativeBegin.GetNumber(); - double begin_index; + double beginIndex; // 9. If relativeBegin < 0, let beginIndex be max((srcLength + relativeBegin), 0); else let beginIndex be // min(relativeBegin, srcLength). - if (relative_begin < 0) { - begin_index = relative_begin + src_length > 0 ? relative_begin + src_length : 0; + if (relativeBegin < 0) { + beginIndex = relativeBegin + srcLength > 0 ? relativeBegin + srcLength : 0; } else { - begin_index = relative_begin < src_length ? relative_begin : src_length; + beginIndex = relativeBegin < srcLength ? relativeBegin : srcLength; } // 10. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be ToInteger(end). - double relative_end = src_length; + double relativeEnd = srcLength; JSHandle end = builtins_common::GetCallArg(argv, 1); if (!end->IsUndefined()) { - JSTaggedNumber t_relative_end = JSTaggedValue::ToInteger(thread, end); + JSTaggedNumber tRelativeEnd = JSTaggedValue::ToInteger(thread, end); // 11. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - relative_end = t_relative_end.GetNumber(); + relativeEnd = tRelativeEnd.GetNumber(); } // 12. If relativeEnd < 0, let endIndex be max((srcLength + relativeEnd), 0); else let endIndex be // min(relativeEnd, srcLength). - double end_index; - if (relative_end < 0) { - end_index = relative_end + src_length > 0 ? relative_end + src_length : 0; + double endIndex; + if (relativeEnd < 0) { + endIndex = relativeEnd + srcLength > 0 ? relativeEnd + srcLength : 0; } else { - end_index = relative_end < src_length ? relative_end : src_length; + endIndex = relativeEnd < srcLength ? relativeEnd : srcLength; } // 13. Let new_length be max(endIndex – beginIndex, 0). - double new_length = (end_index - begin_index) > 0 ? (end_index - begin_index) : 0; + double newLength = (endIndex - beginIndex) > 0 ? (endIndex - beginIndex) : 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 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; + 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; // 21. Let argumentsList be «buffer, beginByteOffset, new_length». // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSTypedArray::Cast(*this_obj)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSTypedArray::Cast(*thisObj)->GetViewedArrayBuffer(); // 22. Return Construct(constructor, argumentsList). - std::array args = {buffer.GetRawData(), JSTaggedValue(begin_byte_offset).GetRawData(), - JSTaggedValue(new_length).GetRawData()}; - JSHandle new_arr = - TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); // 3: three args + std::array args = {buffer.GetRawData(), JSTaggedValue(beginByteOffset).GetRawData(), + JSTaggedValue(newLength).GetRawData()}; + JSHandle newArr = + TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, args.size(), args.data()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return new_arr.GetTaggedValue(); + return newArr.GetTaggedValue(); } // 22.2.3.27 @@ -1416,14 +1409,14 @@ JSTaggedValue typed_array::proto::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, this_handle); + TypedArrayHelper::ValidateTypedArray(thread, thisHandle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); - JSHandle self(this_handle); + JSHandle self(thisHandle); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 4. Return CreateArrayIterator(O, "value"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::VALUE)); @@ -1436,19 +1429,19 @@ JSTaggedValue typed_array::proto::GetToStringTag(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArrayPrototype, GetToStringTag); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. - JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle thisHandle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, return undefined. - if (!this_handle->IsECMAObject()) { + if (!thisHandle->IsECMAObject()) { return JSTaggedValue::Undefined(); } // 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. - if (!this_handle->IsTypedArray()) { + if (!thisHandle->IsTypedArray()) { return JSTaggedValue::Undefined(); } // 4. Let name be the value of O’s [[TypedArrayName]] internal slot. - JSTaggedValue name = JSHandle::Cast(this_handle)->GetTypedArrayName(); + JSTaggedValue name = JSHandle::Cast(thisHandle)->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 df38b9381dc099f1cdd1f49303058dfe28953f7e..dacf622ecb69dcd3371389e4222ce65a39a5b5f3 100644 --- a/runtime/builtins/builtins_weak_map.cpp +++ b/runtime/builtins/builtins_weak_map.cpp @@ -29,39 +29,39 @@ JSTaggedValue weak_map::WeakMapConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, WeakMapConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let WeakMap be OrdinaryCreateFromConstructor(NewTarget, "%WeakMapPrototype%", «‍[[WeakMapData]]» ). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle weak_map = JSHandle::Cast(obj); + JSHandle weakMap = JSHandle::Cast(obj); // 4.Set weakmap’s [[WeakMapData]] internal slot to a new empty List. - JSHandle linked_map = LinkedHashMap::Create(thread, true); - weak_map->SetLinkedMap(thread, linked_map); + JSHandle linkedMap = LinkedHashMap::Create(thread, true); + weakMap->SetLinkedMap(thread, linkedMap); // 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 = builtins_common::GetCallArg(argv, 0); // 8.If iter is undefined, return set if (iterable->IsUndefined() || iterable->IsNull()) { - return weak_map.GetTaggedValue(); + return weakMap.GetTaggedValue(); } if (!iterable->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "iterable is not object", JSTaggedValue::Exception()); } // Let adder be Get(weakMap, "set"). - JSHandle adder_key(factory->NewFromCanBeCompressString("set")); + JSHandle adderKey(factory->NewFromCanBeCompressString("set")); JSHandle adder = - JSObject::GetProperty(thread, JSHandle(weak_map), adder_key).GetValue(); + JSObject::GetProperty(thread, JSHandle(weakMap), adderKey).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 weak_map::WeakMapConstructor(EcmaRuntimeCallInfo *argv) JSHandle iter(JSIterator::GetIterator(thread, iterable)); // ReturnIfAbrupt(iter). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter.GetTaggedValue()); - JSHandle key_index(thread, JSTaggedValue(0)); - JSHandle value_index(thread, JSTaggedValue(1)); + JSHandle keyIndex(thread, JSTaggedValue(0)); + JSHandle valueIndex(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 weak_map::WeakMapConstructor(EcmaRuntimeCallInfo *argv) // ReturnIfAbrupt(next). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // Let nextValue be IteratorValue(next). - JSHandle next_value(JSIterator::IteratorValue(thread, next)); + JSHandle nextValue(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // If Type(nextItem) is not Object - if (!next_value->IsECMAObject()) { - JSHandle type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); + if (!nextValue->IsECMAObject()) { + JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); JSHandle record( - factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(type_error))); + factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(typeError))); JSTaggedValue ret = JSIterator::IteratorClose(thread, iter, record).GetTaggedValue(); if (LIKELY(!thread->HasPendingException())) { - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, type_error.GetTaggedValue(), ret); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, typeError.GetTaggedValue(), ret); }; return ret; } // Let k be Get(nextItem, "0"). - JSHandle key = JSObject::GetProperty(thread, next_value, key_index).GetValue(); + JSHandle key = JSObject::GetProperty(thread, nextValue, keyIndex).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, next_value, value_index).GetValue(); + JSHandle value = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); // If v is an abrupt completion, return IteratorClose(iter, v). if (UNLIKELY(thread->HasPendingException())) { return JSIterator::IteratorCloseAndReturn(thread, iter, value); @@ -111,7 +111,7 @@ JSTaggedValue weak_map::WeakMapConstructor(EcmaRuntimeCallInfo *argv) // Let status be Call(adder, weakMap, «nextValue.[[value]]»). - auto info = NewRuntimeCallInfo(thread, adder, JSHandle(weak_map), JSTaggedValue::Undefined(), 2); + auto info = NewRuntimeCallInfo(thread, adder, JSHandle(weakMap), JSTaggedValue::Undefined(), 2); info->SetCallArgs(key, value); JSTaggedValue ret = JSFunction::Call(info.Get()); // 2: key and value pair @@ -123,7 +123,7 @@ JSTaggedValue weak_map::WeakMapConstructor(EcmaRuntimeCallInfo *argv) // Let next be IteratorStep(iter). next = JSIterator::IteratorStep(thread, iter); } - return weak_map.GetTaggedValue(); + return weakMap.GetTaggedValue(); } JSTaggedValue weak_map::proto::Delete(EcmaRuntimeCallInfo *argv) @@ -131,7 +131,7 @@ JSTaggedValue weak_map::proto::Delete(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMapPrototype, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakMapData]] internal slot, throw a TypeError exception. @@ -139,13 +139,13 @@ JSTaggedValue weak_map::proto::Delete(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakMap.", JSTaggedValue::Exception()); } - JSHandle weak_map(self); + JSHandle weakMap(self); JSHandle key = builtins_common::GetCallArg(argv, 0); // 5.if Type(key) is not Object, return false. if (!key->IsHeapObject()) { return builtins_common::GetTaggedBoolean(false); } - return builtins_common::GetTaggedBoolean(JSWeakMap::Delete(thread, weak_map, key)); + return builtins_common::GetTaggedBoolean(JSWeakMap::Delete(thread, weakMap, key)); } JSTaggedValue weak_map::proto::Has(EcmaRuntimeCallInfo *argv) @@ -153,21 +153,21 @@ JSTaggedValue weak_map::proto::Has(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMapPrototype, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakMapData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakMap.", JSTaggedValue::Exception()); } - JSHandle js_weak_map(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle jsWeakMap(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = builtins_common::GetCallArg(argv, 0); // 5.if Type(key) is not Object, return false. if (!key->IsHeapObject()) { return builtins_common::GetTaggedBoolean(false); } int hash = LinkedHash::Hash(key.GetTaggedValue()); - return builtins_common::GetTaggedBoolean(js_weak_map->Has(key.GetTaggedValue(), hash)); + return builtins_common::GetTaggedBoolean(jsWeakMap->Has(key.GetTaggedValue(), hash)); } JSTaggedValue weak_map::proto::Get(EcmaRuntimeCallInfo *argv) @@ -175,20 +175,20 @@ JSTaggedValue weak_map::proto::Get(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMapPrototype, Get); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakMapData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakMap.", JSTaggedValue::Exception()); } - JSHandle js_weak_map(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle jsWeakMap(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = builtins_common::GetCallArg(argv, 0); if (!key->IsHeapObject()) { return JSTaggedValue::Undefined(); } int hash = LinkedHash::Hash(key.GetTaggedValue()); - return js_weak_map->Get(key.GetTaggedValue(), hash); + return jsWeakMap->Get(key.GetTaggedValue(), hash); } JSTaggedValue weak_map::proto::Set(EcmaRuntimeCallInfo *argv) @@ -196,7 +196,7 @@ JSTaggedValue weak_map::proto::Set(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMapPrototype, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::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 88625ae29f7797b644f25700647da5b7c2e2105a..cc3b1313c534bdbc89e49e69777bba2cd5f736fe 100644 --- a/runtime/builtins/builtins_weak_ref.cpp +++ b/runtime/builtins/builtins_weak_ref.cpp @@ -26,11 +26,11 @@ JSTaggedValue weak_ref::Constructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakRef, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new target must not be undefined", JSTaggedValue::Exception()); } // 2. If Type(target) is not Object, throw a TypeError exception. @@ -40,15 +40,15 @@ JSTaggedValue weak_ref::Constructor(EcmaRuntimeCallInfo *argv) } // 3. Let WeakRef be OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", «[[WeakRefTarget]]» ). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle weak_ref = JSHandle::Cast(obj); + JSHandle weakRef = JSHandle::Cast(obj); // 4. Perform AddToKeptObjects(target). // 5. Set weakRef.[[WeakRefTarget]] to target. - weak_ref->SetReferent(thread, target.GetTaggedValue()); + weakRef->SetReferent(thread, target.GetTaggedValue()); // Return weakRef. - return weak_ref.GetTaggedValue(); + return weakRef.GetTaggedValue(); } JSTaggedValue weak_ref::proto::Deref(EcmaRuntimeCallInfo *argv) @@ -56,15 +56,15 @@ JSTaggedValue weak_ref::proto::Deref(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakRefPrototype, Deref); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::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 weak_ref(self); + JSHandle weakRef(self); // 3. Return WeakRefDeref(weakRef). - return weak_ref->GetReferent(); + return weakRef->GetReferent(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_weak_set.cpp b/runtime/builtins/builtins_weak_set.cpp index 84c527d1488e13e677f58fcce23b2c095911a658..446aac329f6058489ef4bf73188c158f1bd58b36 100644 --- a/runtime/builtins/builtins_weak_set.cpp +++ b/runtime/builtins/builtins_weak_set.cpp @@ -29,24 +29,24 @@ JSTaggedValue weak_set::WeakSetConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, WeakSetConstructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let weakset be OrdinaryCreateFromConstructor(NewTarget, "%WeakSetPrototype%", «‍[[WeakSetData]]» ). JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle weak_set = JSHandle::Cast(obj); + JSHandle weakSet = JSHandle::Cast(obj); // 3.ReturnIfAbrupt(weakSet). // 4.WeakSet set’s [[WeakSetData]] internal slot to a new empty List. - JSHandle linked_set = LinkedHashSet::Create(thread, true); - weak_set->SetLinkedSet(thread, linked_set); + JSHandle linkedSet = LinkedHashSet::Create(thread, true); + weakSet->SetLinkedSet(thread, linkedSet); // add data into weakset from iterable // 5.If iterable is not present, let iterable be undefined. @@ -54,12 +54,12 @@ JSTaggedValue weak_set::WeakSetConstructor(EcmaRuntimeCallInfo *argv) JSHandle iterable(builtins_common::GetCallArg(argv, 0)); // 8.If iter is undefined, return weakset if (iterable->IsUndefined() || iterable->IsNull()) { - return weak_set.GetTaggedValue(); + return weakSet.GetTaggedValue(); } // Let adder be Get(weakset, "add"). - JSHandle adder_key(factory->NewFromCanBeCompressString("add")); - JSHandle weak_set_handle(weak_set); - JSHandle adder = JSObject::GetProperty(thread, weak_set_handle, adder_key).GetValue(); + JSHandle adderKey(factory->NewFromCanBeCompressString("add")); + JSHandle weakSetHandle(weakSet); + JSHandle adder = JSObject::GetProperty(thread, weakSetHandle, adderKey).GetValue(); // ReturnIfAbrupt(adder). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue()); // If IsCallable(adder) is false, throw a TypeError exception @@ -73,23 +73,23 @@ JSTaggedValue weak_set::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 value_index(thread, JSTaggedValue(1)); + JSHandle valueIndex(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 next_value(JSIterator::IteratorValue(thread, next)); + JSHandle nextValue(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next_value.GetTaggedValue()); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); - 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(); + auto info = NewRuntimeCallInfo(thread, adder, weakSet, JSTaggedValue::Undefined(), 1); + if (nextValue->IsArray(thread)) { + auto prop = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); info->SetCallArgs(prop); } else { - info->SetCallArgs(next_value); + info->SetCallArgs(nextValue); } JSTaggedValue ret = JSFunction::Call(info.Get()); @@ -102,7 +102,7 @@ JSTaggedValue weak_set::WeakSetConstructor(EcmaRuntimeCallInfo *argv) // Let next be IteratorStep(iter). next = JSIterator::IteratorStep(thread, iter); } - return weak_set.GetTaggedValue(); + return weakSet.GetTaggedValue(); } JSTaggedValue weak_set::proto::Add(EcmaRuntimeCallInfo *argv) @@ -110,7 +110,7 @@ JSTaggedValue weak_set::proto::Add(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSetPrototype, Add); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -127,10 +127,10 @@ JSTaggedValue weak_set::proto::Add(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "value is Symblol or String", JSTaggedValue::Exception()); } - JSHandle weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle weakSet(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); - JSWeakSet::Add(thread, weak_set, value); - return weak_set.GetTaggedValue(); + JSWeakSet::Add(thread, weakSet, value); + return weakSet.GetTaggedValue(); } JSTaggedValue weak_set::proto::Delete(EcmaRuntimeCallInfo *argv) @@ -138,7 +138,7 @@ JSTaggedValue weak_set::proto::Delete(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSetPrototype, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakSetData]] internal slot, throw a TypeError exception. @@ -146,12 +146,12 @@ JSTaggedValue weak_set::proto::Delete(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakSet", JSTaggedValue::Exception()); } - JSHandle weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle weakSet(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle value = builtins_common::GetCallArg(argv, 0); if (!value->IsHeapObject()) { builtins_common::GetTaggedBoolean(false); } - return builtins_common::GetTaggedBoolean(JSWeakSet::Delete(thread, weak_set, value)); + return builtins_common::GetTaggedBoolean(JSWeakSet::Delete(thread, weakSet, value)); } JSTaggedValue weak_set::proto::Has(EcmaRuntimeCallInfo *argv) @@ -159,19 +159,19 @@ JSTaggedValue weak_set::proto::Has(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSetPrototype, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakSet()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakSet", JSTaggedValue::Exception()); } - JSHandle js_weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle jsWeakSet(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle value = builtins_common::GetCallArg(argv, 0); if (!value->IsHeapObject()) { builtins_common::GetTaggedBoolean(false); } int hash = LinkedHash::Hash(value.GetTaggedValue()); - return builtins_common::GetTaggedBoolean(js_weak_set->Has(value.GetTaggedValue(), hash)); + return builtins_common::GetTaggedBoolean(jsWeakSet->Has(value.GetTaggedValue(), hash)); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/templates/builtins.rb b/runtime/builtins/templates/builtins.rb index c329ca7556e14bc28b30bc2570f13c070db9c1e4..5a6569a953d48c37f27e3a65de7aa61c962ce5d8 100644 --- a/runtime/builtins/templates/builtins.rb +++ b/runtime/builtins/templates/builtins.rb @@ -203,14 +203,14 @@ class InlinableDescr if @instruction raise if @intrinsic str += "auto inlined = - GetGraph()->CreateInst#{@instruction.opcode}(#{GetIRDstType()}, call_inst->GetPc());\n " + GetGraph()->CreateInst#{@instruction.opcode}(#{GetIRDstType()}, callInst->GetPc());\n " @args_type.each_with_index do |arg_type, idx| - str += "inlined->SetInput(#{idx}, saved_inputs_[#{idx}]);\n " + str += "inlined->SetInput(#{idx}, savedInputs_[#{idx}]);\n " end else raise if @instruction str += "auto inlined = - GetGraph()->CreateInstIntrinsic(#{GetIRDstType()}, call_inst->GetPc(), RuntimeInterface::IntrinsicId::INTRINSIC_#{@intrinsic.enum_name});\n " + GetGraph()->CreateInstIntrinsic(#{GetIRDstType()}, callInst->GetPc(), RuntimeInterface::IntrinsicId::INTRINSIC_#{@intrinsic.enum_name});\n " if @intrinsic.clear_flags.include? "require_state" str += "inlined->ReserveInputs(#{@args_type.size}); inlined->AllocateInputTypes(GetGraph()->GetAllocator(), #{@args_type.size});\n " @@ -219,21 +219,21 @@ class InlinableDescr inlined->AllocateInputTypes(GetGraph()->GetAllocator(), #{@args_type.size + 1});\n " end @args_type.each_with_index do |arg_type, idx| - str += "inlined->AppendInput(saved_inputs_[#{idx}]);\n " + str += "inlined->AppendInput(savedInputs_[#{idx}]);\n " str += "inlined->AddInputType(#{IR.get_ir_type(@intrinsic.signature.args[idx])});\n " end if !@intrinsic.clear_flags.include? "require_state" - str += "inlined->AppendInput(call_inst->GetSaveState());\n " + str += "inlined->AppendInput(callInst->GetSaveState());\n " str += "inlined->AddInputType(DataType::NO_TYPE);\n " end end str += " - call_inst->InsertAfter(inlined); - auto cast_to_any_inst = GetGraph()->CreateInstCastValueToAnyType(call_inst->GetPc(), AnyBaseType::#{@res_type}, inlined); - call_inst->ReplaceUsers(cast_to_any_inst); - inlined->InsertAfter(cast_to_any_inst); - call_inst->GetBasicBlock()->RemoveInst(call_inst); + callInst->InsertAfter(inlined); + auto castToAnyInst = GetGraph()->CreateInstCastValueToAnyType(callInst->GetPc(), AnyBaseType::#{@res_type}, inlined); + callInst->ReplaceUsers(castToAnyInst); + inlined->InsertAfter(castToAnyInst); + callInst->GetBasicBlock()->RemoveInst(callInst); " end diff --git a/runtime/builtins/templates/builtins.yaml b/runtime/builtins/templates/builtins.yaml index 82d127ef7723010dbcad80e3e37a23632dd61c75..fd3dbfe65ad7798b7ac3459ea009d11da056003b 100644 --- a/runtime/builtins/templates/builtins.yaml +++ b/runtime/builtins/templates/builtins.yaml @@ -115,11 +115,11 @@ builtins: - name: slice argc: 2 abstract_ops: - - bool IsDetachedBuffer(JSTaggedValue array_buffer) - - JSTaggedValue GetValueFromBuffer(JSThread *thread, JSHandle arr_buf, int32_t byte_index, DataViewType type, bool little_endian) - - JSTaggedValue SetValueInBuffer(JSThread *thread, JSHandle arr_buf, int32_t byte_index, DataViewType type, const JSHandle &value, bool little_endian) - - JSTaggedValue CloneArrayBuffer(JSThread *thread, const JSHandle &src_buffer, int32_t src_byte_offset, JSHandle constructor) - - JSTaggedValue AllocateArrayBuffer(JSThread *thread, const JSHandle &new_target, double byte_length) + - bool IsDetachedBuffer(JSTaggedValue arrayBuffer) + - JSTaggedValue GetValueFromBuffer(JSThread *thread, JSHandle arrBuf, int32_t byteIndex, DataViewType type, bool littleEndian) + - JSTaggedValue SetValueInBuffer(JSThread *thread, JSHandle arrBuf, int32_t byteIndex, DataViewType type, const JSHandle &value, bool littleEndian) + - JSTaggedValue CloneArrayBuffer(JSThread *thread, const JSHandle &srcBuffer, int32_t srcByteOffset, JSHandle constructor) + - JSTaggedValue AllocateArrayBuffer(JSThread *thread, const JSHandle &newTarget, double byteLength) - name: AsyncFromSyncIterator prototype: @@ -1136,8 +1136,8 @@ builtins: abstract_ops: - >- JSTaggedValue PerformPromiseThen(JSThread *thread, const JSHandle &promise, - const JSHandle &on_fulfilled, - const JSHandle &on_rejected, + const JSHandle &onFulfilled, + const JSHandle &onRejected, const JSHandle &capability) - name: Proxy @@ -1213,8 +1213,8 @@ builtins: abstract_ops: - JSTaggedValue RegExpCreate(JSThread *thread, const JSHandle &pattern, const JSHandle &flags) - JSTaggedValue FlagsBitsToString(JSThread *thread, uint8_t flags) - - JSTaggedValue RegExpExec(JSThread *thread, const JSHandle ®exp, const JSHandle &input_string, bool use_cache) - - uint32_t AdvanceStringIndex(const JSHandle &input_str, uint32_t index, bool unicode) + - JSTaggedValue RegExpExec(JSThread *thread, const JSHandle ®exp, const JSHandle &inputString, bool useCache) + - uint32_t AdvanceStringIndex(const JSHandle &inputStr, uint32_t index, bool unicode) - name: RelativeTimeFormat ctor: @@ -1428,9 +1428,9 @@ builtins: abstract_ops: - >- JSTaggedValue GetSubstitution(JSThread *thread, const JSHandle &matched, - const JSHandle &src_string, int position, - const JSHandle &capture_list, - const JSHandle &named_captures, + const JSHandle &srcString, int position, + const JSHandle &captureList, + const JSHandle &namedCaptures, const JSHandle &replacement) - name: Symbol diff --git a/runtime/builtins/templates/builtins_inline_intrinsics_decls_gen.inl.erb b/runtime/builtins/templates/builtins_inline_intrinsics_decls_gen.inl.erb index 5f7e0385e575daf8a2e62a6cd8c5188814b977ca..755975b943fb826b42109ef01347256e25f6a65a 100644 --- a/runtime/builtins/templates/builtins_inline_intrinsics_decls_gen.inl.erb +++ b/runtime/builtins/templates/builtins_inline_intrinsics_decls_gen.inl.erb @@ -13,14 +13,14 @@ * limitations under the License. */ -AnyBaseType FetchInputs(CallInst *call_inst); +AnyBaseType FetchInputs(CallInst *callInst); -void ResolveInputs(AnyBaseType type, CallInst *call_inst); +void ResolveInputs(AnyBaseType type, CallInst *callInst); % Builtins.spaces.each do |space| % space.inlinable_methods.each do |method| -bool TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(CallInst *call_inst); +bool TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(CallInst *callInst); % end % end -bool TryInlineNativeMethodGenECMASCRIPT(CallInst *call_inst); +bool TryInlineNativeMethodGenECMASCRIPT(CallInst *callInst); diff --git a/runtime/builtins/templates/builtins_inline_intrinsics_gen.inl.erb b/runtime/builtins/templates/builtins_inline_intrinsics_gen.inl.erb index fc020053fc249c6fb38706b88ced5b9a4794342a..cc7b56afdcea114f7f2b217855f5b85401191cbf 100644 --- a/runtime/builtins/templates/builtins_inline_intrinsics_gen.inl.erb +++ b/runtime/builtins/templates/builtins_inline_intrinsics_gen.inl.erb @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,26 +17,26 @@ namespace panda::compiler { -AnyBaseType InlineIntrinsics::FetchInputs(CallInst *call_inst) +AnyBaseType InlineIntrinsics::FetchInputs(CallInst *callInst) { types_.clear(); - saved_inputs_.clear(); + savedInputs_.clear(); AnyBaseType type = AnyBaseType::ECMASCRIPT_INT_TYPE; - for (auto &input : call_inst->GetInputs().SubSpan(GetGraph()->GetRuntime()->GetDynamicNumFixedArgs())) { - auto input_inst = input.GetInst(); - if (input_inst->IsSaveState()) { + for (auto &input : callInst->GetInputs().SubSpan(GetGraph()->GetRuntime()->GetDynamicNumFixedArgs())) { + auto inputInst = input.GetInst(); + if (inputInst->IsSaveState()) { continue; } - auto input_type = GetAssumedAnyType(input_inst); + auto inputType = GetAssumedAnyType(inputInst); - if (input_type != AnyBaseType::ECMASCRIPT_INT_TYPE) { - type = input_type; + if (inputType != AnyBaseType::ECMASCRIPT_INT_TYPE) { + type = inputType; } - types_.emplace_back(input_type); - saved_inputs_.emplace_back(input_inst); + types_.emplace_back(inputType); + savedInputs_.emplace_back(inputInst); } // last input is SaveState - ASSERT(GetGraph()->GetRuntime()->GetDynamicNumFixedArgs() + types_.size() + 1 == call_inst->GetInputsCount()); + ASSERT(GetGraph()->GetRuntime()->GetDynamicNumFixedArgs() + types_.size() + 1 == callInst->GetInputsCount()); if (type == AnyBaseType::UNDEFINED_TYPE) { type = AnyBaseType::ECMASCRIPT_DOUBLE_TYPE; } @@ -44,31 +44,31 @@ AnyBaseType InlineIntrinsics::FetchInputs(CallInst *call_inst) return type; } -void InlineIntrinsics::ResolveInputs(AnyBaseType type, CallInst *call_inst) +void InlineIntrinsics::ResolveInputs(AnyBaseType type, CallInst *callInst) { if (type == AnyBaseType::ECMASCRIPT_DOUBLE_TYPE) { for (size_t i = 0; i < types_.size(); i++) { if (types_[i] == AnyBaseType::ECMASCRIPT_INT_TYPE) { - auto any_check = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, call_inst->GetPc(), saved_inputs_[i], call_inst->GetSaveState(), AnyBaseType::ECMASCRIPT_INT_TYPE); - call_inst->InsertBefore(any_check); + auto anyCheck = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, callInst->GetPc(), savedInputs_[i], callInst->GetSaveState(), AnyBaseType::ECMASCRIPT_INT_TYPE); + callInst->InsertBefore(anyCheck); - auto cati = GetGraph()->CreateInstCastAnyTypeValue(call_inst->GetPc(), any_check, AnyBaseType::ECMASCRIPT_INT_TYPE); - call_inst->InsertBefore(cati); + auto cati = GetGraph()->CreateInstCastAnyTypeValue(callInst->GetPc(), anyCheck, AnyBaseType::ECMASCRIPT_INT_TYPE); + callInst->InsertBefore(cati); - auto cast = GetGraph()->CreateInstCast(AnyBaseTypeToDataType(AnyBaseType::ECMASCRIPT_DOUBLE_TYPE), call_inst->GetPc(), cati, DataType::NO_TYPE); - call_inst->InsertBefore(cast); - saved_inputs_[i] = cast; + auto cast = GetGraph()->CreateInstCast(AnyBaseTypeToDataType(AnyBaseType::ECMASCRIPT_DOUBLE_TYPE), callInst->GetPc(), cati, DataType::NO_TYPE); + callInst->InsertBefore(cast); + savedInputs_[i] = cast; } else if ((types_[i] == AnyBaseType::ECMASCRIPT_DOUBLE_TYPE) || (types_[i] == AnyBaseType::UNDEFINED_TYPE)) { - auto any_check = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, call_inst->GetPc(), saved_inputs_[i], call_inst->GetSaveState(), AnyBaseType::ECMASCRIPT_DOUBLE_TYPE); - if (saved_inputs_[i]->GetOpcode() == Opcode::AnyTypeCheck) { - any_check->SetAllowedInputType(saved_inputs_[i]->CastToAnyTypeCheck()->GetAllowedInputType()); - any_check->SetIsIntegerWasSeen(saved_inputs_[i]->CastToAnyTypeCheck()->IsIntegerWasSeen()); + auto anyCheck = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, callInst->GetPc(), savedInputs_[i], callInst->GetSaveState(), AnyBaseType::ECMASCRIPT_DOUBLE_TYPE); + if (savedInputs_[i]->GetOpcode() == Opcode::AnyTypeCheck) { + anyCheck->SetAllowedInputType(savedInputs_[i]->CastToAnyTypeCheck()->GetAllowedInputType()); + anyCheck->SetIsIntegerWasSeen(savedInputs_[i]->CastToAnyTypeCheck()->IsIntegerWasSeen()); } - call_inst->InsertBefore(any_check); + callInst->InsertBefore(anyCheck); - auto cati = GetGraph()->CreateInstCastAnyTypeValue(call_inst->GetPc(), any_check, AnyBaseType::ECMASCRIPT_DOUBLE_TYPE); - call_inst->InsertBefore(cati); - saved_inputs_[i] = cati; + auto cati = GetGraph()->CreateInstCastAnyTypeValue(callInst->GetPc(), anyCheck, AnyBaseType::ECMASCRIPT_DOUBLE_TYPE); + callInst->InsertBefore(cati); + savedInputs_[i] = cati; } else { UNREACHABLE(); } @@ -76,12 +76,12 @@ void InlineIntrinsics::ResolveInputs(AnyBaseType type, CallInst *call_inst) } else if (type == AnyBaseType::ECMASCRIPT_INT_TYPE) { for (size_t i = 0; i < types_.size(); i++) { if ((types_[i] == AnyBaseType::ECMASCRIPT_INT_TYPE) || (types_[i] == AnyBaseType::UNDEFINED_TYPE)) { - auto any_check = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, call_inst->GetPc(), saved_inputs_[i], call_inst->GetSaveState(), AnyBaseType::ECMASCRIPT_INT_TYPE); - call_inst->InsertBefore(any_check); + auto anyCheck = GetGraph()->CreateInstAnyTypeCheck(DataType::ANY, callInst->GetPc(), savedInputs_[i], callInst->GetSaveState(), AnyBaseType::ECMASCRIPT_INT_TYPE); + callInst->InsertBefore(anyCheck); - auto cati = GetGraph()->CreateInstCastAnyTypeValue(call_inst->GetPc(), any_check, AnyBaseType::ECMASCRIPT_INT_TYPE); - call_inst->InsertBefore(cati); - saved_inputs_[i] = cati; + auto cati = GetGraph()->CreateInstCastAnyTypeValue(callInst->GetPc(), anyCheck, AnyBaseType::ECMASCRIPT_INT_TYPE); + callInst->InsertBefore(cati); + savedInputs_[i] = cati; } else { UNREACHABLE(); } @@ -91,10 +91,10 @@ void InlineIntrinsics::ResolveInputs(AnyBaseType type, CallInst *call_inst) % Builtins.spaces.each do |space| % space.inlinable_methods.each do |method| -bool InlineIntrinsics::TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(CallInst *call_inst) +bool InlineIntrinsics::TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(CallInst *callInst) { % raise "Only trivial overloads are currently supported" if !method.trivial_inline_overloads? - [[maybe_unused]] auto resolved_type = FetchInputs(call_inst); + [[maybe_unused]] auto resolvedType = FetchInputs(callInst); % if method.inline_info[0].args_type.size != 0 if (types_.size() != <%= method.inline_info[0].args_type.size %>) { @@ -102,17 +102,17 @@ bool InlineIntrinsics::TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(Cal } % if method.get_integer_overload - if (resolved_type == AnyBaseType::ECMASCRIPT_INT_TYPE) { - ecmascript::EcmaInlining::BuildGuard(call_inst, call_inst->GetCallMethod()); - ResolveInputs(AnyBaseType::ECMASCRIPT_INT_TYPE, call_inst); + if (resolvedType == AnyBaseType::ECMASCRIPT_INT_TYPE) { + ecmascript::EcmaInlining::BuildGuard(callInst, callInst->GetCallMethod()); + ResolveInputs(AnyBaseType::ECMASCRIPT_INT_TYPE, callInst); <%= method.get_integer_overload.do_inline %> return true; } % end % if method.get_double_overload - if ((resolved_type == AnyBaseType::ECMASCRIPT_DOUBLE_TYPE) || (resolved_type == AnyBaseType::ECMASCRIPT_INT_TYPE)) { - ecmascript::EcmaInlining::BuildGuard(call_inst, call_inst->GetCallMethod()); - ResolveInputs(AnyBaseType::ECMASCRIPT_DOUBLE_TYPE, call_inst); + if ((resolvedType == AnyBaseType::ECMASCRIPT_DOUBLE_TYPE) || (resolvedType == AnyBaseType::ECMASCRIPT_INT_TYPE)) { + ecmascript::EcmaInlining::BuildGuard(callInst, callInst->GetCallMethod()); + ResolveInputs(AnyBaseType::ECMASCRIPT_DOUBLE_TYPE, callInst); <%= method.get_double_overload.do_inline %> return true; } @@ -122,7 +122,7 @@ bool InlineIntrinsics::TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(Cal if (!types_.empty()) { return false; } - ecmascript::EcmaInlining::BuildGuard(call_inst, call_inst->GetCallMethod()); + ecmascript::EcmaInlining::BuildGuard(callInst, callInst->GetCallMethod()); <%= method.get_zero_overload.do_inline -%> return true; % end @@ -131,14 +131,14 @@ bool InlineIntrinsics::TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(Cal % end % end -bool InlineIntrinsics::TryInlineNativeMethodGenECMASCRIPT(CallInst *call_inst) +bool InlineIntrinsics::TryInlineNativeMethodGenECMASCRIPT(CallInst *callInst) { - ASSERT(call_inst->GetCallMethod() != nullptr); - switch(GetGraph()->GetRuntime()->ResolveInlinableNativeMethod(call_inst->GetCallMethod())) { + ASSERT(callInst->GetCallMethod() != nullptr); + switch(GetGraph()->GetRuntime()->ResolveInlinableNativeMethod(callInst->GetCallMethod())) { % Builtins.spaces.each do |space| % space.inlinable_methods.each do |method| case panda::ecmascript::EcmaRuntimeCallerId::BUILTINS_ID_<%= space.name %>_<%= method.gen_cpp_id %>: - return TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(call_inst); + return TryInline<%= space.name %><%= method.gen_cpp_id %>Gen(callInst); % end % end default: diff --git a/runtime/class_info_extractor.cpp b/runtime/class_info_extractor.cpp index 7a6b01338d384e7f5e59f66c7fb84313b21b1802..e87b7eeee0d3970cf77d162922be41b56431c37e 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 handle_scope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t literal_buffer_length = literal->GetLength(); + uint32_t literalBufferLength = literal->GetLength(); // non static properties number is hidden in the last index of Literal buffer - uint32_t non_static_num = literal->Get(thread, literal_buffer_length - 1).GetInt(); + uint32_t nonStaticNum = literal->Get(thread, literalBufferLength - 1).GetInt(); // Reserve sufficient length to prevent frequent creation. - 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); + JSHandle nonStaticKeys = factory->NewTaggedArray(nonStaticNum + NON_STATIC_RESERVED_LENGTH); + JSHandle nonStaticProperties = factory->NewTaggedArray(nonStaticNum + NON_STATIC_RESERVED_LENGTH); - non_static_keys->Set(thread, CONSTRUCTOR_INDEX, global_const->GetConstructorString()); + nonStaticKeys->Set(thread, CONSTRUCTOR_INDEX, globalConst->GetConstructorString()); - JSHandle non_static_elements = factory->EmptyArray(); + JSHandle nonStaticElements = factory->EmptyArray(); - if (non_static_num != 0U) { - ExtractContentsDetail non_static_detail {0, non_static_num * 2, NON_STATIC_RESERVED_LENGTH, nullptr}; + if (nonStaticNum != 0U) { + ExtractContentsDetail nonStaticDetail {0, nonStaticNum * 2, NON_STATIC_RESERVED_LENGTH, nullptr}; - if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, non_static_detail, non_static_keys, - non_static_properties, non_static_elements))) { + if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, nonStaticDetail, nonStaticKeys, + nonStaticProperties, nonStaticElements))) { extractor->SetNonStaticWithElements(); - extractor->SetNonStaticElements(thread, non_static_elements); + extractor->SetNonStaticElements(thread, nonStaticElements); } } - extractor->SetNonStaticKeys(thread, non_static_keys); - extractor->SetNonStaticProperties(thread, non_static_properties); + extractor->SetNonStaticKeys(thread, nonStaticKeys); + extractor->SetNonStaticProperties(thread, nonStaticProperties); - JSHandle prototype_h_class = CreatePrototypeHClass(thread, non_static_keys, non_static_properties); - extractor->SetPrototypeHClass(thread, prototype_h_class); + JSHandle prototypeHClass = CreatePrototypeHClass(thread, nonStaticKeys, nonStaticProperties); + extractor->SetPrototypeHClass(thread, prototypeHClass); - uint32_t static_num = (literal_buffer_length - 1) / 2 - non_static_num; + uint32_t staticNum = (literalBufferLength - 1) / 2 - nonStaticNum; // Reserve sufficient length to prevent frequent creation. - JSHandle static_keys = factory->NewTaggedArray(static_num + STATIC_RESERVED_LENGTH); - JSHandle static_properties = factory->NewTaggedArray(static_num + STATIC_RESERVED_LENGTH); + JSHandle staticKeys = factory->NewTaggedArray(staticNum + STATIC_RESERVED_LENGTH); + JSHandle staticProperties = factory->NewTaggedArray(staticNum + STATIC_RESERVED_LENGTH); - 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()); + staticKeys->Set(thread, LENGTH_INDEX, globalConst->GetLengthString()); + staticKeys->Set(thread, NAME_INDEX, globalConst->GetNameString()); + staticKeys->Set(thread, PROTOTYPE_INDEX, globalConst->GetPrototypeString()); - JSHandle static_elements = factory->EmptyArray(); + JSHandle staticElements = factory->EmptyArray(); - if (static_num != 0U) { - ExtractContentsDetail static_detail {non_static_num * 2, literal_buffer_length - 1, STATIC_RESERVED_LENGTH, - extractor->GetConstructorMethod()}; + if (staticNum != 0U) { + ExtractContentsDetail staticDetail {nonStaticNum * 2, literalBufferLength - 1, STATIC_RESERVED_LENGTH, + extractor->GetConstructorMethod()}; - if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, static_detail, static_keys, static_properties, - static_elements))) { + if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, staticDetail, staticKeys, staticProperties, + staticElements))) { extractor->SetStaticWithElements(); - extractor->SetStaticElements(thread, static_elements); + extractor->SetStaticElements(thread, staticElements); } } else { // without static properties, set class name - PandaString cls_name = extractor->GetConstructorMethod()->ParseFunctionName(); - JSHandle cls_name_handle = factory->NewFromString(cls_name); - static_properties->Set(thread, NAME_INDEX, cls_name_handle); + PandaString clsName = extractor->GetConstructorMethod()->ParseFunctionName(); + JSHandle clsNameHandle = factory->NewFromString(clsName); + staticProperties->Set(thread, NAME_INDEX, clsNameHandle); } // set prototype internal accessor - JSHandle prototype_accessor = global_const->GetHandledFunctionPrototypeAccessor(); - static_properties->Set(thread, PROTOTYPE_INDEX, prototype_accessor); + JSHandle prototypeAccessor = globalConst->GetHandledFunctionPrototypeAccessor(); + staticProperties->Set(thread, PROTOTYPE_INDEX, prototypeAccessor); - extractor->SetStaticKeys(thread, static_keys); - extractor->SetStaticProperties(thread, static_properties); + extractor->SetStaticKeys(thread, staticKeys); + extractor->SetStaticProperties(thread, staticProperties); - JSHandle ctor_h_class = CreateConstructorHClass(thread, static_keys, static_properties); - extractor->SetConstructorHClass(thread, ctor_h_class); + JSHandle ctorHClass = CreateConstructorHClass(thread, staticKeys, staticProperties); + extractor->SetConstructorHClass(thread, ctorHClass); } bool ClassInfoExtractor::ExtractAndReturnWhetherWithElements(JSThread *thread, const JSHandle &literal, @@ -100,70 +100,70 @@ bool ClassInfoExtractor::ExtractAndReturnWhetherWithElements(JSThread *thread, c JSHandle &properties, JSHandle &elements) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); ASSERT(keys->GetLength() == properties->GetLength() && elements->GetLength() == 0); - 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; + uint32_t pos = detail.fillStartLoc; + bool withElemenstFlag = false; + bool isStaticFlag = detail.ctorMethod != 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; continue; } // front-end can do better: write index in class literal directly. - 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; + 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; continue; } } - keys->Set(thread, pos, first_value); - properties->Set(thread, pos, second_value); + keys->Set(thread, pos, firstValue); + properties->Set(thread, pos, secondValue); pos++; } - if (is_static_flag) { - if (LIKELY(!keys_has_name_flag)) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + if (isStaticFlag) { + if (LIKELY(!keysHasNameFlag)) { + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - PandaString cls_name = detail.ctor_method->ParseFunctionName(); - JSHandle cls_name_handle = factory->NewFromString(cls_name); - properties->Set(thread, NAME_INDEX, cls_name_handle); + PandaString clsName = detail.ctorMethod->ParseFunctionName(); + JSHandle clsNameHandle = factory->NewFromString(clsName); + properties->Set(thread, NAME_INDEX, clsNameHandle); } else { // class has static name property, reserved length bigger 1 than actual, need trim - uint32_t trim_one_length = keys->GetLength() - 1; - keys->Trim(thread, trim_one_length); - properties->Trim(thread, trim_one_length); + uint32_t trimOneLength = keys->GetLength() - 1; + keys->Trim(thread, trimOneLength); + properties->Trim(thread, trimOneLength); } } - if (UNLIKELY(with_elemenst_flag)) { + if (UNLIKELY(withElemenstFlag)) { ASSERT(pos + elements->GetLength() / 2 == properties->GetLength()); // 2: half keys->Trim(thread, pos); properties->Trim(thread, pos); } - return with_elemenst_flag; + return withElemenstFlag; } JSHandle ClassInfoExtractor::CreatePrototypeHClass(JSThread *thread, JSHandle &keys, @@ -251,7 +251,7 @@ JSHandle ClassInfoExtractor::CreateConstructorHClass(JSThread *thread, layout->AddKey(thread, index, key.GetTaggedValue(), attributes); } - hclass = factory->CreateDynClass(factory->hclass_class_, JSType::JS_FUNCTION, + hclass = factory->CreateDynClass(factory->hclassClass_, JSType::JS_FUNCTION, HClass::IS_CALLABLE, length); // Not need set proto here hclass->SetLayout(thread, layout); @@ -274,69 +274,69 @@ JSHandle ClassHelper::DefineClassTemplate(JSThread *thread, JSHandle { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle prototype_h_class(thread, extractor->GetPrototypeHClass()); - JSHandle prototype = factory->NewJSObject(prototype_h_class); + JSHandle prototypeHClass(thread, extractor->GetPrototypeHClass()); + JSHandle prototype = factory->NewJSObject(prototypeHClass); - JSHandle constructor_h_class(thread, extractor->GetConstructorHClass()); + JSHandle constructorHClass(thread, extractor->GetConstructorHClass()); JSHandle constructor = factory->NewJSFunctionByDynClass( - extractor->GetConstructorMethod(), constructor_h_class, FunctionKind::CLASS_CONSTRUCTOR); + extractor->GetConstructorMethod(), constructorHClass, FunctionKind::CLASS_CONSTRUCTOR); // non-static - 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); + 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); } - prototype->SetPropertyInlinedProps(thread, index, prop_value.GetTaggedValue()); + prototype->SetPropertyInlinedProps(thread, index, propValue.GetTaggedValue()); } } else { - JSHandle non_static_keys(thread, extractor->GetNonStaticKeys()); - JSHandle dict = BuildDictionaryPropeties( - thread, prototype, non_static_keys, non_static_properties, ClassPropertyType::NON_STATIC, constantpool); + JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys()); + JSHandle dict = BuildDictionaryPropeties(thread, prototype, nonStaticKeys, nonStaticProperties, + ClassPropertyType::NON_STATIC, constantpool); prototype->SetProperties(thread, dict); } // non-static elements if (UNLIKELY(extractor->IsNonStaticWithElements())) { - JSHandle non_static_elements(thread, extractor->GetNonStaticElements()); - ClassHelper::HandleElementsProperties(thread, prototype, non_static_elements, constantpool); + JSHandle nonStaticElements(thread, extractor->GetNonStaticElements()); + ClassHelper::HandleElementsProperties(thread, prototype, nonStaticElements, constantpool); } // static - 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 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::Cast(constructor)->SetPropertyInlinedProps(thread, index, prop_value.GetTaggedValue()); + JSHandle::Cast(constructor)->SetPropertyInlinedProps(thread, index, propValue.GetTaggedValue()); } } else { - JSHandle static_keys(thread, extractor->GetStaticKeys()); + JSHandle staticKeys(thread, extractor->GetStaticKeys()); JSHandle dict = - BuildDictionaryPropeties(thread, JSHandle(constructor), static_keys, static_properties, + BuildDictionaryPropeties(thread, JSHandle(constructor), staticKeys, staticProperties, ClassPropertyType::STATIC, constantpool); constructor->SetProperties(thread, dict); } // static elements if (UNLIKELY(extractor->IsStaticWithElements())) { - JSHandle static_elements(thread, extractor->GetStaticElements()); - ClassHelper::HandleElementsProperties(thread, JSHandle(constructor), static_elements, constantpool); + JSHandle staticElements(thread, extractor->GetStaticElements()); + ClassHelper::HandleElementsProperties(thread, JSHandle(constructor), staticElements, constantpool); } constructor->SetProtoOrDynClass(thread, prototype); @@ -356,8 +356,8 @@ JSHandle ClassHelper::BuildDictionaryPropeties(JSThread *thread, JSMutableHandle dict(thread, NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(length))); - JSMutableHandle prop_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle prop_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle propKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle propValue(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 } - 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); + 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); } - JSHandle new_dict = NameDictionary::PutIfAbsent(thread, dict, prop_key, prop_value, attributes); - dict.Update(new_dict); + JSHandle newDict = NameDictionary::PutIfAbsent(thread, dict, propKey, propValue, attributes); + dict.Update(newDict); } 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 elements_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle elements_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle elementsKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle elementsValue(thread, JSTaggedValue::Undefined()); for (uint32_t index = 0; index < elements->GetLength(); index += 2) { // 2: key-value pair - elements_key.Update(elements->Get(index)); - elements_value.Update(elements->Get(index + 1)); + elementsKey.Update(elements->Get(index)); + elementsValue.Update(elements->Get(index + 1)); // class property attribute is not default, will transition to dictionary directly. - JSObject::DefinePropertyByLiteral(thread, object, elements_key, elements_value, true); + JSObject::DefinePropertyByLiteral(thread, object, elementsKey, elementsValue, true); - if (elements_value->IsJSFunction()) { - JSHandle elements_func = JSHandle::Cast(elements_value); - elements_func->SetHomeObject(thread, object); - elements_func->SetConstantPool(thread, constantpool); + if (elementsValue->IsJSFunction()) { + JSHandle elementsFunc = JSHandle::Cast(elementsValue); + elementsFunc->SetHomeObject(thread, object); + elementsFunc->SetConstantPool(thread, constantpool); } } } diff --git a/runtime/class_info_extractor.h b/runtime/class_info_extractor.h index d18cbcabf80c1b3decd0aba2bd5c181b64169cac..537c04b0a6048a2aca398fba240039871db9756f 100644 --- a/runtime/class_info_extractor.h +++ b/runtime/class_info_extractor.h @@ -34,10 +34,10 @@ public: static constexpr uint8_t PROTOTYPE_INDEX = 2; struct ExtractContentsDetail { - uint32_t extract_begin; - uint32_t extract_end; - uint8_t fill_start_loc; - JSMethod *ctor_method; + uint32_t extractBegin; + uint32_t extractEnd; + uint8_t fillStartLoc; + JSMethod *ctorMethod; }; CAST_CHECK(ClassInfoExtractor, IsClassInfoExtractor); @@ -56,15 +56,15 @@ public: inline void SetNonStaticWithElements() { uint8_t bits = GetBitField(); - uint8_t new_val = NonStaticWithElementsBit::Update(bits, true); - SetBitField(new_val); + uint8_t newVal = NonStaticWithElementsBit::Update(bits, true); + SetBitField(newVal); } inline void SetStaticWithElements() { uint8_t bits = GetBitField(); - uint8_t new_val = StaticWithElementsBit::Update(bits, true); - SetBitField(new_val); + uint8_t newVal = StaticWithElementsBit::Update(bits, true); + SetBitField(newVal); } inline bool IsNonStaticWithElements() const diff --git a/runtime/class_linker/panda_file_translator.cpp b/runtime/class_linker/panda_file_translator.cpp index 5213892d830e2daa7d111053eeb7e92847de19f7..77090addf75c4f523e1ee6619a0c8e1d6167f8cd 100644 --- a/runtime/class_linker/panda_file_translator.cpp +++ b/runtime/class_linker/panda_file_translator.cpp @@ -41,15 +41,15 @@ namespace panda::ecmascript { PandaFileTranslator::PandaFileTranslator(EcmaVM *vm) - : ecma_vm_(vm), factory_(vm->GetFactory()), thread_(vm->GetJSThread()) + : ecmaVm_(vm), factory_(vm->GetFactory()), thread_(vm->GetJSThread()) { } JSHandle PandaFileTranslator::TranslatePandaFile(EcmaVM *vm, const panda_file::File &pf, - const PandaString &method_name) + const PandaString &methodName) { PandaFileTranslator translator(vm); - translator.TranslateClasses(pf, method_name); + translator.TranslateClasses(pf, methodName); auto result = translator.GenerateProgram(pf); return JSHandle(translator.thread_, result); } @@ -76,67 +76,67 @@ const JSMethod *PandaFileTranslator::FindMethods(uint32_t offset) const return nullptr; } -void PandaFileTranslator::TranslateClasses(const panda_file::File &pf, const PandaString &method_name) +void PandaFileTranslator::TranslateClasses(const panda_file::File &pf, const PandaString &methodName) { - Span class_indexes = pf.GetClasses(); + Span classIndexes = pf.GetClasses(); methods_ = MakePandaUnique>(); - panda_file::File::StringData sd = {static_cast(method_name.size()), - reinterpret_cast(method_name.c_str())}; + panda_file::File::StringData sd = {static_cast(methodName.size()), + reinterpret_cast(methodName.c_str())}; - auto aot_manager = Runtime::GetCurrent()->GetClassLinker()->GetAotManager(); + auto aotManager = Runtime::GetCurrent()->GetClassLinker()->GetAotManager(); auto filename = os::GetAbsolutePath(pf.GetFilename()); - auto aot_pfile = aot_manager->FindPandaFile(filename); + auto aotPfile = aotManager->FindPandaFile(filename); - for (const uint32_t index : class_indexes) { - panda_file::File::EntityId class_id(index); - if (pf.IsExternal(class_id)) { + for (const uint32_t index : classIndexes) { + panda_file::File::EntityId classId(index); + if (pf.IsExternal(classId)) { continue; } - panda_file::ClassDataAccessor cda(pf, class_id); + panda_file::ClassDataAccessor cda(pf, classId); auto descriptor = cda.GetDescriptor(); - compiler::AotClass aot_class = - (aot_pfile != nullptr) ? aot_pfile->GetClass(class_id.GetOffset()) : compiler::AotClass::Invalid(); + compiler::AotClass aotClass = + (aotPfile != nullptr) ? aotPfile->GetClass(classId.GetOffset()) : compiler::AotClass::Invalid(); - cda.EnumerateMethods([this, &aot_class, &sd, &pf, &descriptor](panda_file::MethodDataAccessor &mda) { - TranslateMethod(aot_class, sd, pf, descriptor, mda); + cda.EnumerateMethods([this, &aotClass, &sd, &pf, &descriptor](panda_file::MethodDataAccessor &mda) { + TranslateMethod(aotClass, sd, pf, descriptor, mda); }); } } -void PandaFileTranslator::TranslateMethod(const compiler::AotClass &aot_class, const panda_file::File::StringData &sd, +void PandaFileTranslator::TranslateMethod(const compiler::AotClass &aotClass, const panda_file::File::StringData &sd, const panda_file::File &pf, const uint8_t *descriptor, panda_file::MethodDataAccessor &mda) { - auto code_id = mda.GetCodeId(); - ASSERT(code_id.has_value()); + auto codeId = mda.GetCodeId(); + ASSERT(codeId.has_value()); - panda_file::CodeDataAccessor code_data_accessor(pf, code_id.value()); - uint32_t code_size = code_data_accessor.GetCodeSize(); + panda_file::CodeDataAccessor codeDataAccessor(pf, codeId.value()); + uint32_t codeSize = codeDataAccessor.GetCodeSize(); - if (main_method_index_ == 0 && pf.GetStringData(mda.GetNameId()) == sd) { - main_method_index_ = mda.GetMethodId().GetOffset(); + if (mainMethodIndex_ == 0 && pf.GetStringData(mda.GetNameId()) == sd) { + mainMethodIndex_ = mda.GetMethodId().GetOffset(); } panda_file::ProtoDataAccessor pda(pf, mda.GetProtoId()); - auto *class_linker = Runtime::GetCurrent()->GetClassLinker(); - auto *extension = class_linker->GetExtension(panda::panda_file::SourceLang::ECMASCRIPT); + auto *classLinker = Runtime::GetCurrent()->GetClassLinker(); + auto *extension = classLinker->GetExtension(panda::panda_file::SourceLang::ECMASCRIPT); auto klass = extension->GetClass(descriptor); if (klass == nullptr) { // Case for ark_aot. This is workaround. - klass = class_linker->LoadClass(&pf, descriptor, panda::panda_file::SourceLang::ECMASCRIPT); + klass = classLinker->LoadClass(&pf, descriptor, panda::panda_file::SourceLang::ECMASCRIPT); } ASSERT(klass != nullptr); // Very important assert. - methods_->emplace_back(klass, &pf, mda.GetMethodId(), code_data_accessor.GetCodeId(), mda.GetAccessFlags(), - code_data_accessor.GetNumArgs(), reinterpret_cast(pda.GetShorty().Data())); + methods_->emplace_back(klass, &pf, mda.GetMethodId(), codeDataAccessor.GetCodeId(), mda.GetAccessFlags(), + codeDataAccessor.GetNumArgs(), reinterpret_cast(pda.GetShorty().Data())); JSMethod *method = &methods_->back(); - if (aot_class.IsValid()) { - auto entry = aot_class.FindMethodCodeEntry(methods_->size() - 1); + if (aotClass.IsValid()) { + auto entry = aotClass.FindMethodCodeEntry(methods_->size() - 1); if (entry != nullptr) { method->SetCompiledEntryPoint(entry); } else { @@ -148,130 +148,127 @@ void PandaFileTranslator::TranslateMethod(const compiler::AotClass &aot_class, c method->SetCallTypeFromAnnotation(); method->InitProfileVector(); - const uint8_t *insns = code_data_accessor.GetInstructions(); + const uint8_t *insns = codeDataAccessor.GetInstructions(); - if (translated_code_.find(insns) == translated_code_.end()) { - translated_code_.insert(insns); - if (pf.GetHeader()->quickened_flag != 0U) { - TranslateBytecode(code_size, insns, pf, method); + if (translatedCode_.find(insns) == translatedCode_.end()) { + translatedCode_.insert(insns); + if (pf.GetHeader()->quickenedFlag != 0U) { + TranslateBytecode(codeSize, insns, pf, method); } else { - TranslateBytecode(code_size, insns, pf, method); + TranslateBytecode(codeSize, insns, pf, method); } } } Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) { - EcmaHandleScope handle_scope(thread_); + EcmaHandleScope handleScope(thread_); JSHandle program = factory_->NewProgram(); JSHandle location = factory_->NewFromStdStringUnCheck(pf.GetFilename(), true, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); // +1 for program - JSHandle constpool = factory_->NewConstantPool(constpool_index_ + 1); + JSHandle constpool = factory_->NewConstantPool(constpoolIndex_ + 1); program->SetConstantPool(thread_, constpool.GetTaggedValue()); program->SetLocation(thread_, location.GetTaggedValue()); - JSHandle env = ecma_vm_->GetGlobalEnv(); + JSHandle env = ecmaVm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetFunctionClassWithProto()); - 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()); + JSHandle normalDynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); + JSHandle asyncDynclass = JSHandle::Cast(env->GetAsyncFunctionClass()); + JSHandle generatorDynclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); + JSHandle asyncgeneratorDynclass = JSHandle::Cast(env->GetAsyncGeneratorFunctionClass()); - for (const auto &it : constpool_map_) { + for (const auto &it : constpoolMap_) { ConstPoolValue value(it.second); if (value.GetConstpoolType() == ConstPoolType::STRING) { panda_file::File::EntityId id(it.first); - 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); + auto foundStr = pf.GetStringData(id); + auto string = factory_->GetRawStringFromStringTable(foundStr.data, foundStr.utf16Length, foundStr.isAscii, + panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); if (string == nullptr) { LOG(FATAL, ECMASCRIPT) << "Not enough memory"; } constpool->Set(thread_, value.GetConstpoolIndex(), JSTaggedValue(string)); } else if (value.GetConstpoolType() == ConstPoolType::BASE_FUNCTION) { - ASSERT(main_method_index_ != it.first); + ASSERT(mainMethodIndex_ != it.first); panda_file::File::EntityId id(it.first); auto method = const_cast(FindMethods(it.first)); ASSERT(method != nullptr); - JSHandle js_func = factory_->NewJSFunctionByDynClass( + JSHandle jsFunc = factory_->NewJSFunctionByDynClass( method, dynclass, FunctionKind::BASE_CONSTRUCTOR, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); - constpool->Set(thread_, value.GetConstpoolIndex(), js_func.GetTaggedValue()); - js_func->SetConstantPool(thread_, constpool.GetTaggedValue()); + constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); + jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::NC_FUNCTION) { - ASSERT(main_method_index_ != it.first); + ASSERT(mainMethodIndex_ != 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, 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()); + JSHandle jsFunc = factory_->NewJSFunctionByDynClass( + method, normalDynclass, FunctionKind::NORMAL_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); + jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::GENERATOR_FUNCTION) { - ASSERT(main_method_index_ != it.first); + ASSERT(mainMethodIndex_ != 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, generator_dynclass, FunctionKind::GENERATOR_FUNCTION, + JSHandle jsFunc = + factory_->NewJSFunctionByDynClass(method, generatorDynclass, 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 // is the initial value of the generator function's "prototype" property. - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle initial_generator_func_prototype = factory_->NewJSObjectByConstructor( - JSHandle(obj_fun), obj_fun, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); - JSObject::SetPrototype(thread_, initial_generator_func_prototype, env->GetGeneratorPrototype()); - js_func->SetProtoOrDynClass(thread_, initial_generator_func_prototype); - - constpool->Set(thread_, value.GetConstpoolIndex(), js_func.GetTaggedValue()); - js_func->SetConstantPool(thread_, constpool.GetTaggedValue()); + JSHandle objFun = env->GetObjectFunction(); + JSHandle initialGeneratorFuncPrototype = factory_->NewJSObjectByConstructor( + JSHandle(objFun), objFun, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, env->GetGeneratorPrototype()); + jsFunc->SetProtoOrDynClass(thread_, initialGeneratorFuncPrototype); + + constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); + jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::ASYNC_FUNCTION) { - ASSERT(main_method_index_ != it.first); + ASSERT(mainMethodIndex_ != 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, 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()); + JSHandle jsFunc = factory_->NewJSFunctionByDynClass( + method, asyncDynclass, FunctionKind::ASYNC_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); + jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::ASYNC_GENERATOR_FUNCTION) { - ASSERT(main_method_index_ != it.first); + ASSERT(mainMethodIndex_ != 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, asyncgenerator_dynclass, FunctionKind::ASYNC_GENERATOR_FUNCTION, + JSHandle jsFunc = factory_->NewJSFunctionByDynClass( + method, asyncgeneratorDynclass, 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()); + constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); + jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::CLASS_FUNCTION) { - ASSERT(main_method_index_ != it.first); + ASSERT(mainMethodIndex_ != it.first); panda_file::File::EntityId id(it.first); auto method = const_cast(FindMethods(it.first)); ASSERT(method != nullptr); - JSHandle class_info_extractor = factory_->NewClassInfoExtractor(method); - constpool->Set(thread_, value.GetConstpoolIndex(), class_info_extractor.GetTaggedValue()); + JSHandle classInfoExtractor = factory_->NewClassInfoExtractor(method); + constpool->Set(thread_, value.GetConstpoolIndex(), classInfoExtractor.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::METHOD) { - ASSERT(main_method_index_ != it.first); + ASSERT(mainMethodIndex_ != 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, 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()); + JSHandle jsFunc = factory_->NewJSFunctionByDynClass( + method, normalDynclass, FunctionKind::NORMAL_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); + jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::OBJECT_LITERAL) { size_t index = it.first; JSMutableHandle elements(thread_, JSTaggedValue::Undefined()); @@ -281,15 +278,15 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) thread_, properties, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); JSMutableHandle key(thread_, JSTaggedValue::Undefined()); - 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. + 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. key.Update(elements->Get(i)); if (key->IsHole()) { break; } - value_handle.Update(elements->Get(i + 1)); - JSObject::DefinePropertyByLiteral(thread_, obj, key, value_handle); + valueHandle.Update(elements->Get(i + 1)); + JSObject::DefinePropertyByLiteral(thread_, obj, key, valueHandle); } constpool->Set(thread_, value.GetConstpoolIndex(), obj.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::ARRAY_LITERAL) { @@ -310,15 +307,15 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) } } { - auto method = const_cast(FindMethods(main_method_index_)); + auto method = const_cast(FindMethods(mainMethodIndex_)); ASSERT(method != nullptr); - JSHandle main_func = factory_->NewJSFunctionByDynClass( + JSHandle mainFunc = factory_->NewJSFunctionByDynClass( method, dynclass, FunctionKind::BASE_CONSTRUCTOR, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); - main_func->SetConstantPool(thread_, constpool.GetTaggedValue()); - program->SetMainFunction(thread_, main_func.GetTaggedValue()); + mainFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); + program->SetMainFunction(thread_, mainFunc.GetTaggedValue()); program->SetMethodsData(methods_.release()); // link program - constpool->Set(thread_, constpool_index_, program.GetTaggedValue()); + constpool->Set(thread_, constpoolIndex_, program.GetTaggedValue()); } DefineClassInConstPool(constpool); @@ -327,7 +324,7 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) template void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[maybe_unused]] uint32_t index, - uint32_t fix_order) const + uint32_t fixOrder) const { using EnumT = std::conditional_t; using R = BytecodeInstructionResolver; @@ -384,10 +381,10 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ case R::template Get(): case R::template Get(): { ASSERT(static_cast(index) == index); - uint16_t u16_index = index; + uint16_t u16Index = 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, &u16Index, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -396,7 +393,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ case R::template Get(): { // Usually, we fix one part of instruction one time. But as for instruction DefineClassWithBuffer, // which use both method id and literal buffer id.Using fix_order indicates fix Location. - if (fix_order == 0) { + if (fixOrder == 0) { uint8_t size = sizeof(uint16_t); ASSERT(static_cast(index) == index); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -406,12 +403,12 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ } break; } - if (fix_order == 1) { + if (fixOrder == 1) { ASSERT(static_cast(index) == index); - uint16_t u16_index = index; + uint16_t u16Index = 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, &u16Index, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -425,108 +422,108 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ } template -void PandaFileTranslator::TranslateBytecode(uint32_t ins_sz, const uint8_t *ins_arr, const panda_file::File &pf, +void PandaFileTranslator::TranslateBytecode(uint32_t insSz, const uint8_t *insArr, const panda_file::File &pf, const JSMethod *method) { using EnumT = std::conditional_t; using R = BytecodeInstructionResolver; - auto bc_ins = BytecodeInstruction(ins_arr); - auto bc_ins_last = bc_ins.JumpTo(ins_sz); + auto bcIns = BytecodeInstruction(insArr); + auto bcInsLast = bcIns.JumpTo(insSz); - while (bc_ins.GetAddress() != bc_ins_last.GetAddress()) { - if (bc_ins.HasFlag(BytecodeInstruction::Flags::STRING_ID) && - BytecodeInstruction::HasId(bc_ins.GetFormat(), 0)) { - auto index = GetOrInsertConstantPool(ConstPoolType::STRING, bc_ins.GetId().AsFileId().GetOffset()); - FixInstructionId32(bc_ins, index); + while (bcIns.GetAddress() != bcInsLast.GetAddress()) { + if (bcIns.HasFlag(BytecodeInstruction::Flags::STRING_ID) && + BytecodeInstruction::HasId(bcIns.GetFormat(), 0)) { + auto index = GetOrInsertConstantPool(ConstPoolType::STRING, bcIns.GetId().AsFileId().GetOffset()); + FixInstructionId32(bcIns, index); } else { - auto opcode = bc_ins.GetOpcode(); + auto opcode = bcIns.GetOpcode(); switch (opcode) { uint32_t index; - uint32_t method_id; + uint32_t methodId; case R::template Get(): - method_id = pf.ResolveMethodIndex(method->GetFileId(), bc_ins.GetId().AsIndex()).GetOffset(); - index = GetOrInsertConstantPool(ConstPoolType::BASE_FUNCTION, method_id); - FixInstructionId32(bc_ins, index); + methodId = pf.ResolveMethodIndex(method->GetFileId(), bcIns.GetId().AsIndex()).GetOffset(); + index = GetOrInsertConstantPool(ConstPoolType::BASE_FUNCTION, methodId); + FixInstructionId32(bcIns, index); break; case R::template Get(): - method_id = pf.ResolveMethodIndex(method->GetFileId(), bc_ins.GetId().AsIndex()).GetOffset(); - index = GetOrInsertConstantPool(ConstPoolType::NC_FUNCTION, method_id); - FixInstructionId32(bc_ins, index); + methodId = pf.ResolveMethodIndex(method->GetFileId(), bcIns.GetId().AsIndex()).GetOffset(); + index = GetOrInsertConstantPool(ConstPoolType::NC_FUNCTION, methodId); + FixInstructionId32(bcIns, index); break; case R::template Get(): - method_id = pf.ResolveMethodIndex(method->GetFileId(), bc_ins.GetId().AsIndex()).GetOffset(); - index = GetOrInsertConstantPool(ConstPoolType::GENERATOR_FUNCTION, method_id); - FixInstructionId32(bc_ins, index); + methodId = pf.ResolveMethodIndex(method->GetFileId(), bcIns.GetId().AsIndex()).GetOffset(); + index = GetOrInsertConstantPool(ConstPoolType::GENERATOR_FUNCTION, methodId); + FixInstructionId32(bcIns, index); break; case R::template Get(): - method_id = pf.ResolveMethodIndex(method->GetFileId(), bc_ins.GetId().AsIndex()).GetOffset(); - index = GetOrInsertConstantPool(ConstPoolType::ASYNC_FUNCTION, method_id); - FixInstructionId32(bc_ins, index); + methodId = pf.ResolveMethodIndex(method->GetFileId(), bcIns.GetId().AsIndex()).GetOffset(); + index = GetOrInsertConstantPool(ConstPoolType::ASYNC_FUNCTION, methodId); + FixInstructionId32(bcIns, index); break; case R::template Get(): - method_id = pf.ResolveMethodIndex(method->GetFileId(), bc_ins.GetId().AsIndex()).GetOffset(); - index = GetOrInsertConstantPool(ConstPoolType::ASYNC_GENERATOR_FUNCTION, method_id); - FixInstructionId32(bc_ins, index); + methodId = pf.ResolveMethodIndex(method->GetFileId(), bcIns.GetId().AsIndex()).GetOffset(); + index = GetOrInsertConstantPool(ConstPoolType::ASYNC_GENERATOR_FUNCTION, methodId); + FixInstructionId32(bcIns, index); break; case R::template Get(): - method_id = pf.ResolveMethodIndex(method->GetFileId(), bc_ins.GetId().AsIndex()).GetOffset(); - index = GetOrInsertConstantPool(ConstPoolType::METHOD, method_id); - FixInstructionId32(bc_ins, index); + methodId = pf.ResolveMethodIndex(method->GetFileId(), bcIns.GetId().AsIndex()).GetOffset(); + index = GetOrInsertConstantPool(ConstPoolType::METHOD, methodId); + FixInstructionId32(bcIns, index); break; case R::template Get(): case R::template Get(): index = GetOrInsertConstantPool(ConstPoolType::OBJECT_LITERAL, - bc_ins.GetId().AsFileId().GetOffset()); - FixInstructionId32(bc_ins, index); + bcIns.GetId().AsFileId().GetOffset()); + FixInstructionId32(bcIns, index); break; case R::template Get(): index = GetOrInsertConstantPool(ConstPoolType::ARRAY_LITERAL, - bc_ins.GetId().AsFileId().GetOffset()); - FixInstructionId32(bc_ins, index); + bcIns.GetId().AsFileId().GetOffset()); + FixInstructionId32(bcIns, index); break; case R::template Get(): case R::template Get(): { index = GetOrInsertConstantPool(ConstPoolType::TAGGED_ARRAY, - bc_ins.GetId().AsFileId().GetOffset()); - FixInstructionId32(bc_ins, index); + bcIns.GetId().AsFileId().GetOffset()); + FixInstructionId32(bcIns, index); break; } case R::template Get(): - method_id = pf.ResolveMethodIndex(method->GetFileId(), bc_ins.GetId().AsIndex()).GetOffset(); - index = GetOrInsertConstantPool(ConstPoolType::CLASS_FUNCTION, method_id); - FixInstructionId32(bc_ins, index); + methodId = pf.ResolveMethodIndex(method->GetFileId(), bcIns.GetId().AsIndex()).GetOffset(); + index = GetOrInsertConstantPool(ConstPoolType::CLASS_FUNCTION, methodId); + FixInstructionId32(bcIns, index); index = GetOrInsertConstantPool( ConstPoolType::TAGGED_ARRAY, - bc_ins.GetImm()>()); - FixInstructionId32(bc_ins, index, 1); + bcIns.GetImm()>()); + FixInstructionId32(bcIns, index, 1); break; default: break; } } - UpdateICOffset(const_cast(method), ins_sz, bc_ins); - bc_ins = bc_ins.GetNext(); + UpdateICOffset(const_cast(method), insSz, bcIns); + bcIns = bcIns.GetNext(); } } template -void PandaFileTranslator::UpdateICOffset(JSMethod *method, uint32_t ins_sz, const BytecodeInstruction &inst) const +void PandaFileTranslator::UpdateICOffset(JSMethod *method, uint32_t insSz, const BytecodeInstruction &inst) const { using EnumT = std::conditional_t; using R = BytecodeInstructionResolver; auto opcode = inst.GetOpcode(); - uint32_t bc_offset = inst.GetAddress() - method->GetInstructions(); - uint32_t slot_size = 0; + uint32_t bcOffset = inst.GetAddress() - method->GetInstructions(); + uint32_t slotSize = 0; using ICMappingType = JSMethod::ICMappingType; static_assert(std::is_pointer::value); using ICMappingElementType = std::remove_pointer::type; - ICMappingType ic_mapping = method->GetICMapping(); + ICMappingType icMapping = method->GetICMapping(); if (method->GetSlotSize() > std::numeric_limits::max()) { - if (ic_mapping != nullptr) { - mem::InternalAllocator<>::GetInternalAllocatorFromRuntime()->Free(ic_mapping); + if (icMapping != nullptr) { + mem::InternalAllocator<>::GetInternalAllocatorFromRuntime()->Free(icMapping); method->SetICMapping(nullptr); } return; @@ -536,79 +533,79 @@ void PandaFileTranslator::UpdateICOffset(JSMethod *method, uint32_t ins_sz, cons case R::template Get(): case R::template Get(): case R::template Get(): - slot_size = ICRuntimeStub::SlotSizeForGlobalICByName(); + slotSize = ICRuntimeStub::SlotSizeForGlobalICByName(); break; case R::template Get(): case R::template Get(): case R::template Get(): - slot_size = ICRuntimeStub::SlotSizeForICByValue(); + slotSize = ICRuntimeStub::SlotSizeForICByValue(); break; case R::template Get(): case R::template Get(): case R::template Get(): - slot_size = ICRuntimeStub::SlotSizeForICByName(); + slotSize = ICRuntimeStub::SlotSizeForICByName(); break; default: return; } - if (ic_mapping == nullptr && ins_sz < ProfileTypeInfo::MAX_FUNCTION_SIZE) { - ic_mapping = - mem::InternalAllocator<>::GetInternalAllocatorFromRuntime()->AllocArray(ins_sz); - memset_s(ic_mapping, ins_sz, 0, ins_sz); - method->SetICMapping(ic_mapping); + if (icMapping == nullptr && insSz < ProfileTypeInfo::MAX_FUNCTION_SIZE) { + icMapping = + mem::InternalAllocator<>::GetInternalAllocatorFromRuntime()->AllocArray(insSz); + memset_s(icMapping, insSz, 0, insSz); + method->SetICMapping(icMapping); } - if (ic_mapping != nullptr) { + if (icMapping != nullptr) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - ic_mapping[bc_offset] = method->GetSlotSize(); - method->AddSlotSize(slot_size); + icMapping[bcOffset] = method->GetSlotSize(); + method->AddSlotSize(slotSize); } } uint32_t PandaFileTranslator::GetOrInsertConstantPool(ConstPoolType type, uint32_t offset) { - auto it = constpool_map_.find(offset); - if (it != constpool_map_.cend()) { + auto it = constpoolMap_.find(offset); + if (it != constpoolMap_.cend()) { ConstPoolValue value(it->second); return value.GetConstpoolIndex(); } - ASSERT(constpool_index_ != UINT32_MAX); - uint32_t index = constpool_index_++; + ASSERT(constpoolIndex_ != UINT32_MAX); + uint32_t index = constpoolIndex_++; ConstPoolValue value(type, index); - constpool_map_.insert({offset, value.GetValue()}); + constpoolMap_.insert({offset, value.GetValue()}); return index; } -JSHandle PandaFileTranslator::DefineMethodInLiteral(uint32_t method_id, FunctionKind kind) const +JSHandle PandaFileTranslator::DefineMethodInLiteral(uint32_t methodId, FunctionKind kind) const { - auto method = const_cast(FindMethods(method_id)); + auto method = const_cast(FindMethods(methodId)); ASSERT(method != nullptr); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle function_class; + JSHandle functionClass; if (kind == FunctionKind::NORMAL_FUNCTION) { - function_class = JSHandle::Cast(env->GetFunctionClassWithoutProto()); + functionClass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); } else { - function_class = JSHandle::Cast(env->GetGeneratorFunctionClass()); + functionClass = JSHandle::Cast(env->GetGeneratorFunctionClass()); } - JSHandle js_func = factory_->NewJSFunctionByDynClass(method, function_class, kind, - panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + JSHandle jsFunc = + factory_->NewJSFunctionByDynClass(method, functionClass, kind, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); if (kind == FunctionKind::GENERATOR_FUNCTION) { - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle initial_generator_func_prototype = factory_->NewJSObjectByConstructor( - JSHandle(obj_fun), obj_fun, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); - JSObject::SetPrototype(thread_, initial_generator_func_prototype, env->GetGeneratorPrototype()); - js_func->SetProtoOrDynClass(thread_, initial_generator_func_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle initialGeneratorFuncPrototype = factory_->NewJSObjectByConstructor( + JSHandle(objFun), objFun, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, env->GetGeneratorPrototype()); + jsFunc->SetProtoOrDynClass(thread_, initialGeneratorFuncPrototype); } else if (kind == FunctionKind::ASYNC_GENERATOR_FUNCTION) { - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle initial_async_generator_func_prototype = factory_->NewJSObjectByConstructor( - JSHandle(obj_fun), obj_fun, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); - JSObject::SetPrototype(thread_, initial_async_generator_func_prototype, env->GetAsyncGeneratorPrototype()); - js_func->SetProtoOrDynClass(thread_, initial_async_generator_func_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle initialAsyncGeneratorFuncPrototype = factory_->NewJSObjectByConstructor( + JSHandle(objFun), objFun, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + JSObject::SetPrototype(thread_, initialAsyncGeneratorFuncPrototype, env->GetAsyncGeneratorPrototype()); + jsFunc->SetProtoOrDynClass(thread_, initialAsyncGeneratorFuncPrototype); } - js_func->SetupFunctionLength(thread_); - return js_func; + jsFunc->SetupFunctionLength(thread_); + return jsFunc; } void PandaFileTranslator::DefineClassInConstPool(const JSHandle &constpool) const @@ -624,11 +621,11 @@ void PandaFileTranslator::DefineClassInConstPool(const JSHandle &c // Here, using a law: when inserting ctor in index of constantpool, the index + 1 location will be inserted by // corresponding class literal. Because translator fixes ECMA_DEFINECLASSWITHBUFFER two consecutive times. - JSTaggedValue next_value = constpool->Get(index + 1); - ASSERT(next_value.IsTaggedArray()); + JSTaggedValue nextValue = constpool->Get(index + 1); + ASSERT(nextValue.IsTaggedArray()); JSHandle extractor(thread_, value); - JSHandle literal(thread_, next_value); + JSHandle literal(thread_, nextValue); ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread_, extractor, literal); JSHandle cls = ClassHelper::DefineClassTemplate(thread_, extractor, constpool); constpool->Set(thread_, index, cls); diff --git a/runtime/class_linker/panda_file_translator.h b/runtime/class_linker/panda_file_translator.h index 0b8071fb327141b0f6500f3c88743cce26ecef21..0b03e128c6dd5b042c886bc2fe5eefd99e1602df 100644 --- a/runtime/class_linker/panda_file_translator.h +++ b/runtime/class_linker/panda_file_translator.h @@ -35,8 +35,8 @@ public: ~PandaFileTranslator() = default; NO_COPY_SEMANTIC(PandaFileTranslator); NO_MOVE_SEMANTIC(PandaFileTranslator); - static JSHandle TranslatePandaFile(EcmaVM *vm, const panda_file::File &pf, const PandaString &method_name); - JSHandle DefineMethodInLiteral(uint32_t method_id, FunctionKind kind) const; + static JSHandle TranslatePandaFile(EcmaVM *vm, const panda_file::File &pf, const PandaString &methodName); + JSHandle DefineMethodInLiteral(uint32_t methodId, FunctionKind kind) const; static void QuickPandaFile(EcmaVM *vm, const panda_file::File &pf); private: @@ -92,26 +92,26 @@ private: uint32_t GetOrInsertConstantPool(ConstPoolType type, uint32_t offset); const JSMethod *FindMethods(uint32_t offset) const; Program *GenerateProgram(const panda_file::File &pf); - void TranslateClasses(const panda_file::File &pf, const PandaString &method_name); - void TranslateMethod(const compiler::AotClass &aot_class, const panda_file::File::StringData &sd, + void TranslateClasses(const panda_file::File &pf, const PandaString &methodName); + void TranslateMethod(const compiler::AotClass &aotClass, const panda_file::File::StringData &sd, const panda_file::File &pf, const uint8_t *descriptor, panda_file::MethodDataAccessor &mda); template - void TranslateBytecode(uint32_t ins_sz, const uint8_t *ins_arr, const panda_file::File &pf, const JSMethod *method); + void TranslateBytecode(uint32_t insSz, const uint8_t *insArr, const panda_file::File &pf, const JSMethod *method); template - void FixInstructionId32(const BytecodeInstruction &inst, uint32_t index, uint32_t fix_order = 0) const; + void FixInstructionId32(const BytecodeInstruction &inst, uint32_t index, uint32_t fixOrder = 0) const; template - void UpdateICOffset(JSMethod *method, uint32_t ins_sz, const BytecodeInstruction &inst) const; + void UpdateICOffset(JSMethod *method, uint32_t insSz, const BytecodeInstruction &inst) const; void DefineClassInConstPool(const JSHandle &constpool) const; - EcmaVM *ecma_vm_; + EcmaVM *ecmaVm_; ObjectFactory *factory_; JSThread *thread_; - uint32_t constpool_index_ {0}; - uint32_t main_method_index_ {0}; + uint32_t constpoolIndex_ {0}; + uint32_t mainMethodIndex_ {0}; PandaUniquePtr> methods_; - std::unordered_map constpool_map_; - std::set translated_code_; + std::unordered_map constpoolMap_; + std::set translatedCode_; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_CLASS_LINKER_PANDA_FILE_TRANSLATOR_H diff --git a/runtime/compiler/ecmascript_runtime_interface.cpp b/runtime/compiler/ecmascript_runtime_interface.cpp index 79af18fb780b5ea466006576314c61846949055c..ddab040ad8493fd4ed2448d1d63bb366a3a9d251 100644 --- a/runtime/compiler/ecmascript_runtime_interface.cpp +++ b/runtime/compiler/ecmascript_runtime_interface.cpp @@ -31,15 +31,15 @@ namespace panda::ecmascript { -EcmaRuntimeInterface::EcmaRuntimeInterface(const EcmaVM *ecma_vm, mem::InternalAllocatorPtr internal_allocator) - : ecma_vm_(ecma_vm), internal_allocator_(internal_allocator) +EcmaRuntimeInterface::EcmaRuntimeInterface(const EcmaVM *ecmaVm, mem::InternalAllocatorPtr internalAllocator) + : ecmaVm_(ecmaVm), internalAllocator_(internalAllocator) { } EcmaRuntimeInterface::~EcmaRuntimeInterface() { - os::memory::LockHolder lock(mutex_h_); - for (auto it : handles_by_method_table_) { - internal_allocator_->template Delete(it.second); + os::memory::LockHolder lock(mutexH_); + for (auto it : handlesByMethodTable_) { + internalAllocator_->template Delete(it.second); } } @@ -48,7 +48,7 @@ size_t EcmaRuntimeInterface::GetLanguageExtensionSize([[maybe_unused]] Arch arch return cross_values::GetEcmascriptEnvironmentSize(arch); } -std::string EcmaRuntimeInterface::GetMethodFullName(MethodPtr method, [[maybe_unused]] bool with_signature) const +std::string EcmaRuntimeInterface::GetMethodFullName(MethodPtr method, [[maybe_unused]] bool withSignature) const { ASSERT(panda::panda_file::IsDynamicLanguage(MethodCast(method)->GetClass()->GetSourceLang())); return std::string(static_cast(MethodCast(method))->GetFullName()); @@ -96,11 +96,11 @@ uintptr_t EcmaRuntimeInterface::GetGlobalVarAddress(MethodPtr method, size_t id) #include "plugins/ecmascript/runtime/builtins/generated/builtins_resolve_inlinable_gen.inl" -EcmaRuntimeInterface::MethodProfile EcmaRuntimeInterface::GetMethodProfile(MethodPtr method, bool from_vector) const +EcmaRuntimeInterface::MethodProfile EcmaRuntimeInterface::GetMethodProfile(MethodPtr method, bool fromVector) const { - if (from_vector) { - if (auto prof_vector = JsMethodCast(method)->GetProfilingVector(); prof_vector != nullptr) { - return reinterpret_cast(prof_vector); + if (fromVector) { + if (auto profVector = JsMethodCast(method)->GetProfilingVector(); profVector != nullptr) { + return reinterpret_cast(profVector); } return profiling::INVALID_PROFILE; } @@ -115,54 +115,54 @@ EcmaRuntimeInterface::MethodProfile EcmaRuntimeInterface::GetMethodProfile(Metho } EcmaRuntimeInterface::BytecodeProfile EcmaRuntimeInterface::GetBytecodeProfile(MethodProfile profile, - const uint8_t *bc_inst, + const uint8_t *bcInst, [[maybe_unused]] size_t pc) const { if (profile == nullptr) { return 0; } - auto profile_id = BytecodeInstruction(bc_inst).GetProfileId(); - if (profile_id == -1) { + auto profileId = BytecodeInstruction(bcInst).GetProfileId(); + if (profileId == -1) { return 0; } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - return reinterpret_cast(reinterpret_cast(profile) + profile_id); + return reinterpret_cast(reinterpret_cast(profile) + profileId); } -bool EcmaRuntimeInterface::CanInlineLdStObjByIndex(const BytecodeInstruction *bc_inst, size_t pc, - MethodProfile method_profile) const +bool EcmaRuntimeInterface::CanInlineLdStObjByIndex(const BytecodeInstruction *bcInst, size_t pc, + MethodProfile methodProfile) const { - auto profile = GetBytecodeProfile(method_profile, bc_inst->GetAddress(), pc); - auto ecma_prof = reinterpret_cast(profile); - panda::ecmascript::ObjByIndexOperationProfile p(ecma_prof); + auto profile = GetBytecodeProfile(methodProfile, bcInst->GetAddress(), pc); + auto ecmaProf = reinterpret_cast(profile); + panda::ecmascript::ObjByIndexOperationProfile p(ecmaProf); return p.GetOperandType(0).GetType() == panda::ecmascript::ProfilingIndexedAccessBits::OBJECT_ARRAY_ACCESS; } profiling::CallKind EcmaRuntimeInterface::GetCallProfile(MethodPtr method, uint32_t pc, ArenaVector *methods, - bool is_aot) + bool isAot) { - auto profile = GetMethodProfile(method, !is_aot); + auto profile = GetMethodProfile(method, !isAot); if (profile == nullptr) { return profiling::CallKind::UNKNOWN; } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto bc_inst = MethodCast(method)->GetInstructions() + pc; - auto profile_id = BytecodeInstruction(bc_inst).GetProfileId(); - if (profile_id == -1) { + auto bcInst = MethodCast(method)->GetInstructions() + pc; + auto profileId = BytecodeInstruction(bcInst).GetProfileId(); + if (profileId == -1) { return profiling::CallKind::UNKNOWN; } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto call_prof = CallProfile::FromBuffer(reinterpret_cast(profile) + profile_id); - auto call_kind = call_prof->GetCallKind(); - if (call_kind != profiling::CallKind::UNKNOWN && call_kind != profiling::CallKind::MEGAMORPHIC) { - for (auto ptr : call_prof->GetCalleesPtr(ecma_vm_->GetEcmaCallProfileTable())) { + auto callProf = CallProfile::FromBuffer(reinterpret_cast(profile) + profileId); + auto callKind = callProf->GetCallKind(); + if (callKind != profiling::CallKind::UNKNOWN && callKind != profiling::CallKind::MEGAMORPHIC) { + for (auto ptr : callProf->GetCalleesPtr(ecmaVm_->GetEcmaCallProfileTable())) { if (ptr == CallProfile::UNKNOWN) { break; } methods->push_back(ptr); } } - return call_kind; + return callKind; } Expected EcmaRuntimeInterface::AddProfile(std::string_view fname) @@ -182,16 +182,16 @@ Expected EcmaRuntimeInterface::AddProfile(std::string_view f } inline compiler::AnyBaseType GetTypeOfType(panda::ecmascript::ProfilingTypeOfBits::Type type, - profiling::AnyInputType *allowed_input_type, bool *is_type_profiled) + profiling::AnyInputType *allowedInputType, bool *isTypeProfiled) { if (type == panda::ecmascript::ProfilingTypeOfBits::NONE) { return compiler::AnyBaseType::UNDEFINED_TYPE; } - *is_type_profiled = true; + *isTypeProfiled = true; switch (type) { case panda::ecmascript::ProfilingTypeOfBits::NUMBER: { - *allowed_input_type = profiling::AnyInputType::INTEGER; + *allowedInputType = profiling::AnyInputType::INTEGER; return compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE; } case panda::ecmascript::ProfilingTypeOfBits::SYMBOL: @@ -212,9 +212,9 @@ inline compiler::AnyBaseType GetTypeOfType(panda::ecmascript::ProfilingTypeOfBit return compiler::AnyBaseType::UNDEFINED_TYPE; } -static bool IsEqualsInst(const BytecodeInstruction *bc_inst) +static bool IsEqualsInst(const BytecodeInstruction *bcInst) { - switch (bc_inst->GetOpcode()) { + switch (bcInst->GetOpcode()) { case BytecodeInstruction::Opcode::ECMA_EQDYN_PREF_V8_PROF16: case BytecodeInstruction::Opcode::ECMA_NOTEQDYN_PREF_V8_PROF16: case BytecodeInstruction::Opcode::ECMA_STRICTEQDYN_PREF_V8_PROF16: @@ -226,23 +226,23 @@ static bool IsEqualsInst(const BytecodeInstruction *bc_inst) } compiler::AnyBaseType EcmaRuntimeInterface::GetProfilingAnyType(RuntimeInterface::BytecodeProfile profile, - const BytecodeInstruction *bc_inst, unsigned index, - profiling::AnyInputType *allowed_input_type, - bool *is_type_profiled) + const BytecodeInstruction *bcInst, unsigned index, + profiling::AnyInputType *allowedInputType, + bool *isTypeProfiled) { - auto kind = profiling::GetProfileKind(bc_inst->GetOpcode()); - auto ecma_prof = reinterpret_cast(profile); + auto kind = profiling::GetProfileKind(bcInst->GetOpcode()); + auto ecmaProf = reinterpret_cast(profile); ProfilingTypeBits::Type type = ProfilingTypeBits::NONE; switch (kind) { case profiling::ProfilingKind::TYPE_OF: { - panda::ecmascript::TypeOfOperationProfile p(ecma_prof); - return GetTypeOfType(p.GetOperandType(index).GetType(), allowed_input_type, is_type_profiled); + panda::ecmascript::TypeOfOperationProfile p(ecmaProf); + return GetTypeOfType(p.GetOperandType(index).GetType(), allowedInputType, isTypeProfiled); } case profiling::ProfilingKind::UNARY_ARITH: { - UnaryOperationProfile p(ecma_prof); + UnaryOperationProfile p(ecmaProf); type = p.GetOperandType(index).GetType(); if (type != ProfilingTypeBits::NONE) { - *is_type_profiled = true; + *isTypeProfiled = true; } if (type == ProfilingTypeBits::STRING) { @@ -254,22 +254,22 @@ compiler::AnyBaseType EcmaRuntimeInterface::GetProfilingAnyType(RuntimeInterface break; } case profiling::ProfilingKind::BINARY_ARITH: { - BinaryOperationProfile p(ecma_prof); + BinaryOperationProfile p(ecmaProf); type = p.GetOperandType(index).GetType(); if (type != ProfilingTypeBits::NONE) { - *is_type_profiled = true; + *isTypeProfiled = true; } - auto other_operand_type = p.GetOperandType(1 - index).GetType(); - if (type == ProfilingTypeBits::STRING && other_operand_type == ProfilingTypeBits::STRING) { + auto otherOperandType = p.GetOperandType(1 - index).GetType(); + if (type == ProfilingTypeBits::STRING && otherOperandType == ProfilingTypeBits::STRING) { return compiler::AnyBaseType::ECMASCRIPT_STRING_TYPE; } - auto object_count = ((type & ProfilingTypeBits::HEAP_OBJECT) != 0 ? 1 : 0) + - ((other_operand_type & ProfilingTypeBits::HEAP_OBJECT) != 0 ? 1 : 0); + auto objectCount = ((type & ProfilingTypeBits::HEAP_OBJECT) != 0 ? 1 : 0) + + ((otherOperandType & ProfilingTypeBits::HEAP_OBJECT) != 0 ? 1 : 0); // For opcodes like eq non-numeric types are common, do not inline them if object was seen as one of inputs // For arithmetic opcodes if we saw double and object, assume double type and deoptimize without method // destruction in case of object - if (object_count == 2 || (object_count == 1 && IsEqualsInst(bc_inst))) { - *is_type_profiled = true; + if (objectCount == 2 || (objectCount == 1 && IsEqualsInst(bcInst))) { + *isTypeProfiled = true; return compiler::AnyBaseType::UNDEFINED_TYPE; } break; @@ -285,14 +285,14 @@ compiler::AnyBaseType EcmaRuntimeInterface::GetProfilingAnyType(RuntimeInterface if (type == ProfilingTypeBits::BOOLEAN) { return compiler::AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE; } - auto accept_special = (type & ProfilingTypeBits::SPECIAL) != 0 || (type & ProfilingTypeBits::BOOLEAN) != 0; - if (accept_special && IsEqualsInst(bc_inst)) { + auto acceptSpecial = (type & ProfilingTypeBits::SPECIAL) != 0 || (type & ProfilingTypeBits::BOOLEAN) != 0; + if (acceptSpecial && IsEqualsInst(bcInst)) { // some instructions treat NaN and undefined or true and 1 differently return compiler::AnyBaseType::UNDEFINED_TYPE; } if ((type & ProfilingTypeBits::SPECIAL_INT) == type) { - if (accept_special) { - *allowed_input_type = profiling::AnyInputType::SPECIAL; + if (acceptSpecial) { + *allowedInputType = profiling::AnyInputType::SPECIAL; } return compiler::AnyBaseType::ECMASCRIPT_INT_TYPE; } @@ -300,34 +300,34 @@ compiler::AnyBaseType EcmaRuntimeInterface::GetProfilingAnyType(RuntimeInterface // If object was seen only in one of inputs and we have seen a number as input, // build AnyTypeCheck with Double type for this input if ((type & ProfilingTypeBits::DOUBLE_INTEGER) != 0) { - uint8_t allowed_type_mask = 0; - if (accept_special) { - allowed_type_mask |= profiling::AnyInputType::SPECIAL; + uint8_t allowedTypeMask = 0; + if (acceptSpecial) { + allowedTypeMask |= profiling::AnyInputType::SPECIAL; } if ((type & ProfilingTypeBits::INTEGER) != 0) { - allowed_type_mask |= profiling::AnyInputType::INTEGER; + allowedTypeMask |= profiling::AnyInputType::INTEGER; } - *allowed_input_type = static_cast(allowed_type_mask); + *allowedInputType = static_cast(allowedTypeMask); return compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE; } return compiler::AnyBaseType::UNDEFINED_TYPE; } -compiler::AnyBaseType EcmaRuntimeInterface::ResolveSpecialAnyTypeByConstant(coretypes::TaggedValue any_const) +compiler::AnyBaseType EcmaRuntimeInterface::ResolveSpecialAnyTypeByConstant(coretypes::TaggedValue anyConst) { - JSTaggedValue js_any_const(any_const); - ASSERT(js_any_const.IsSpecial()); - if (js_any_const == JSTaggedValue::Hole()) { + JSTaggedValue jsAnyConst(anyConst); + ASSERT(jsAnyConst.IsSpecial()); + if (jsAnyConst == JSTaggedValue::Hole()) { return compiler::AnyBaseType::ECMASCRIPT_HOLE_TYPE; } - if (js_any_const == JSTaggedValue::Undefined()) { + if (jsAnyConst == JSTaggedValue::Undefined()) { return compiler::AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE; } - if ((js_any_const == JSTaggedValue::False()) || (js_any_const == JSTaggedValue::True())) { + if ((jsAnyConst == JSTaggedValue::False()) || (jsAnyConst == JSTaggedValue::True())) { return compiler::AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE; } - if (js_any_const == JSTaggedValue::Null()) { + if (jsAnyConst == JSTaggedValue::Null()) { return compiler::AnyBaseType::ECMASCRIPT_NULL_TYPE; } return compiler::AnyBaseType::UNDEFINED_TYPE; @@ -335,39 +335,39 @@ compiler::AnyBaseType EcmaRuntimeInterface::ResolveSpecialAnyTypeByConstant(core size_t EcmaRuntimeInterface::GetGlobalConstStringOffsetForAnyType(compiler::AnyBaseType type, Arch arch) const { - auto global_const_array_offset = + auto globalConstArrayOffset = cross_values::GetJsthreadGlobalConstantsOffset(arch) + cross_values::GetGlobalConstConstantsOffset(arch); switch (type) { case compiler::AnyBaseType::ECMASCRIPT_UNDEFINED_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::UNDEFINED_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::UNDEFINED_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_STRING_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::STRING_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::STRING_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_INT_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_DOUBLE_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::NUMBER_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_SYMBOL_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::SYMBOL_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::SYMBOL_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_CALLABLE_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::FUNCTION_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::FUNCTION_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_BOOLEAN_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::BOOLEAN_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::BOOLEAN_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_NULL_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_BIGINT_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::BIGINT_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::BIGINT_STRING_INDEX); case compiler::AnyBaseType::ECMASCRIPT_HEAP_OBJECT_TYPE: - return global_const_array_offset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( - panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); + return globalConstArrayOffset + panda::ecmascript::GlobalEnvConstants::GetGlobalConstantOffset( + panda::ecmascript::ConstantIndex::OBJECT_STRING_INDEX); default: UNREACHABLE(); } @@ -378,25 +378,25 @@ RuntimeInterface::NewObjDynInfo EcmaRuntimeInterface::GetNewObjDynInfo(uintptr_t 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()) { + JSObject *ctorPtr = *reinterpret_cast(ctor); + if (ctorPtr == nullptr || !ctorPtr->IsJSFunction()) { return SLOW_PATH; } - auto js_fun = static_cast(ctor_ptr); - if (!js_fun->IsConstructor()) { + auto jsFun = static_cast(ctorPtr); + if (!jsFun->IsConstructor()) { return SLOW_PATH; } - auto method = js_fun->GetMethod(); + auto method = jsFun->GetMethod(); if (method->IsNative()) { - if (js_fun->IsBuiltinConstructor()) { + if (jsFun->IsBuiltinConstructor()) { return {NewObjDynInfo::AllocatorType::UNDEFINED, NewObjDynInfo::ResolverType::USE_CTOR_RESULT}; } return SLOW_PATH; } - if (!js_fun->IsBase()) { - if (js_fun->IsDerivedConstructor()) { + if (!jsFun->IsBase()) { + if (jsFun->IsDerivedConstructor()) { return {NewObjDynInfo::AllocatorType::UNDEFINED, NewObjDynInfo::ResolverType::RESOLVE}; } return SLOW_PATH; @@ -406,116 +406,116 @@ RuntimeInterface::NewObjDynInfo EcmaRuntimeInterface::GetNewObjDynInfo(uintptr_t bool EcmaRuntimeInterface::AddProfileInfo(PandaRuntimeInterface::MethodPtr m, ArenaVector *profile, - ProfileTypeInfo *profile_type_info, uint8_t slot, uintptr_t key) + ProfileTypeInfo *profileTypeInfo, uint8_t slot, uintptr_t key) { - JSTaggedValue hclass_value = profile_type_info->Get(slot); - if (!hclass_value.IsHeapObject()) { + JSTaggedValue hclassValue = profileTypeInfo->Get(slot); + if (!hclassValue.IsHeapObject()) { return false; } - auto klass = static_cast(hclass_value.GetHeapObject())->GetHClass(); - JSTaggedValue handler = profile_type_info->Get(slot + 1); + auto klass = static_cast(hclassValue.GetHeapObject())->GetHClass(); + JSTaggedValue handler = profileTypeInfo->Get(slot + 1); if (UNLIKELY(handler.IsUndefined())) { return false; } auto method = MethodCast(m); if (LIKELY(handler.IsInt())) { - auto handler_info = static_cast(handler.GetInt()); - if (LIKELY(HandlerBase::IsField(handler_info))) { - if (HandlerBase::IsArrayOverflowed(handler_info)) { + auto handlerInfo = static_cast(handler.GetInt()); + if (LIKELY(HandlerBase::IsField(handlerInfo))) { + if (HandlerBase::IsArrayOverflowed(handlerInfo)) { return false; } - int index = HandlerBase::GetOffset(handler_info); - bool is_inlined = HandlerBase::IsInlinedProps(handler_info); + int index = HandlerBase::GetOffset(handlerInfo); + bool isInlined = HandlerBase::IsInlinedProps(handlerInfo); NamedAccessProfileType type = - is_inlined ? NamedAccessProfileType::FIELD_INLINED : NamedAccessProfileType::FIELD; - auto offset = is_inlined ? static_cast(index * JSTaggedValue::TaggedTypeSize()) - : static_cast(index); - AddObjectHandle(method, hclass_value.GetHeapObject()); + isInlined ? NamedAccessProfileType::FIELD_INLINED : NamedAccessProfileType::FIELD; + auto offset = isInlined ? static_cast(index * JSTaggedValue::TaggedTypeSize()) + : static_cast(index); + AddObjectHandle(method, hclassValue.GetHeapObject()); profile->push_back({klass, 0, key, offset, type}); return true; } return false; } if (handler.IsTransitionHandler()) { - TransitionHandler *transition_handler = TransitionHandler::Cast(handler.GetTaggedObject()); - JSHClass *new_h_class = JSHClass::Cast(transition_handler->GetTransitionHClass().GetTaggedObject()); - uint32_t handler_info = transition_handler->GetHandlerInfo().GetInt(); - ASSERT(HandlerBase::IsField(handler_info)); - if (HandlerBase::IsArrayOverflowed(handler_info)) { + TransitionHandler *transitionHandler = TransitionHandler::Cast(handler.GetTaggedObject()); + JSHClass *newHClass = JSHClass::Cast(transitionHandler->GetTransitionHClass().GetTaggedObject()); + uint32_t handlerInfo = transitionHandler->GetHandlerInfo().GetInt(); + ASSERT(HandlerBase::IsField(handlerInfo)); + if (HandlerBase::IsArrayOverflowed(handlerInfo)) { return false; } - int index = HandlerBase::GetOffset(handler_info); - bool is_inlined = HandlerBase::IsInlinedProps(handler_info); + int index = HandlerBase::GetOffset(handlerInfo); + bool isInlined = HandlerBase::IsInlinedProps(handlerInfo); NamedAccessProfileType type = - is_inlined ? NamedAccessProfileType::TRANSITION_INLINED : NamedAccessProfileType::TRANSITION; + isInlined ? NamedAccessProfileType::TRANSITION_INLINED : NamedAccessProfileType::TRANSITION; auto offset = - is_inlined ? static_cast(index * JSTaggedValue::TaggedTypeSize()) : static_cast(index); - AddObjectHandle(method, hclass_value.GetHeapObject()); - AddObjectHandle(method, new_h_class); - profile->push_back({klass, reinterpret_cast(new_h_class->GetHClass()), key, offset, type}); + isInlined ? static_cast(index * JSTaggedValue::TaggedTypeSize()) : static_cast(index); + AddObjectHandle(method, hclassValue.GetHeapObject()); + AddObjectHandle(method, newHClass); + profile->push_back({klass, reinterpret_cast(newHClass->GetHClass()), key, offset, type}); return true; } if (handler.IsPrototypeHandler()) { - PrototypeHandler *prototype_handler = PrototypeHandler::Cast(handler.GetTaggedObject()); - auto cell_value = prototype_handler->GetProtoCell(); - if (cell_value.IsFalse()) { + PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); + auto cellValue = prototypeHandler->GetProtoCell(); + if (cellValue.IsFalse()) { // For access to undefined property of object without prototype tagged false is stored to proto cell return false; } - ASSERT(cell_value.IsProtoChangeMarker()); - ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cell_value.GetHeapObject()); + ASSERT(cellValue.IsProtoChangeMarker()); + ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetHeapObject()); if (cell->GetHasChanged()) { return false; } - JSTaggedValue handler_value = prototype_handler->GetHandlerInfo(); - if (!handler_value.IsInt()) { + JSTaggedValue handlerValue = prototypeHandler->GetHandlerInfo(); + if (!handlerValue.IsInt()) { return false; } - uint32_t handler_info = handler_value.GetInt(); - if (!HandlerBase::IsField(handler_info)) { + uint32_t handlerInfo = handlerValue.GetInt(); + if (!HandlerBase::IsField(handlerInfo)) { return false; } - int index = HandlerBase::GetOffset(handler_info); - bool is_inlined = HandlerBase::IsInlinedProps(handler_info); + int index = HandlerBase::GetOffset(handlerInfo); + bool isInlined = HandlerBase::IsInlinedProps(handlerInfo); NamedAccessProfileType type = - is_inlined ? NamedAccessProfileType::PROTOTYPE_INLINED : NamedAccessProfileType::PROTOTYPE; + isInlined ? NamedAccessProfileType::PROTOTYPE_INLINED : NamedAccessProfileType::PROTOTYPE; auto offset = - is_inlined ? static_cast(index * JSTaggedValue::TaggedTypeSize()) : static_cast(index); - auto ref_addr = AddFixedObjectHandle(method, handler.GetHeapObject()); - if (ref_addr == 0) { + isInlined ? static_cast(index * JSTaggedValue::TaggedTypeSize()) : static_cast(index); + auto refAddr = AddFixedObjectHandle(method, handler.GetHeapObject()); + if (refAddr == 0) { return false; } - AddObjectHandle(method, hclass_value.GetHeapObject()); - profile->push_back({klass, ref_addr, key, offset, type}); + AddObjectHandle(method, hclassValue.GetHeapObject()); + profile->push_back({klass, refAddr, key, offset, type}); return true; } return false; } bool EcmaRuntimeInterface::AddElementInfo(ArenaVector *profile, - ProfileTypeInfo *profile_type_info, uint8_t slot) + ProfileTypeInfo *profileTypeInfo, uint8_t slot) { - JSTaggedValue hclass_value = profile_type_info->Get(slot); - if (!hclass_value.IsHeapObject()) { + JSTaggedValue hclassValue = profileTypeInfo->Get(slot); + if (!hclassValue.IsHeapObject()) { return false; } - ASSERT(hclass_value.IsJSHClass()); - auto klass = static_cast(hclass_value.GetHeapObject())->GetHClass(); - JSTaggedValue handler = profile_type_info->Get(slot + 1); + ASSERT(hclassValue.IsJSHClass()); + auto klass = static_cast(hclassValue.GetHeapObject())->GetHClass(); + JSTaggedValue handler = profileTypeInfo->Get(slot + 1); if (UNLIKELY(handler.IsUndefined())) { return false; } ASSERT(handler.IsInt()); - auto handler_info = static_cast(handler.GetInt()); + auto handlerInfo = static_cast(handler.GetInt()); // NOTE(pishin) support for double - if (UNLIKELY(!HandlerBase::IsKeyInt(handler_info))) { + if (UNLIKELY(!HandlerBase::IsKeyInt(handlerInfo))) { return false; } - if (HandlerBase::IsArrayOverflowed(handler_info)) { + if (HandlerBase::IsArrayOverflowed(handlerInfo)) { return false; } - if (HandlerBase::IsJSArray(handler_info)) { + if (HandlerBase::IsJSArray(handlerInfo)) { profile->push_back({klass, 0, 0, 0, NamedAccessProfileType::ARRAY_ELEMENT}); } else { profile->push_back({klass, 0, 0, 0, NamedAccessProfileType::ELEMENT}); @@ -525,38 +525,38 @@ bool EcmaRuntimeInterface::AddElementInfo(ArenaVector *p bool EcmaRuntimeInterface::AddProfileValueInfo(PandaRuntimeInterface::MethodPtr m, ArenaVector *profile, - ProfileTypeInfo *profile_type_info, uint8_t slot) + ProfileTypeInfo *profileTypeInfo, uint8_t slot) { - JSTaggedValue first_value = profile_type_info->Get(slot); - if (!first_value.IsHeapObject()) { + JSTaggedValue firstValue = profileTypeInfo->Get(slot); + if (!firstValue.IsHeapObject()) { return false; } - if (first_value.IsJSHClass()) { - if (AddElementInfo(profile, profile_type_info, slot)) { - AddElementInfo(profile, profile_type_info, slot + 2); + if (firstValue.IsJSHClass()) { + if (AddElementInfo(profile, profileTypeInfo, slot)) { + AddElementInfo(profile, profileTypeInfo, slot + 2); return true; } return false; } - auto ref_addr = AddFixedObjectHandle(MethodCast(m), first_value.GetHeapObject()); - if (ref_addr == 0) { + auto refAddr = AddFixedObjectHandle(MethodCast(m), firstValue.GetHeapObject()); + if (refAddr == 0) { return false; } - return AddProfileInfo(m, profile, profile_type_info, slot + 1, ref_addr); + return AddProfileInfo(m, profile, profileTypeInfo, slot + 1, refAddr); } -inline ProfileTypeInfo *EcmaRuntimeInterface::GetProfileTypeInfo(PandaRuntimeInterface::MethodPtr m, uintptr_t slot_id, +inline ProfileTypeInfo *EcmaRuntimeInterface::GetProfileTypeInfo(PandaRuntimeInterface::MethodPtr m, uintptr_t slotId, uint8_t *slot) const { // ProfileTypeInfo is manage object // We need to have lock in caller method, because we return ProfileTypeInfo - ASSERT(ecma_vm_->GetMutatorLock()->HasLock()); + ASSERT(ecmaVm_->GetMutatorLock()->HasLock()); uint8_t *mapping = JsMethodCast(m)->GetICMapping(); if (mapping == nullptr) { return nullptr; } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *slot = mapping[slot_id]; + *slot = mapping[slotId]; if (auto func = GetJSFunctionByMethod(m); func != nullptr) { auto pti = func->GetProfileTypeInfo(); if (pti.IsHeapObject()) { @@ -566,36 +566,36 @@ inline ProfileTypeInfo *EcmaRuntimeInterface::GetProfileTypeInfo(PandaRuntimeInt return nullptr; } -inline ProfileTypeInfo *EcmaRuntimeInterface::GetProfileTypeInfo(uintptr_t func_address, uintptr_t slot_id, +inline ProfileTypeInfo *EcmaRuntimeInterface::GetProfileTypeInfo(uintptr_t funcAddress, uintptr_t slotId, uint8_t *slot) const { - ASSERT(func_address != 0); + ASSERT(funcAddress != 0); // ProfileTypeInfo is manage object // We need to have lock in caller method, because we return ProfileTypeInfo - ASSERT(ecma_vm_->GetMutatorLock()->HasLock()); + ASSERT(ecmaVm_->GetMutatorLock()->HasLock()); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto js_func = TaggedValue(reinterpret_cast(func_address)[0]); - if (!js_func.IsHeapObject()) { + auto jsFunc = TaggedValue(reinterpret_cast(funcAddress)[0]); + if (!jsFunc.IsHeapObject()) { return nullptr; } - auto func = JSFunction::Cast(js_func.GetHeapObject()); + auto func = JSFunction::Cast(jsFunc.GetHeapObject()); uint8_t *mapping = func->GetMethod()->GetICMapping(); if (mapping == nullptr) { return nullptr; } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *slot = mapping[slot_id]; - auto profile_info_obj = func->GetProfileTypeInfo(); - if (profile_info_obj.IsUndefined()) { + *slot = mapping[slotId]; + auto profileInfoObj = func->GetProfileTypeInfo(); + if (profileInfoObj.IsUndefined()) { return nullptr; } - return ProfileTypeInfo::Cast(profile_info_obj.GetTaggedObject()); + return ProfileTypeInfo::Cast(profileInfoObj.GetTaggedObject()); } template bool EcmaRuntimeInterface::GetProfileDataForNamedAccessImpl(PandaRuntimeInterface::MethodPtr m, Func func, - uintptr_t slot_id, + uintptr_t slotId, ArenaVector *profile) { if (profile == nullptr) { @@ -604,12 +604,12 @@ bool EcmaRuntimeInterface::GetProfileDataForNamedAccessImpl(PandaRuntimeInterfac profile->clear(); ScopedMutatorLock lock; uint8_t slot; - ProfileTypeInfo *profile_type_info = GetProfileTypeInfo(func, slot_id, &slot); - if (profile_type_info == nullptr) { + ProfileTypeInfo *profileTypeInfo = GetProfileTypeInfo(func, slotId, &slot); + if (profileTypeInfo == nullptr) { return false; } - if (AddProfileInfo(m, profile, profile_type_info, slot)) { - AddProfileInfo(m, profile, profile_type_info, slot + 2); + if (AddProfileInfo(m, profile, profileTypeInfo, slot)) { + AddProfileInfo(m, profile, profileTypeInfo, slot + 2); return true; } return false; @@ -617,7 +617,7 @@ bool EcmaRuntimeInterface::GetProfileDataForNamedAccessImpl(PandaRuntimeInterfac template bool EcmaRuntimeInterface::GetProfileDataForValueAccessImpl(PandaRuntimeInterface::MethodPtr m, Func func, - uintptr_t slot_id, + uintptr_t slotId, ArenaVector *profile) { if (profile == nullptr) { @@ -626,26 +626,26 @@ bool EcmaRuntimeInterface::GetProfileDataForValueAccessImpl(PandaRuntimeInterfac profile->clear(); ScopedMutatorLock lock; uint8_t slot; - ProfileTypeInfo *profile_type_info = GetProfileTypeInfo(func, slot_id, &slot); - if (profile_type_info == nullptr) { + ProfileTypeInfo *profileTypeInfo = GetProfileTypeInfo(func, slotId, &slot); + if (profileTypeInfo == nullptr) { return false; } - return AddProfileValueInfo(m, profile, profile_type_info, slot); + return AddProfileValueInfo(m, profile, profileTypeInfo, slot); } void EcmaRuntimeInterface::CleanFunction(Method *method) { os::memory::LockHolder lock(mutex_); - auto it = js_function_table_.find(method); - if (it == js_function_table_.end()) { + auto it = jsFunctionTable_.find(method); + if (it == jsFunctionTable_.end()) { return; } auto func = it->second; - js_function_table_.erase(it); - ASSERT(ecma_vm_ != nullptr); - ecma_vm_->GetGlobalObjectStorage()->Remove(func); + jsFunctionTable_.erase(it); + ASSERT(ecmaVm_ != nullptr); + ecmaVm_->GetGlobalObjectStorage()->Remove(func); } size_t EcmaRuntimeInterface::GetLexicalEnvParentEnvIndex() const @@ -665,10 +665,10 @@ size_t EcmaRuntimeInterface::GetTaggedArrayElementSize() const void EcmaRuntimeInterface::CleanObjectHandles(Method *method) { - os::memory::LockHolder lock(mutex_h_); - auto it = handles_by_method_table_.find(method); - auto gos = ecma_vm_->GetGlobalObjectStorage(); - if (it == handles_by_method_table_.end()) { + os::memory::LockHolder lock(mutexH_); + auto it = handlesByMethodTable_.find(method); + auto gos = ecmaVm_->GetGlobalObjectStorage(); + if (it == handlesByMethodTable_.end()) { return; } auto vector = it->second; @@ -676,21 +676,21 @@ void EcmaRuntimeInterface::CleanObjectHandles(Method *method) for (auto *ref : *vector) { gos->Remove(ref); } - handles_by_method_table_.erase(it); - internal_allocator_->template Delete(vector); + handlesByMethodTable_.erase(it); + internalAllocator_->template Delete(vector); } void EcmaRuntimeInterface::AddObjectHandle(Method *method, ObjectHeader *obj) { - os::memory::LockHolder lock(mutex_h_); - auto it = handles_by_method_table_.find(method); - auto gos = ecma_vm_->GetGlobalObjectStorage(); + os::memory::LockHolder lock(mutexH_); + auto it = handlesByMethodTable_.find(method); + auto gos = ecmaVm_->GetGlobalObjectStorage(); // Create new Vector for the method - if (it == handles_by_method_table_.end()) { - auto vector = internal_allocator_->template New>(); - auto func_ref = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL); - vector->push_back(func_ref); - handles_by_method_table_.insert({method, vector}); + if (it == handlesByMethodTable_.end()) { + auto vector = internalAllocator_->template New>(); + auto funcRef = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL); + vector->push_back(funcRef); + handlesByMethodTable_.insert({method, vector}); return; } auto vector = it->second; @@ -700,25 +700,25 @@ void EcmaRuntimeInterface::AddObjectHandle(Method *method, ObjectHeader *obj) return; } } - auto func_ref = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL); - vector->push_back(func_ref); + auto funcRef = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL); + vector->push_back(funcRef); } uintptr_t EcmaRuntimeInterface::AddFixedObjectHandle(Method *method, ObjectHeader *obj) { - os::memory::LockHolder lock(mutex_h_); - auto it = handles_by_method_table_.find(method); - auto gos = ecma_vm_->GetGlobalObjectStorage(); + os::memory::LockHolder lock(mutexH_); + auto it = handlesByMethodTable_.find(method); + auto gos = ecmaVm_->GetGlobalObjectStorage(); // Create new Vector for the method - if (it == handles_by_method_table_.end()) { - auto vector = internal_allocator_->template New>(); - auto func_ref = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL_FIXED); - if (func_ref == nullptr) { + if (it == handlesByMethodTable_.end()) { + auto vector = internalAllocator_->template New>(); + auto funcRef = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL_FIXED); + if (funcRef == nullptr) { return 0; } - vector->push_back(func_ref); - handles_by_method_table_.insert({method, vector}); - return gos->GetAddressForRef(func_ref); + vector->push_back(funcRef); + handlesByMethodTable_.insert({method, vector}); + return gos->GetAddressForRef(funcRef); } auto vector = it->second; // Find the object in the vector @@ -727,18 +727,18 @@ uintptr_t EcmaRuntimeInterface::AddFixedObjectHandle(Method *method, ObjectHeade return gos->GetAddressForRef(ref); } } - auto func_ref = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL_FIXED); - if (func_ref == nullptr) { + auto funcRef = gos->Add(obj, panda::mem::Reference::ObjectType::GLOBAL_FIXED); + if (funcRef == nullptr) { return 0; } - vector->push_back(func_ref); - return gos->GetAddressForRef(func_ref); + vector->push_back(funcRef); + return gos->GetAddressForRef(funcRef); } template PandaRuntimeInterface::GlobalVarInfo EcmaRuntimeInterface::GetGlobalVarInfoImpl(PandaRuntimeInterface::MethodPtr method, Func func, size_t id, - uintptr_t slot_id) const + uintptr_t slotId) const { auto thread = TryGetJSThread(); if (thread == nullptr) { @@ -771,11 +771,11 @@ PandaRuntimeInterface::GlobalVarInfo EcmaRuntimeInterface::GetGlobalVarInfoImpl( } uint8_t slot; - ProfileTypeInfo *profile_type_info = GetProfileTypeInfo(func, slot_id, &slot); - if (profile_type_info == nullptr) { + ProfileTypeInfo *profileTypeInfo = GetProfileTypeInfo(func, slotId, &slot); + if (profileTypeInfo == nullptr) { return {}; } - JSTaggedValue handler = profile_type_info->Get(slot); + JSTaggedValue handler = profileTypeInfo->Get(slot); if (!handler.IsHeapObject()) { return {}; } @@ -789,10 +789,10 @@ PandaRuntimeInterface::GlobalVarInfo EcmaRuntimeInterface::GetGlobalVarInfoImpl( JSThread *EcmaRuntimeInterface::TryGetJSThread() const { - if (ecma_vm_ == nullptr) { + if (ecmaVm_ == nullptr) { return nullptr; } - auto thread = ecma_vm_->GetJSThread(); + auto thread = ecmaVm_->GetJSThread(); if (thread == nullptr || !thread->IsThreadAlive()) { return nullptr; } @@ -802,21 +802,21 @@ JSThread *EcmaRuntimeInterface::TryGetJSThread() const std::pair EcmaRuntimeInterface::GetGlobalDictionaryEntry(JSThread *thread, MethodPtr method, size_t id) const { - auto panda_file = JsMethodCast(method)->GetPandaFile(); - JSTaggedValue constant_pool(JSTaggedValue::VALUE_HOLE); + auto pandaFile = JsMethodCast(method)->GetPandaFile(); + JSTaggedValue constantPool(JSTaggedValue::VALUE_HOLE); - auto func = [&](Program *p) { constant_pool = p->GetConstantPool(); }; - ecma_vm_->EnumerateProgram(func, panda_file->GetFilename()); - if (constant_pool.IsUndefined()) { + auto func = [&](Program *p) { constantPool = p->GetConstantPool(); }; + ecmaVm_->EnumerateProgram(func, pandaFile->GetFilename()); + if (constantPool.IsUndefined()) { return {nullptr, -1}; } - ASSERT(!constant_pool.IsHole()); + ASSERT(!constantPool.IsHole()); - JSTaggedValue key = ConstantPool::Cast(constant_pool.GetHeapObject())->GetObjectFromCache(id); - auto global_obj = thread->GetGlobalObject(); - auto js_obj = JSObject::Cast(global_obj.GetTaggedObject()); - TaggedArray *array = TaggedArray::Cast(js_obj->GetProperties().GetTaggedObject()); + JSTaggedValue key = ConstantPool::Cast(constantPool.GetHeapObject())->GetObjectFromCache(id); + auto globalObj = thread->GetGlobalObject(); + auto jsObj = JSObject::Cast(globalObj.GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(jsObj->GetProperties().GetTaggedObject()); if (array->GetLength() == 0) { return {nullptr, -1}; } @@ -829,22 +829,22 @@ JSFunction *EcmaRuntimeInterface::GetJSFunctionByMethod(PandaRuntimeInterface::M { // JSFunction is manage object // We need to have lock in caller method, because we return JSFunction - ASSERT(ecma_vm_->GetMutatorLock()->HasLock()); + ASSERT(ecmaVm_->GetMutatorLock()->HasLock()); os::memory::LockHolder lock(mutex_); - auto it = js_function_table_.find(MethodCast(m)); - if (it == js_function_table_.end()) { + auto it = jsFunctionTable_.find(MethodCast(m)); + if (it == jsFunctionTable_.end()) { return nullptr; } - auto func = JSFunction::Cast(ecma_vm_->GetGlobalObjectStorage()->Get(it->second)); + auto func = JSFunction::Cast(ecmaVm_->GetGlobalObjectStorage()->Get(it->second)); ASSERT(func->GetCallTarget() == MethodCast(m)); return func; } PandaRuntimeInterface::MethodPtr EcmaRuntimeInterface::GetMethodByIdAndSaveJsFunction( - PandaRuntimeInterface::MethodPtr parent_method, MethodId id) + PandaRuntimeInterface::MethodPtr parentMethod, MethodId id) { ScopedMutatorLock lock; - auto func = GetJSFunctionByMethod(parent_method); + auto func = GetJSFunctionByMethod(parentMethod); if (func == nullptr) { return nullptr; } @@ -853,9 +853,9 @@ PandaRuntimeInterface::MethodPtr EcmaRuntimeInterface::GetMethodByIdAndSaveJsFun auto method = target->GetCallTarget(); // Store JsFunction for recursive static inlining and futher optimizations - auto gos = ecma_vm_->GetGlobalObjectStorage(); - auto func_ref = gos->Add(JSTaggedValue(target).GetHeapObject(), panda::mem::Reference::ObjectType::GLOBAL); - AddFunctionInMap(method, func_ref); + auto gos = ecmaVm_->GetGlobalObjectStorage(); + auto funcRef = gos->Add(JSTaggedValue(target).GetHeapObject(), panda::mem::Reference::ObjectType::GLOBAL); + AddFunctionInMap(method, funcRef); return method; } @@ -870,12 +870,12 @@ void *EcmaRuntimeInterface::GetConstantPool(PandaRuntimeInterface::MethodPtr met return func->GetConstantPool().GetHeapObject(); } -void *EcmaRuntimeInterface::GetConstantPool(uintptr_t func_address) +void *EcmaRuntimeInterface::GetConstantPool(uintptr_t funcAddress) { - ASSERT(func_address != 0); + ASSERT(funcAddress != 0); ScopedMutatorLock lock; - auto js_func = JSTaggedValue(*reinterpret_cast(func_address)); - return JSFunction::Cast(js_func.GetHeapObject())->GetConstantPool().GetHeapObject(); + auto jsFunc = JSTaggedValue(*reinterpret_cast(funcAddress)); + return JSFunction::Cast(jsFunc.GetHeapObject())->GetConstantPool().GetHeapObject(); } } // namespace panda::ecmascript diff --git a/runtime/compiler/ecmascript_runtime_interface.h b/runtime/compiler/ecmascript_runtime_interface.h index 95b89263ec793630a3bc5f10c673d951d2f7a53b..1ccd93608b8b17596159b2c8cd4930e5044b7184 100644 --- a/runtime/compiler/ecmascript_runtime_interface.h +++ b/runtime/compiler/ecmascript_runtime_interface.h @@ -34,7 +34,7 @@ enum class ObjectFieldType : uint8_t { INVALID = 0, ELEMENTS, COUNT }; class EcmaRuntimeInterface : public PandaRuntimeInterface { public: - explicit EcmaRuntimeInterface(const EcmaVM *ecma_vm, mem::InternalAllocatorPtr internal_allocator); + explicit EcmaRuntimeInterface(const EcmaVM *ecmaVm, mem::InternalAllocatorPtr internalAllocator); ~EcmaRuntimeInterface() override; NO_COPY_SEMANTIC(EcmaRuntimeInterface); NO_MOVE_SEMANTIC(EcmaRuntimeInterface); @@ -46,7 +46,7 @@ public: size_t GetLanguageExtensionSize(Arch arch) const override; - std::string GetMethodFullName(MethodPtr method, [[maybe_unused]] bool with_signature) const override; + std::string GetMethodFullName(MethodPtr method, [[maybe_unused]] bool withSignature) const override; uint64_t DynamicCastDoubleToInt(double value, size_t bits) const override; @@ -158,15 +158,15 @@ public: return ClassCast(klass)->GetName(); } - MethodProfile GetMethodProfile(MethodPtr method, bool from_vector) const override; + MethodProfile GetMethodProfile(MethodPtr method, bool fromVector) const override; - BytecodeProfile GetBytecodeProfile(MethodProfile prof, const uint8_t *bc_inst, size_t pc) const override; + BytecodeProfile GetBytecodeProfile(MethodProfile prof, const uint8_t *bcInst, size_t pc) const override; - bool CanInlineLdStObjByIndex(const BytecodeInstruction *bc_inst, size_t pc, - MethodProfile method_profile) const override; + bool CanInlineLdStObjByIndex(const BytecodeInstruction *bcInst, size_t pc, + MethodProfile methodProfile) const override; profiling::CallKind GetCallProfile(MethodPtr method, uint32_t pc, ArenaVector *methods, - bool is_aot) override; + bool isAot) override; Expected AddProfile(std::string_view fname) override; @@ -175,51 +175,50 @@ public: return utf::Mutf8AsCString(JsMethodCast(method)->GetName().data); } - MethodPtr GetMethodByIdAndSaveJsFunction(MethodPtr parent_method, MethodId id) override; + MethodPtr GetMethodByIdAndSaveJsFunction(MethodPtr parentMethod, MethodId id) override; MethodPtr GetMethodFromFunction(uintptr_t function) const override { ScopedMutatorLock lock; - auto *js_func = *(reinterpret_cast(function)); - return js_func == nullptr ? nullptr : js_func->GetCallTarget(); + auto *jsFunc = *(reinterpret_cast(function)); + return jsFunc == nullptr ? nullptr : jsFunc->GetCallTarget(); } compiler::AnyBaseType GetProfilingAnyType(RuntimeInterface::BytecodeProfile profile, - const BytecodeInstruction *bc_inst, unsigned index, - profiling::AnyInputType *allowed_input_type, - bool *is_type_profiled) override; + const BytecodeInstruction *bcInst, unsigned index, + profiling::AnyInputType *allowedInputType, bool *isTypeProfiled) override; - compiler::AnyBaseType ResolveSpecialAnyTypeByConstant(coretypes::TaggedValue any_const) override; + compiler::AnyBaseType ResolveSpecialAnyTypeByConstant(coretypes::TaggedValue anyConst) override; size_t GetGlobalConstStringOffsetForAnyType(compiler::AnyBaseType type, Arch arch) const override; NewObjDynInfo GetNewObjDynInfo(uintptr_t ctor) const override; - bool GetProfileDataForNamedAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t slot_id, + bool GetProfileDataForNamedAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t slotId, ArenaVector *profile) override { - return GetProfileDataForNamedAccessImpl(m, m, slot_id, profile); + return GetProfileDataForNamedAccessImpl(m, m, slotId, profile); } - bool GetProfileDataForNamedAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t func_address, uintptr_t slot_id, + bool GetProfileDataForNamedAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t funcAddress, uintptr_t slotId, ArenaVector *profile) override { - return GetProfileDataForNamedAccessImpl(m, func_address, slot_id, profile); + return GetProfileDataForNamedAccessImpl(m, funcAddress, slotId, profile); } - bool GetProfileDataForValueAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t slot_id, + bool GetProfileDataForValueAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t slotId, ArenaVector *profile) override { - return GetProfileDataForValueAccessImpl(m, m, slot_id, profile); + return GetProfileDataForValueAccessImpl(m, m, slotId, profile); } - bool GetProfileDataForValueAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t func_address, uintptr_t slot_id, + bool GetProfileDataForValueAccess(PandaRuntimeInterface::MethodPtr m, uintptr_t funcAddress, uintptr_t slotId, ArenaVector *profile) override { - return GetProfileDataForValueAccessImpl(m, func_address, slot_id, profile); + return GetProfileDataForValueAccessImpl(m, funcAddress, slotId, profile); } - GlobalVarInfo GetGlobalVarInfo(MethodPtr method, uintptr_t id, uintptr_t slot_id) const override + GlobalVarInfo GetGlobalVarInfo(MethodPtr method, uintptr_t id, uintptr_t slotId) const override { - return GetGlobalVarInfoImpl(method, method, id, slot_id); + return GetGlobalVarInfoImpl(method, method, id, slotId); } - GlobalVarInfo GetGlobalVarInfo(MethodPtr method, uintptr_t func_address, uintptr_t id, - uintptr_t slot_id) const override + GlobalVarInfo GetGlobalVarInfo(MethodPtr method, uintptr_t funcAddress, uintptr_t id, + uintptr_t slotId) const override { - return GetGlobalVarInfoImpl(method, func_address, id, slot_id); + return GetGlobalVarInfoImpl(method, funcAddress, id, slotId); } void CleanFunction(Method *method); @@ -227,7 +226,7 @@ public: void AddFunctionInMap(Method *method, panda::mem::Reference *func) { os::memory::LockHolder lock(mutex_); - js_function_table_.insert({method, func}); + jsFunctionTable_.insert({method, func}); } void CleanObjectHandles(PandaRuntimeInterface::MethodPtr method) override @@ -246,7 +245,7 @@ public: } void *GetConstantPool(MethodPtr method) override; - void *GetConstantPool(uintptr_t func_address) override; + void *GetConstantPool(uintptr_t funcAddress) override; private: JSFunction *GetJSFunctionByMethod(PandaRuntimeInterface::MethodPtr m) const; @@ -255,20 +254,20 @@ private: void AddObjectHandle(Method *method, ObjectHeader *obj); uintptr_t AddFixedObjectHandle(Method *method, ObjectHeader *obj); bool AddProfileInfo(PandaRuntimeInterface::MethodPtr m, ArenaVector *profile, - ProfileTypeInfo *profile_type_info, uint8_t slot, uintptr_t key = 0); + ProfileTypeInfo *profileTypeInfo, uint8_t slot, uintptr_t key = 0); bool AddProfileValueInfo(PandaRuntimeInterface::MethodPtr m, ArenaVector *profile, - ProfileTypeInfo *profile_type_info, uint8_t slot); - bool AddElementInfo(ArenaVector *profile, ProfileTypeInfo *profile_type_info, uint8_t slot); - ProfileTypeInfo *GetProfileTypeInfo(PandaRuntimeInterface::MethodPtr m, uintptr_t slot_id, uint8_t *slot) const; - ProfileTypeInfo *GetProfileTypeInfo(uintptr_t func_address, uintptr_t slot_id, uint8_t *slot) const; + ProfileTypeInfo *profileTypeInfo, uint8_t slot); + bool AddElementInfo(ArenaVector *profile, ProfileTypeInfo *profileTypeInfo, uint8_t slot); + ProfileTypeInfo *GetProfileTypeInfo(PandaRuntimeInterface::MethodPtr m, uintptr_t slotId, uint8_t *slot) const; + ProfileTypeInfo *GetProfileTypeInfo(uintptr_t funcAddress, uintptr_t slotId, uint8_t *slot) const; template - bool GetProfileDataForNamedAccessImpl(PandaRuntimeInterface::MethodPtr m, Func func, uintptr_t slot_id, + bool GetProfileDataForNamedAccessImpl(PandaRuntimeInterface::MethodPtr m, Func func, uintptr_t slotId, ArenaVector *profile); template - bool GetProfileDataForValueAccessImpl(PandaRuntimeInterface::MethodPtr m, Func func, uintptr_t slot_id, + bool GetProfileDataForValueAccessImpl(PandaRuntimeInterface::MethodPtr m, Func func, uintptr_t slotId, ArenaVector *profile); template - GlobalVarInfo GetGlobalVarInfoImpl(MethodPtr method, Func func, uintptr_t id, uintptr_t slot_id) const; + GlobalVarInfo GetGlobalVarInfoImpl(MethodPtr method, Func func, uintptr_t id, uintptr_t slotId) const; size_t GetLexicalEnvParentEnvIndex() const override; @@ -280,13 +279,13 @@ private: std::pair GetGlobalDictionaryEntry(JSThread *thread, MethodPtr method, size_t id) const; private: - const EcmaVM *ecma_vm_ {nullptr}; - mem::InternalAllocatorPtr internal_allocator_; + const EcmaVM *ecmaVm_ {nullptr}; + mem::InternalAllocatorPtr internalAllocator_; panda::ecmascript::EcmaProfileContainer profile_; - PandaUnorderedMap js_function_table_ GUARDED_BY(mutex_); - PandaUnorderedMap *> handles_by_method_table_ GUARDED_BY(mutex_h_); + PandaUnorderedMap jsFunctionTable_ GUARDED_BY(mutex_); + PandaUnorderedMap *> handlesByMethodTable_ GUARDED_BY(mutexH_); mutable os::memory::Mutex mutex_; - mutable os::memory::Mutex mutex_h_; + mutable os::memory::Mutex mutexH_; }; } // namespace panda::ecmascript diff --git a/runtime/containers/containers_arraylist.cpp b/runtime/containers/containers_arraylist.cpp index 8f6d217adc2b9e3f176c4085159301bd62f3314a..a30e766b812520229793ab8195dea73cfda110b5 100644 --- a/runtime/containers/containers_arraylist.cpp +++ b/runtime/containers/containers_arraylist.cpp @@ -25,14 +25,14 @@ JSTaggedValue ContainersArrayList::ArrayListConstructor(EcmaRuntimeCallInfo *arg ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayList, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_target = builtins_common::GetNewTarget(argv); - if (new_target->IsUndefined()) { + JSHandle newTarget = builtins_common::GetNewTarget(argv); + if (newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } JSHandle constructor = builtins_common::GetConstructor(argv); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -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 handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = builtins_common::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 handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); return JSTaggedValue::Undefined(); } } // namespace panda::ecmascript::containers diff --git a/runtime/containers/containers_private.cpp b/runtime/containers/containers_private.cpp index b4de8302424ba09d61b0a722b6bce693e3c0d2e0..4068bb125e81903ade55c2f1c0c5b00d90518e01 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 handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle argv = builtins_common::GetCallArg(msg, 0); - JSHandle this_value(builtins_common::GetThis(msg)); + JSHandle thisValue(builtins_common::GetThis(msg)); uint32_t tag = 0; if (!JSTaggedValue::ToElementIndex(argv.GetTaggedValue(), &tag) || tag >= ContainerTag::END) { @@ -41,13 +41,13 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) case ContainerTag::ARRAY_LIST: { JSHandle key(factory->NewFromCanBeCompressString("ArrayListConstructor")); JSTaggedValue value = - FastRuntimeStub::GetPropertyByName(thread, this_value.GetTaggedValue(), key.GetTaggedValue()); + FastRuntimeStub::GetPropertyByName(thread, thisValue.GetTaggedValue(), key.GetTaggedValue()); if (value != JSTaggedValue::Undefined()) { res = value; } else { - JSHandle array_list = InitializeArrayList(thread); - SetFrozenConstructor(thread, this_value, "ArrayListConstructor", array_list); - res = array_list.GetTaggedValue(); + JSHandle arrayList = InitializeArrayList(thread); + SetFrozenConstructor(thread, thisValue, "ArrayListConstructor", arrayList); + res = arrayList.GetTaggedValue(); } break; } @@ -62,21 +62,21 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) } JSHandle ContainersPrivate::NewContainerConstructor(JSThread *thread, const JSHandle &prototype, - EcmaEntrypoint ctor_func, const char *name, int length) + EcmaEntrypoint ctorFunc, const char *name, int length) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle ctor = - factory->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_CONSTRUCTOR); + factory->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_CONSTRUCTOR); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSFunction::SetFunctionLength(thread, ctor, JSTaggedValue(length)); - JSHandle name_string(factory->NewFromCanBeCompressString(name)); - JSFunction::SetFunctionName(thread, JSHandle(ctor), name_string, + JSHandle nameString(factory->NewFromCanBeCompressString(name)); + JSFunction::SetFunctionName(thread, JSHandle(ctor), nameString, JSHandle(thread, JSTaggedValue::Undefined())); - JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); PropertyDescriptor descriptor1(thread, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread, prototype, constructor_key, descriptor1); + JSObject::DefineOwnProperty(thread, prototype, constructorKey, descriptor1); /* set "prototype" in constructor */ ctor->SetFunctionPrototype(thread, prototype.GetTaggedValue()); @@ -88,18 +88,18 @@ void ContainersPrivate::SetFrozenFunction(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); - JSHandle key_string(factory->NewFromCanBeCompressString(key)); - JSHandle function = NewFunction(thread, key_string, func, length); + JSHandle keyString(factory->NewFromCanBeCompressString(key)); + JSHandle function = NewFunction(thread, keyString, func, length); PropertyDescriptor descriptor(thread, JSHandle(function), false, false, false); - JSObject::DefineOwnProperty(thread, obj, key_string, descriptor); + JSObject::DefineOwnProperty(thread, obj, keyString, descriptor); } -void ContainersPrivate::SetFrozenConstructor(JSThread *thread, const JSHandle &obj, const char *key_char, +void ContainersPrivate::SetFrozenConstructor(JSThread *thread, const JSHandle &obj, const char *keyChar, JSHandle &value) { JSObject::PreventExtensions(thread, obj); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle key(factory->NewFromCanBeCompressString(key_char)); + JSHandle key(factory->NewFromCanBeCompressString(keyChar)); 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 base_function(function); - JSFunction::SetFunctionName(thread, base_function, key, thread->GlobalConstants()->GetHandledUndefined()); + JSHandle baseFunction(function); + JSFunction::SetFunctionName(thread, baseFunction, 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 func_name(factory->NewFromString(name)); + JSHandle funcName(factory->NewFromString(name)); JSHandle prefix = thread->GlobalConstants()->GetHandledGetString(); - JSFunction::SetFunctionName(thread, JSHandle(function), func_name, prefix); + JSFunction::SetFunctionName(thread, JSHandle(function), funcName, 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 name_string(factory->NewFromString(name)); - JSHandle base_function(function); - JSFunction::SetFunctionName(thread, base_function, name_string, thread->GlobalConstants()->GetHandledUndefined()); + JSHandle nameString(factory->NewFromString(name)); + JSHandle baseFunction(function); + JSFunction::SetFunctionName(thread, baseFunction, nameString, thread->GlobalConstants()->GetHandledUndefined()); PropertyDescriptor descriptor(thread, JSHandle::Cast(function), false, false, false); JSObject::DefineOwnProperty(thread, obj, symbol, descriptor); @@ -166,28 +166,26 @@ void ContainersPrivate::SetStringTagSymbol(JSThread *thread, const JSHandle ContainersPrivate::InitializeArrayList(JSThread *thread) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // ArrayList.prototype - JSHandle array_list_func_prototype = factory->NewEmptyJSObject(); - JSHandle array_list_func_prototype_value(array_list_func_prototype); + JSHandle arrayListFuncPrototype = factory->NewEmptyJSObject(); + JSHandle arrayListFuncPrototypeValue(arrayListFuncPrototype); // ArrayList.prototype_or_dynclass - JSHandle array_list_instance_dynclass = - factory->CreateDynClass(JSType::JS_ARRAY_LIST, array_list_func_prototype_value); + JSHandle arrayListInstanceDynclass = + factory->CreateDynClass(JSType::JS_ARRAY_LIST, arrayListFuncPrototypeValue); // ArrayList() = new Function() - 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()); + JSHandle arrayListFunction(NewContainerConstructor( + thread, arrayListFuncPrototype, ContainersArrayList::ArrayListConstructor, "ArrayList", FuncLength::ZERO)); + JSHandle(arrayListFunction)->SetFunctionPrototype(thread, arrayListInstanceDynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread, JSHandle(array_list_func_prototype), constructor_key, - array_list_function); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread, JSHandle(arrayListFuncPrototype), constructorKey, arrayListFunction); // ArrayList.prototype.add() - SetFrozenFunction(thread, array_list_func_prototype, "add", ContainersArrayList::Add, FuncLength::ONE); + SetFrozenFunction(thread, arrayListFuncPrototype, "add", ContainersArrayList::Add, FuncLength::ONE); - return array_list_function; + return arrayListFunction; } } // namespace panda::ecmascript::containers diff --git a/runtime/containers/containers_private.h b/runtime/containers/containers_private.h index acb7a72ee8c35e43e97679e52cbad367845d0ccb..4292187347bc8330e8306f9ad582d6d40a3258e1 100644 --- a/runtime/containers/containers_private.h +++ b/runtime/containers/containers_private.h @@ -46,12 +46,12 @@ public: private: static JSHandle NewContainerConstructor(JSThread *thread, const JSHandle &prototype, - EcmaEntrypoint ctor_func, const char *name, int length); + EcmaEntrypoint ctorFunc, 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 *key_char, + static void SetFrozenConstructor(JSThread *thread, const JSHandle &obj, const char *keyChar, 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 445aa8443b37f716bc7c7978a00373706139fd7d..0bcc9ee1f2e5877a2278fd318e07480e62fc8291 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 with_detail) +static void DumpHClass(JSThread *thread, const JSHClass *jshclass, std::ostream &os, bool withDetail) { 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 (with_detail && !attrs.IsNull()) { - LayoutInfo *layout_info = LayoutInfo::Cast(attrs.GetTaggedObject()); - layout_info->Dump(thread, os); + if (withDetail && !attrs.IsNull()) { + LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); + layoutInfo->Dump(thread, os); } os << " - Transitions :" << std::setw(DUMP_TYPE_OFFSET); JSTaggedValue transtions = jshclass->GetTransitions(); transtions.DumpTaggedValue(thread, os); os << "\n"; - if (with_detail && !transtions.IsNull()) { + if (withDetail && !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 fast_mode, std::ostream &os) +static void DumpAttr(const PropertyAttributes &attr, bool fastMode, std::ostream &os) { if (attr.IsAccessor()) { os << "(Accessor) "; @@ -381,7 +381,7 @@ static void DumpAttr(const PropertyAttributes &attr, bool fast_mode, std::ostrea os << " InlinedProps: " << attr.IsInlinedProps(); - if (fast_mode) { + if (fastMode) { os << " Order: " << std::dec << attr.GetOffset(); os << " SortedIndex: " << std::dec << attr.GetSortedIndex(); } else { @@ -392,8 +392,8 @@ static void DumpAttr(const PropertyAttributes &attr, bool fast_mode, std::ostrea // NOLINTNEXTLINE(readability-function-size) static void DumpObject(JSThread *thread, TaggedObject *obj, std::ostream &os) { - auto js_hclass = obj->GetClass(); - JSType type = js_hclass->GetObjectType(); + auto jsHclass = obj->GetClass(); + JSType type = jsHclass->GetObjectType(); switch (type) { case JSType::HCLASS: @@ -646,7 +646,7 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, std::ostream &os) break; } - DumpHClass(thread, js_hclass, os, false); + DumpHClass(thread, jsHclass, os, false); } void JSTaggedValue::DumpSpecialValue([[maybe_unused]] JSThread *thread, std::ostream &os) const @@ -681,9 +681,9 @@ void JSTaggedValue::DumpSpecialValue([[maybe_unused]] JSThread *thread, std::ost void JSTaggedValue::DumpHeapObjectType([[maybe_unused]] JSThread *thread, std::ostream &os) const { ASSERT(IsWeak() || IsHeapObject()); - bool is_weak = IsWeak(); - TaggedObject *obj = is_weak ? GetTaggedWeakRef() : GetTaggedObject(); - if (is_weak) { + bool isWeak = IsWeak(); + TaggedObject *obj = isWeak ? GetTaggedWeakRef() : GetTaggedObject(); + if (isWeak) { os << "----------Dump Weak Referent----------" << "\n"; } @@ -695,9 +695,9 @@ void JSTaggedValue::DumpHeapObjectType([[maybe_unused]] JSThread *thread, std::o } else { std::ostringstream address; address << obj; - PandaString addr_str = PandaString(address.str()); + PandaString addrStr = PandaString(address.str()); - os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[" + JSHClass::DumpJSType(type) + "(" + addr_str + ")]"; + os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[" + JSHClass::DumpJSType(type) + "(" + addrStr + ")]"; } } @@ -747,15 +747,15 @@ void JSThread::DumpStack() void NumberDictionary::Dump(JSThread *thread, std::ostream &os) const { int size = Size(); - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hash_index)); + JSTaggedValue val(GetValue(hashIndex)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << static_cast(JSTaggedNumber(key).GetNumber()) << ": "; val.DumpTaggedValue(thread, os); os << " "; - DumpAttr(GetAttributes(hash_index), false, os); + DumpAttr(GetAttributes(hashIndex), 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 hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hash_index)); + JSTaggedValue val(GetValue(hashIndex)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); DumpPropertyKey(key, os); os << ": "; val.DumpTaggedValue(thread, os); os << " "; - DumpAttr(GetAttributes(hash_index), false, os); + DumpAttr(GetAttributes(hashIndex), 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 hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hash_index)); + JSTaggedValue val(GetValue(hashIndex)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); DumpPropertyKey(key, os); os << " : "; val.DumpTaggedValue(thread, os); os << " "; - DumpAttr(GetAttributes(hash_index), false, os); + DumpAttr(GetAttributes(hashIndex), 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 hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); DumpPropertyKey(key, os); os << " : "; - GetValue(hash_index).DumpTaggedValue(thread, os); + GetValue(hashIndex).DumpTaggedValue(thread, os); os << " : "; - GetAttributes(hash_index).DumpTaggedValue(thread, os); + GetAttributes(hashIndex).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 hash_index = 0; hash_index < capacity; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); 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 hash_index = 0; hash_index < capacity; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hash_index)); + JSTaggedValue val(GetValue(hashIndex)); 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 *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); + 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); 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 hash_field = GetHashField(); - hash_field.D(); + JSTaggedValue hashField = GetHashField(); + hashField.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 global_const = thread->GlobalConstants(); + auto globalConst = 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 "; - global_const->GetEmptyString().Dump(thread, os); + globalConst->GetEmptyString().Dump(thread, os); os << " - EmptyTaggedQueue: "; GetEmptyTaggedQueue().GetTaggedValue().Dump(thread, os); os << " - PrototypeString: "; - global_const->GetPrototypeString().Dump(thread, os); + globalConst->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: "; - global_const->GetConstructorString().Dump(thread, os); + globalConst->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: "; - global_const->GetLengthString().Dump(thread, os); + globalConst->GetLengthString().Dump(thread, os); os << " - ValueString: "; - global_const->GetValueString().Dump(thread, os); + globalConst->GetValueString().Dump(thread, os); os << " - WritableString: "; - global_const->GetWritableString().Dump(thread, os); + globalConst->GetWritableString().Dump(thread, os); os << " - GetString: "; - global_const->GetGetString().Dump(thread, os); + globalConst->GetGetString().Dump(thread, os); os << " - SetString: "; - global_const->GetSetString().Dump(thread, os); + globalConst->GetSetString().Dump(thread, os); os << " - EnumerableString: "; - global_const->GetEnumerableString().Dump(thread, os); + globalConst->GetEnumerableString().Dump(thread, os); os << " - ConfigurableString: "; - global_const->GetConfigurableString().Dump(thread, os); + globalConst->GetConfigurableString().Dump(thread, os); os << " - NameString: "; - global_const->GetNameString().Dump(thread, os); + globalConst->GetNameString().Dump(thread, os); os << " - ValueOfString: "; - global_const->GetValueOfString().Dump(thread, os); + globalConst->GetValueOfString().Dump(thread, os); os << " - ToStringString: "; - global_const->GetToStringString().Dump(thread, os); + globalConst->GetToStringString().Dump(thread, os); os << " - ToLocaleStringString: "; - global_const->GetToLocaleStringString().Dump(thread, os); + globalConst->GetToLocaleStringString().Dump(thread, os); os << " - UndefinedString: "; - global_const->GetUndefinedString().Dump(thread, os); + globalConst->GetUndefinedString().Dump(thread, os); os << " - NullString: "; - global_const->GetNullString().Dump(thread, os); + globalConst->GetNullString().Dump(thread, os); os << " - TrueString: "; - global_const->GetTrueString().Dump(thread, os); + globalConst->GetTrueString().Dump(thread, os); os << " - FalseString: "; - global_const->GetFalseString().Dump(thread, os); + globalConst->GetFalseString().Dump(thread, os); os << " - RegisterSymbols: "; GetRegisterSymbols().GetTaggedValue().Dump(thread, os); os << " - ThrowTypeError: "; GetThrowTypeError().GetTaggedValue().Dump(thread, os); os << " - GetPrototypeOfString: "; - global_const->GetGetPrototypeOfString().Dump(thread, os); + globalConst->GetGetPrototypeOfString().Dump(thread, os); os << " - SetPrototypeOfString: "; - global_const->GetSetPrototypeOfString().Dump(thread, os); + globalConst->GetSetPrototypeOfString().Dump(thread, os); os << " - IsExtensibleString: "; - global_const->GetIsExtensibleString().Dump(thread, os); + globalConst->GetIsExtensibleString().Dump(thread, os); os << " - PreventExtensionsString: "; - global_const->GetPreventExtensionsString().Dump(thread, os); + globalConst->GetPreventExtensionsString().Dump(thread, os); os << " - GetOwnPropertyDescriptorString: "; - global_const->GetGetOwnPropertyDescriptorString().Dump(thread, os); + globalConst->GetGetOwnPropertyDescriptorString().Dump(thread, os); os << " - DefinePropertyString: "; - global_const->GetDefinePropertyString().Dump(thread, os); + globalConst->GetDefinePropertyString().Dump(thread, os); os << " - HasString: "; - global_const->GetHasString().Dump(thread, os); + globalConst->GetHasString().Dump(thread, os); os << " - DeletePropertyString: "; - global_const->GetDeletePropertyString().Dump(thread, os); + globalConst->GetDeletePropertyString().Dump(thread, os); os << " - EnumerateString: "; - global_const->GetEnumerateString().Dump(thread, os); + globalConst->GetEnumerateString().Dump(thread, os); os << " - OwnKeysString: "; - global_const->GetOwnKeysString().Dump(thread, os); + globalConst->GetOwnKeysString().Dump(thread, os); os << " - ApplyString: "; - global_const->GetApplyString().Dump(thread, os); + globalConst->GetApplyString().Dump(thread, os); os << " - ProxyString: "; - global_const->GetProxyString().Dump(thread, os); + globalConst->GetProxyString().Dump(thread, os); os << " - RevokeString: "; - global_const->GetRevokeString().Dump(thread, os); + globalConst->GetRevokeString().Dump(thread, os); os << " - ProxyConstructString: "; - global_const->GetProxyConstructString().Dump(thread, os); + globalConst->GetProxyConstructString().Dump(thread, os); os << " - ProxyCallString: "; - global_const->GetProxyCallString().Dump(thread, os); + globalConst->GetProxyCallString().Dump(thread, os); os << " - DoneString: "; - global_const->GetDoneString().Dump(thread, os); + globalConst->GetDoneString().Dump(thread, os); os << " - NegativeZeroString: "; - global_const->GetNegativeZeroString().Dump(thread, os); + globalConst->GetNegativeZeroString().Dump(thread, os); os << " - NextString: "; - global_const->GetNextString().Dump(thread, os); + globalConst->GetNextString().Dump(thread, os); os << " - PromiseThenString: "; - global_const->GetPromiseThenString().Dump(thread, os); + globalConst->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: "; - global_const->GetScriptJobString().Dump(thread, os); + globalConst->GetScriptJobString().Dump(thread, os); os << " - PromiseString: "; - global_const->GetPromiseString().Dump(thread, os); + globalConst->GetPromiseString().Dump(thread, os); os << " - IdentityString: "; - global_const->GetIdentityString().Dump(thread, os); + globalConst->GetIdentityString().Dump(thread, os); os << " - AsyncFunctionString: "; - global_const->GetAsyncFunctionString().Dump(thread, os); + globalConst->GetAsyncFunctionString().Dump(thread, os); os << " - ThrowerString: "; - global_const->GetThrowerString().Dump(thread, os); + globalConst->GetThrowerString().Dump(thread, os); os << " - Undefined: "; - global_const->GetUndefined().Dump(thread, os); + globalConst->GetUndefined().Dump(thread, os); } void JSDataView::Dump([[maybe_unused]] JSThread *thread, std::ostream &os) const @@ -2072,10 +2072,10 @@ static void DumpDynClass([[maybe_unused]] JSThread *thread, TaggedObject *obj, // NOLINTNEXTLINE(readability-function-size) static void DumpObject(JSThread *thread, TaggedObject *obj, std::vector> &vec, - bool is_vm_mode) + bool isVmMode) { - auto js_hclass = obj->GetClass(); - JSType type = js_hclass->GetObjectType(); + auto jsHclass = obj->GetClass(); + JSType type = jsHclass->GetObjectType(); switch (type) { case JSType::HCLASS: @@ -2276,7 +2276,7 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, std::vectorDumpForSnapshot(thread, vec); @@ -2318,8 +2318,8 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, std::vectorGetLength() == 0) { - PandaString empty_str = "EmptyString"; - res.append(empty_str); + PandaString emptyStr = "EmptyString"; + res.append(emptyStr); } PandaString string = ConvertToPandaString(str); @@ -2348,10 +2348,10 @@ static void KeyToStd(PandaString &res, JSTaggedValue key) } void JSTaggedValue::DumpForSnapshot(JSThread *thread, std::vector> &vec, - bool is_vm_mode) const + bool isVmMode) const { if (IsHeapObject()) { - return DumpObject(thread, GetTaggedObject(), vec, is_vm_mode); + return DumpObject(thread, GetTaggedObject(), vec, isVmMode); } UNREACHABLE(); @@ -2361,10 +2361,10 @@ void NumberDictionary::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { int size = Size(); - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val(GetValue(hash_index)); + JSTaggedValue val(GetValue(hashIndex)); 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 hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val(GetValue(hash_index)); + JSTaggedValue val(GetValue(hashIndex)); 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 hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { PandaString str; KeyToStd(str, key); - JSTaggedValue val = GetValue(hash_index); + JSTaggedValue val = GetValue(hashIndex); 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 hash_index = 0; hash_index < capacity; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); 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 hash_index = 0; hash_index < capacity; hash_index++) { - JSTaggedValue key(GetKey(hash_index)); + for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { + JSTaggedValue key(GetKey(hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val = GetValue(hash_index); + JSTaggedValue val = GetValue(hashIndex); 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 < prop_number; i++) { - JSTaggedValue key = layout_info->GetKey(i); - PropertyAttributes attr = layout_info->GetAttr(i); + LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); + int propNumber = jshclass->NumberOfProps(); + for (int i = 0; i < propNumber; i++) { + JSTaggedValue key = layoutInfo->GetKey(i); + PropertyAttributes attr = layoutInfo->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 global_const = thread->GlobalConstants(); + auto globalConst = 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())); @@ -2745,9 +2745,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"), global_const->GetEmptyString())); + vec.emplace_back(std::make_pair(PandaString("EmptyString"), globalConst->GetEmptyString())); vec.emplace_back(std::make_pair(PandaString("EmptyTaggedQueue"), GetEmptyTaggedQueue().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("PrototypeString"), global_const->GetPrototypeString())); + vec.emplace_back(std::make_pair(PandaString("PrototypeString"), globalConst->GetPrototypeString())); vec.emplace_back(std::make_pair(PandaString("HasInstanceSymbol"), GetHasInstanceSymbol().GetTaggedValue())); vec.emplace_back( std::make_pair(PandaString("IsConcatSpreadableSymbol"), GetIsConcatSpreadableSymbol().GetTaggedValue())); @@ -2761,7 +2761,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"), global_const->GetConstructorString())); + vec.emplace_back(std::make_pair(PandaString("ConstructorString"), globalConst->GetConstructorString())); vec.emplace_back(std::make_pair(PandaString("IteratorPrototype"), GetIteratorPrototype().GetTaggedValue())); vec.emplace_back( std::make_pair(PandaString("ForinIteratorPrototype"), GetForinIteratorPrototype().GetTaggedValue())); @@ -2774,54 +2774,53 @@ 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"), 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("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("RegisterSymbols"), GetRegisterSymbols().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("ThrowTypeError"), GetThrowTypeError().GetTaggedValue())); - 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("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("GetOwnPropertyDescriptorString"), - 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())); + 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())); 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"), 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())); + 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())); } void JSDataView::DumpForSnapshot([[maybe_unused]] JSThread *thread, diff --git a/runtime/ecma_call_profiling_table.cpp b/runtime/ecma_call_profiling_table.cpp index c50f5db2d9b357b44a753e322528c372c61c620e..ade57864c0ad53624239df09b6cc3b2bd4bebe76 100644 --- a/runtime/ecma_call_profiling_table.cpp +++ b/runtime/ecma_call_profiling_table.cpp @@ -23,9 +23,9 @@ EcmaCallProfilingTable::EcmaCallProfilingTable(uint32_t size) // We need to save std::numeric_limits::max() value to indentify MEGAMORPHIC profile // And we need to reserve first element in table to indentify UNKNOWN profile ASSERT(size <= std::numeric_limits::max() - 2U); - call_profiling_table_.resize(size + 1); - call_profiling_bit_map_.resize(size + 1); - call_profiling_bit_map_[0] = true; + callProfilingTable_.resize(size + 1); + callProfilingBitMap_.resize(size + 1); + callProfilingBitMap_[0] = true; } void EcmaCallProfilingTable::ClearObject([[maybe_unused]] uint16_t idx) @@ -33,48 +33,48 @@ void EcmaCallProfilingTable::ClearObject([[maybe_unused]] uint16_t idx) UNREACHABLE(); } -std::optional EcmaCallProfilingTable::InsertNewObject(ECMAObject *js_func) +std::optional EcmaCallProfilingTable::InsertNewObject(ECMAObject *jsFunc) { - os::memory::LockHolder holder(table_lock_); + os::memory::LockHolder holder(tableLock_); // find first free elem uint32_t idx = 1; - for (; idx < call_profiling_bit_map_.size(); idx++) { - if (!call_profiling_bit_map_[idx]) { + for (; idx < callProfilingBitMap_.size(); idx++) { + if (!callProfilingBitMap_[idx]) { break; } } - if (idx == call_profiling_bit_map_.size()) { - LOG(DEBUG, INTERPRETER) << "CallProfileTable: Table is full. Don't insert object " << std::hex << js_func; + if (idx == callProfilingBitMap_.size()) { + LOG(DEBUG, INTERPRETER) << "CallProfileTable: Table is full. Don't insert object " << std::hex << jsFunc; return std::nullopt; } ASSERT(idx != 0); - LOG(DEBUG, INTERPRETER) << "CallProfileTable: Insert object " << std::hex << js_func << std::dec << " in slot " + LOG(DEBUG, INTERPRETER) << "CallProfileTable: Insert object " << std::hex << jsFunc << std::dec << " in slot " << idx; - ASSERT(call_profiling_table_[idx] == nullptr); - call_profiling_bit_map_[idx] = true; - call_profiling_table_[idx] = js_func; + ASSERT(callProfilingTable_[idx] == nullptr); + callProfilingBitMap_[idx] = true; + callProfilingTable_[idx] = jsFunc; return idx; } ECMAObject *EcmaCallProfilingTable::GetObject(uint16_t idx) const { ASSERT(idx != 0); - os::memory::LockHolder holder(table_lock_); - return call_profiling_table_[idx]; + os::memory::LockHolder holder(tableLock_); + return callProfilingTable_[idx]; } uintptr_t EcmaCallProfilingTable::GetObjectPtr(uint16_t idx) const { ASSERT(idx != 0); - os::memory::LockHolder holder(table_lock_); - return reinterpret_cast(&call_profiling_table_[idx]); + os::memory::LockHolder holder(tableLock_); + return reinterpret_cast(&callProfilingTable_[idx]); } void EcmaCallProfilingTable::Sweep(const GCObjectVisitor &visitor) { - os::memory::LockHolder holder(table_lock_); - for (size_t i = 1; i < call_profiling_table_.size(); ++i) { - auto *object = call_profiling_table_[i]; + os::memory::LockHolder holder(tableLock_); + for (size_t i = 1; i < callProfilingTable_.size(); ++i) { + auto *object = callProfilingTable_[i]; if (object == nullptr) { continue; } @@ -82,23 +82,23 @@ void EcmaCallProfilingTable::Sweep(const GCObjectVisitor &visitor) if (visitor(object) == ObjectStatus::DEAD_OBJECT) { LOG(DEBUG, GC) << "CallProfileTable: delete js function " << std::hex << object << std::dec << " in slot " << i; - call_profiling_table_[i] = nullptr; + callProfilingTable_[i] = nullptr; } } } void EcmaCallProfilingTable::UpdateMoved() { - os::memory::LockHolder holder(table_lock_); - for (size_t i = 1; i < call_profiling_table_.size(); ++i) { - auto *object = call_profiling_table_[i]; + os::memory::LockHolder holder(tableLock_); + for (size_t i = 1; i < callProfilingTable_.size(); ++i) { + auto *object = callProfilingTable_[i]; if (object == nullptr) { continue; } if (object->IsForwarded()) { - ObjectHeader *fwd_object = panda::mem::GetForwardAddress(object); - call_profiling_table_[i] = static_cast(fwd_object); - LOG(DEBUG, GC) << "CallProfileTable: forward " << std::hex << object << " -> " << fwd_object << std::dec + ObjectHeader *fwdObject = panda::mem::GetForwardAddress(object); + callProfilingTable_[i] = static_cast(fwdObject); + LOG(DEBUG, GC) << "CallProfileTable: forward " << std::hex << object << " -> " << fwdObject << std::dec << " in slot " << i; } } @@ -106,9 +106,9 @@ void EcmaCallProfilingTable::UpdateMoved() void EcmaCallProfilingTable::VisitRoots(const GCRootVisitor &visitor) { - os::memory::LockHolder holder(table_lock_); - for (size_t i = 1; i < call_profiling_table_.size(); ++i) { - auto *object = call_profiling_table_[i]; + os::memory::LockHolder holder(tableLock_); + for (size_t i = 1; i < callProfilingTable_.size(); ++i) { + auto *object = callProfilingTable_[i]; if (object == nullptr) { continue; } diff --git a/runtime/ecma_call_profiling_table.h b/runtime/ecma_call_profiling_table.h index 4e4bdbf62c1f1e0cb6e2469142beff208a98cb3e..ef442da352c96182f462fb0c311031c75a3076f3 100644 --- a/runtime/ecma_call_profiling_table.h +++ b/runtime/ecma_call_profiling_table.h @@ -28,7 +28,7 @@ public: explicit EcmaCallProfilingTable(uint32_t size); ~EcmaCallProfilingTable() = default; - std::optional InsertNewObject(ECMAObject *js_func); + std::optional InsertNewObject(ECMAObject *jsFunc); void ClearObject(uint16_t idx); ECMAObject *GetObject(uint16_t idx) const; uintptr_t GetObjectPtr(uint16_t idx) const; @@ -41,9 +41,9 @@ private: NO_MOVE_SEMANTIC(EcmaCallProfilingTable); private: - PandaVector call_profiling_table_ GUARDED_BY(table_lock_); - PandaVector call_profiling_bit_map_ GUARDED_BY(table_lock_); - mutable os::memory::Mutex table_lock_; + PandaVector callProfilingTable_ GUARDED_BY(tableLock_); + PandaVector callProfilingBitMap_ GUARDED_BY(tableLock_); + mutable os::memory::Mutex tableLock_; }; } // namespace panda::ecmascript diff --git a/runtime/ecma_class_linker_extension.cpp b/runtime/ecma_class_linker_extension.cpp index 96751814a7a48ff7b1fa73769e286c07e25344d6..587be0611eb9f902e74408aec42e13012890b13d 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 cmp_str_enabled) +bool EcmaClassLinkerExtension::InitializeImpl([[maybe_unused]] bool cmpStrEnabled) { return true; } @@ -44,39 +44,39 @@ void EcmaClassLinkerExtension::InitClasses(EcmaVM *vm) LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(GetLanguage()); [[maybe_unused]] EcmaHandleScope scope(vm->GetJSThread()); - auto *class_class = NewClass(ctx.GetClassClassDescriptor(), 0, 0, GetClassSize(ClassRoot::CLASS)); - if (class_class == nullptr) { + auto *classClass = NewClass(ctx.GetClassClassDescriptor(), 0, 0, GetClassSize(ClassRoot::CLASS)); + if (classClass == nullptr) { return; } - class_class->SetObjectSize(ObjectHeader::ObjectHeaderSize()); - class_class->SetState(Class::State::LOADED); - Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::CLASS, class_class); + classClass->SetObjectSize(ObjectHeader::ObjectHeaderSize()); + classClass->SetState(Class::State::LOADED); + Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::CLASS, classClass); - auto *obj_class = NewClass(ctx.GetObjectClassDescriptor(), 0, 0, GetClassSize(ClassRoot::OBJECT)); - if (obj_class == nullptr) { + auto *objClass = NewClass(ctx.GetObjectClassDescriptor(), 0, 0, GetClassSize(ClassRoot::OBJECT)); + if (objClass == nullptr) { return; } - obj_class->SetObjectSize(TaggedObject::TaggedObjectSize()); - obj_class->SetState(Class::State::LOADED); - Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::OBJECT, obj_class); + objClass->SetObjectSize(TaggedObject::TaggedObjectSize()); + objClass->SetState(Class::State::LOADED); + Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::OBJECT, objClass); } ClassLinkerContext *EcmaClassLinkerExtension::CreateApplicationClassLinkerContext(const PandaVector &path) { - PandaVector app_files; - app_files.reserve(path.size()); + PandaVector appFiles; + appFiles.reserve(path.size()); for (auto &p : path) { auto pf = panda_file::OpenPandaFileOrZip(p, panda_file::File::READ_WRITE); if (pf == nullptr) { return nullptr; } - app_files.push_back(std::move(pf)); + appFiles.push_back(std::move(pf)); } - return ClassLinkerExtension::CreateApplicationClassLinkerContext(std::move(app_files)); + return ClassLinkerExtension::CreateApplicationClassLinkerContext(std::move(appFiles)); } -Class *EcmaClassLinkerExtension::NewClass(const uint8_t *descriptor, size_t vtable_size, size_t imt_size, - size_t class_size) +Class *EcmaClassLinkerExtension::NewClass(const uint8_t *descriptor, size_t vtableSize, size_t imtSize, + size_t classSize) { ASSERT(IsInitialized()); if (vm_ == nullptr) { @@ -105,20 +105,20 @@ Class *EcmaClassLinkerExtension::NewClass(const uint8_t *descriptor, size_t vtab return nullptr; } // We must cover the whole panda::Class by the native_field_mask - ASSERT(class_size < std::numeric_limits::digits * sizeof(JSTaggedType)); - JSHClass *hclass_ptr = reinterpret_cast(hclass.GetTaggedValue().GetTaggedObject()); - hclass_ptr->SetObjectSize(ObjectHeader::ObjectHeaderSize() + class_size); - hclass_ptr->GetHClass()->SetNativeFieldMask(std::numeric_limits::max()); + ASSERT(classSize < std::numeric_limits::digits * sizeof(JSTaggedType)); + JSHClass *hclassPtr = reinterpret_cast(hclass.GetTaggedValue().GetTaggedObject()); + hclassPtr->SetObjectSize(ObjectHeader::ObjectHeaderSize() + classSize); + hclassPtr->GetHClass()->SetNativeFieldMask(std::numeric_limits::max()); // All fields must be set before call SetClass to make TSAN happy. // The intstance of this HClass may be read by update remset thread. // The thread skips the object if this class is null. - hclass_ptr->SetClassWithoutBarrier(hclass_ptr); + hclassPtr->SetClassWithoutBarrier(hclassPtr); - JSHandle klass_obj(vm_->GetJSThread(), factory->NewNonMovableDynObject(hclass)); + JSHandle klassObj(vm_->GetJSThread(), factory->NewNonMovableDynObject(hclass)); auto *klass = - reinterpret_cast(ToUintPtr(klass_obj.GetObject()) + ObjectHeader::ObjectHeaderSize()); - new (klass) Class(descriptor, panda_file::SourceLang::ECMASCRIPT, vtable_size, imt_size, class_size); - klass->SetManagedObject(klass_obj.GetObject()); + reinterpret_cast(ToUintPtr(klassObj.GetObject()) + ObjectHeader::ObjectHeaderSize()); + new (klass) Class(descriptor, panda_file::SourceLang::ECMASCRIPT, vtableSize, imtSize, classSize); + klass->SetManagedObject(klassObj.GetObject()); AddCreatedClass(klass); return klass; } diff --git a/runtime/ecma_class_linker_extension.h b/runtime/ecma_class_linker_extension.h index 167a81c07fb5dcb77ba81c44cfc6dac05d1dd53a..944325dfb0d4ec1306ebdbf816782a6e756593c6 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 *component_class) override + bool InitializeArrayClass([[maybe_unused]] Class *arrayClass, [[maybe_unused]] Class *componentClass) override { return true; } - void InitializePrimitiveClass([[maybe_unused]] Class *primitive_class) override {} + void InitializePrimitiveClass([[maybe_unused]] Class *primitiveClass) 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 vtable_size, size_t imt_size, + Class *CreateClass([[maybe_unused]] const uint8_t *descriptor, [[maybe_unused]] size_t vtableSize, size_t imtSize, [[maybe_unused]] size_t size) override { - return NewClass(descriptor, vtable_size, imt_size, size); + return NewClass(descriptor, vtableSize, imtSize, size); } bool InitializeClass([[maybe_unused]] Class *klass) override @@ -103,8 +103,8 @@ public: void FreeClass(Class *klass) override; private: - bool InitializeImpl(bool cmp_str_enabled) override; - Class *NewClass(const uint8_t *descriptor, size_t vtable_size, size_t imt_size, size_t size); + bool InitializeImpl(bool cmpStrEnabled) override; + Class *NewClass(const uint8_t *descriptor, size_t vtableSize, size_t imtSize, size_t size); EcmaVM *vm_ {nullptr}; }; diff --git a/runtime/ecma_compiler.cpp b/runtime/ecma_compiler.cpp index 69d8dc9be619443e6b26191df81ac0021a03d6de..fd82c5d19c95be03d8212f746c2496a996bfd6fb 100644 --- a/runtime/ecma_compiler.cpp +++ b/runtime/ecma_compiler.cpp @@ -31,9 +31,9 @@ void EcmaCompiler::AddTask(CompilerTask &&task, TaggedValue func) if (auto stack = StackWalker::Create(GetJSThread()); !stack.IsCFrame()) { auto frame = stack.GetIFrame(); if (frame != nullptr && !frame->GetMethod()->IsNative()) { - auto curr_func = JSFunction::Cast(JSFrame::GetJSEnv(frame)->GetThisFunc()); - if (curr_func->GetMethod() == task.GetMethod()) { - func = TaggedValue(curr_func); + auto currFunc = JSFunction::Cast(JSFrame::GetJSEnv(frame)->GetThisFunc()); + if (currFunc->GetMethod() == task.GetMethod()) { + func = TaggedValue(currFunc); } } } @@ -44,8 +44,8 @@ void EcmaCompiler::AddTask(CompilerTask &&task, TaggedValue func) if (!func.IsHole()) { ASSERT(JSFunction::Cast(func.GetHeapObject())->GetCallTarget() == task.GetMethod()); auto gos = task.GetVM()->GetGlobalObjectStorage(); - auto func_ref = gos->Add(func.GetHeapObject(), panda::mem::Reference::ObjectType::GLOBAL); - static_cast(GetRuntimeInterface())->AddFunctionInMap(task.GetMethod(), func_ref); + auto funcRef = gos->Add(func.GetHeapObject(), panda::mem::Reference::ObjectType::GLOBAL); + static_cast(GetRuntimeInterface())->AddFunctionInMap(task.GetMethod(), funcRef); } Compiler::AddTask(std::move(task), func); } diff --git a/runtime/ecma_compiler.h b/runtime/ecma_compiler.h index 01e0d7629964e71db486dc059f610bcc51ef9df7..eecb6f4bfa00a99c1aca99d96381d5a7a8d954a1 100644 --- a/runtime/ecma_compiler.h +++ b/runtime/ecma_compiler.h @@ -25,10 +25,10 @@ class JSThread; class EcmaCompiler : public Compiler { public: - explicit EcmaCompiler(CodeAllocator *code_allocator, mem::InternalAllocatorPtr internal_allocator, - const RuntimeOptions &options, mem::MemStatsType *mem_stats, - compiler::RuntimeInterface *runtime_iface) - : Compiler(code_allocator, internal_allocator, options, mem_stats, runtime_iface) + explicit EcmaCompiler(CodeAllocator *codeAllocator, mem::InternalAllocatorPtr internalAllocator, + const RuntimeOptions &options, mem::MemStatsType *memStats, + compiler::RuntimeInterface *runtimeIface) + : Compiler(codeAllocator, internalAllocator, options, memStats, runtimeIface) { } diff --git a/runtime/ecma_entrypoints.cpp b/runtime/ecma_entrypoints.cpp index ba86c05dd4ecf161667a918dcf97ebe106b4e92d..e47d293caf176468f2b9062b724b9eca78d0f261 100644 --- a/runtime/ecma_entrypoints.cpp +++ b/runtime/ecma_entrypoints.cpp @@ -25,16 +25,16 @@ extern "C" uintptr_t JSGetGlobalVarAddress(uint64_t cp, uint32_t id) { auto thread = JSThread::GetCurrent(); JSTaggedValue key = ConstantPool::Cast(cp)->GetObjectFromCache(id); - auto global_obj = thread->GetGlobalObject(); + auto globalObj = thread->GetGlobalObject(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle global_handle(thread, global_obj); - ObjectOperator op(thread, global_obj, key); + JSHandle globalHandle(thread, globalObj); + ObjectOperator op(thread, globalObj, key); auto res = op.GetValue(); if (res.IsUndefined() || !res.IsPropertyBox()) { PropertyAttributes attributes = PropertyAttributes::Default(true, true, false); // Reread key because GC can move it in ctor of ObjectOperator - JSHandle key_handle(thread, ConstantPool::Cast(cp)->GetObjectFromCache(id)); - op.AddProperty(global_handle, key_handle, attributes); + JSHandle keyHandle(thread, ConstantPool::Cast(cp)->GetObjectFromCache(id)); + op.AddProperty(globalHandle, keyHandle, attributes); res = op.GetValue(); } ASSERT(res.IsPropertyBox()); @@ -47,14 +47,14 @@ extern "C" void ThrowDerivedCtorTypeErrorSlowPath() SlowRuntimeStub::ThrowTypeError(thread, "Derived constructor must return object or undefined"); } -extern "C" uint64_t AllocDynObjectSlowPath(uint64_t ctor_raw) +extern "C" uint64_t AllocDynObjectSlowPath(uint64_t ctorRaw) { auto thread = JSThread::GetCurrent(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle ctor(thread, JSTaggedValue(ctor_raw)); - JSHandle new_tgt(thread, JSTaggedValue(ctor_raw)); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle ctor(thread, JSTaggedValue(ctorRaw)); + JSHandle newTgt(thread, JSTaggedValue(ctorRaw)); ASSERT(!ctor->IsBuiltinConstructor() && ctor->IsBase()); - return thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(ctor, new_tgt).GetTaggedValue().GetRawData(); + return thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(ctor, newTgt).GetTaggedValue().GetRawData(); } } // namespace panda::ecmascript diff --git a/runtime/ecma_exceptions.cpp b/runtime/ecma_exceptions.cpp index 387b93f8446ab8b6d442d8bdee27479a21bedee3..0db235882bbcc4d9770935ab2f4f5914bd8ad0a7 100644 --- a/runtime/ecma_exceptions.cpp +++ b/runtime/ecma_exceptions.cpp @@ -31,21 +31,21 @@ void SetException(JSThread *thread, JSObject *error) void ThrowException(JSThread *thread, const char *name, const char *msg) { - auto js_thread = static_cast(thread); - [[maybe_unused]] EcmaHandleScope handle_scope(js_thread); - ObjectFactory *factory = js_thread->GetEcmaVM()->GetFactory(); + auto jsThread = static_cast(thread); + [[maybe_unused]] EcmaHandleScope handleScope(jsThread); + ObjectFactory *factory = jsThread->GetEcmaVM()->GetFactory(); if (std::strcmp(name, REFERENCE_ERROR_STRING) == 0) { - SetException(js_thread, *factory->GetJSError(base::ErrorType::REFERENCE_ERROR, msg)); + SetException(jsThread, *factory->GetJSError(base::ErrorType::REFERENCE_ERROR, msg)); return; } if (std::strcmp(name, TYPE_ERROR_STRING) == 0) { - SetException(js_thread, *factory->GetJSError(base::ErrorType::TYPE_ERROR, msg)); + SetException(jsThread, *factory->GetJSError(base::ErrorType::TYPE_ERROR, msg)); return; } if (std::strcmp(name, RANGE_ERROR_STRING) == 0) { - SetException(js_thread, *factory->GetJSError(base::ErrorType::RANGE_ERROR, msg)); + SetException(jsThread, *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 709a5c6db48145820ccfae71b0602a8d3d3d3c8e..249237e9769c6f764261a16ec4831c90eea828ee 100644 --- a/runtime/ecma_global_storage-inl.h +++ b/runtime/ecma_global_storage-inl.h @@ -29,16 +29,16 @@ EcmaGlobalStorage::Node *EcmaGlobalStorage::NodeList::NewNode(JSTaggedType value if (IsFull()) { return nullptr; } - Node *node = &node_list_[index_++]; + Node *node = &nodeList_[index_++]; node->SetPrev(nullptr); - node->SetNext(used_list_); + node->SetNext(usedList_); node->SetObject(value); node->SetFree(false); - if (used_list_ != nullptr) { - used_list_->SetPrev(node); + if (usedList_ != nullptr) { + usedList_->SetPrev(node); } - used_list_ = node; + usedList_ = node; return node; } @@ -50,35 +50,35 @@ void EcmaGlobalStorage::NodeList::FreeNode(EcmaGlobalStorage::Node *node) if (node->GetNext() != nullptr) { node->GetNext()->SetPrev(node->GetPrev()); } - if (node == used_list_) { - used_list_ = node->GetNext(); + if (node == usedList_) { + usedList_ = node->GetNext(); } node->SetPrev(nullptr); - node->SetNext(free_list_); + node->SetNext(freeList_); node->SetObject(JSTaggedValue::Undefined().GetRawData()); node->SetFree(true); - if (free_list_ != nullptr) { - free_list_->SetPrev(node); + if (freeList_ != nullptr) { + freeList_->SetPrev(node); } - free_list_ = node; + freeList_ = node; } EcmaGlobalStorage::Node *EcmaGlobalStorage::NodeList::GetFreeNode(JSTaggedType value) { - Node *node = free_list_; + Node *node = freeList_; if (node != nullptr) { - free_list_ = node->GetNext(); + freeList_ = node->GetNext(); node->SetPrev(nullptr); - node->SetNext(used_list_); + node->SetNext(usedList_); node->SetObject(value); node->SetFree(false); - if (used_list_ != nullptr) { - used_list_->SetPrev(node); + if (usedList_ != nullptr) { + usedList_->SetPrev(node); } - used_list_ = node; + usedList_ = node; } return node; } @@ -98,22 +98,22 @@ void EcmaGlobalStorage::NodeList::RemoveList() if (prev_ != nullptr) { prev_->SetNext(next_); } - if (free_next_ != nullptr) { - free_next_->SetFreePrev(free_prev_); + if (freeNext_ != nullptr) { + freeNext_->SetFreePrev(freePrev_); } - if (free_prev_ != nullptr) { - free_prev_->SetFreeNext(free_next_); + if (freePrev_ != nullptr) { + freePrev_->SetFreeNext(freeNext_); } } -uintptr_t EcmaGlobalStorage::NewGlobalHandleImplement(NodeList **storage, NodeList **free_list, bool is_weak, +uintptr_t EcmaGlobalStorage::NewGlobalHandleImplement(NodeList **storage, NodeList **freeList, bool isWeak, JSTaggedType value) { auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - if (*free_list == nullptr) { + if (*freeList == nullptr) { if ((*storage)->IsFull()) { // alloc new block - auto block = allocator->New(is_weak); + auto block = allocator->New(isWeak); block->LinkTo(*storage); *storage = block; } @@ -129,29 +129,29 @@ uintptr_t EcmaGlobalStorage::NewGlobalHandleImplement(NodeList **storage, NodeLi } // use free_list node - node = (*free_list)->GetFreeNode(value); + node = (*freeList)->GetFreeNode(value); ASSERT(node != nullptr); - if (!(*free_list)->HasFreeNode()) { - auto next = (*free_list)->GetFreeNext(); - (*free_list)->SetFreeNext(nullptr); - (*free_list)->SetFreePrev(nullptr); + if (!(*freeList)->HasFreeNode()) { + auto next = (*freeList)->GetFreeNext(); + (*freeList)->SetFreeNext(nullptr); + (*freeList)->SetFreePrev(nullptr); if (next != nullptr) { next->SetFreePrev(nullptr); } - *free_list = next; + *freeList = next; } return node->GetObjectAddress(); } inline uintptr_t EcmaGlobalStorage::NewGlobalHandle(JSTaggedType value) { - return NewGlobalHandleImplement(&last_global_nodes_, &free_list_nodes_, false, value); + return NewGlobalHandleImplement(&lastGlobalNodes_, &freeListNodes_, false, value); } -inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t node_addr) +inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t nodeAddr) { auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - Node *node = reinterpret_cast(node_addr); + Node *node = reinterpret_cast(nodeAddr); if (node->IsFree()) { return; } @@ -159,22 +159,22 @@ inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t node_addr) list->FreeNode(node); // If NodeList has no usage node, then delete NodeList - NodeList **free_list = nullptr; + NodeList **freeList = nullptr; NodeList **top = nullptr; NodeList **last = nullptr; if (list->IsWeak()) { - free_list = &weak_free_list_nodes_; - top = &top_weak_global_nodes_; - last = &last_weak_global_nodes_; + freeList = &weakFreeListNodes_; + top = &topWeakGlobalNodes_; + last = &lastWeakGlobalNodes_; } else { - free_list = &free_list_nodes_; - top = &top_global_nodes_; - last = &last_global_nodes_; + freeList = &freeListNodes_; + top = &topGlobalNodes_; + last = &lastGlobalNodes_; } if (!list->HasUsagedNode() && (*top != *last)) { list->RemoveList(); - if (*free_list == list) { - *free_list = list->GetNext(); + if (*freeList == list) { + *freeList = list->GetNext(); } if (*top == list) { *top = list->GetNext(); @@ -185,21 +185,21 @@ inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t node_addr) allocator->Delete(list); } else { // Add to free_list - if (list != *free_list && list->GetFreeNext() == nullptr && list->GetFreePrev() == nullptr) { - list->SetFreeNext(*free_list); - if (*free_list != nullptr) { - (*free_list)->SetFreePrev(list); + if (list != *freeList && list->GetFreeNext() == nullptr && list->GetFreePrev() == nullptr) { + list->SetFreeNext(*freeList); + if (*freeList != nullptr) { + (*freeList)->SetFreePrev(list); } - *free_list = list; + *freeList = list; } } } -inline uintptr_t EcmaGlobalStorage::SetWeak(uintptr_t node_addr) +inline uintptr_t EcmaGlobalStorage::SetWeak(uintptr_t nodeAddr) { - auto value = reinterpret_cast(node_addr)->GetObject(); - DisposeGlobalHandle(node_addr); - return NewGlobalHandleImplement(&last_weak_global_nodes_, &weak_free_list_nodes_, true, value); + auto value = reinterpret_cast(nodeAddr)->GetObject(); + DisposeGlobalHandle(nodeAddr); + return NewGlobalHandleImplement(&lastWeakGlobalNodes_, &weakFreeListNodes_, true, value); } inline bool EcmaGlobalStorage::IsWeak(uintptr_t addr) const diff --git a/runtime/ecma_global_storage.h b/runtime/ecma_global_storage.h index 30aaba53d06fc3e75669aad5842324ae693ccf7c..0d8389a37397365d121f26ad31fa8e9a826f630b 100644 --- a/runtime/ecma_global_storage.h +++ b/runtime/ecma_global_storage.h @@ -27,14 +27,14 @@ public: explicit EcmaGlobalStorage() { auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - top_global_nodes_ = last_global_nodes_ = allocator->New(false); - top_weak_global_nodes_ = last_weak_global_nodes_ = allocator->New(true); + topGlobalNodes_ = lastGlobalNodes_ = allocator->New(false); + topWeakGlobalNodes_ = lastWeakGlobalNodes_ = allocator->New(true); } ~EcmaGlobalStorage() { auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - NodeList *next = top_global_nodes_; + NodeList *next = topGlobalNodes_; NodeList *current = nullptr; while (next != nullptr) { current = next; @@ -42,7 +42,7 @@ public: allocator->Delete(current); } - next = top_weak_global_nodes_; + next = topWeakGlobalNodes_; while (next != nullptr) { current = next; next = current->GetNext(); @@ -94,12 +94,12 @@ public: void SetFree(bool free) { - is_free_ = free; + isFree_ = free; } bool IsFree() const { - return is_free_; + return isFree_; } uintptr_t GetObjectAddress() const @@ -112,15 +112,15 @@ public: Node *next_ {nullptr}; Node *prev_ {nullptr}; int32_t index_ {-1}; - bool is_free_ {false}; + bool isFree_ {false}; }; class NodeList { public: - explicit NodeList(bool is_weak) : is_weak_(is_weak) + explicit NodeList(bool isWeak) : isWeak_(isWeak) { for (int i = 0; i < GLOBAL_BLOCK_SIZE; i++) { - node_list_[i].SetIndex(i); + nodeList_[i].SetIndex(i); } } ~NodeList() = default; @@ -141,17 +141,17 @@ public: inline bool IsWeak() { - return is_weak_; + return isWeak_; } inline bool HasFreeNode() { - return free_list_ != nullptr; + return freeList_ != nullptr; } inline bool HasUsagedNode() { - return !IsFull() || used_list_ != nullptr; + return !IsFull() || usedList_ != nullptr; } inline void SetNext(NodeList *next) @@ -174,26 +174,26 @@ public: inline void SetFreeNext(NodeList *next) { - free_next_ = next; + freeNext_ = next; } inline NodeList *GetFreeNext() const { - return free_next_; + return freeNext_; } inline void SetFreePrev(NodeList *prev) { - free_prev_ = prev; + freePrev_ = prev; } inline NodeList *GetFreePrev() const { - return free_prev_; + return freePrev_; } template inline void IterateUsageGlobal(Callback callback) { - Node *next = used_list_; + Node *next = usedList_; Node *current = nullptr; while (next != nullptr) { current = next; @@ -207,15 +207,15 @@ public: DEFAULT_COPY_SEMANTIC(NodeList); private: - std::array node_list_; // all - Node *free_list_ {nullptr}; // dispose node - Node *used_list_ {nullptr}; // usage node + std::array nodeList_; // all + Node *freeList_ {nullptr}; // dispose node + Node *usedList_ {nullptr}; // usage node int32_t index_ {0}; - bool is_weak_ {false}; + bool isWeak_ {false}; NodeList *next_ {nullptr}; NodeList *prev_ {nullptr}; - NodeList *free_next_ {nullptr}; - NodeList *free_prev_ {nullptr}; + NodeList *freeNext_ {nullptr}; + NodeList *freePrev_ {nullptr}; }; inline uintptr_t NewGlobalHandle(JSTaggedType value); @@ -226,7 +226,7 @@ public: template void IterateUsageGlobal(Callback callback) { - NodeList *next = top_global_nodes_; + NodeList *next = topGlobalNodes_; NodeList *current = nullptr; while (next != nullptr) { current = next; @@ -239,7 +239,7 @@ public: template void IterateWeakUsageGlobal(Callback callback) { - NodeList *next = top_weak_global_nodes_; + NodeList *next = topWeakGlobalNodes_; NodeList *current = nullptr; while (next != nullptr) { current = next; @@ -253,16 +253,15 @@ private: NO_COPY_SEMANTIC(EcmaGlobalStorage); NO_MOVE_SEMANTIC(EcmaGlobalStorage); - inline uintptr_t NewGlobalHandleImplement(NodeList **storage, NodeList **free_list, bool is_weak, - JSTaggedType value); + inline uintptr_t NewGlobalHandleImplement(NodeList **storage, NodeList **freeList, bool isWeak, JSTaggedType value); - NodeList *top_global_nodes_ {nullptr}; - NodeList *last_global_nodes_ {nullptr}; - NodeList *free_list_nodes_ {nullptr}; + NodeList *topGlobalNodes_ {nullptr}; + NodeList *lastGlobalNodes_ {nullptr}; + NodeList *freeListNodes_ {nullptr}; - NodeList *top_weak_global_nodes_ {nullptr}; - NodeList *last_weak_global_nodes_ {nullptr}; - NodeList *weak_free_list_nodes_ {nullptr}; + NodeList *topWeakGlobalNodes_ {nullptr}; + NodeList *lastWeakGlobalNodes_ {nullptr}; + NodeList *weakFreeListNodes_ {nullptr}; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_ECMA_GLOABL_STORAGE_H diff --git a/runtime/ecma_handle_scope-inl.h b/runtime/ecma_handle_scope-inl.h index 6af465448fff4c9c0814741e095345d11afd4665..1ee2a7268690148ce1e95d4452218dcdb10f1bae 100644 --- a/runtime/ecma_handle_scope-inl.h +++ b/runtime/ecma_handle_scope-inl.h @@ -22,9 +22,9 @@ namespace panda::ecmascript { inline EcmaHandleScope::EcmaHandleScope(JSThread *thread) : thread_(thread), - prev_next_(thread->handle_scope_storage_next_), - prev_end_(thread->handle_scope_storage_end_), - prev_handle_storage_index_(thread->current_handle_storage_index_) + prevNext_(thread->handleScopeStorageNext_), + prevEnd_(thread->handleScopeStorageEnd_), + prevHandleStorageIndex_(thread->currentHandleStorageIndex_) { thread->HandleScopeCountAdd(); } @@ -32,23 +32,23 @@ inline EcmaHandleScope::EcmaHandleScope(JSThread *thread) inline EcmaHandleScope::~EcmaHandleScope() { thread_->HandleScopeCountDec(); - thread_->handle_scope_storage_next_ = prev_next_; - if (thread_->handle_scope_storage_end_ != prev_end_) { - thread_->handle_scope_storage_end_ = prev_end_; - thread_->ShrinkHandleStorage(prev_handle_storage_index_); + thread_->handleScopeStorageNext_ = prevNext_; + if (thread_->handleScopeStorageEnd_ != prevEnd_) { + thread_->handleScopeStorageEnd_ = prevEnd_; + thread_->ShrinkHandleStorage(prevHandleStorageIndex_); } } uintptr_t EcmaHandleScope::NewHandle(JSThread *thread, JSTaggedType value) { // Each Handle must be managed by HandleScope, otherwise it may cause Handle leakage. - ASSERT(thread->handle_scope_count_ > 0); - auto result = thread->handle_scope_storage_next_; - if (result == thread->handle_scope_storage_end_) { + ASSERT(thread->handleScopeCount_ > 0); + auto result = thread->handleScopeStorageNext_; + if (result == thread->handleScopeStorageEnd_) { result = reinterpret_cast(thread->ExpandHandleStorage()); } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - thread->handle_scope_storage_next_ = result + 1; + thread->handleScopeStorageNext_ = result + 1; *result = value; return reinterpret_cast(result); } diff --git a/runtime/ecma_handle_scope.h b/runtime/ecma_handle_scope.h index 5da11547e230f7aeb25dd637f8e845eeafd1831a..14478f6911dc32ce2e05fd7fe44543abc1d7fc86 100644 --- a/runtime/ecma_handle_scope.h +++ b/runtime/ecma_handle_scope.h @@ -40,9 +40,9 @@ public: private: JSThread *thread_; - JSTaggedType *prev_next_; - JSTaggedType *prev_end_; - int prev_handle_storage_index_ {-1}; + JSTaggedType *prevNext_; + JSTaggedType *prevEnd_; + int prevHandleStorageIndex_ {-1}; NO_COPY_SEMANTIC(EcmaHandleScope); NO_MOVE_SEMANTIC(EcmaHandleScope); diff --git a/runtime/ecma_language_context.cpp b/runtime/ecma_language_context.cpp index 8f1fe70063358cc8112a0c070fa2269eefc66c89..19b348bad1b98f856f105a75365cd944fa395867 100644 --- a/runtime/ecma_language_context.cpp +++ b/runtime/ecma_language_context.cpp @@ -39,22 +39,22 @@ using ecmascript::JSThread; std::pair EcmaLanguageContext::GetCatchMethodAndOffset(Method *method, ManagedThread *thread) const { - Method *catch_method = method; - uint32_t catch_offset = 0; - auto js_thread = static_cast(thread); + Method *catchMethod = method; + uint32_t catchOffset = 0; + auto jsThread = static_cast(thread); for (auto stack = StackWalker::Create(thread); stack.HasFrame(); stack.NextFrame()) { - catch_method = stack.GetMethod(); - if (catch_method->IsNative()) { + catchMethod = stack.GetMethod(); + if (catchMethod->IsNative()) { continue; } - catch_offset = catch_method->FindCatchBlock(js_thread->GetException().GetTaggedObject()->ClassAddr(), - stack.GetBytecodePc()); - if (catch_offset != panda_file::INVALID_OFFSET) { + catchOffset = catchMethod->FindCatchBlock(jsThread->GetException().GetTaggedObject()->ClassAddr(), + stack.GetBytecodePc()); + if (catchOffset != panda_file::INVALID_OFFSET) { break; } } - return std::make_pair(catch_method, catch_offset); + return std::make_pair(catchMethod, catchOffset); } PandaVM *EcmaLanguageContext::CreateVM(Runtime *runtime, const RuntimeOptions &options) const @@ -76,11 +76,10 @@ PandaUniquePtr EcmaLanguageContext::CreatePtLangExt() const return PandaUniquePtr(); } -void EcmaLanguageContext::ThrowException(ManagedThread *thread, const uint8_t *mutf8_name, - const uint8_t *mutf8_msg) const +void EcmaLanguageContext::ThrowException(ManagedThread *thread, const uint8_t *mutf8Name, const uint8_t *mutf8Msg) const { - ecmascript::ThrowException(JSThread::Cast(thread), reinterpret_cast(mutf8_name), - reinterpret_cast(mutf8_msg)); + ecmascript::ThrowException(JSThread::Cast(thread), reinterpret_cast(mutf8Name), + reinterpret_cast(mutf8Msg)); } void EcmaLanguageContext::ThrowStackOverflowException(ManagedThread *thread) const @@ -99,35 +98,35 @@ PandaUniquePtr EcmaLanguageContext::CreateVTableBuilder() const return MakePandaUnique(); } -size_t EcmaLanguageContext::GetStringSize(const ObjectHeader *string_object) const +size_t EcmaLanguageContext::GetStringSize(const ObjectHeader *stringObject) const { - auto string = static_cast(string_object); + auto string = static_cast(stringObject); return string->ObjectSize(); } using VRegType = panda::compiler::VRegInfo::VRegType; -void EcmaLanguageContext::RestoreEnv(Frame *current_iframe, const StackWalker::EnvData &env_data) const +void EcmaLanguageContext::RestoreEnv(Frame *currentIframe, const StackWalker::EnvData &envData) const { - auto *iframe_env = ecmascript::JSExtFrame::FromFrame(current_iframe)->GetExtData(); - iframe_env->SetThisFunc( - ecmascript::JSFunction::Cast(ecmascript::JSTaggedValue(env_data[VRegType::THIS_FUNC]).GetHeapObject())); - iframe_env->SetConstantPool(ecmascript::ConstantPool::Cast(env_data[VRegType::CONST_POOL])); - iframe_env->SetLexicalEnv(ecmascript::LexicalEnv::Cast(env_data[VRegType::LEX_ENV])); + auto *iframeEnv = ecmascript::JSExtFrame::FromFrame(currentIframe)->GetExtData(); + iframeEnv->SetThisFunc( + ecmascript::JSFunction::Cast(ecmascript::JSTaggedValue(envData[VRegType::THIS_FUNC]).GetHeapObject())); + iframeEnv->SetConstantPool(ecmascript::ConstantPool::Cast(envData[VRegType::CONST_POOL])); + iframeEnv->SetLexicalEnv(ecmascript::LexicalEnv::Cast(envData[VRegType::LEX_ENV])); // restore func parameter - auto num_vregs = current_iframe->GetMethod()->GetNumVregs(); - DynamicFrameHandler frame_handler(current_iframe); - frame_handler.GetVReg(num_vregs + ecmascript::js_method_args::FUNC_IDX).SetValue(env_data[VRegType::THIS_FUNC]); + auto numVregs = currentIframe->GetMethod()->GetNumVregs(); + DynamicFrameHandler frameHandler(currentIframe); + frameHandler.GetVReg(numVregs + ecmascript::js_method_args::FUNC_IDX).SetValue(envData[VRegType::THIS_FUNC]); } -void EcmaLanguageContext::InitializeOsrCframeSlots(Span param_slots) const +void EcmaLanguageContext::InitializeOsrCframeSlots(Span paramSlots) const { - std::fill(param_slots.begin(), param_slots.end(), TaggedValue::VALUE_UNDEFINED); + std::fill(paramSlots.begin(), paramSlots.end(), TaggedValue::VALUE_UNDEFINED); } -uint64_t EcmaLanguageContext::GetOsrEnv(const Frame *iframe, compiler::VRegInfo vreg_info) const +uint64_t EcmaLanguageContext::GetOsrEnv(const Frame *iframe, compiler::VRegInfo vregInfo) const { auto env = ecmascript::JSFrame::GetJSEnv(iframe); - switch (vreg_info.GetVRegType()) { + switch (vregInfo.GetVRegType()) { case compiler::VRegInfo::VRegType::THIS_FUNC: return TaggedValue(env->GetThisFunc()).GetRawData(); case compiler::VRegInfo::VRegType::CONST_POOL: diff --git a/runtime/ecma_language_context.h b/runtime/ecma_language_context.h index 3b06940454ef19c5087d093fa30fdd192f56592e..efd085e7825c44d3b6ee6514879f59d8e5138fb5 100644 --- a/runtime/ecma_language_context.h +++ b/runtime/ecma_language_context.h @@ -49,7 +49,7 @@ public: PandaUniquePtr CreatePtLangExt() const override; - void ThrowException(ManagedThread *thread, const uint8_t *mutf8_name, const uint8_t *mutf8_msg) const override; + void ThrowException(ManagedThread *thread, const uint8_t *mutf8Name, const uint8_t *mutf8Msg) const override; void ThrowStackOverflowException(ManagedThread *thread) const override; @@ -64,10 +64,10 @@ public: UNREACHABLE(); } - mem::GC *CreateGC([[maybe_unused]] mem::GCType gc_type, [[maybe_unused]] mem::ObjectAllocatorBase *object_allocator, + mem::GC *CreateGC([[maybe_unused]] mem::GCType gcType, [[maybe_unused]] mem::ObjectAllocatorBase *objectAllocator, [[maybe_unused]] const mem::GCSettings &settings) const override { - return mem::CreateGC(gc_type, object_allocator, settings); + return mem::CreateGC(gcType, objectAllocator, settings); } void SetExceptionToVReg([[maybe_unused]] interpreter::AccVRegister &vreg, @@ -280,23 +280,23 @@ public: PandaUniquePtr CreateVTableBuilder() const override; - bool InitializeClass(ClassLinker *class_linker, ManagedThread *thread, Class *klass) const override + bool InitializeClass(ClassLinker *classLinker, ManagedThread *thread, Class *klass) const override { - return ClassInitializer::Initialize(class_linker, thread, klass); + return ClassInitializer::Initialize(classLinker, thread, klass); } - size_t GetStringSize(const ObjectHeader *string_object) const override; + size_t GetStringSize(const ObjectHeader *stringObject) const override; - void RestoreEnv(Frame *current_iframe, const StackWalker::EnvData &env_data) const override; + void RestoreEnv(Frame *currentIframe, const StackWalker::EnvData &envData) const override; bool IsEnabledCHA() const override { return false; } - void InitializeOsrCframeSlots(Span param_slots) const override; + void InitializeOsrCframeSlots(Span paramSlots) const override; - uint64_t GetOsrEnv(const Frame *iframe, compiler::VRegInfo vreg_info) const override; + uint64_t GetOsrEnv(const Frame *iframe, compiler::VRegInfo vregInfo) const override; }; } // namespace panda diff --git a/runtime/ecma_module.cpp b/runtime/ecma_module.cpp index 698d2e8f23ea694ccd473f08427487e6107ef6b2..a379f1faa0af1fef8d6a3a14b112e49af256ef0d 100644 --- a/runtime/ecma_module.cpp +++ b/runtime/ecma_module.cpp @@ -22,83 +22,83 @@ #include "plugins/ecmascript/runtime/tagged_dictionary.h" namespace panda::ecmascript { -JSHandle EcmaModule::GetItem(const JSThread *thread, JSHandle item_name) +JSHandle EcmaModule::GetItem(const JSThread *thread, JSHandle itemName) { - JSHandle module_items(thread, NameDictionary::Cast(GetNameDictionary().GetTaggedObject())); - int entry = module_items->FindEntry(item_name.GetTaggedValue()); + JSHandle moduleItems(thread, NameDictionary::Cast(GetNameDictionary().GetTaggedObject())); + int entry = moduleItems->FindEntry(itemName.GetTaggedValue()); if (entry != -1) { - return JSHandle(thread, module_items->GetValue(entry)); + return JSHandle(thread, moduleItems->GetValue(entry)); } return JSHandle(thread, JSTaggedValue::Undefined()); } -void EcmaModule::AddItem(const JSThread *thread, JSHandle module, JSHandle item_name, - JSHandle item_value) +void EcmaModule::AddItem(const JSThread *thread, JSHandle module, JSHandle itemName, + JSHandle itemValue) { JSMutableHandle data(thread, module->GetNameDictionary()); if (data->IsUndefined()) { data.Update(NameDictionary::Create(thread, DEAULT_DICTIONART_CAPACITY)); } - JSHandle data_dict = JSHandle::Cast(data); - JSHandle new_dict = - NameDictionary::Put(thread, data_dict, item_name, item_value, PropertyAttributes::Default()); - module->SetNameDictionary(thread, new_dict); + JSHandle dataDict = JSHandle::Cast(data); + JSHandle newDict = + NameDictionary::Put(thread, dataDict, itemName, itemValue, PropertyAttributes::Default()); + module->SetNameDictionary(thread, newDict); } -void EcmaModule::RemoveItem(const JSThread *thread, JSHandle module, JSHandle item_name) +void EcmaModule::RemoveItem(const JSThread *thread, JSHandle module, JSHandle itemName) { JSHandle data(thread, module->GetNameDictionary()); if (data->IsUndefined()) { return; } - JSHandle module_items(data); - int entry = module_items->FindEntry(item_name.GetTaggedValue()); + JSHandle moduleItems(data); + int entry = moduleItems->FindEntry(itemName.GetTaggedValue()); if (entry != -1) { - JSHandle new_dict = NameDictionary::Remove(thread, module_items, entry); - module->SetNameDictionary(thread, new_dict); + JSHandle newDict = NameDictionary::Remove(thread, moduleItems, entry); + module->SetNameDictionary(thread, newDict); } } -void EcmaModule::CopyModuleInternal(const JSThread *thread, JSHandle dst_module, - JSHandle src_module) +void EcmaModule::CopyModuleInternal(const JSThread *thread, JSHandle dstModule, + JSHandle srcModule) { - JSHandle module_items(thread, - NameDictionary::Cast(src_module->GetNameDictionary().GetTaggedObject())); - uint32_t num_all_keys = module_items->EntriesCount(); + JSHandle moduleItems(thread, + NameDictionary::Cast(srcModule->GetNameDictionary().GetTaggedObject())); + uint32_t numAllKeys = moduleItems->EntriesCount(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle all_keys = factory->NewTaggedArray(num_all_keys); - module_items->GetAllKeys(thread, 0, all_keys.GetObject()); + JSHandle allKeys = factory->NewTaggedArray(numAllKeys); + moduleItems->GetAllKeys(thread, 0, allKeys.GetObject()); - JSMutableHandle item_name(thread, JSTaggedValue::Undefined()); - JSMutableHandle item_value(thread, JSTaggedValue::Undefined()); - unsigned int capcity = all_keys->GetLength(); + JSMutableHandle itemName(thread, JSTaggedValue::Undefined()); + JSMutableHandle itemValue(thread, JSTaggedValue::Undefined()); + unsigned int capcity = allKeys->GetLength(); for (unsigned int i = 0; i < capcity; i++) { - int entry = module_items->FindEntry(all_keys->Get(i)); + int entry = moduleItems->FindEntry(allKeys->Get(i)); if (entry != -1) { - item_name.Update(all_keys->Get(i)); - item_value.Update(module_items->GetValue(entry)); - EcmaModule::AddItem(thread, dst_module, item_name, item_value); + itemName.Update(allKeys->Get(i)); + itemValue.Update(moduleItems->GetValue(entry)); + EcmaModule::AddItem(thread, dstModule, itemName, itemValue); } } } void EcmaModule::DebugPrint(const JSThread *thread, const PandaString &caller) { - JSHandle module_items(thread, NameDictionary::Cast(GetNameDictionary().GetTaggedObject())); - uint32_t num_all_keys = module_items->EntriesCount(); + JSHandle moduleItems(thread, NameDictionary::Cast(GetNameDictionary().GetTaggedObject())); + uint32_t numAllKeys = moduleItems->EntriesCount(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle all_keys = factory->NewTaggedArray(num_all_keys); - module_items->GetAllKeys(thread, 0, all_keys.GetObject()); + JSHandle allKeys = factory->NewTaggedArray(numAllKeys); + moduleItems->GetAllKeys(thread, 0, allKeys.GetObject()); - unsigned int capcity = all_keys->GetLength(); + unsigned int capcity = allKeys->GetLength(); for (unsigned int i = 0; i < capcity; i++) { - int entry = module_items->FindEntry(all_keys->Get(i)); + int entry = moduleItems->FindEntry(allKeys->Get(i)); if (entry != -1) { std::cout << "[" << caller << "]" << std::endl - << "--itemName: " << ConvertToPandaString(EcmaString::Cast(all_keys->Get(i).GetTaggedObject())) + << "--itemName: " << ConvertToPandaString(EcmaString::Cast(allKeys->Get(i).GetTaggedObject())) << std::endl - << "--itemValue(ObjRef): 0x" << std::hex << module_items->GetValue(entry).GetRawData() + << "--itemValue(ObjRef): 0x" << std::hex << moduleItems->GetValue(entry).GetRawData() << std::endl; } } @@ -106,80 +106,79 @@ void EcmaModule::DebugPrint(const JSThread *thread, const PandaString &caller) ModuleManager::ModuleManager(EcmaVM *vm) : vm_(vm) { - ecma_modules_ = NameDictionary::Create(vm_->GetJSThread(), DEAULT_DICTIONART_CAPACITY).GetTaggedValue(); + ecmaModules_ = NameDictionary::Create(vm_->GetJSThread(), DEAULT_DICTIONART_CAPACITY).GetTaggedValue(); } // class ModuleManager -void ModuleManager::AddModule(JSHandle module_name, JSHandle module) +void ModuleManager::AddModule(JSHandle moduleName, JSHandle module) { JSThread *thread = vm_->GetJSThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle dict(thread, ecma_modules_); - ecma_modules_ = - NameDictionary::Put(thread, dict, module_name, module, PropertyAttributes::Default()).GetTaggedValue(); + JSHandle dict(thread, ecmaModules_); + ecmaModules_ = + NameDictionary::Put(thread, dict, moduleName, module, PropertyAttributes::Default()).GetTaggedValue(); } -void ModuleManager::RemoveModule(JSHandle module_name) +void ModuleManager::RemoveModule(JSHandle moduleName) { JSThread *thread = vm_->GetJSThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle module_items(thread, ecma_modules_); - int entry = module_items->FindEntry(module_name.GetTaggedValue()); + JSHandle moduleItems(thread, ecmaModules_); + int entry = moduleItems->FindEntry(moduleName.GetTaggedValue()); if (entry != -1) { - ecma_modules_ = NameDictionary::Remove(thread, module_items, entry).GetTaggedValue(); + ecmaModules_ = NameDictionary::Remove(thread, moduleItems, entry).GetTaggedValue(); } } JSHandle ModuleManager::GetModule(const JSThread *thread, - [[maybe_unused]] JSHandle module_name) + [[maybe_unused]] JSHandle moduleName) { - int entry = NameDictionary::Cast(ecma_modules_.GetTaggedObject())->FindEntry(module_name.GetTaggedValue()); + int entry = NameDictionary::Cast(ecmaModules_.GetTaggedObject())->FindEntry(moduleName.GetTaggedValue()); if (entry != -1) { - return JSHandle(thread, NameDictionary::Cast(ecma_modules_.GetTaggedObject())->GetValue(entry)); + return JSHandle(thread, NameDictionary::Cast(ecmaModules_.GetTaggedObject())->GetValue(entry)); } return thread->GlobalConstants()->GetHandledUndefined(); } -PandaString ModuleManager::GenerateModuleFullPath(const std::string ¤t_path_file, - const PandaString &relative_file) +PandaString ModuleManager::GenerateModuleFullPath(const std::string ¤tPathFile, const PandaString &relativeFile) { // NOLINTNEXTLINE(abseil-string-find-startswith) - if (relative_file.find("./") != 0 && relative_file.find("../") != 0) { // not start with "./" or "../" - return relative_file; // not relative + if (relativeFile.find("./") != 0 && relativeFile.find("../") != 0) { // not start with "./" or "../" + return relativeFile; // not relative } - auto slash_pos = current_path_file.find_last_of('/'); - if (slash_pos == std::string::npos) { - return relative_file; // no need to process + auto slashPos = currentPathFile.find_last_of('/'); + if (slashPos == std::string::npos) { + return relativeFile; // no need to process } - auto dot_pos = relative_file.find_last_of('.'); - if (dot_pos == std::string::npos) { - dot_pos = 0; + auto dotPos = relativeFile.find_last_of('.'); + if (dotPos == std::string::npos) { + dotPos = 0; } - PandaString full_path; - full_path.append(current_path_file.substr(0, slash_pos + 1)); // 1: with "/" - full_path.append(relative_file.substr(0, dot_pos)); - full_path.append(".abc"); // ".js" -> ".abc" - return full_path; + PandaString fullPath; + fullPath.append(currentPathFile.substr(0, slashPos + 1)); // 1: with "/" + fullPath.append(relativeFile.substr(0, dotPos)); + fullPath.append(".abc"); // ".js" -> ".abc" + return fullPath; } const PandaString &ModuleManager::GetCurrentExportModuleName() { - return module_names_.back(); + return moduleNames_.back(); } -void ModuleManager::SetCurrentExportModuleName(const std::string_view &module_file) +void ModuleManager::SetCurrentExportModuleName(const std::string_view &moduleFile) { - module_names_.emplace_back(PandaString(module_file)); // xx/xx/x.abc + moduleNames_.emplace_back(PandaString(moduleFile)); // xx/xx/x.abc } void ModuleManager::RestoreCurrentExportModuleName() { - auto s = module_names_.size(); + auto s = moduleNames_.size(); if (s > 0) { - module_names_.resize(s - 1); + moduleNames_.resize(s - 1); return; } UNREACHABLE(); @@ -188,61 +187,61 @@ void ModuleManager::RestoreCurrentExportModuleName() const PandaString &ModuleManager::GetPrevExportModuleName() { static const int MINIMUM_COUNT = 2; - auto count = module_names_.size(); + auto count = moduleNames_.size(); ASSERT(count >= MINIMUM_COUNT); - return module_names_[count - MINIMUM_COUNT]; + return moduleNames_[count - MINIMUM_COUNT]; } -void ModuleManager::AddModuleItem(const JSThread *thread, JSHandle item_name, +void ModuleManager::AddModuleItem(const JSThread *thread, JSHandle itemName, JSHandle value) { - PandaString name_str = GetCurrentExportModuleName(); + PandaString nameStr = GetCurrentExportModuleName(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle module_name = factory->NewFromString(name_str); + JSHandle moduleName = factory->NewFromString(nameStr); - JSHandle module = GetModule(thread, JSHandle::Cast(module_name)); + JSHandle module = GetModule(thread, JSHandle::Cast(moduleName)); if (module->IsUndefined()) { - JSHandle empty_module = factory->NewEmptyEcmaModule(); - EcmaModule::AddItem(thread, empty_module, item_name, value); + JSHandle emptyModule = factory->NewEmptyEcmaModule(); + EcmaModule::AddItem(thread, emptyModule, itemName, value); - AddModule(JSHandle::Cast(module_name), JSHandle::Cast(empty_module)); + AddModule(JSHandle::Cast(moduleName), JSHandle::Cast(emptyModule)); } else { - EcmaModule::AddItem(thread, JSHandle(module), item_name, value); + EcmaModule::AddItem(thread, JSHandle(module), itemName, value); } } JSHandle ModuleManager::GetModuleItem(const JSThread *thread, JSHandle module, - JSHandle item_name) + JSHandle itemName) { - return EcmaModule::Cast(module->GetTaggedObject())->GetItem(thread, item_name); // Assume the module is exist + return EcmaModule::Cast(module->GetTaggedObject())->GetItem(thread, itemName); // Assume the module is exist } void ModuleManager::CopyModule(const JSThread *thread, JSHandle src) { ASSERT(src->IsHeapObject()); - JSHandle src_module = JSHandle::Cast(src); - PandaString name_str = GetCurrentExportModuleName(); // Assume the srcModule exist when dstModule Execute + JSHandle srcModule = JSHandle::Cast(src); + PandaString nameStr = GetCurrentExportModuleName(); // Assume the srcModule exist when dstModule Execute ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle module_name = factory->NewFromString(name_str); + JSHandle moduleName = factory->NewFromString(nameStr); - JSHandle dst_module = GetModule(thread, JSHandle::Cast(module_name)); + JSHandle dstModule = GetModule(thread, JSHandle::Cast(moduleName)); - if (dst_module->IsUndefined()) { - JSHandle empty_module = factory->NewEmptyEcmaModule(); - EcmaModule::CopyModuleInternal(thread, empty_module, src_module); + if (dstModule->IsUndefined()) { + JSHandle emptyModule = factory->NewEmptyEcmaModule(); + EcmaModule::CopyModuleInternal(thread, emptyModule, srcModule); - AddModule(JSHandle::Cast(module_name), JSHandle::Cast(empty_module)); + AddModule(JSHandle::Cast(moduleName), JSHandle::Cast(emptyModule)); } else { - EcmaModule::CopyModuleInternal(thread, JSHandle(dst_module), src_module); + EcmaModule::CopyModuleInternal(thread, JSHandle(dstModule), srcModule); } } void ModuleManager::DebugPrint([[maybe_unused]] const JSThread *thread, [[maybe_unused]] const PandaString &caller) { std::cout << "ModuleStack:"; - for_each(module_names_.cbegin(), module_names_.cend(), [](const PandaString &s) -> void { std::cout << s << " "; }); + for_each(moduleNames_.cbegin(), moduleNames_.cend(), [](const PandaString &s) -> void { std::cout << s << " "; }); std::cout << "\n"; } } // namespace panda::ecmascript diff --git a/runtime/ecma_module.h b/runtime/ecma_module.h index 30ce047dca598cfc03e58b820a6aefbc987f53fe..9e8f71c7fdbc1890758833f776428e280fc2ca6f 100644 --- a/runtime/ecma_module.h +++ b/runtime/ecma_module.h @@ -31,12 +31,12 @@ public: return static_cast(object); } - JSHandle GetItem(const JSThread *thread, JSHandle item_name); + JSHandle GetItem(const JSThread *thread, JSHandle itemName); - static void AddItem(const JSThread *thread, JSHandle module, JSHandle item_name, - JSHandle item_value); + static void AddItem(const JSThread *thread, JSHandle module, JSHandle itemName, + JSHandle itemValue); - static void RemoveItem(const JSThread *thread, JSHandle module, JSHandle item_name); + static void RemoveItem(const JSThread *thread, JSHandle module, JSHandle itemName); void DebugPrint(const JSThread *thread, const PandaString &caller); @@ -49,8 +49,8 @@ public: DECL_DUMP() protected: - static void CopyModuleInternal(const JSThread *thread, JSHandle dst_module, - JSHandle src_module); + static void CopyModuleInternal(const JSThread *thread, JSHandle dstModule, + JSHandle srcModule); friend class ModuleManager; }; @@ -60,26 +60,26 @@ public: explicit ModuleManager(EcmaVM *vm); ~ModuleManager() = default; - void AddModule(JSHandle module_name, JSHandle module); + void AddModule(JSHandle moduleName, JSHandle module); - void RemoveModule(JSHandle module_name); + void RemoveModule(JSHandle moduleName); - JSHandle GetModule(const JSThread *thread, JSHandle module_name); + JSHandle GetModule(const JSThread *thread, JSHandle moduleName); - PandaString GenerateModuleFullPath(const std::string ¤t_path_file, const PandaString &relative_file); + PandaString GenerateModuleFullPath(const std::string ¤tPathFile, const PandaString &relativeFile); const PandaString &GetCurrentExportModuleName(); const PandaString &GetPrevExportModuleName(); - void SetCurrentExportModuleName(const std::string_view &module_file); + void SetCurrentExportModuleName(const std::string_view &moduleFile); void RestoreCurrentExportModuleName(); - void AddModuleItem(const JSThread *thread, JSHandle item_name, JSHandle value); + void AddModuleItem(const JSThread *thread, JSHandle itemName, JSHandle value); JSHandle GetModuleItem(const JSThread *thread, JSHandle module, - JSHandle item_name); + JSHandle itemName); void CopyModule(const JSThread *thread, JSHandle src); @@ -92,8 +92,8 @@ private: NO_MOVE_SEMANTIC(ModuleManager); EcmaVM *vm_ {nullptr}; - JSTaggedValue ecma_modules_ {JSTaggedValue::Hole()}; - std::vector module_names_ {DEAULT_DICTIONART_CAPACITY}; + JSTaggedValue ecmaModules_ {JSTaggedValue::Hole()}; + std::vector moduleNames_ {DEAULT_DICTIONART_CAPACITY}; friend class EcmaVM; }; diff --git a/runtime/ecma_profiling.cpp b/runtime/ecma_profiling.cpp index c1af3f51e5d43d74f5b3ad029a30a336061bd33a..460ebd9fdb4e0fa3aa98e259259d9bf05b1ff376 100644 --- a/runtime/ecma_profiling.cpp +++ b/runtime/ecma_profiling.cpp @@ -18,29 +18,29 @@ namespace panda::ecmascript { -void CallProfile::Update(ECMAObject *js_func, EcmaCallProfilingTable *table) +void CallProfile::Update(ECMAObject *jsFunc, EcmaCallProfilingTable *table) { - if (callees_idx_[0] == MEGAMORPHIC) { + if (calleesIdx_[0] == MEGAMORPHIC) { return; } - auto method = js_func->GetCallTarget(); + auto method = jsFunc->GetCallTarget(); for (size_t i = 0; i < MAX_FUNC_NUMBER; ++i) { - if (callees_idx_[i] == UNKNOWN) { - auto idx = table->InsertNewObject(js_func); + if (calleesIdx_[i] == UNKNOWN) { + auto idx = table->InsertNewObject(jsFunc); if (idx) { // Atomic with release order reason: profile data may be updated while the compiler thread loads it - reinterpret_cast *>(&callees_idx_[i])->store(idx.value(), std::memory_order_release); + reinterpret_cast *>(&calleesIdx_[i])->store(idx.value(), std::memory_order_release); } return; } - ASSERT(callees_idx_[i] > 0 && callees_idx_[i] <= std::numeric_limits::max() - 1U); - if (table->GetObject(callees_idx_[i])->GetCallTarget() == method) { + ASSERT(calleesIdx_[i] > 0 && calleesIdx_[i] <= std::numeric_limits::max() - 1U); + if (table->GetObject(calleesIdx_[i])->GetCallTarget() == method) { return; } } // NOTE(schernykh): Create way for clear call profiling table, and clear it in this place. // Atomic with release order reason: profile data may be updated while the compiler thread loads it - reinterpret_cast *>(&callees_idx_[0])->store(MEGAMORPHIC, std::memory_order_release); + reinterpret_cast *>(&calleesIdx_[0])->store(MEGAMORPHIC, std::memory_order_release); } } // namespace panda::ecmascript diff --git a/runtime/ecma_profiling.h b/runtime/ecma_profiling.h index 444c409922e4ddc640192ae127f751e09e1a4cd4..2b2b4e10717bf121894f6d197da0af8b6c927a0b 100644 --- a/runtime/ecma_profiling.h +++ b/runtime/ecma_profiling.h @@ -319,10 +319,10 @@ public: static_assert(std::is_integral_v, "Only integer type supported"); ValueProfileBase() = default; - explicit ValueProfileBase(void *prof_data) + explicit ValueProfileBase(void *profData) // Atomic with acquire order reason: profile data may be updated while the compiler thread loads it - : value_(prof_data != nullptr - ? reinterpret_cast *>(prof_data)->load(std::memory_order_acquire) + : value_(profData != nullptr + ? reinterpret_cast *>(profData)->load(std::memory_order_acquire) : 0) { } @@ -379,11 +379,11 @@ public: } // NOLINTNEXTLINE(readability-non-const-parameter) - static void Update(void *data, ProfilingIndexedAccessBits::Type access_type) + static void Update(void *data, ProfilingIndexedAccessBits::Type accessType) { // Atomic with release order reason: profile data may be updated while the compiler thread loads it reinterpret_cast *>(data)->store( - *(reinterpret_cast(data)) | OperandType::Encode(access_type), std::memory_order_release); + *(reinterpret_cast(data)) | OperandType::Encode(accessType), std::memory_order_release); } protected: @@ -516,16 +516,15 @@ public: panda::profiling::CallKind GetCallKind() const { // Atomic with acquire order reason: profile data may be updated while the compiler thread loads it - auto callee_idx = - reinterpret_cast *>(&callees_idx_[0])->load(std::memory_order_acquire); - if (callee_idx == MEGAMORPHIC) { + auto calleeIdx = reinterpret_cast *>(&calleesIdx_[0])->load(std::memory_order_acquire); + if (calleeIdx == MEGAMORPHIC) { return panda::profiling::CallKind::MEGAMORPHIC; } - if (callee_idx == UNKNOWN) { + if (calleeIdx == UNKNOWN) { return panda::profiling::CallKind::UNKNOWN; } // Atomic with acquire order reason: profile data may be updated while the compiler thread loads it - if (reinterpret_cast *>(&callees_idx_[1])->load(std::memory_order_acquire) == UNKNOWN) { + if (reinterpret_cast *>(&calleesIdx_[1])->load(std::memory_order_acquire) == UNKNOWN) { return panda::profiling::CallKind::MONOMORPHIC; } return panda::profiling::CallKind::POLYMORPHIC; @@ -533,37 +532,37 @@ public: std::array GetCalleesPtr(EcmaCallProfilingTable *table) const { - std::array obj_ptrs {}; + std::array objPtrs {}; for (size_t i = 0; i < MAX_FUNC_NUMBER; ++i) { - if (callees_idx_[i] == UNKNOWN) { - return obj_ptrs; + if (calleesIdx_[i] == UNKNOWN) { + return objPtrs; } - obj_ptrs[i] = table->GetObjectPtr(callees_idx_[i]); + objPtrs[i] = table->GetObjectPtr(calleesIdx_[i]); } - return obj_ptrs; + return objPtrs; } void Clear(EcmaCallProfilingTable *table) { - if (callees_idx_[0] == MEGAMORPHIC) { + if (calleesIdx_[0] == MEGAMORPHIC) { return; } for (size_t i = 0; i < MAX_FUNC_NUMBER; ++i) { - if (callees_idx_[i] == UNKNOWN) { + if (calleesIdx_[i] == UNKNOWN) { break; } - table->ClearObject(callees_idx_[i]); - callees_idx_[i] = UNKNOWN; + table->ClearObject(calleesIdx_[i]); + calleesIdx_[i] = UNKNOWN; } } - void Update(ECMAObject *js_func, EcmaCallProfilingTable *table); + void Update(ECMAObject *jsFunc, EcmaCallProfilingTable *table); private: - std::array callees_idx_ {}; + std::array calleesIdx_ {}; // if you want to increase callees_idx_ size, // you need to update size in profiles::Call in ecmascript/isa/isa.yaml - static_assert(sizeof(callees_idx_) == 8); + static_assert(sizeof(calleesIdx_) == 8); }; /// The following types are used in profile data serialization. diff --git a/runtime/ecma_runtime_call_info.h b/runtime/ecma_runtime_call_info.h index ac47a4686c3d03b876a4885636826495c90f7bca..87ab96110e6332af573b4be5b16bf587abff4fe0 100644 --- a/runtime/ecma_runtime_call_info.h +++ b/runtime/ecma_runtime_call_info.h @@ -29,10 +29,10 @@ using EcmaEntrypoint = JSTaggedValue (*)(EcmaRuntimeCallInfo *); class EcmaRuntimeCallInfo { public: - EcmaRuntimeCallInfo(JSThread *thread, uint32_t num_args, JSTaggedValue *args) - : thread_(thread), num_args_(num_args), args_(args) + EcmaRuntimeCallInfo(JSThread *thread, uint32_t numArgs, JSTaggedValue *args) + : thread_(thread), numArgs_(numArgs), args_(args) { - ASSERT(num_args >= js_method_args::NUM_MANDATORY_ARGS); + ASSERT(numArgs >= js_method_args::NUM_MANDATORY_ARGS); } ~EcmaRuntimeCallInfo() = default; @@ -90,12 +90,12 @@ public: */ inline uint32_t GetArgsNumber() const { - return num_args_ - js_method_args::NUM_MANDATORY_ARGS; + return numArgs_ - js_method_args::NUM_MANDATORY_ARGS; } inline uintptr_t GetArgAddress(uint32_t idx) const { - ASSERT(idx < num_args_); + ASSERT(idx < numArgs_); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) return reinterpret_cast(&args_[idx]); } @@ -113,7 +113,7 @@ public: inline uint32_t GetInternalArgsNum() const { - return num_args_; + return numArgs_; } inline JSTaggedValue *GetInternalArgs() const @@ -151,29 +151,29 @@ private: private: alignas(sizeof(JSTaggedType)) JSThread *thread_ {nullptr}; - alignas(sizeof(JSTaggedType)) uint32_t num_args_ {0}; + alignas(sizeof(JSTaggedType)) uint32_t numArgs_ {0}; alignas(sizeof(JSTaggedType)) JSTaggedValue *args_ {nullptr}; }; template ALWAYS_INLINE inline void EcmaRuntimeCallInfo::SetCallArgs(Args... args) { - std::array args_arr {UnpackIfHandle(args).GetRawData()...}; - SetCallArg(args_arr.size(), args_arr.data(), 0); + std::array argsArr {UnpackIfHandle(args).GetRawData()...}; + SetCallArg(argsArr.size(), argsArr.data(), 0); } class ScopedCallInfo { public: ScopedCallInfo() = default; - ScopedCallInfo(JSThread *thread, uint32_t num_args) + ScopedCallInfo(JSThread *thread, uint32_t numArgs) { - num_args += js_method_args::NUM_MANDATORY_ARGS; + numArgs += js_method_args::NUM_MANDATORY_ARGS; auto allocator = thread->GetStackFrameAllocator(); auto *mem = reinterpret_cast( - allocator->Alloc(AlignUp(num_args * sizeof(JSTaggedValue), GetAlignmentInBytes(DEFAULT_FRAME_ALIGNMENT)))); + allocator->Alloc(AlignUp(numArgs * sizeof(JSTaggedValue), GetAlignmentInBytes(DEFAULT_FRAME_ALIGNMENT)))); LOG_IF(mem == nullptr, FATAL, ECMASCRIPT) << "Cannot allocate ScopedCallInfo frame"; - new (&cinfo_) EcmaRuntimeCallInfo(thread, num_args, mem); + new (&cinfo_) EcmaRuntimeCallInfo(thread, numArgs, mem); AddToChain(); } @@ -191,8 +191,8 @@ public: { auto thread = other.cinfo_.thread_; ASSERT(this->cinfo_.thread_ == nullptr); - ASSERT(thread->scoped_call_info_ == &other); - thread->scoped_call_info_ = this; + ASSERT(thread->scopedCallInfo_ == &other); + thread->scopedCallInfo_ = this; std::swap(this->prev_, other.prev_); std::swap(this->cinfo_, other.cinfo_); @@ -206,11 +206,11 @@ public: static void IterateChain(JSThread *thread, const RootRangeVisitor &v0) { - for (auto head = thread->scoped_call_info_; head != nullptr; head = head->prev_) { + for (auto head = thread->scopedCallInfo_; head != nullptr; head = head->prev_) { auto *args = head->cinfo_.args_; - auto num_args = head->cinfo_.num_args_; + auto numArgs = head->cinfo_.numArgs_; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - v0(Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(args)), ObjectSlot(ToUintPtr(args + num_args))); + v0(Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(args)), ObjectSlot(ToUintPtr(args + numArgs))); } } @@ -230,15 +230,15 @@ private: void AddToChain() { auto thread = cinfo_.thread_; - prev_ = thread->scoped_call_info_; - thread->scoped_call_info_ = this; + prev_ = thread->scopedCallInfo_; + thread->scopedCallInfo_ = this; } void RemoveFromChain() { auto thread = cinfo_.thread_; - ASSERT(thread->scoped_call_info_ == this); - thread->scoped_call_info_ = prev_; + ASSERT(thread->scopedCallInfo_ == this); + thread->scopedCallInfo_ = prev_; } EcmaRuntimeCallInfo cinfo_ {}; @@ -246,13 +246,12 @@ private: }; template -static inline ScopedCallInfo NewRuntimeCallInfo(JSThread *thread, TF func, TT this_obj, TN new_target, - uint32_t num_args) +static inline ScopedCallInfo NewRuntimeCallInfo(JSThread *thread, TF func, TT thisObj, TN newTarget, uint32_t numArgs) { - ScopedCallInfo info(thread, num_args); + ScopedCallInfo info(thread, numArgs); info->SetFunction(EcmaRuntimeCallInfo::UnpackIfHandle(func)); - info->SetThis(EcmaRuntimeCallInfo::UnpackIfHandle(this_obj)); - info->SetNewTarget(EcmaRuntimeCallInfo::UnpackIfHandle(new_target)); + info->SetThis(EcmaRuntimeCallInfo::UnpackIfHandle(thisObj)); + info->SetNewTarget(EcmaRuntimeCallInfo::UnpackIfHandle(newTarget)); return info; } diff --git a/runtime/ecma_string-inl.h b/runtime/ecma_string-inl.h index 444da07e5ca4e45d34c3707b819b15fb9f155440..4746b41833c43b25ad6b6a1c9bcb122db4010392 100644 --- a/runtime/ecma_string-inl.h +++ b/runtime/ecma_string-inl.h @@ -47,48 +47,48 @@ inline EcmaString *EcmaString::CreateEmptyString(const EcmaVM *vm) } /* static */ -inline EcmaString *EcmaString::CreateFromUtf8(const uint8_t *utf8_data, uint32_t utf8_len, const EcmaVM *vm, - bool can_be_compress, panda::SpaceType space_type) +inline EcmaString *EcmaString::CreateFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len, const EcmaVM *vm, + bool canBeCompress, panda::SpaceType spaceType) { - if (utf8_len == 0) { + if (utf8Len == 0) { return vm->GetFactory()->GetEmptyString().GetObject(); } EcmaString *string = nullptr; - if (can_be_compress) { - string = AllocStringObject(utf8_len, true, vm, space_type); + if (canBeCompress) { + string = AllocStringObject(utf8Len, true, vm, spaceType); ASSERT(string != nullptr); - if (memcpy_s(string->GetDataUtf8Writable(), utf8_len, utf8_data, utf8_len) != EOK) { + if (memcpy_s(string->GetDataUtf8Writable(), utf8Len, utf8Data, utf8Len) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } else { - auto utf16_len = utf::Utf8ToUtf16Size(utf8_data, utf8_len); - string = AllocStringObject(utf16_len, false, vm, space_type); + auto utf16Len = utf::Utf8ToUtf16Size(utf8Data, utf8Len); + string = AllocStringObject(utf16Len, false, vm, spaceType); ASSERT(string != nullptr); [[maybe_unused]] auto len = - utf::ConvertRegionUtf8ToUtf16(utf8_data, string->GetDataUtf16Writable(), utf8_len, utf16_len, 0); - ASSERT(len == utf16_len); + utf::ConvertRegionUtf8ToUtf16(utf8Data, string->GetDataUtf16Writable(), utf8Len, utf16Len, 0); + ASSERT(len == utf16Len); } return string; } -inline EcmaString *EcmaString::CreateFromUtf16(const uint16_t *utf16_data, uint32_t utf16_len, const EcmaVM *vm, - bool can_be_compress, panda::SpaceType space_type) +inline EcmaString *EcmaString::CreateFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len, const EcmaVM *vm, + bool canBeCompress, panda::SpaceType spaceType) { - if (utf16_len == 0) { + if (utf16Len == 0) { return vm->GetFactory()->GetEmptyString().GetObject(); } - auto string = AllocStringObject(utf16_len, can_be_compress, vm, space_type); + auto string = AllocStringObject(utf16Len, canBeCompress, vm, spaceType); ASSERT(string != nullptr); - if (can_be_compress) { - CopyUtf16AsUtf8(utf16_data, string->GetDataUtf8Writable(), utf16_len); + if (canBeCompress) { + CopyUtf16AsUtf8(utf16Data, string->GetDataUtf8Writable(), utf16Len); } else { - uint32_t len = utf16_len * (sizeof(uint16_t) / sizeof(uint8_t)); - if (memcpy_s(string->GetDataUtf16Writable(), len, utf16_data, len) != EOK) { + uint32_t len = utf16Len * (sizeof(uint16_t) / sizeof(uint8_t)); + if (memcpy_s(string->GetDataUtf16Writable(), len, utf16Data, len) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -116,10 +116,10 @@ inline uint16_t EcmaString::At(int32_t index) const /* static */ inline EcmaString *EcmaString::AllocStringObject(size_t length, bool compressed, const EcmaVM *vm, - panda::SpaceType space_type) + panda::SpaceType spaceType) { size_t size = compressed ? ComputeSizeUtf8(length) : ComputeSizeUtf16(length); - auto string = space_type == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT + auto string = spaceType == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT ? reinterpret_cast(vm->GetFactory()->AllocNonMovableStringObject(size)) : reinterpret_cast(vm->GetFactory()->AllocStringObject(size)); string->SetLength(length, compressed); @@ -127,12 +127,12 @@ inline EcmaString *EcmaString::AllocStringObject(size_t length, bool compressed, return reinterpret_cast(string); } -void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t dest_size, uint32_t length) +void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length) { if (IsUtf8()) { ASSERT(src->IsUtf8()); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (length != 0 && memcpy_s(GetDataUtf8Writable() + start, dest_size, src->GetDataUtf8(), length) != EOK) { + if (length != 0 && memcpy_s(GetDataUtf8Writable() + start, destSize, src->GetDataUtf8(), length) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -145,8 +145,8 @@ void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t dest_size, } } else { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (length != 0 && memcpy_s(GetDataUtf16Writable() + start, ComputeDataSizeUtf16(dest_size), - src->GetDataUtf16(), ComputeDataSizeUtf16(length)) != EOK) { + if (length != 0 && memcpy_s(GetDataUtf16Writable() + start, ComputeDataSizeUtf16(destSize), src->GetDataUtf16(), + ComputeDataSizeUtf16(length)) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } diff --git a/runtime/ecma_string.cpp b/runtime/ecma_string.cpp index 846720e2facf243c22963b37a4f7496b30caca48..b8a464702a42755f518f8a900193035a03086f9c 100644 --- a/runtime/ecma_string.cpp +++ b/runtime/ecma_string.cpp @@ -18,46 +18,46 @@ #include "plugins/ecmascript/runtime/js_symbol.h" namespace panda::ecmascript { -bool EcmaString::compressed_strings_enabled_ = true; +bool EcmaString::compressedStringsEnabled_ = true; static constexpr int SMALL_STRING_SIZE = 128; -EcmaString *EcmaString::Concat(const JSHandle &str1_handle, const JSHandle &str2_handle, +EcmaString *EcmaString::Concat(const JSHandle &str1Handle, const JSHandle &str2Handle, const EcmaVM *vm) { // allocator may trig gc and move src, need to hold it - EcmaString *string1 = *str1_handle; - EcmaString *string2 = *str2_handle; + EcmaString *string1 = *str1Handle; + EcmaString *string2 = *str2Handle; uint32_t length1 = string1->GetLength(); uint32_t length2 = string2->GetLength(); - uint32_t new_length = length1 + length2; - if (new_length == 0) { + uint32_t newLength = length1 + length2; + if (newLength == 0) { return vm->GetFactory()->GetEmptyString().GetObject(); } bool compressed = GetCompressedStringsEnabled() && (!string1->IsUtf16() && !string2->IsUtf16()); - auto new_string = AllocStringObject(new_length, compressed, vm); + auto newString = AllocStringObject(newLength, compressed, vm); // retrieve strings after gc - string1 = *str1_handle; - string2 = *str2_handle; + string1 = *str1Handle; + string2 = *str2Handle; if (compressed) { - Span sp(new_string->GetDataUtf8Writable(), new_length); + Span sp(newString->GetDataUtf8Writable(), newLength); Span src1(string1->GetDataUtf8(), length1); - EcmaString::StringCopy(sp, new_length, src1, length1); + EcmaString::StringCopy(sp, newLength, src1, length1); sp = sp.SubSpan(length1); Span src2(string2->GetDataUtf8(), length2); - EcmaString::StringCopy(sp, new_length - length1, src2, length2); + EcmaString::StringCopy(sp, newLength - length1, src2, length2); } else { - Span sp(new_string->GetDataUtf16Writable(), new_length); + Span sp(newString->GetDataUtf16Writable(), newLength); if (!string1->IsUtf16()) { for (uint32_t i = 0; i < length1; ++i) { sp[i] = string1->At(i); } } else { Span src1(string1->GetDataUtf16(), length1); - EcmaString::StringCopy(sp, new_length << 1U, src1, length1 << 1U); + EcmaString::StringCopy(sp, newLength << 1U, src1, length1 << 1U); } sp = sp.SubSpan(length1); if (!string2->IsUtf16()) { @@ -71,48 +71,48 @@ EcmaString *EcmaString::Concat(const JSHandle &str1_handle, const JS } } - return new_string; + return newString; } /* static */ -EcmaString *EcmaString::FastSubString(const JSHandle &src, uint32_t start, uint32_t utf16_len, +EcmaString *EcmaString::FastSubString(const JSHandle &src, uint32_t start, uint32_t utf16Len, const EcmaVM *vm) { - if (utf16_len == 0) { + if (utf16Len == 0) { return vm->GetFactory()->GetEmptyString().GetObject(); } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - bool can_be_compressed = !src->IsUtf16(); + bool canBeCompressed = !src->IsUtf16(); // allocator may trig gc and move src, need to hold it - auto string = AllocStringObject(utf16_len, can_be_compressed, vm); + auto string = AllocStringObject(utf16Len, canBeCompressed, vm); if (src->IsUtf16()) { - if (can_be_compressed) { + if (canBeCompressed) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - CopyUtf16AsUtf8(src->GetDataUtf16() + start, string->GetDataUtf8Writable(), utf16_len); + CopyUtf16AsUtf8(src->GetDataUtf16() + start, string->GetDataUtf8Writable(), utf16Len); } else { - uint32_t len = utf16_len * (sizeof(uint16_t) / sizeof(uint8_t)); - Span dst(string->GetDataUtf16Writable(), utf16_len); + uint32_t len = utf16Len * (sizeof(uint16_t) / sizeof(uint8_t)); + Span dst(string->GetDataUtf16Writable(), utf16Len); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - Span source(src->GetDataUtf16() + start, utf16_len); + Span source(src->GetDataUtf16() + start, utf16Len); EcmaString::StringCopy(dst, len, source, len); } } else { - Span dst(string->GetDataUtf8Writable(), utf16_len); + Span dst(string->GetDataUtf8Writable(), utf16Len); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - Span source(src->GetDataUtf8() + start, utf16_len); - EcmaString::StringCopy(dst, utf16_len, source, utf16_len); + Span source(src->GetDataUtf8() + start, utf16Len); + EcmaString::StringCopy(dst, utf16Len, source, utf16Len); } return string; } template -int32_t CompareStringSpan(Span &lhs_sp, Span &rhs_sp, int32_t count) +int32_t CompareStringSpan(Span &lhsSp, Span &rhsSp, int32_t count) { for (int32_t i = 0; i < count; ++i) { - auto left = static_cast(lhs_sp[i]); - auto right = static_cast(rhs_sp[i]); + auto left = static_cast(lhsSp[i]); + auto right = static_cast(rhsSp[i]); if (left != right) { return left - right; } @@ -126,62 +126,62 @@ int32_t EcmaString::Compare(const EcmaString *rhs) const if (lhs == rhs) { return 0; } - int32_t lhs_count = lhs->GetLength(); - int32_t rhs_count = rhs->GetLength(); - int32_t count_diff = lhs_count - rhs_count; - int32_t min_count = (count_diff < 0) ? lhs_count : rhs_count; + int32_t lhsCount = lhs->GetLength(); + int32_t rhsCount = rhs->GetLength(); + int32_t countDiff = lhsCount - rhsCount; + int32_t minCount = (countDiff < 0) ? lhsCount : rhsCount; if (!lhs->IsUtf16() && !rhs->IsUtf16()) { - Span lhs_sp(lhs->GetDataUtf8(), lhs_count); - Span rhs_sp(rhs->GetDataUtf8(), rhs_count); - int32_t char_diff = CompareStringSpan(lhs_sp, rhs_sp, min_count); - if (char_diff != 0) { - return char_diff; + Span lhsSp(lhs->GetDataUtf8(), lhsCount); + Span rhsSp(rhs->GetDataUtf8(), rhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); + if (charDiff != 0) { + return charDiff; } } else if (!lhs->IsUtf16()) { - Span lhs_sp(lhs->GetDataUtf8(), lhs_count); - Span rhs_sp(rhs->GetDataUtf16(), rhs_count); - int32_t char_diff = CompareStringSpan(lhs_sp, rhs_sp, min_count); - if (char_diff != 0) { - return char_diff; + Span lhsSp(lhs->GetDataUtf8(), lhsCount); + Span rhsSp(rhs->GetDataUtf16(), rhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); + if (charDiff != 0) { + return charDiff; } } else if (!rhs->IsUtf16()) { - Span lhs_sp(lhs->GetDataUtf16(), rhs_count); - Span rhs_sp(rhs->GetDataUtf8(), lhs_count); - int32_t char_diff = CompareStringSpan(lhs_sp, rhs_sp, min_count); - if (char_diff != 0) { - return char_diff; + Span lhsSp(lhs->GetDataUtf16(), rhsCount); + Span rhsSp(rhs->GetDataUtf8(), lhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); + if (charDiff != 0) { + return charDiff; } } else { - Span lhs_sp(lhs->GetDataUtf16(), lhs_count); - Span rhs_sp(rhs->GetDataUtf16(), rhs_count); - int32_t char_diff = CompareStringSpan(lhs_sp, rhs_sp, min_count); - if (char_diff != 0) { - return char_diff; + Span lhsSp(lhs->GetDataUtf16(), lhsCount); + Span rhsSp(rhs->GetDataUtf16(), rhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); + if (charDiff != 0) { + return charDiff; } } - return count_diff; + return countDiff; } /* static */ template -int32_t EcmaString::IndexOf(Span &lhs_sp, Span &rhs_sp, int32_t pos, int32_t max) +int32_t EcmaString::IndexOf(Span &lhsSp, Span &rhsSp, int32_t pos, int32_t max) { - ASSERT(!rhs_sp.empty()); - auto first = static_cast(rhs_sp[0]); + ASSERT(!rhsSp.empty()); + auto first = static_cast(rhsSp[0]); int32_t i; for (i = pos; i <= max; i++) { - if (static_cast(lhs_sp[i]) != first) { + if (static_cast(lhsSp[i]) != first) { i++; - while (i <= max && static_cast(lhs_sp[i]) != first) { + while (i <= max && static_cast(lhsSp[i]) != first) { i++; } } /* Found first character, now look at the rest of rhs_sp */ if (i <= max) { int j = i + 1; - int end = j + rhs_sp.size() - 1; + int end = j + rhsSp.size() - 1; - for (int k = 1; j < end && static_cast(lhs_sp[j]) == static_cast(rhs_sp[k]); j++, k++) { + for (int k = 1; j < end && static_cast(lhsSp[j]) == static_cast(rhsSp[k]); j++, k++) { } if (j == end) { /* Found whole string. */ @@ -198,14 +198,14 @@ int32_t EcmaString::IndexOf(const EcmaString *rhs, int32_t pos) const return -1; } const EcmaString *lhs = this; - int32_t lhs_count = lhs->GetLength(); - int32_t rhs_count = rhs->GetLength(); + int32_t lhsCount = lhs->GetLength(); + int32_t rhsCount = rhs->GetLength(); - if (pos > lhs_count) { + if (pos > lhsCount) { return -1; } - if (rhs_count == 0) { + if (rhsCount == 0) { return pos; } @@ -213,75 +213,75 @@ int32_t EcmaString::IndexOf(const EcmaString *rhs, int32_t pos) const pos = 0; } - int32_t max = lhs_count - rhs_count; + int32_t max = lhsCount - rhsCount; if (max < 0) { return -1; } if (rhs->IsUtf8() && lhs->IsUtf8()) { - Span lhs_sp(lhs->GetDataUtf8(), lhs_count); - Span rhs_sp(rhs->GetDataUtf8(), rhs_count); - return EcmaString::IndexOf(lhs_sp, rhs_sp, pos, max); + Span lhsSp(lhs->GetDataUtf8(), lhsCount); + Span rhsSp(rhs->GetDataUtf8(), rhsCount); + return EcmaString::IndexOf(lhsSp, rhsSp, pos, max); } if (rhs->IsUtf16() && lhs->IsUtf16()) { // NOLINT(readability-else-after-return) - Span lhs_sp(lhs->GetDataUtf16(), lhs_count); - Span rhs_sp(rhs->GetDataUtf16(), rhs_count); - return EcmaString::IndexOf(lhs_sp, rhs_sp, pos, max); + Span lhsSp(lhs->GetDataUtf16(), lhsCount); + Span rhsSp(rhs->GetDataUtf16(), rhsCount); + return EcmaString::IndexOf(lhsSp, rhsSp, pos, max); } if (rhs->IsUtf16()) { - Span lhs_sp(lhs->GetDataUtf8(), lhs_count); - Span rhs_sp(rhs->GetDataUtf16(), rhs_count); - return EcmaString::IndexOf(lhs_sp, rhs_sp, pos, max); + Span lhsSp(lhs->GetDataUtf8(), lhsCount); + Span rhsSp(rhs->GetDataUtf16(), rhsCount); + return EcmaString::IndexOf(lhsSp, rhsSp, pos, max); } - Span lhs_sp(lhs->GetDataUtf16(), lhs_count); - Span rhs_sp(rhs->GetDataUtf8(), rhs_count); - return EcmaString::IndexOf(lhs_sp, rhs_sp, pos, max); + Span lhsSp(lhs->GetDataUtf16(), lhsCount); + Span rhsSp(rhs->GetDataUtf8(), rhsCount); + return EcmaString::IndexOf(lhsSp, rhsSp, pos, max); return -1; } // static -bool EcmaString::CanBeCompressed(const uint8_t *utf8_data, uint32_t utf8_len) +bool EcmaString::CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len) { - if (!compressed_strings_enabled_) { + if (!compressedStringsEnabled_) { return false; } - bool is_compressed = true; + bool isCompressed = true; uint32_t index = 0; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - while (index < utf8_len) { + while (index < utf8Len) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (!IsASCIICharacter(utf8_data[index])) { - is_compressed = false; + if (!IsASCIICharacter(utf8Data[index])) { + isCompressed = false; break; } ++index; } - return is_compressed; + return isCompressed; } /* static */ -bool EcmaString::CanBeCompressed(const uint16_t *utf16_data, uint32_t utf16_len) +bool EcmaString::CanBeCompressed(const uint16_t *utf16Data, uint32_t utf16Len) { - if (!compressed_strings_enabled_) { + if (!compressedStringsEnabled_) { return false; } - bool is_compressed = true; - Span data(utf16_data, utf16_len); - for (uint32_t i = 0; i < utf16_len; i++) { + bool isCompressed = true; + Span data(utf16Data, utf16Len); + for (uint32_t i = 0; i < utf16Len; i++) { if (!IsASCIICharacter(data[i])) { - is_compressed = false; + isCompressed = false; break; } } - return is_compressed; + return isCompressed; } /* static */ -void EcmaString::CopyUtf16AsUtf8(const uint16_t *utf16_from, uint8_t *utf8_to, uint32_t utf16_len) +void EcmaString::CopyUtf16AsUtf8(const uint16_t *utf16From, uint8_t *utf8To, uint32_t utf16Len) { - Span from(utf16_from, utf16_len); - Span to(utf8_to, utf16_len); - for (uint32_t i = 0; i < utf16_len; i++) { + Span from(utf16From, utf16Len); + Span to(utf8To, utf16Len); + for (uint32_t i = 0; i < utf16Len; i++) { to[i] = from[i]; } } @@ -305,36 +305,36 @@ bool EcmaString::StringsAreEqual(EcmaString *str1, EcmaString *str2) } /* static */ -bool EcmaString::StringsAreEqualUtf8(const EcmaString *str1, const uint8_t *utf8_data, uint32_t utf8_len, - bool can_be_compress) +bool EcmaString::StringsAreEqualUtf8(const EcmaString *str1, const uint8_t *utf8Data, uint32_t utf8Len, + bool canBeCompress) { - if (can_be_compress != str1->IsUtf8()) { + if (canBeCompress != str1->IsUtf8()) { return false; } - if (can_be_compress && str1->GetLength() != utf8_len) { + if (canBeCompress && str1->GetLength() != utf8Len) { return false; } - if (can_be_compress) { - Span data1(str1->GetDataUtf8(), utf8_len); - Span data2(utf8_data, utf8_len); + if (canBeCompress) { + Span data1(str1->GetDataUtf8(), utf8Len); + Span data2(utf8Data, utf8Len); return EcmaString::StringsAreEquals(data1, data2); } - return IsUtf8EqualsUtf16(utf8_data, utf8_len, str1->GetDataUtf16(), str1->GetLength()); + return IsUtf8EqualsUtf16(utf8Data, utf8Len, str1->GetDataUtf16(), str1->GetLength()); } /* static */ -bool EcmaString::StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *utf16_data, uint32_t utf16_len) +bool EcmaString::StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len) { bool result = false; - if (str1->GetLength() != utf16_len) { + if (str1->GetLength() != utf16Len) { result = false; } else if (!str1->IsUtf16()) { - result = IsUtf8EqualsUtf16(str1->GetDataUtf8(), str1->GetLength(), utf16_data, utf16_len); + result = IsUtf8EqualsUtf16(str1->GetDataUtf8(), str1->GetLength(), utf16Data, utf16Len); } else { Span data1(str1->GetDataUtf16(), str1->GetLength()); - Span data2(utf16_data, utf16_len); + Span data2(utf16Data, utf16Len); result = EcmaString::StringsAreEquals(data1, data2); } return result; @@ -358,9 +358,9 @@ bool EcmaString::StringsAreEquals(Span &str1, Span &str2) } template -bool EcmaString::StringCopy(Span &dst, size_t dst_max, Span &src, size_t count) +bool EcmaString::StringCopy(Span &dst, size_t dstMax, Span &src, size_t count) { - ASSERT(dst_max >= count); + ASSERT(dstMax >= count); ASSERT(dst.Size() >= src.Size()); if (src.Size() < SMALL_STRING_SIZE) { for (size_t i = 0; i < src.Size(); i++) { @@ -368,22 +368,22 @@ bool EcmaString::StringCopy(Span &dst, size_t dst_max, Span &src, si } return true; } - if (memcpy_s(dst.data(), dst_max, src.data(), count) != EOK) { + if (memcpy_s(dst.data(), dstMax, src.data(), count) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } return true; } -static int32_t ComputeHashForUtf8(const uint8_t *utf8_data, size_t utf8_len) +static int32_t ComputeHashForUtf8(const uint8_t *utf8Data, size_t utf8Len) { - if (utf8_data == nullptr) { + if (utf8Data == nullptr) { return 0; } uint32_t hash = 0; - while (utf8_len-- > 0) { + while (utf8Len-- > 0) { constexpr size_t SHIFT = 5; - hash = (hash << SHIFT) - hash + *utf8_data++; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + hash = (hash << SHIFT) - hash + *utf8Data++; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } return static_cast(hash); } @@ -391,7 +391,7 @@ static int32_t ComputeHashForUtf8(const uint8_t *utf8_data, size_t utf8_len) uint32_t EcmaString::ComputeHashcode() const { uint32_t hash; - if (compressed_strings_enabled_) { + if (compressedStringsEnabled_) { if (!IsUtf16()) { hash = ComputeHashForData(GetDataUtf8(), GetLength()); } else { @@ -405,41 +405,41 @@ uint32_t EcmaString::ComputeHashcode() const } /* static */ -uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8_data, size_t utf8_len, bool can_be_compress) +uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len, bool canBeCompress) { uint32_t hash; - if (can_be_compress) { - hash = ComputeHashForUtf8(utf8_data, utf8_len); + if (canBeCompress) { + hash = ComputeHashForUtf8(utf8Data, utf8Len); } else { - auto utf16_len = utf::Utf8ToUtf16Size(utf8_data, utf8_len); - PandaVector tmp_buffer(utf16_len); - [[maybe_unused]] auto len = utf::ConvertRegionUtf8ToUtf16(utf8_data, tmp_buffer.data(), utf8_len, utf16_len, 0); - ASSERT(len == utf16_len); - hash = ComputeHashForData(tmp_buffer.data(), utf16_len); + auto utf16Len = utf::Utf8ToUtf16Size(utf8Data, utf8Len); + PandaVector tmpBuffer(utf16Len); + [[maybe_unused]] auto len = utf::ConvertRegionUtf8ToUtf16(utf8Data, tmpBuffer.data(), utf8Len, utf16Len, 0); + ASSERT(len == utf16Len); + hash = ComputeHashForData(tmpBuffer.data(), utf16Len); } return hash; } /* static */ -uint32_t EcmaString::ComputeHashcodeUtf16(const uint16_t *utf16_data, uint32_t length) +uint32_t EcmaString::ComputeHashcodeUtf16(const uint16_t *utf16Data, uint32_t length) { - return ComputeHashForData(utf16_data, length); + return ComputeHashForData(utf16Data, length); } /* static */ -bool EcmaString::IsUtf8EqualsUtf16(const uint8_t *utf8_data, size_t utf8_len, const uint16_t *utf16_data, - uint32_t utf16_len) +bool EcmaString::IsUtf8EqualsUtf16(const uint8_t *utf8Data, size_t utf8Len, const uint16_t *utf16Data, + uint32_t utf16Len) { // length is one more than compared utf16_data, don't need convert all utf8_data to utf16_data - uint32_t utf8_convert_length = utf16_len + 1; - PandaVector tmp_buffer(utf8_convert_length); - auto len = utf::ConvertRegionUtf8ToUtf16(utf8_data, tmp_buffer.data(), utf8_len, utf8_convert_length, 0); - if (len != utf16_len) { + uint32_t utf8ConvertLength = utf16Len + 1; + PandaVector tmpBuffer(utf8ConvertLength); + auto len = utf::ConvertRegionUtf8ToUtf16(utf8Data, tmpBuffer.data(), utf8Len, utf8ConvertLength, 0); + if (len != utf16Len) { return false; } - Span data1(tmp_buffer.data(), len); - Span data2(utf16_data, utf16_len); + Span data1(tmpBuffer.data(), len); + Span data2(utf16Data, utf16Len); return EcmaString::StringsAreEquals(data1, data2); } } // namespace panda::ecmascript diff --git a/runtime/ecma_string.h b/runtime/ecma_string.h index 071722ce28ce8ed9a0a867f2d150631f5b958aeb..e8d8a5c884739fea446fd77cb1701dbfbdd47342 100644 --- a/runtime/ecma_string.h +++ b/runtime/ecma_string.h @@ -53,15 +53,14 @@ public: static const EcmaString *ConstCast(const TaggedObject *object); static EcmaString *CreateEmptyString(const EcmaVM *vm); - static EcmaString *CreateFromUtf8(const uint8_t *utf8_data, uint32_t utf8_len, const EcmaVM *vm, - bool can_be_compress, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); - static EcmaString *CreateFromUtf16(const uint16_t *utf16_data, uint32_t utf16_len, const EcmaVM *vm, - bool can_be_compress, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); - static EcmaString *Concat(const JSHandle &str1_handle, const JSHandle &str2_handle, + static EcmaString *CreateFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len, const EcmaVM *vm, bool canBeCompress, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); + static EcmaString *CreateFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len, const EcmaVM *vm, + bool canBeCompress, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); + static EcmaString *Concat(const JSHandle &str1Handle, const JSHandle &str2Handle, const EcmaVM *vm); - static EcmaString *FastSubString(const JSHandle &src, uint32_t start, uint32_t utf16_len, + static EcmaString *FastSubString(const JSHandle &src, uint32_t start, uint32_t utf16Len, const EcmaVM *vm); static constexpr uint32_t STRING_COMPRESSED_BIT = 0x1; @@ -78,12 +77,12 @@ public: bool IsUtf16() const { - return compressed_strings_enabled_ ? ((GetMixLength() & STRING_COMPRESSED_BIT) == STRING_UNCOMPRESSED) : true; + return compressedStringsEnabled_ ? ((GetMixLength() & STRING_COMPRESSED_BIT) == STRING_UNCOMPRESSED) : true; } bool IsUtf8() const { - return compressed_strings_enabled_ ? ((GetMixLength() & STRING_COMPRESSED_BIT) == STRING_COMPRESSED) : false; + return compressedStringsEnabled_ ? ((GetMixLength() & STRING_COMPRESSED_BIT) == STRING_COMPRESSED) : false; } static size_t ComputeDataSizeUtf16(uint32_t length) @@ -92,9 +91,9 @@ public: } /// Methods for uncompressed strings (UTF16): - static size_t ComputeSizeUtf16(uint32_t utf16_len) + static size_t ComputeSizeUtf16(uint32_t utf16Len) { - return DATA_OFFSET + ComputeDataSizeUtf16(utf16_len); + return DATA_OFFSET + ComputeDataSizeUtf16(utf16Len); } inline uint16_t *GetData() const @@ -109,9 +108,9 @@ public: } /// Methods for compresses strings (UTF8 or LATIN1): - static size_t ComputeSizeUtf8(uint32_t utf8_len) + static size_t ComputeSizeUtf8(uint32_t utf8Len) { - return DATA_OFFSET + utf8_len; + return DATA_OFFSET + utf8Len; } /// It's Utf8 format, but without 0 in the end. @@ -134,17 +133,17 @@ public: return GetLength(); } - inline size_t CopyDataUtf8(uint8_t *buf, size_t max_length) const + inline size_t CopyDataUtf8(uint8_t *buf, size_t maxLength) const { - ASSERT(max_length > 0); + ASSERT(maxLength > 0); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - buf[max_length - 1] = '\0'; - return CopyDataRegionUtf8(buf, 0, GetLength(), max_length) + 1; // add place for zero in the end + buf[maxLength - 1] = '\0'; + return CopyDataRegionUtf8(buf, 0, GetLength(), maxLength) + 1; // add place for zero in the end } - size_t CopyDataRegionUtf8(uint8_t *buf, size_t start, size_t length, size_t max_length) const + size_t CopyDataRegionUtf8(uint8_t *buf, size_t start, size_t length, size_t maxLength) const { - if (length > max_length) { + if (length > maxLength) { return 0; } uint32_t len = GetLength(); @@ -157,23 +156,23 @@ public: UNREACHABLE(); } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (memcpy_s(buf, max_length, GetDataUtf8() + start, length) != EOK) { + if (memcpy_s(buf, maxLength, GetDataUtf8() + start, length) != EOK) { LOG(FATAL, RUNTIME) << "memcpy_s failed"; UNREACHABLE(); } return length; } - return utf::ConvertRegionUtf16ToUtf8(GetDataUtf16(), buf, length, max_length - 1, start); + return utf::ConvertRegionUtf16ToUtf8(GetDataUtf16(), buf, length, maxLength - 1, start); } - inline uint32_t CopyDataUtf16(uint16_t *buf, uint32_t max_length) const + inline uint32_t CopyDataUtf16(uint16_t *buf, uint32_t maxLength) const { - return CopyDataRegionUtf16(buf, 0, GetLength(), max_length); + return CopyDataRegionUtf16(buf, 0, GetLength(), maxLength); } - uint32_t CopyDataRegionUtf16(uint16_t *buf, uint32_t start, uint32_t length, uint32_t max_length) const + uint32_t CopyDataRegionUtf16(uint16_t *buf, uint32_t start, uint32_t length, uint32_t maxLength) const { - if (length > max_length) { + if (length > maxLength) { return 0; } uint32_t len = GetLength(); @@ -182,14 +181,14 @@ public: } if (IsUtf16()) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (memcpy_s(buf, ComputeDataSizeUtf16(max_length), GetDataUtf16() + start, ComputeDataSizeUtf16(length)) != + if (memcpy_s(buf, ComputeDataSizeUtf16(maxLength), GetDataUtf16() + start, ComputeDataSizeUtf16(length)) != EOK) { LOG(FATAL, RUNTIME) << "memcpy_s failed"; UNREACHABLE(); } return length; } - return utf::ConvertRegionUtf8ToUtf16(GetDataUtf8(), buf, len, max_length, start); + return utf::ConvertRegionUtf8ToUtf16(GetDataUtf8(), buf, len, maxLength, start); } // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -202,7 +201,7 @@ public: return std::unique_ptr(buf); } - inline void WriteData(EcmaString *src, uint32_t start, uint32_t dest_size, uint32_t length); + inline void WriteData(EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length); inline void WriteData(char src, uint32_t start); uint32_t GetLength() const { @@ -245,28 +244,28 @@ public: /// Compares strings by bytes, It doesn't check canonical unicode equivalence. static bool StringsAreEqual(EcmaString *str1, EcmaString *str2); /// Compares strings by bytes, It doesn't check canonical unicode equivalence. - static bool StringsAreEqualUtf8(const EcmaString *str1, const uint8_t *utf8_data, uint32_t utf8_len, - bool can_be_compress); + static bool StringsAreEqualUtf8(const EcmaString *str1, const uint8_t *utf8Data, uint32_t utf8Len, + bool canBeCompress); /// Compares strings by bytes, It doesn't check canonical unicode equivalence. - static bool StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *utf16_data, uint32_t utf16_len); - static uint32_t ComputeHashcodeUtf8(const uint8_t *utf8_data, size_t utf8_len, bool can_be_compress); - static uint32_t ComputeHashcodeUtf16(const uint16_t *utf16_data, uint32_t length); + static bool StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len); + static uint32_t ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len, bool canBeCompress); + static uint32_t ComputeHashcodeUtf16(const uint16_t *utf16Data, uint32_t length); static void SetCompressedStringsEnabled(bool val) { - compressed_strings_enabled_ = val; + compressedStringsEnabled_ = val; } static bool GetCompressedStringsEnabled() { - return compressed_strings_enabled_; + return compressedStringsEnabled_; } static EcmaString *AllocStringObject(size_t length, bool compressed, const EcmaVM *vm, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); - static bool CanBeCompressed(const uint8_t *utf8_data, uint32_t utf8_len); - static bool CanBeCompressed(const uint16_t *utf16_data, uint32_t utf16_len); + static bool CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len); + static bool CanBeCompressed(const uint16_t *utf16Data, uint32_t utf16Len); // In last bit of mix_length we store if this string is compressed or not. ACCESSORS_START(TaggedObjectSize()) @@ -298,9 +297,9 @@ private: } uint32_t ComputeHashcode() const; - static void CopyUtf16AsUtf8(const uint16_t *utf16_from, uint8_t *utf8_to, uint32_t utf16_len); + static void CopyUtf16AsUtf8(const uint16_t *utf16From, uint8_t *utf8To, uint32_t utf16Len); - static bool compressed_strings_enabled_; + static bool compressedStringsEnabled_; static bool IsASCIICharacter(uint16_t data) { @@ -312,8 +311,8 @@ private: * str1 should have the same length as utf16_data. * Converts utf8_data to utf16 and compare it with given utf16_data. */ - static bool IsUtf8EqualsUtf16(const uint8_t *utf8_data, size_t utf8_len, const uint16_t *utf16_data, - uint32_t utf16_len); + static bool IsUtf8EqualsUtf16(const uint8_t *utf8Data, size_t utf8Len, const uint16_t *utf16Data, + uint32_t utf16Len); template /// Check that two spans are equal. Should have the same length. @@ -321,10 +320,10 @@ private: template /// Copy String from src to dst - static bool StringCopy(Span &dst, size_t dst_max, Span &src, size_t count); + static bool StringCopy(Span &dst, size_t dstMax, Span &src, size_t count); template - static int32_t IndexOf(Span &lhs_sp, Span &rhs_sp, int32_t pos, int32_t max); + static int32_t IndexOf(Span &lhsSp, Span &rhsSp, int32_t pos, int32_t max); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_STRING_H diff --git a/runtime/ecma_string_table.cpp b/runtime/ecma_string_table.cpp index de0dec8475dcf24120efb3055f83c52394a84c84..1b26a61bf94a2df768f0aeaf348e08e6e4971087 100644 --- a/runtime/ecma_string_table.cpp +++ b/runtime/ecma_string_table.cpp @@ -24,27 +24,27 @@ namespace panda::ecmascript { EcmaStringTable::EcmaStringTable(const EcmaVM *vm) : vm_(vm) {} -EcmaString *EcmaStringTable::GetString(const uint8_t *utf8_data, uint32_t utf8_len, bool can_be_compress) const +EcmaString *EcmaStringTable::GetString(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress) const { - uint32_t hash_code = EcmaString::ComputeHashcodeUtf8(utf8_data, utf8_len, can_be_compress); - os::memory::ReadLockHolder holder(table_lock_); - for (auto it = table_.find(hash_code); it != table_.end(); it++) { - auto founded_string = it->second; - if (EcmaString::StringsAreEqualUtf8(founded_string, utf8_data, utf8_len, can_be_compress)) { - return founded_string; + uint32_t hashCode = EcmaString::ComputeHashcodeUtf8(utf8Data, utf8Len, canBeCompress); + os::memory::ReadLockHolder holder(tableLock_); + for (auto it = table_.find(hashCode); it != table_.end(); it++) { + auto foundedString = it->second; + if (EcmaString::StringsAreEqualUtf8(foundedString, utf8Data, utf8Len, canBeCompress)) { + return foundedString; } } return nullptr; } -EcmaString *EcmaStringTable::GetString(const uint16_t *utf16_data, uint32_t utf16_len) const +EcmaString *EcmaStringTable::GetString(const uint16_t *utf16Data, uint32_t utf16Len) const { - uint32_t hash_code = EcmaString::ComputeHashcodeUtf16(const_cast(utf16_data), utf16_len); - os::memory::ReadLockHolder holder(table_lock_); - for (auto it = table_.find(hash_code); it != table_.end(); it++) { - auto founded_string = it->second; - if (EcmaString::StringsAreEqualUtf16(founded_string, utf16_data, utf16_len)) { - return founded_string; + uint32_t hashCode = EcmaString::ComputeHashcodeUtf16(const_cast(utf16Data), utf16Len); + os::memory::ReadLockHolder holder(tableLock_); + for (auto it = table_.find(hashCode); it != table_.end(); it++) { + auto foundedString = it->second; + if (EcmaString::StringsAreEqualUtf16(foundedString, utf16Data, utf16Len)) { + return foundedString; } } return nullptr; @@ -53,11 +53,11 @@ EcmaString *EcmaStringTable::GetString(const uint16_t *utf16_data, uint32_t utf1 EcmaString *EcmaStringTable::GetString(EcmaString *string) const { auto hash = string->GetHashcode(); - os::memory::ReadLockHolder holder(table_lock_); + os::memory::ReadLockHolder holder(tableLock_); for (auto it = table_.find(hash); it != table_.end(); it++) { - auto founded_string = it->second; - if (EcmaString::StringsAreEqual(founded_string, string)) { - return founded_string; + auto foundedString = it->second; + if (EcmaString::StringsAreEqual(foundedString, string)) { + return foundedString; } } return nullptr; @@ -65,14 +65,14 @@ EcmaString *EcmaStringTable::GetString(EcmaString *string) const ObjectHeader *EcmaStringTable::ResolveString(const panda_file::File &pf, panda_file::File::EntityId id) { - auto found_str = pf.GetStringData(id); + auto foundStr = pf.GetStringData(id); const auto factory = vm_->GetFactory(); - if (UNLIKELY(found_str.utf16_length == 0)) { + if (UNLIKELY(foundStr.utf16Length == 0)) { return *(factory->GetEmptyString()); } - return EcmaString::Cast(this->GetOrInternString(found_str.data, found_str.utf16_length, found_str.is_ascii)); + return EcmaString::Cast(this->GetOrInternString(foundStr.data, foundStr.utf16Length, foundStr.isAscii)); } void EcmaStringTable::InternString(EcmaString *string) @@ -80,38 +80,38 @@ void EcmaStringTable::InternString(EcmaString *string) if (string->IsInternString()) { return; } - os::memory::WriteLockHolder holder(table_lock_); + os::memory::WriteLockHolder holder(tableLock_); table_.insert(std::pair(string->GetHashcode(), string)); string->SetIsInternString(); } -void EcmaStringTable::InternEmptyString(EcmaString *empty_str) +void EcmaStringTable::InternEmptyString(EcmaString *emptyStr) { - InternString(empty_str); + InternString(emptyStr); } -EcmaString *EcmaStringTable::GetOrInternString(const uint8_t *utf8_data, uint32_t utf8_len, bool can_be_compress, - panda::SpaceType space_type) +EcmaString *EcmaStringTable::GetOrInternString(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, + panda::SpaceType spaceType) { - EcmaString *result = GetString(utf8_data, utf8_len, can_be_compress); + EcmaString *result = GetString(utf8Data, utf8Len, canBeCompress); if (result != nullptr) { return result; } - result = EcmaString::CreateFromUtf8(utf8_data, utf8_len, vm_, can_be_compress, space_type); + result = EcmaString::CreateFromUtf8(utf8Data, utf8Len, vm_, canBeCompress, spaceType); InternString(result); return result; } -EcmaString *EcmaStringTable::GetOrInternString(const uint16_t *utf16_data, uint32_t utf16_len, bool can_be_compress, - panda::SpaceType space_type) +EcmaString *EcmaStringTable::GetOrInternString(const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress, + panda::SpaceType spaceType) { - EcmaString *result = GetString(utf16_data, utf16_len); + EcmaString *result = GetString(utf16Data, utf16Len); if (result != nullptr) { return result; } - result = EcmaString::CreateFromUtf16(utf16_data, utf16_len, vm_, can_be_compress, space_type); + result = EcmaString::CreateFromUtf16(utf16Data, utf16Len, vm_, canBeCompress, spaceType); InternString(result); return result; } @@ -133,7 +133,7 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaString *string) void EcmaStringTable::VisitRoots(const StringTable::StringVisitor &visitor, [[maybe_unused]] mem::VisitGCRootFlags flags) { - os::memory::ReadLockHolder holder(table_lock_); + os::memory::ReadLockHolder holder(tableLock_); for (const auto &v : table_) { visitor(v.second); } @@ -141,15 +141,15 @@ void EcmaStringTable::VisitRoots(const StringTable::StringVisitor &visitor, void EcmaStringTable::Sweep(const GCObjectVisitor &visitor) { - os::memory::WriteLockHolder holder(table_lock_); + os::memory::WriteLockHolder holder(tableLock_); for (auto it = table_.begin(); it != table_.end();) { auto *object = it->second; if (object->IsForwarded()) { ASSERT(visitor(object) != ObjectStatus::DEAD_OBJECT); - ObjectHeader *fwd_string = panda::mem::GetForwardAddress(object); - it->second = static_cast(fwd_string); + ObjectHeader *fwdString = panda::mem::GetForwardAddress(object); + it->second = static_cast(fwdString); ++it; - LOG(DEBUG, GC) << "StringTable: forward " << std::hex << object << " -> " << fwd_string; + LOG(DEBUG, GC) << "StringTable: forward " << std::hex << object << " -> " << fwdString; } else if (visitor(object) == ObjectStatus::DEAD_OBJECT) { LOG(DEBUG, GC) << "StringTable: delete string " << std::hex << object << ", val = " << ConvertToPandaString(object); @@ -163,13 +163,13 @@ void EcmaStringTable::Sweep(const GCObjectVisitor &visitor) bool EcmaStringTable::UpdateMoved() { bool updated = false; - os::memory::WriteLockHolder holder(table_lock_); + os::memory::WriteLockHolder holder(tableLock_); for (auto it = table_.begin(); it != table_.end();) { ObjectHeader *object = it->second; if (object->IsForwarded()) { - ObjectHeader *fwd_string = panda::mem::GetForwardAddress(object); - it->second = static_cast(fwd_string); - LOG(DEBUG, GC) << "StringTable: forward " << std::hex << object << " -> " << fwd_string; + ObjectHeader *fwdString = panda::mem::GetForwardAddress(object); + it->second = static_cast(fwdString); + LOG(DEBUG, GC) << "StringTable: forward " << std::hex << object << " -> " << fwdString; updated = true; } ++it; @@ -179,7 +179,7 @@ bool EcmaStringTable::UpdateMoved() void EcmaStringTable::SweepWeakReference(const WeakRootVisitor &visitor) { - os::memory::WriteLockHolder holder(table_lock_); + os::memory::WriteLockHolder holder(tableLock_); for (auto it = table_.begin(); it != table_.end();) { auto *object = it->second; auto fwd = visitor(object); diff --git a/runtime/ecma_string_table.h b/runtime/ecma_string_table.h index 2c189159d082a3de2234325133068fe7f5cd5f41..fb6630e0cc4aacff0b96dacfee263499b15b682f 100644 --- a/runtime/ecma_string_table.h +++ b/runtime/ecma_string_table.h @@ -29,15 +29,15 @@ public: explicit EcmaStringTable(const EcmaVM *vm); virtual ~EcmaStringTable() { - os::memory::WriteLockHolder holder(table_lock_); + os::memory::WriteLockHolder holder(tableLock_); table_.clear(); } - void InternEmptyString(EcmaString *empty_str); - EcmaString *GetOrInternString(const uint8_t *utf8_data, uint32_t utf8_len, bool can_be_compress, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); - EcmaString *GetOrInternString(const uint16_t *utf16_data, uint32_t utf16_len, bool can_be_compress, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); + void InternEmptyString(EcmaString *emptyStr); + EcmaString *GetOrInternString(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); + EcmaString *GetOrInternString(const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); EcmaString *GetOrInternString(EcmaString *string); void SweepWeakReference(const WeakRootVisitor &visitor); @@ -54,8 +54,8 @@ private: NO_COPY_SEMANTIC(EcmaStringTable); NO_MOVE_SEMANTIC(EcmaStringTable); - EcmaString *GetString(const uint8_t *utf8_data, uint32_t utf8_len, bool can_be_compress) const; - EcmaString *GetString(const uint16_t *utf16_data, uint32_t utf16_len) const; + EcmaString *GetString(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress) const; + EcmaString *GetString(const uint16_t *utf16Data, uint32_t utf16Len) const; EcmaString *GetString(EcmaString *string) const; void InternString(EcmaString *string); @@ -68,8 +68,8 @@ private: } } - PandaUnorderedMultiMap table_ GUARDED_BY(table_lock_); - mutable os::memory::RWLock table_lock_; + PandaUnorderedMultiMap table_ GUARDED_BY(tableLock_); + mutable os::memory::RWLock tableLock_; const EcmaVM *vm_ {nullptr}; }; } // namespace panda::ecmascript diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index 0db8ca135f04ca8eafe85af7c622bc8205e83c3c..3daca74c285c443afdb59f6da7e78dff9d12fa8f 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -87,10 +87,10 @@ static const std::string_view ENTRY_METHOD_POINTER = "func_main_0"; JSRuntimeOptions EcmaVM::options_; // NOLINT(fuchsia-statically-constructed-objects) // Create MemoryManager by RuntimeOptions -static mem::MemoryManager *CreateMM(const LanguageContext &ctx, mem::InternalAllocatorPtr internal_allocator, +static mem::MemoryManager *CreateMM(const LanguageContext &ctx, mem::InternalAllocatorPtr internalAllocator, const RuntimeOptions &options) { - mem::MemoryManager::HeapOptions heap_options { + mem::MemoryManager::HeapOptions heapOptions { nullptr, // is_object_finalizeble_func nullptr, // register_finalize_reference_func options.GetMaxGlobalRefSize(), // max_global_ref_size @@ -100,14 +100,14 @@ static mem::MemoryManager *CreateMM(const LanguageContext &ctx, mem::InternalAll options.IsStartAsZygote(), // is_start_as_zygote }; - mem::GCTriggerConfig gc_trigger_config(options, panda_file::SourceLang::ECMASCRIPT); + mem::GCTriggerConfig gcTriggerConfig(options, panda_file::SourceLang::ECMASCRIPT); - mem::GCSettings gc_settings(options, panda_file::SourceLang::ECMASCRIPT); + mem::GCSettings gcSettings(options, panda_file::SourceLang::ECMASCRIPT); - mem::GCType gc_type = Runtime::GetGCType(options, panda_file::SourceLang::ECMASCRIPT); - ASSERT(gc_type != mem::GCType::GEN_GC); + mem::GCType gcType = Runtime::GetGCType(options, panda_file::SourceLang::ECMASCRIPT); + ASSERT(gcType != mem::GCType::GEN_GC); - return mem::MemoryManager::Create(ctx, internal_allocator, gc_type, gc_settings, gc_trigger_config, heap_options); + return mem::MemoryManager::Create(ctx, internalAllocator, gcType, gcSettings, gcTriggerConfig, heapOptions); } /* static */ @@ -120,9 +120,9 @@ EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options) return nullptr; } vm->InitializeGC(); - auto js_thread = JSThread::Create(runtime, vm); - vm->thread_ = js_thread; - vm->thread_manager_->SetMainThread(js_thread); + auto jsThread = JSThread::Create(runtime, vm); + vm->thread_ = jsThread; + vm->threadManager_->SetMainThread(jsThread); if (!vm->Initialize()) { LOG_ECMA(ERROR) << "Failed to initialize jsvm"; runtime->GetInternalAllocator()->Delete(vm); @@ -154,46 +154,46 @@ Expected EcmaVM::Create(Runtime *runtime, const JSRuntime return nullptr; } vm->InitializeGC(); - auto js_thread = ecmascript::JSThread::Create(runtime, vm); - vm->thread_ = js_thread; - vm->thread_manager_->SetMainThread(js_thread); + auto jsThread = ecmascript::JSThread::Create(runtime, vm); + vm->thread_ = jsThread; + vm->threadManager_->SetMainThread(jsThread); return vm; } -EcmaVM::EcmaVM(JSRuntimeOptions options) : string_table_(new EcmaStringTable(this)) +EcmaVM::EcmaVM(JSRuntimeOptions options) : stringTable_(new EcmaStringTable(this)) { auto runtime = Runtime::GetCurrent(); options_ = std::move(options); - ic_enable_ = options_.IsIcEnable(); - optional_log_enabled_ = options_.IsEnableOptionalLog(); - framework_abc_file_name_ = options_.GetFrameworkAbcFile(); + icEnable_ = options_.IsIcEnable(); + optionalLogEnabled_ = options_.IsEnableOptionalLog(); + frameworkAbcFileName_ = options_.GetFrameworkAbcFile(); auto allocator = runtime->GetInternalAllocator(); - thread_manager_ = allocator->New(); + threadManager_ = allocator->New(); rendezvous_ = allocator->New(this); - notification_manager_ = allocator->New(runtime->GetInternalAllocator()); - notification_manager_->SetRendezvous(rendezvous_); + notificationManager_ = allocator->New(runtime->GetInternalAllocator()); + notificationManager_->SetRendezvous(rendezvous_); InitializeRandomEngine(); LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(panda_file::SourceLang::ECMASCRIPT); mm_ = CreateMM(ctx, Runtime::GetCurrent()->GetInternalAllocator(), options_); if (options_.IsReferenceProcessorEnable()) { - ecma_reference_processor_ = MakePandaUnique(this); + ecmaReferenceProcessor_ = MakePandaUnique(this); } else { - ecma_reference_processor_ = MakePandaUnique(); + ecmaReferenceProcessor_ = MakePandaUnique(); } - is_profiling_enabled_ = options_.IsCompilerEnableJit() || options_.WasSetProfileOutput(); + isProfilingEnabled_ = options_.IsCompilerEnableJit() || options_.WasSetProfileOutput(); - if (is_profiling_enabled_) { - call_profiling_table_ = allocator->New(options_.GetCallProfilingTableSize()); + if (isProfilingEnabled_) { + callProfilingTable_ = allocator->New(options_.GetCallProfilingTableSize()); } - auto heap_manager = mm_->GetHeapManager(); - auto internal_allocator = heap_manager->GetInternalAllocator(); - runtime_iface_ = internal_allocator->New(this, internal_allocator); - compiler_ = internal_allocator->New(heap_manager->GetCodeAllocator(), internal_allocator, options_, - heap_manager->GetMemStats(), runtime_iface_); + auto heapManager = mm_->GetHeapManager(); + auto internalAllocator = heapManager->GetInternalAllocator(); + runtimeIface_ = internalAllocator->New(this, internalAllocator); + compiler_ = internalAllocator->New(heapManager->GetCodeAllocator(), internalAllocator, options_, + heapManager->GetMemStats(), runtimeIface_); SetFrameExtSize(ecmascript::JSExtFrame::GetExtSize()); } @@ -222,8 +222,8 @@ bool EcmaVM::Initialize() ECMA_BYTRACE_NAME(BYTRACE_TAG_ARK, "EcmaVM::Initialize"); auto runtime = Runtime::GetCurrent(); - auto global_const = const_cast(thread_->GlobalConstants()); - reg_exp_parser_cache_ = new RegExpParserCache(); + auto globalConst = const_cast(thread_->GlobalConstants()); + regExpParserCache_ = new RegExpParserCache(); factory_ = runtime->GetInternalAllocator()->New(thread_); if (UNLIKELY(factory_ == nullptr)) { LOG_ECMA(FATAL) << "alloc factory_ failed"; @@ -242,58 +242,57 @@ bool EcmaVM::Initialize() [[maybe_unused]] EcmaHandleScope scope(thread_); LOG_ECMA(DEBUG) << "EcmaVM::Initialize run builtins"; - JSHandle dyn_class_class_handle = factory_->NewEcmaDynClassClass(nullptr, JSHClass::SIZE, JSType::HCLASS); - JSHClass *dynclass = reinterpret_cast(dyn_class_class_handle.GetTaggedValue().GetTaggedObject()); + JSHandle dynClassClassHandle = factory_->NewEcmaDynClassClass(nullptr, JSHClass::SIZE, JSType::HCLASS); + JSHClass *dynclass = reinterpret_cast(dynClassClassHandle.GetTaggedValue().GetTaggedObject()); dynclass->SetClass(dynclass); dynclass->GetHClass()->SetNativeFieldMask(JSHClass::NATIVE_FIELDS_MASK); - JSHandle global_env_class = - factory_->CreateDynClass(*dyn_class_class_handle, JSType::GLOBAL_ENV); + JSHandle globalEnvClass = factory_->CreateDynClass(*dynClassClassHandle, JSType::GLOBAL_ENV); - JSHandle global_env_handle = factory_->NewGlobalEnv(*global_env_class); - global_env_ = global_env_handle.GetTaggedValue(); + JSHandle globalEnvHandle = factory_->NewGlobalEnv(*globalEnvClass); + globalEnv_ = globalEnvHandle.GetTaggedValue(); // init global env - global_const->InitRootsClass(thread_, dyn_class_class_handle); + globalConst->InitRootsClass(thread_, dynClassClassHandle); factory_->ObtainRootClass(GetGlobalEnv()); - global_const->InitGlobalConstant(thread_); - JSHandle global_env_handle_array = factory_->NewEmptyArray(); - global_env_handle->SetEmptyArray(thread_, global_env_handle_array); - JSHandle global_env_handle_weak_array = factory_->NewEmptyArray(true); - global_env_handle->SetEmptyWeakArray(thread_, global_env_handle_weak_array); - auto layout_info_handle = factory_->CreateLayoutInfo(0); - global_env_handle->SetEmptyLayoutInfo(thread_, layout_info_handle); - auto symbol_table_handle = SymbolTable::Create(thread_); - global_env_handle->SetRegisterSymbols(thread_, symbol_table_handle); - JSTaggedValue empty_str = thread_->GlobalConstants()->GetEmptyString(); - string_table_->InternEmptyString(EcmaString::Cast(empty_str.GetTaggedObject())); - auto tagged_queue_handle = factory_->NewTaggedQueue(0); - global_env_handle->SetEmptyTaggedQueue(thread_, tagged_queue_handle); - auto template_map_handle = TemplateMap::Create(thread_); - global_env_handle->SetTemplateMap(thread_, template_map_handle); - auto symbol_table_2_handle = SymbolTable::Create(GetJSThread()); - global_env_handle->SetRegisterSymbols(GetJSThread(), symbol_table_2_handle); + globalConst->InitGlobalConstant(thread_); + JSHandle globglobalEnvHandleArray = factory_->NewEmptyArray(); + globalEnvHandle->SetEmptyArray(thread_, globglobalEnvHandleArray); + JSHandle globalEnvHandleWeakArray = factory_->NewEmptyArray(true); + globalEnvHandle->SetEmptyWeakArray(thread_, globalEnvHandleWeakArray); + auto layoutInfoHandle = factory_->CreateLayoutInfo(0); + globalEnvHandle->SetEmptyLayoutInfo(thread_, layoutInfoHandle); + auto symbolTableHandle = SymbolTable::Create(thread_); + globalEnvHandle->SetRegisterSymbols(thread_, symbolTableHandle); + JSTaggedValue emptyStr = thread_->GlobalConstants()->GetEmptyString(); + stringTable_->InternEmptyString(EcmaString::Cast(emptyStr.GetTaggedObject())); + auto taggedQueueHandle = factory_->NewTaggedQueue(0); + globalEnvHandle->SetEmptyTaggedQueue(thread_, taggedQueueHandle); + auto templateMapHandle = TemplateMap::Create(thread_); + globalEnvHandle->SetTemplateMap(thread_, templateMapHandle); + auto symbolTable2Handle = SymbolTable::Create(GetJSThread()); + globalEnvHandle->SetRegisterSymbols(GetJSThread(), symbolTable2Handle); SetupRegExpResultCache(); - micro_job_queue_ = factory_->NewMicroJobQueue().GetTaggedValue(); + microJobQueue_ = factory_->NewMicroJobQueue().GetTaggedValue(); { builtins::Builtins builtins; - builtins.Initialize(global_env_handle, thread_); + builtins.Initialize(globalEnvHandle, thread_); } - thread_->SetGlobalObject(global_env_handle->GetGlobalObject()); + thread_->SetGlobalObject(globalEnvHandle->GetGlobalObject()); - module_manager_ = new ModuleManager(this); + moduleManager_ = new ModuleManager(this); InitializeFinish(); - notification_manager_->VmStartEvent(); - notification_manager_->VmInitializationEvent(thread_->GetThreadId()); + notificationManager_->VmStartEvent(); + notificationManager_->VmInitializationEvent(thread_->GetThreadId()); return true; } void EcmaVM::InitializeEcmaScriptRunStat() { // NOLINTNEXTLINE(modernize-avoid-c-arrays) - static const char *runtime_caller_names[] = { + static const char *runtimeCallerNames[] = { // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define INTERPRETER_CALLER_NAME(name) "InterPreter::" #name, INTERPRETER_CALLER_LIST(INTERPRETER_CALLER_NAME) // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) @@ -310,11 +309,11 @@ void EcmaVM::InitializeEcmaScriptRunStat() ABSTRACT_OPERATION_LIST(ABSTRACT_OPERATION_NAME) #undef ABSTRACT_OPERATION_NAME }; - static_assert(sizeof(runtime_caller_names) == sizeof(const char *) * ecmascript::RUNTIME_CALLER_NUMBER, + static_assert(sizeof(runtimeCallerNames) == sizeof(const char *) * ecmascript::RUNTIME_CALLER_NUMBER, "Invalid runtime caller number"); auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - runtime_stat_ = allocator->New(runtime_caller_names, ecmascript::RUNTIME_CALLER_NUMBER); - if (UNLIKELY(runtime_stat_ == nullptr)) { + runtimeStat_ = allocator->New(runtimeCallerNames, ecmascript::RUNTIME_CALLER_NUMBER); + if (UNLIKELY(runtimeStat_ == nullptr)) { LOG_ECMA(FATAL) << "alloc runtime_stat_ failed"; UNREACHABLE(); } @@ -323,43 +322,43 @@ void EcmaVM::InitializeEcmaScriptRunStat() void EcmaVM::SetRuntimeStatEnable(bool flag) { if (flag) { - if (runtime_stat_ == nullptr) { + if (runtimeStat_ == nullptr) { InitializeEcmaScriptRunStat(); } } else { - if (runtime_stat_enabled_) { - runtime_stat_->Print(); - runtime_stat_->ResetAllCount(); + if (runtimeStatEnabled_) { + runtimeStat_->Print(); + runtimeStat_->ResetAllCount(); } } - runtime_stat_enabled_ = flag; + runtimeStatEnabled_ = flag; } bool EcmaVM::InitializeFinish() { - vm_initialized_ = true; + vmInitialized_ = true; return true; } void EcmaVM::SaveProfileInfo() { if (GetOptions().WasSetProfileOutput()) { - if (profiles_methods_.empty()) { + if (profilesMethods_.empty()) { LOG(WARNING, RUNTIME) << "Profiled methods list is empty"; return; } EcmaProfileContainer proto; - for (auto method : profiles_methods_) { - auto method_name = method->GetFullName(); + for (auto method : profilesMethods_) { + auto methodName = method->GetFullName(); if (method->GetProfilingVector() != nullptr) { panda_file::MethodDataAccessor mda(*method->GetPandaFile(), method->GetFileId()); - auto profile_data = method->GetProfilingVector(); - auto profile_size = mda.GetProfileSize().value(); + auto profileData = method->GetProfilingVector(); + auto profileSize = mda.GetProfileSize().value(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - proto[method_name] = std::vector(profile_data, profile_data + profile_size); + proto[methodName] = std::vector(profileData, profileData + profileSize); } } @@ -393,7 +392,7 @@ void EcmaVM::CleanUpTask(Method *method) EcmaVM::~EcmaVM() { - vm_initialized_ = false; + vmInitialized_ = false; ClearNativeMethodsData(); if (panda::plugins::RuntimeTypeToLang(Runtime::GetCurrent()->GetRuntimeType()) != @@ -402,24 +401,24 @@ EcmaVM::~EcmaVM() Runtime::GetCurrent()->GetClassLinker()->ResetExtension(panda_file::SourceLang::ECMASCRIPT); } - if (runtime_stat_ != nullptr && runtime_stat_enabled_) { - runtime_stat_->Print(); + if (runtimeStat_ != nullptr && runtimeStatEnabled_) { + runtimeStat_->Print(); } // clear c_address: c++ pointer delete ClearBufferData(); - delete reg_exp_parser_cache_; - reg_exp_parser_cache_ = nullptr; + delete regExpParserCache_; + regExpParserCache_ = nullptr; - if (string_table_ != nullptr) { - delete string_table_; - string_table_ = nullptr; + if (stringTable_ != nullptr) { + delete stringTable_; + stringTable_ = nullptr; } - if (module_manager_ != nullptr) { - delete module_manager_; - module_manager_ = nullptr; + if (moduleManager_ != nullptr) { + delete moduleManager_; + moduleManager_ = nullptr; } if (thread_ != nullptr) { @@ -428,44 +427,44 @@ EcmaVM::~EcmaVM() thread_ = nullptr; } - extractor_cache_.clear(); - framework_program_methods_.clear(); + extractorCache_.clear(); + frameworkProgramMethods_.clear(); mem::InternalAllocatorPtr allocator = mm_->GetHeapManager()->GetInternalAllocator(); - allocator->Delete(notification_manager_); + allocator->Delete(notificationManager_); allocator->Delete(factory_); - allocator->Delete(runtime_stat_); + allocator->Delete(runtimeStat_); allocator->Delete(rendezvous_); - allocator->Delete(thread_manager_); - allocator->Delete(runtime_iface_); + allocator->Delete(threadManager_); + allocator->Delete(runtimeIface_); allocator->Delete(compiler_); - if (call_profiling_table_ != nullptr) { - allocator->Delete(call_profiling_table_); + if (callProfilingTable_ != nullptr) { + allocator->Delete(callProfilingTable_); } mm_->Finalize(); mem::MemoryManager::Destroy(mm_); } -bool EcmaVM::ExecuteFromPf(std::string_view filename, std::string_view entry_point, - const std::vector &args, bool is_module) +bool EcmaVM::ExecuteFromPf(std::string_view filename, std::string_view entryPoint, const std::vector &args, + bool isModule) { std::unique_ptr pf; - if (framework_panda_file_ == nullptr || !IsFrameworkPandaFile(filename)) { + if (frameworkPandaFile_ == nullptr || !IsFrameworkPandaFile(filename)) { pf = panda_file::OpenPandaFileOrZip(filename, panda_file::File::READ_WRITE); if (pf == nullptr) { return false; } - AddPandaFile(pf.get(), is_module); // Store here prevent from being automatically cleared - notification_manager_->LoadModuleEvent(pf->GetFilename()); + AddPandaFile(pf.get(), isModule); // Store here prevent from being automatically cleared + notificationManager_->LoadModuleEvent(pf->GetFilename()); } else { - pf.reset(framework_panda_file_); + pf.reset(frameworkPandaFile_); } - return Execute(std::move(pf), entry_point, args, is_module); + return Execute(std::move(pf), entryPoint, args, isModule); } -bool EcmaVM::ExecuteFromBuffer(const void *buffer, size_t size, std::string_view entry_point, +bool EcmaVM::ExecuteFromBuffer(const void *buffer, size_t size, std::string_view entryPoint, const std::vector &args) { auto pf = panda_file::OpenPandaFileFromMemory(buffer, size); @@ -473,31 +472,31 @@ bool EcmaVM::ExecuteFromBuffer(const void *buffer, size_t size, std::string_view return false; } AddPandaFile(pf.get(), false); // Store here prevent from being automatically cleared - notification_manager_->LoadModuleEvent(pf->GetFilename()); + notificationManager_->LoadModuleEvent(pf->GetFilename()); - return Execute(std::move(pf), entry_point, args); + return Execute(std::move(pf), entryPoint, args); } -void EcmaVM::DumpHeap(PandaOStringStream *o_str) const +void EcmaVM::DumpHeap(PandaOStringStream *oStr) const { - size_t obj_cnt = 0; - *o_str << "Dumping heap" << std::endl; - GetHeapManager()->IterateOverObjects([&obj_cnt, &o_str](ObjectHeader *mem) { - JSTaggedValue(mem).Dump(nullptr, *o_str); - obj_cnt++; + size_t objCnt = 0; + *oStr << "Dumping heap" << std::endl; + GetHeapManager()->IterateOverObjects([&objCnt, &oStr](ObjectHeader *mem) { + JSTaggedValue(mem).Dump(nullptr, *oStr); + objCnt++; }); - *o_str << "\nTotal dumped " << obj_cnt << std::endl; + *oStr << "\nTotal dumped " << objCnt << std::endl; } PandaString EcmaVM::GetClassesFootprint() const { - PandaUnorderedMap classes_footprint; + PandaUnorderedMap classesFootprint; PandaStringStream result; - GetHeapManager()->IterateOverObjects([&classes_footprint](ObjectHeader *mem) { - auto obj_type = JSTaggedValue(mem).GetTaggedObject()->GetClass()->GetObjectType(); - classes_footprint[obj_type] += mem->ObjectSize(); + GetHeapManager()->IterateOverObjects([&classesFootprint](ObjectHeader *mem) { + auto objType = JSTaggedValue(mem).GetTaggedObject()->GetClass()->GetObjectType(); + classesFootprint[objType] += mem->ObjectSize(); }); - for (const auto &it : classes_footprint) { + for (const auto &it : classesFootprint) { result << "class: " << JSHClass::DumpJSType(it.first) << ", footprint - " << it.second << std::endl; } return result.str(); @@ -506,56 +505,56 @@ PandaString EcmaVM::GetClassesFootprint() const tooling::ecmascript::PtJSExtractor *EcmaVM::GetDebugInfoExtractor(const panda_file::File *file) { tooling::ecmascript::PtJSExtractor *res = nullptr; - auto it = extractor_cache_.find(file); - if (it == extractor_cache_.end()) { + auto it = extractorCache_.find(file); + if (it == extractorCache_.end()) { auto extractor = std::make_unique(file); res = extractor.get(); - extractor_cache_[file] = std::move(extractor); + extractorCache_[file] = std::move(extractor); } else { res = it->second.get(); } return res; } -bool EcmaVM::Execute(std::unique_ptr pf, std::string_view entry_point, - const std::vector &args, bool is_module) +bool EcmaVM::Execute(std::unique_ptr pf, std::string_view entryPoint, + const std::vector &args, bool isModule) { if (pf == nullptr) { return false; } - const panda_file::File *pf_ptr = pf.get(); + const panda_file::File *pfPtr = pf.get(); Runtime::GetCurrent()->GetClassLinker()->AddPandaFile(std::move(pf)); // Get ClassName and MethodName - size_t pos = entry_point.find_last_of("::"); + size_t pos = entryPoint.find_last_of("::"); if (pos == std::string_view::npos) { - LOG_ECMA(ERROR) << "EntryPoint:" << entry_point << " is illegal"; + LOG_ECMA(ERROR) << "EntryPoint:" << entryPoint << " is illegal"; return false; } - PandaString method_name(entry_point.substr(pos + 1)); + PandaString methodName(entryPoint.substr(pos + 1)); // For Ark application startup - if (!is_module) { + if (!isModule) { thread_->ManagedCodeBegin(); } - InvokeEcmaEntrypoint(*pf_ptr, method_name, args); - if (!is_module) { + InvokeEcmaEntrypoint(*pfPtr, methodName, args); + if (!isModule) { thread_->ManagedCodeEnd(); } return true; } -void EcmaVM::SweepVmRefs(const GCObjectVisitor &gc_object_visitor) +void EcmaVM::SweepVmRefs(const GCObjectVisitor &gcObjectVisitor) { - GetEcmaStringTable()->Sweep(gc_object_visitor); + GetEcmaStringTable()->Sweep(gcObjectVisitor); if (HasEcmaCallProfileTable()) { - GetEcmaCallProfileTable()->Sweep(gc_object_visitor); + GetEcmaCallProfileTable()->Sweep(gcObjectVisitor); } - auto it = finalization_registries_.begin(); - while (it != finalization_registries_.end()) { - if (gc_object_visitor(*it) == ObjectStatus::DEAD_OBJECT) { - auto to_remove = it++; - finalization_registries_.erase(to_remove); + auto it = finalizationRegistries_.begin(); + while (it != finalizationRegistries_.end()) { + if (gcObjectVisitor(*it) == ObjectStatus::DEAD_OBJECT) { + auto toRemove = it++; + finalizationRegistries_.erase(toRemove); } else { ++it; } @@ -564,27 +563,27 @@ void EcmaVM::SweepVmRefs(const GCObjectVisitor &gc_object_visitor) JSHandle EcmaVM::GetGlobalEnv() const { - return JSHandle(reinterpret_cast(&global_env_)); + return JSHandle(reinterpret_cast(&globalEnv_)); } JSHandle EcmaVM::GetMicroJobQueue() const { - return JSHandle(reinterpret_cast(µ_job_queue_)); + return JSHandle(reinterpret_cast(µJobQueue_)); } Method *EcmaVM::GetNativeMethodWrapper() { - if (native_method_wrapper_ != nullptr) { - return native_method_wrapper_; + if (nativeMethodWrapper_ != nullptr) { + return nativeMethodWrapper_; } - auto mutf8_name = reinterpret_cast("LEcmascript/Intrinsics;"); + auto mutf8Name = reinterpret_cast("LEcmascript/Intrinsics;"); auto klass = - Runtime::GetCurrent()->GetClassLinker()->GetExtension(panda_file::SourceLang::ECMASCRIPT)->GetClass(mutf8_name); + Runtime::GetCurrent()->GetClassLinker()->GetExtension(panda_file::SourceLang::ECMASCRIPT)->GetClass(mutf8Name); if (klass == nullptr) { return nullptr; } - mutf8_name = reinterpret_cast("NativeMethodWrapper"); + mutf8Name = reinterpret_cast("NativeMethodWrapper"); Method::Proto proto; auto &shorty = proto.GetShorty(); @@ -592,33 +591,33 @@ Method *EcmaVM::GetNativeMethodWrapper() shorty.emplace_back(panda_file::Type::TypeId::VOID); shorty.emplace_back(panda_file::Type::TypeId::TAGGED); - native_method_wrapper_ = klass->GetDirectMethod(mutf8_name, proto); - return native_method_wrapper_; + nativeMethodWrapper_ = klass->GetDirectMethod(mutf8Name, proto); + return nativeMethodWrapper_; } JSMethod *EcmaVM::GetMethodForNativeFunction(const void *func) { - Method *n_wrapper = GetNativeMethodWrapper(); - ASSERT(n_wrapper != nullptr); + Method *nWrapper = GetNativeMethodWrapper(); + ASSERT(nWrapper != nullptr); auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - auto method = allocator->New(n_wrapper); + auto method = allocator->New(nWrapper); method->SetNativePointer(const_cast(func)); method->SetCompiledEntryPoint(reinterpret_cast(CompiledCodeToBuiltinBridge)); - native_methods_.push_back(method); - return native_methods_.back(); + nativeMethods_.push_back(method); + return nativeMethods_.back(); } void EcmaVM::RedirectMethod(const panda_file::File &pf) { - for (auto method : framework_program_methods_) { + for (auto method : frameworkProgramMethods_) { method->SetPandaFile(&pf); } } void EcmaVM::RegisterFinalizationRegistry(JSHandle registry) { - finalization_registries_.push_back(*registry); + finalizationRegistries_.push_back(*registry); } Expected EcmaVM::InvokeEntrypointImpl(Method *entrypoint, const std::vector &args) @@ -626,20 +625,20 @@ Expected EcmaVM::InvokeEntrypointImpl(Method *entrypoint, c // For testcase startup const panda_file::File *file = entrypoint->GetPandaFile(); AddPandaFile(file, false); - ScopedManagedCodeThread managed_scope(thread_); + ScopedManagedCodeThread managedScope(thread_); return InvokeEcmaEntrypoint(*file, utf::Mutf8AsCString(entrypoint->GetName().data), args); } Expected EcmaVM::GetInvocableFunction(const panda_file::File &pf, - const PandaString &method_name) + const PandaString &methodName) { [[maybe_unused]] EcmaHandleScope scope(thread_); JSHandle program; - if (&pf != framework_panda_file_) { - program = PandaFileTranslator::TranslatePandaFile(this, pf, method_name); + if (&pf != frameworkPandaFile_) { + program = PandaFileTranslator::TranslatePandaFile(this, pf, methodName); } else { JSHandle string = factory_->NewFromStdStringUnCheck(pf.GetFilename(), true); - program = JSHandle(thread_, framework_program_); + program = JSHandle(thread_, frameworkProgram_); program->SetLocation(thread_, string); RedirectMethod(pf); } @@ -653,20 +652,20 @@ Expected EcmaVM::GetInvocableFunction(const panda return program->GetMainFunction(); } -Expected EcmaVM::InvokeEcmaEntrypoint(const panda_file::File &pf, const PandaString &method_name, +Expected EcmaVM::InvokeEcmaEntrypoint(const panda_file::File &pf, const PandaString &methodName, const std::vector &args) { [[maybe_unused]] EcmaHandleScope scope(thread_); - auto resolve_func = GetInvocableFunction(pf, method_name); + auto resolveFunc = GetInvocableFunction(pf, methodName); - if (!resolve_func.HasValue()) { - return Unexpected(resolve_func.Error()); + if (!resolveFunc.HasValue()) { + return Unexpected(resolveFunc.Error()); } - JSHandle func(thread_, resolve_func.Value()); - JSHandle global = GlobalEnv::Cast(global_env_.GetTaggedObject())->GetJSGlobalObject(); - JSHandle new_target(thread_, JSTaggedValue::Undefined()); - auto info = NewRuntimeCallInfo(thread_, func, global, new_target, args.size()); + JSHandle func(thread_, resolveFunc.Value()); + JSHandle global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject(); + JSHandle newTarget(thread_, JSTaggedValue::Undefined()); + auto info = NewRuntimeCallInfo(thread_, func, global, newTarget, args.size()); uint32_t i = 0; for (const std::string &str : args) { JSHandle strobj(factory_->NewFromStdString(str)); @@ -683,18 +682,18 @@ Expected EcmaVM::InvokeEcmaEntrypoint(const panda_file::Fil return 0; } -void EcmaVM::AddPandaFile(const panda_file::File *pf, bool is_module) +void EcmaVM::AddPandaFile(const panda_file::File *pf, bool isModule) { ASSERT(pf != nullptr); - os::memory::LockHolder lock(panda_file_with_program_lock_); - panda_file_with_program_.push_back(std::make_tuple(nullptr, pf, is_module)); + os::memory::LockHolder lock(pandaFileWithProgramLock_); + pandaFileWithProgram_.push_back(std::make_tuple(nullptr, pf, isModule)); } #ifndef NDEBUG static bool IsNonMovable(ObjectHeader *obj, EcmaVM *vm) { - mem::GCType gc_type = vm->GetGC()->GetType(); - if (gc_type == mem::GCType::EPSILON_GC || gc_type == mem::GCType::STW_GC) { + mem::GCType gcType = vm->GetGC()->GetType(); + if (gcType == mem::GCType::EPSILON_GC || gcType == mem::GCType::STW_GC) { return true; } return PoolManager::GetMmapMemPool()->GetSpaceTypeForAddr(obj) == SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT; @@ -704,17 +703,17 @@ static bool IsNonMovable(ObjectHeader *obj, EcmaVM *vm) void EcmaVM::SetProgram(Program *program, const panda_file::File *pf) { ASSERT(IsNonMovable(program, this)); - os::memory::LockHolder lock(panda_file_with_program_lock_); - auto it = std::find_if(panda_file_with_program_.begin(), panda_file_with_program_.end(), + os::memory::LockHolder lock(pandaFileWithProgramLock_); + auto it = std::find_if(pandaFileWithProgram_.begin(), pandaFileWithProgram_.end(), [pf](auto entry) { return std::get<1>(entry) == pf; }); - ASSERT(it != panda_file_with_program_.end()); + ASSERT(it != pandaFileWithProgram_.end()); std::get<0>(*it) = program; } bool EcmaVM::IsFrameworkPandaFile(std::string_view filename) const { - return filename.size() >= framework_abc_file_name_.size() && - filename.substr(filename.size() - framework_abc_file_name_.size()) == framework_abc_file_name_; + return filename.size() >= frameworkAbcFileName_.size() && + filename.substr(filename.size() - frameworkAbcFileName_.size()) == frameworkAbcFileName_; } JSHandle EcmaVM::GetEcmaUncaughtException() const @@ -722,77 +721,77 @@ JSHandle EcmaVM::GetEcmaUncaughtException() const if (thread_->GetException().IsHole()) { return JSHandle(); } - JSHandle exception_handle(thread_, thread_->GetException()); + JSHandle exceptionHandle(thread_, thread_->GetException()); thread_->ClearException(); // clear for ohos app - if (exception_handle->IsObjectWrapper()) { - JSHandle wrapper_value = JSHandle::Cast(exception_handle); - JSHandle throw_value(thread_, wrapper_value->GetValue()); - return throw_value; + if (exceptionHandle->IsObjectWrapper()) { + JSHandle wrapperValue = JSHandle::Cast(exceptionHandle); + JSHandle throwValue(thread_, wrapperValue->GetValue()); + return throwValue; } - return exception_handle; + return exceptionHandle; } void EcmaVM::EnableUserUncaughtErrorHandler() { - is_uncaught_exception_registered_ = true; + isUncaughtExceptionRegistered_ = true; } void EcmaVM::HandleUncaughtException() { - if (is_uncaught_exception_registered_) { + if (isUncaughtExceptionRegistered_) { return; } ScopedManagedCodeThread s(thread_); - [[maybe_unused]] EcmaHandleScope handle_scope(thread_); - JSHandle exception_handle(thread_, JSTaggedValue(thread_->GetException())); + [[maybe_unused]] EcmaHandleScope handleScope(thread_); + JSHandle exceptionHandle(thread_, JSTaggedValue(thread_->GetException())); // if caught exceptionHandle type is JSError thread_->ClearException(); - if (exception_handle->IsJSError()) { - PrintJSErrorInfo(exception_handle); + if (exceptionHandle->IsJSError()) { + PrintJSErrorInfo(exceptionHandle); return; } - if (exception_handle->IsObjectWrapper()) { - JSHandle wrapper_value = JSHandle::Cast(exception_handle); - JSHandle throw_value(thread_, wrapper_value->GetValue()); - if (throw_value->IsJSError()) { - PrintJSErrorInfo(throw_value); + if (exceptionHandle->IsObjectWrapper()) { + JSHandle wrapperValue = JSHandle::Cast(exceptionHandle); + JSHandle throwValue(thread_, wrapperValue->GetValue()); + if (throwValue->IsJSError()) { + PrintJSErrorInfo(throwValue); } else { - JSHandle result = JSTaggedValue::ToString(thread_, throw_value); + JSHandle result = JSTaggedValue::ToString(thread_, throwValue); PandaString string = ConvertToPandaString(*result); LOG(ERROR, RUNTIME) << string; } } } -void EcmaVM::PrintJSErrorInfo(const JSHandle &exception_info) +void EcmaVM::PrintJSErrorInfo(const JSHandle &exceptionInfo) { - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle name(JSObject::GetProperty(thread_, exception_info, name_key).GetValue()); - JSHandle msg_key = thread_->GlobalConstants()->GetHandledMessageString(); - JSHandle msg(JSObject::GetProperty(thread_, exception_info, msg_key).GetValue()); - JSHandle stack_key = thread_->GlobalConstants()->GetHandledStackString(); - JSHandle stack(JSObject::GetProperty(thread_, exception_info, stack_key).GetValue()); - - PandaString name_buffer = ConvertToPandaString(*name); - PandaString msg_buffer = ConvertToPandaString(*msg); - PandaString stack_buffer = ConvertToPandaString(*stack); - LOG(ERROR, RUNTIME) << name_buffer << ": " << msg_buffer << "\n" << stack_buffer; + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle name(JSObject::GetProperty(thread_, exceptionInfo, nameKey).GetValue()); + JSHandle msgKey = thread_->GlobalConstants()->GetHandledMessageString(); + JSHandle msg(JSObject::GetProperty(thread_, exceptionInfo, msgKey).GetValue()); + JSHandle stackKey = thread_->GlobalConstants()->GetHandledStackString(); + JSHandle stack(JSObject::GetProperty(thread_, exceptionInfo, stackKey).GetValue()); + + PandaString nameBuffer = ConvertToPandaString(*name); + PandaString msgBuffer = ConvertToPandaString(*msg); + PandaString stackBuffer = ConvertToPandaString(*stack); + LOG(ERROR, RUNTIME) << nameBuffer << ": " << msgBuffer << "\n" << stackBuffer; } void EcmaVM::ProcessReferences(const WeakRootVisitor &v0) { - if (reg_exp_parser_cache_ != nullptr) { - reg_exp_parser_cache_->Clear(); + if (regExpParserCache_ != nullptr) { + regExpParserCache_->Clear(); } // array buffer - for (auto iter = array_buffer_data_list_.begin(); iter != array_buffer_data_list_.end();) { + for (auto iter = arrayBufferDataList_.begin(); iter != arrayBufferDataList_.end();) { JSNativePointer *object = *iter; auto fwd = v0(reinterpret_cast(object)); if (fwd == nullptr) { object->Destroy(); - iter = array_buffer_data_list_.erase(iter); + iter = arrayBufferDataList_.erase(iter); } else if (fwd != reinterpret_cast(object)) { *iter = JSNativePointer::Cast(fwd); ++iter; @@ -808,7 +807,7 @@ void EcmaVM::HandleGCRoutineInMutator() ASSERT(Thread::GetCurrent() == thread_); ASSERT(GetMutatorLock()->HasLock()); [[maybe_unused]] EcmaHandleScope scope(thread_); - for (JSFinalizationRegistry *registry : finalization_registries_) { + for (JSFinalizationRegistry *registry : finalizationRegistries_) { JSHandle handle(thread_, registry); JSFinalizationRegistry::CallCleanupCallback(thread_, handle); } @@ -816,33 +815,32 @@ void EcmaVM::HandleGCRoutineInMutator() void EcmaVM::PushToArrayDataList(JSNativePointer *array) { - if (std::find(array_buffer_data_list_.begin(), array_buffer_data_list_.end(), array) != - array_buffer_data_list_.end()) { + if (std::find(arrayBufferDataList_.begin(), arrayBufferDataList_.end(), array) != arrayBufferDataList_.end()) { return; } - array_buffer_data_list_.emplace_back(array); + arrayBufferDataList_.emplace_back(array); } void EcmaVM::RemoveArrayDataList(JSNativePointer *array) { - auto iter = std::find(array_buffer_data_list_.begin(), array_buffer_data_list_.end(), array); - if (iter != array_buffer_data_list_.end()) { - array_buffer_data_list_.erase(iter); + auto iter = std::find(arrayBufferDataList_.begin(), arrayBufferDataList_.end(), array); + if (iter != arrayBufferDataList_.end()) { + arrayBufferDataList_.erase(iter); } } -bool EcmaVM::VerifyFilePath(const PandaString &file_path) const +bool EcmaVM::VerifyFilePath(const PandaString &filePath) const { - if (file_path.size() > PATH_MAX) { + if (filePath.size() > PATH_MAX) { return false; } - PandaVector resolved_path(PATH_MAX); - auto result = realpath(file_path.c_str(), resolved_path.data()); + PandaVector resolvedPath(PATH_MAX); + auto result = realpath(filePath.c_str(), resolvedPath.data()); if (result == nullptr) { return false; } - std::ifstream file(resolved_path.data()); + std::ifstream file(resolvedPath.data()); if (!file.good()) { return false; } @@ -852,17 +850,17 @@ bool EcmaVM::VerifyFilePath(const PandaString &file_path) const void EcmaVM::ClearBufferData() { - for (auto iter : array_buffer_data_list_) { + for (auto iter : arrayBufferDataList_) { iter->Destroy(); } - array_buffer_data_list_.clear(); + arrayBufferDataList_.clear(); - os::memory::LockHolder lock(panda_file_with_program_lock_); - for (auto iter = panda_file_with_program_.begin(); iter != panda_file_with_program_.end();) { + os::memory::LockHolder lock(pandaFileWithProgramLock_); + for (auto iter = pandaFileWithProgram_.begin(); iter != pandaFileWithProgram_.end();) { std::get<0>(*iter)->FreeMethodData(); - iter = panda_file_with_program_.erase(iter); + iter = pandaFileWithProgram_.erase(iter); } - panda_file_with_program_.clear(); + pandaFileWithProgram_.clear(); } bool EcmaVM::ExecutePromisePendingJob() const @@ -897,13 +895,13 @@ void EcmaVM::CollectGarbage() const void EcmaVM::Iterate(const RootVisitor &v) { - v(Root::ROOT_VM, ObjectSlot(ToUintPtr(&global_env_))); - v(Root::ROOT_VM, ObjectSlot(ToUintPtr(µ_job_queue_))); - v(Root::ROOT_VM, ObjectSlot(ToUintPtr(&module_manager_->ecma_modules_))); - v(Root::ROOT_VM, ObjectSlot(ToUintPtr(®exp_cache_))); + v(Root::ROOT_VM, ObjectSlot(ToUintPtr(&globalEnv_))); + v(Root::ROOT_VM, ObjectSlot(ToUintPtr(µJobQueue_))); + v(Root::ROOT_VM, ObjectSlot(ToUintPtr(&moduleManager_->ecmaModules_))); + v(Root::ROOT_VM, ObjectSlot(ToUintPtr(®expCache_))); - os::memory::LockHolder lock(panda_file_with_program_lock_); - for (const auto &iter : panda_file_with_program_) { + os::memory::LockHolder lock(pandaFileWithProgramLock_); + for (const auto &iter : pandaFileWithProgram_) { v(Root::ROOT_VM, ObjectSlot(ToUintPtr(&std::get<0>(iter)))); } } @@ -911,71 +909,71 @@ void EcmaVM::Iterate(const RootVisitor &v) void EcmaVM::SetGlobalEnv(GlobalEnv *global) { ASSERT(global != nullptr); - global_env_ = JSTaggedValue(global); + globalEnv_ = JSTaggedValue(global); } void EcmaVM::SetMicroJobQueue(job::MicroJobQueue *queue) { ASSERT(queue != nullptr); - micro_job_queue_ = JSTaggedValue(queue); + microJobQueue_ = JSTaggedValue(queue); } const panda_file::File *EcmaVM::GetLastLoadedPandaFile() { - os::memory::LockHolder lock(panda_file_with_program_lock_); - auto current_file_tuple = panda_file_with_program_.back(); - return std::get<1>(current_file_tuple); + os::memory::LockHolder lock(pandaFileWithProgramLock_); + auto currentFileTuple = pandaFileWithProgram_.back(); + return std::get<1>(currentFileTuple); } -JSHandle EcmaVM::GetModuleByName(JSHandle module_name) +JSHandle EcmaVM::GetModuleByName(JSHandle moduleName) { - const std::string ¤t_path_file = GetLastLoadedPandaFile()->GetFilename(); - PandaString relative_file = ConvertToPandaString(EcmaString::Cast(module_name->GetTaggedObject())); + const std::string ¤tPathFile = GetLastLoadedPandaFile()->GetFilename(); + PandaString relativeFile = ConvertToPandaString(EcmaString::Cast(moduleName->GetTaggedObject())); // generate full path - PandaString abc_path = module_manager_->GenerateModuleFullPath(current_path_file, relative_file); + PandaString abcPath = moduleManager_->GenerateModuleFullPath(currentPathFile, relativeFile); // Uniform module name - JSHandle abcmodule_name = factory_->NewFromString(abc_path); + JSHandle abcmoduleName = factory_->NewFromString(abcPath); - JSHandle module = module_manager_->GetModule(thread_, JSHandle::Cast(abcmodule_name)); + JSHandle module = moduleManager_->GetModule(thread_, JSHandle::Cast(abcmoduleName)); if (module->IsUndefined()) { - PandaString file = ConvertToPandaString(abcmodule_name.GetObject()); + PandaString file = ConvertToPandaString(abcmoduleName.GetObject()); std::vector argv; ExecuteModule(file, ENTRY_POINTER, argv); - module = module_manager_->GetModule(thread_, JSHandle::Cast(abcmodule_name)); + module = moduleManager_->GetModule(thread_, JSHandle::Cast(abcmoduleName)); } return module; } -void EcmaVM::ExecuteModule(std::string_view module_file, std::string_view entry_point, +void EcmaVM::ExecuteModule(std::string_view moduleFile, std::string_view entryPoint, const std::vector &args) { - module_manager_->SetCurrentExportModuleName(module_file); + moduleManager_->SetCurrentExportModuleName(moduleFile); // Update Current Module - EcmaVM::ExecuteFromPf(module_file, entry_point, args, true); + EcmaVM::ExecuteFromPf(moduleFile, entryPoint, args, true); // Restore Current Module - module_manager_->RestoreCurrentExportModuleName(); + moduleManager_->RestoreCurrentExportModuleName(); } void EcmaVM::ClearNativeMethodsData() { auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - for (auto iter : native_methods_) { + for (auto iter : nativeMethods_) { allocator->Delete(iter); } - native_methods_.clear(); + nativeMethods_.clear(); } void EcmaVM::SetupRegExpResultCache() { - regexp_cache_ = builtins::RegExpExecResultCache::CreateCacheTable(thread_); + regexpCache_ = builtins::RegExpExecResultCache::CreateCacheTable(thread_); } -void EcmaVM::HandleLdaStr(Frame *frame, BytecodeId string_id) +void EcmaVM::HandleLdaStr(Frame *frame, BytecodeId stringId) { auto cp = ConstantPool::Cast(JSFrame::GetJSEnv(frame)->GetConstantPool()); - auto value = cp->GetObjectFromCache(string_id.AsIndex()); + auto value = cp->GetObjectFromCache(stringId.AsIndex()); frame->GetAcc().Set(value.GetRawData()); } @@ -992,15 +990,15 @@ coretypes::String *EcmaVM::ResolveString(Frame *frame, panda_file::File::EntityI std::unique_ptr EcmaVM::OpenPandaFile(std::string_view location) { - panda_file::File::OpenMode open_mode = GetLanguageContext().GetBootPandaFilesOpenMode(); - auto pf = panda_file::OpenPandaFile(location, "", open_mode); + panda_file::File::OpenMode openMode = GetLanguageContext().GetBootPandaFilesOpenMode(); + auto pf = panda_file::OpenPandaFile(location, "", openMode); // PandaFileTranslator can trigger GC. ScopedManagedCodeThread s(thread_); - [[maybe_unused]] EcmaHandleScope handle_scope(GetJSThread()); + [[maybe_unused]] EcmaHandleScope handleScope(GetJSThread()); auto program = PandaFileTranslator::TranslatePandaFile(this, *pf, ENTRY_METHOD_POINTER.data()); { - os::memory::LockHolder lock(panda_file_with_program_lock_); - panda_file_with_program_.emplace_back(program.GetObject(), pf.get(), false); + os::memory::LockHolder lock(pandaFileWithProgramLock_); + pandaFileWithProgram_.emplace_back(program.GetObject(), pf.get(), false); } return pf; } @@ -1016,8 +1014,8 @@ void EcmaVM::HandleReturnFrame() {} void EcmaVM::VisitVmRoots(const GCRootVisitor &visitor) { PandaVM::VisitVmRoots(visitor); - ObjectXRay root_manager(this); - auto common_visitor = [&visitor](Root type, ObjectSlot slot) { + ObjectXRay rootManager(this); + auto commonVisitor = [&visitor](Root type, ObjectSlot slot) { mem::RootType root; switch (type) { case Root::ROOT_FRAME: @@ -1033,14 +1031,14 @@ void EcmaVM::VisitVmRoots(const GCRootVisitor &visitor) } }; - auto single_visitor = [&common_visitor](Root type, ObjectSlot slot) { common_visitor(type, slot); }; + auto singleVisitor = [&commonVisitor](Root type, ObjectSlot slot) { commonVisitor(type, slot); }; - auto range_visitor = [&common_visitor](Root type, ObjectSlot start, ObjectSlot end) { + auto rangeVisitor = [&commonVisitor](Root type, ObjectSlot start, ObjectSlot end) { for (ObjectSlot slot = start; slot < end; slot++) { - common_visitor(type, slot); + commonVisitor(type, slot); } }; - root_manager.VisitVMRoots(single_visitor, range_visitor); + rootManager.VisitVMRoots(singleVisitor, rangeVisitor); if (HasEcmaCallProfileTable()) { GetEcmaCallProfileTable()->VisitRoots(visitor); } @@ -1049,8 +1047,8 @@ void EcmaVM::VisitVmRoots(const GCRootVisitor &visitor) void EcmaVM::UpdateVmRefs() { PandaVM::UpdateVmRefs(); - ObjectXRay root_manager(this); - auto single_visitor = []([[maybe_unused]] Root type, ObjectSlot slot) { + ObjectXRay rootManager(this); + auto singleVisitor = []([[maybe_unused]] Root type, ObjectSlot slot) { JSTaggedValue value(slot.GetTaggedType()); if (value.IsHeapObject()) { ObjectHeader *object = value.GetHeapObject(); @@ -1059,29 +1057,29 @@ void EcmaVM::UpdateVmRefs() } } }; - auto single_ptr_visitor = []([[maybe_unused]] Root type, ObjectHeader **object) { + auto singlePtrVisitor = []([[maybe_unused]] Root type, ObjectHeader **object) { if ((*object)->IsForwarded()) { *object = TaggedObject::Cast(panda::mem::GetForwardAddress(*object)); } }; - auto range_visitor = [&single_visitor](Root type, ObjectSlot start, ObjectSlot end) { + auto rangeVisitor = [&singleVisitor](Root type, ObjectSlot start, ObjectSlot end) { for (ObjectSlot slot = start; slot < end; slot++) { - single_visitor(type, slot); + singleVisitor(type, slot); } }; - root_manager.VisitVMRoots(single_visitor, range_visitor); + rootManager.VisitVMRoots(singleVisitor, rangeVisitor); // Special handling of array_buffer_data_list_ // Don't handle it in ObjectXRay because these refs shouldn't be marked // as gc roots // NOLINTNEXTLINE(modernize-loop-convert) - for (size_t i = 0; i < array_buffer_data_list_.size(); ++i) { - single_ptr_visitor(Root::ROOT_VM, reinterpret_cast(&array_buffer_data_list_[i])); + for (size_t i = 0; i < arrayBufferDataList_.size(); ++i) { + singlePtrVisitor(Root::ROOT_VM, reinterpret_cast(&arrayBufferDataList_[i])); } - for (auto &entry : finalization_registries_) { - single_ptr_visitor(Root::ROOT_VM, reinterpret_cast(&entry)); + for (auto &entry : finalizationRegistries_) { + singlePtrVisitor(Root::ROOT_VM, reinterpret_cast(&entry)); } // Update call profiling table diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index 199c6c8b514c60ae11559de6668c4bd9024ee51e..7a901593ac5582a2d1eb56fcd5850b71fb40a19b 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -105,23 +105,23 @@ public: ~EcmaVM() override; - bool ExecuteFromPf(std::string_view filename, std::string_view entry_point, const std::vector &args, - bool is_module = false); + bool ExecuteFromPf(std::string_view filename, std::string_view entryPoint, const std::vector &args, + bool isModule = false); - bool ExecuteFromBuffer(const void *buffer, size_t size, std::string_view entry_point, + bool ExecuteFromBuffer(const void *buffer, size_t size, std::string_view entryPoint, const std::vector &args); Expected GetInvocableFunction(const panda_file::File &pf, - const PandaString &method_name); + const PandaString &methodName); PtJSExtractor *GetDebugInfoExtractor(const panda_file::File *file); bool IsInitialized() const { - return vm_initialized_; + return vmInitialized_; } - void HandleLdaStr(Frame *frame, BytecodeId string_id) override; + void HandleLdaStr(Frame *frame, BytecodeId stringId) override; ObjectFactory *GetFactory() const { @@ -203,8 +203,8 @@ public: coretypes::String *ResolveString(const panda_file::File &pf, panda_file::File::EntityId id) override { - ASSERT(string_table_ != nullptr); - auto str = string_table_->ResolveString(pf, id); + ASSERT(stringTable_ != nullptr); + auto str = stringTable_->ResolveString(pf, id); return coretypes::String::Cast(str); } @@ -221,7 +221,7 @@ public: SingleThreadManager *GetThreadManager() const override { - return thread_manager_; + return threadManager_; } void VisitStringTable(const StringTable::StringVisitor &visitor, mem::VisitGCRootFlags flags) override @@ -234,7 +234,7 @@ public: VisitStringTable(visitor, mem::VisitGCRootFlags::ACCESS_ROOT_ALL); } - void SweepVmRefs(const GCObjectVisitor &gc_object_visitor) override; + void SweepVmRefs(const GCObjectVisitor &gcObjectVisitor) override; bool UpdateMovedStrings() override { @@ -263,7 +263,7 @@ public: compiler::RuntimeInterface *GetCompilerRuntimeInterface() const override { - return runtime_iface_; + return runtimeIface_; } ObjectHeader *GetOOMErrorObject() override @@ -274,7 +274,7 @@ public: panda::mem::ReferenceProcessor *GetReferenceProcessor() const override { - return ecma_reference_processor_.get(); + return ecmaReferenceProcessor_.get(); } const RuntimeOptions &GetOptions() const override @@ -295,27 +295,27 @@ public: RegExpParserCache *GetRegExpParserCache() const { - ASSERT(reg_exp_parser_cache_ != nullptr); - return reg_exp_parser_cache_; + ASSERT(regExpParserCache_ != nullptr); + return regExpParserCache_; } PANDA_PUBLIC_API JSMethod *GetMethodForNativeFunction(const void *func); EcmaStringTable *GetEcmaStringTable() const { - ASSERT(string_table_ != nullptr); - return string_table_; + ASSERT(stringTable_ != nullptr); + return stringTable_; } bool HasEcmaCallProfileTable() const { - return call_profiling_table_ != nullptr; + return callProfilingTable_ != nullptr; } EcmaCallProfilingTable *GetEcmaCallProfileTable() const { - ASSERT(call_profiling_table_ != nullptr); - return call_profiling_table_; + ASSERT(callProfilingTable_ != nullptr); + return callProfilingTable_; } JSThread *GetJSThread() const @@ -325,7 +325,7 @@ public: bool ICEnable() const { - return ic_enable_; + return icEnable_; } void HandleReferences([[maybe_unused]] const GCTask &task, const mem::GC::ReferenceClearPredicateT &pred) override @@ -344,8 +344,8 @@ public: template void EnumeratePandaFiles(Callback cb) const { - os::memory::LockHolder lock(panda_file_with_program_lock_); - for (const auto &iter : panda_file_with_program_) { + os::memory::LockHolder lock(pandaFileWithProgramLock_); + for (const auto &iter : pandaFileWithProgram_) { if (!cb(std::get<0>(iter), std::get<1>(iter))) { break; } @@ -353,11 +353,11 @@ public: } template - void EnumerateProgram(Callback cb, const std::string &panda_file) const + void EnumerateProgram(Callback cb, const std::string &pandaFile) const { - os::memory::LockHolder lock(panda_file_with_program_lock_); - for (const auto &iter : panda_file_with_program_) { - if (panda_file == std::get<1>(iter)->GetFilename()) { + os::memory::LockHolder lock(pandaFileWithProgramLock_); + for (const auto &iter : pandaFileWithProgram_) { + if (pandaFile == std::get<1>(iter)->GetFilename()) { cb(std::get<0>(iter)); break; } @@ -366,19 +366,19 @@ public: EcmaRuntimeStat *GetRuntimeStat() const { - return runtime_stat_; + return runtimeStat_; } void SetRuntimeStatEnable(bool flag); bool IsRuntimeStatEnabled() const { - return runtime_stat_enabled_; + return runtimeStatEnabled_; } bool IsOptionalLogEnabled() const { - return optional_log_enabled_; + return optionalLogEnabled_; } /// @brief Calls GC::RegisterNativeAllocation and allocates memory in internal space @@ -394,36 +394,35 @@ public: void ProcessReferences(const WeakRootVisitor &v0); void HandleGCRoutineInMutator() override; - JSHandle GetModuleByName(JSHandle module_name); + JSHandle GetModuleByName(JSHandle moduleName); - void ExecuteModule(std::string_view module_file, std::string_view entry_point, - const std::vector &args); + void ExecuteModule(std::string_view moduleFile, std::string_view entryPoint, const std::vector &args); ModuleManager *GetModuleManager() const { - return module_manager_; + return moduleManager_; } void SetupRegExpResultCache(); JSHandle GetRegExpCache() const { - return JSHandle(reinterpret_cast(®exp_cache_)); + return JSHandle(reinterpret_cast(®expCache_)); } - void SetRegExpCache(JSTaggedValue new_cache) + void SetRegExpCache(JSTaggedValue newCache) { - regexp_cache_ = new_cache; + regexpCache_ = newCache; } RuntimeNotificationManager *GetNotificationManager() const { - return notification_manager_; + return notificationManager_; } bool IsBytecodeProfilingEnabled() const override { - return is_profiling_enabled_; + return isProfilingEnabled_; } std::unique_ptr OpenPandaFile(std::string_view location) override; @@ -432,7 +431,7 @@ public: const PandaVector &GetNativeMethods() const { - return native_methods_; + return nativeMethods_; } void SetData(void *data) @@ -442,24 +441,24 @@ public: void SetPromiseRejectCallback(PromiseRejectCallback cb) { - promise_reject_callback_ = cb; + promiseRejectCallback_ = cb; } PromiseRejectCallback GetPromiseRejectCallback() const { - return promise_reject_callback_; + return promiseRejectCallback_; } void SetHostPromiseRejectionTracker(HostPromiseRejectionTracker cb) { - host_promise_rejection_tracker_ = cb; + hostPromiseRejectionTracker_ = cb; } void PromiseRejectionTracker(const JSHandle &promise, const JSHandle &reason, const PromiseRejectionEvent operation) { - if (host_promise_rejection_tracker_ != nullptr) { - host_promise_rejection_tracker_(this, promise, reason, operation, data_); + if (hostPromiseRejectionTracker_ != nullptr) { + hostPromiseRejectionTracker_(this, promise, reason, operation, data_); } } @@ -467,22 +466,22 @@ public: void AddMethodToProfile(JSMethod *method) { - profiles_methods_.insert(method); + profilesMethods_.insert(method); } - void DumpHeap(PandaOStringStream *o_str) const final; + void DumpHeap(PandaOStringStream *oStr) const final; PandaString GetClassesFootprint() const final; static constexpr size_t GetGlobalEnvOffset() { - return MEMBER_OFFSET(EcmaVM, global_env_); + return MEMBER_OFFSET(EcmaVM, globalEnv_); } std::default_random_engine &GetRandomEngine() { - ASSERT(random_engine_); - return *random_engine_; + ASSERT(randomEngine_); + return *randomEngine_; } protected: @@ -496,13 +495,13 @@ protected: void HandleUncaughtException() override; - void PrintJSErrorInfo(const JSHandle &exception_info); + void PrintJSErrorInfo(const JSHandle &exceptionInfo); private: static constexpr uint32_t THREAD_SLEEP_TIME = 16 * 1000; static constexpr uint32_t THREAD_SLEEP_COUNT = 100; - void AddPandaFile(const panda_file::File *pf, bool is_module); + void AddPandaFile(const panda_file::File *pf, bool isModule); void SetProgram(Program *program, const panda_file::File *pf); bool IsFrameworkPandaFile(std::string_view filename) const; @@ -510,17 +509,17 @@ private: void SetMicroJobQueue(job::MicroJobQueue *queue); - bool Execute(std::unique_ptr pf, std::string_view entry_point, - const std::vector &args, bool is_module = false); + bool Execute(std::unique_ptr pf, std::string_view entryPoint, + const std::vector &args, bool isModule = false); - Expected InvokeEcmaEntrypoint(const panda_file::File &pf, const PandaString &method_name, + Expected InvokeEcmaEntrypoint(const panda_file::File &pf, const PandaString &methodName, const std::vector &args); void InitializeEcmaScriptRunStat(); void RedirectMethod(const panda_file::File &pf); - bool VerifyFilePath(const PandaString &file_path) const; + bool VerifyFilePath(const PandaString &filePath) const; void ClearBufferData(); @@ -532,76 +531,76 @@ private: void InitializeRandomEngine() { - ASSERT(!random_engine_); + ASSERT(!randomEngine_); std::random_device rd; - random_engine_.emplace(rd()); + randomEngine_.emplace(rd()); } NO_MOVE_SEMANTIC(EcmaVM); NO_COPY_SEMANTIC(EcmaVM); mem::MemoryManager *mm_ {nullptr}; - PandaUniquePtr ecma_reference_processor_; + PandaUniquePtr ecmaReferenceProcessor_; - SingleThreadManager *thread_manager_ {nullptr}; + SingleThreadManager *threadManager_ {nullptr}; Rendezvous *rendezvous_ {nullptr}; - bool is_test_mode_ {false}; + bool isTestMode_ {false}; - PandaSet profiles_methods_; + PandaSet profilesMethods_; // VM startup states. static JSRuntimeOptions options_; - bool ic_enable_ {true}; - bool vm_initialized_ {false}; - bool is_uncaught_exception_registered_ {false}; - bool is_profiling_enabled_ {false}; + bool icEnable_ {true}; + bool vmInitialized_ {false}; + bool isUncaughtExceptionRegistered_ {false}; + bool isProfilingEnabled_ {false}; // VM memory management. - EcmaCallProfilingTable *call_profiling_table_ {nullptr}; - EcmaStringTable *string_table_ {nullptr}; + EcmaCallProfilingTable *callProfilingTable_ {nullptr}; + EcmaStringTable *stringTable_ {nullptr}; ObjectFactory *factory_ {nullptr}; - PandaVector array_buffer_data_list_; + PandaVector arrayBufferDataList_; // VM execution states. JSThread *thread_ {nullptr}; - RegExpParserCache *reg_exp_parser_cache_ {nullptr}; - JSTaggedValue global_env_ {JSTaggedValue::Hole()}; - JSTaggedValue regexp_cache_ {JSTaggedValue::Hole()}; - JSTaggedValue micro_job_queue_ {JSTaggedValue::Hole()}; - bool runtime_stat_enabled_ {false}; - EcmaRuntimeStat *runtime_stat_ {nullptr}; + RegExpParserCache *regExpParserCache_ {nullptr}; + JSTaggedValue globalEnv_ {JSTaggedValue::Hole()}; + JSTaggedValue regexpCache_ {JSTaggedValue::Hole()}; + JSTaggedValue microJobQueue_ {JSTaggedValue::Hole()}; + bool runtimeStatEnabled_ {false}; + EcmaRuntimeStat *runtimeStat_ {nullptr}; // App framework resources. - JSTaggedValue framework_program_ {JSTaggedValue::Hole()}; - PandaString framework_abc_file_name_; - const panda_file::File *framework_panda_file_ {nullptr}; - PandaVector framework_program_methods_; + JSTaggedValue frameworkProgram_ {JSTaggedValue::Hole()}; + PandaString frameworkAbcFileName_; + const panda_file::File *frameworkPandaFile_ {nullptr}; + PandaVector frameworkProgramMethods_; // VM resources. - PandaVector native_methods_ {}; - ModuleManager *module_manager_ {nullptr}; - bool optional_log_enabled_ {false}; + PandaVector nativeMethods_ {}; + ModuleManager *moduleManager_ {nullptr}; + bool optionalLogEnabled_ {false}; // weak reference need Redirect address - PandaVector> panda_file_with_program_ - GUARDED_BY(panda_file_with_program_lock_); - mutable os::memory::Mutex panda_file_with_program_lock_; + PandaVector> pandaFileWithProgram_ + GUARDED_BY(pandaFileWithProgramLock_); + mutable os::memory::Mutex pandaFileWithProgramLock_; PandaMap>> - functions_arg_type_cache_; - Method *native_method_wrapper_ {nullptr}; + functionsArgTypeCache_; + Method *nativeMethodWrapper_ {nullptr}; CompilerInterface *compiler_ {nullptr}; - compiler::RuntimeInterface *runtime_iface_ {nullptr}; + compiler::RuntimeInterface *runtimeIface_ {nullptr}; // Debugger - RuntimeNotificationManager *notification_manager_ {nullptr}; - PandaUnorderedMap> extractor_cache_; + RuntimeNotificationManager *notificationManager_ {nullptr}; + PandaUnorderedMap> extractorCache_; // Registered Callbacks - PromiseRejectCallback promise_reject_callback_ {nullptr}; - HostPromiseRejectionTracker host_promise_rejection_tracker_ {nullptr}; + PromiseRejectCallback promiseRejectCallback_ {nullptr}; + HostPromiseRejectionTracker hostPromiseRejectionTracker_ {nullptr}; void *data_ {nullptr}; - PandaList finalization_registries_; + PandaList finalizationRegistries_; // optional for lazy initialization - std::optional random_engine_; + std::optional randomEngine_; friend class ObjectFactory; friend class panda::JSNApi; diff --git a/runtime/generator_helper.cpp b/runtime/generator_helper.cpp index 4f170864ee2b6dd30d12cd969017128f9f05a608..b5f01d9a96761a03f576c2363541a8781aec7615 100644 --- a/runtime/generator_helper.cpp +++ b/runtime/generator_helper.cpp @@ -20,16 +20,16 @@ #include "libpandafile/bytecode_instruction-inl.h" namespace panda::ecmascript { -JSHandle GeneratorHelper::Continue(JSThread *thread, const JSHandle &gen_context, - GeneratorResumeMode resume_mode, JSTaggedValue value) +JSHandle GeneratorHelper::Continue(JSThread *thread, const JSHandle &genContext, + GeneratorResumeMode resumeMode, JSTaggedValue value) { - EcmaInterpreter::ChangeGenContext(thread, gen_context); + EcmaInterpreter::ChangeGenContext(thread, genContext); - JSHandle gen_object(thread, gen_context->GetGeneratorObject()); - gen_object->SetResumeMode(thread, JSTaggedValue(static_cast(resume_mode))); - gen_object->SetResumeResult(thread, value); + JSHandle genObject(thread, genContext->GetGeneratorObject()); + genObject->SetResumeMode(thread, JSTaggedValue(static_cast(resumeMode))); + genObject->SetResumeResult(thread, value); - JSHandle result(thread, EcmaInterpreter::GeneratorReEnterInterpreter(thread, gen_context)); + JSHandle result(thread, EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext)); EcmaInterpreter::ResumeContext(thread); return result; diff --git a/runtime/generator_helper.h b/runtime/generator_helper.h index 46903655513a10b1951089fcf091c82b2d5123b5..4249eef2d010a12261fea07ba081d4cccf4bc094 100644 --- a/runtime/generator_helper.h +++ b/runtime/generator_helper.h @@ -30,8 +30,8 @@ enum class GeneratorResumeMode { class GeneratorHelper { public: - static JSHandle Continue(JSThread *thread, const JSHandle &gen_context, - GeneratorResumeMode resume_mode, JSTaggedValue value); + static JSHandle Continue(JSThread *thread, const JSHandle &genContext, + GeneratorResumeMode resumeMode, JSTaggedValue value); }; } // namespace panda::ecmascript diff --git a/runtime/global_dictionary-inl.h b/runtime/global_dictionary-inl.h index 28ae7c3ece51d096128d74c6446cf28a99fc43e7..6477a23dbee4b96174df897236708b48d5283680 100644 --- a/runtime/global_dictionary-inl.h +++ b/runtime/global_dictionary-inl.h @@ -26,12 +26,12 @@ int GlobalDictionary::Hash(const JSTaggedValue &key) { if (key.IsHeapObject()) { if (key.IsSymbol()) { - auto symbol_string = JSSymbol::Cast(key.GetTaggedObject()); - return static_cast(symbol_string->GetHashField()).GetInt(); + auto symbolString = JSSymbol::Cast(key.GetTaggedObject()); + return static_cast(symbolString->GetHashField()).GetInt(); } if (key.IsString()) { - auto key_string = EcmaString::Cast(key.GetTaggedObject()); - return key_string->GetHashcode(); + auto keyString = EcmaString::Cast(key.GetTaggedObject()); + return keyString->GetHashcode(); } } // key must be object @@ -88,21 +88,21 @@ void GlobalDictionary::ClearEntry(const JSThread *thread, int entry) box->Clear(thread); #endif JSTaggedValue hole = JSTaggedValue::Hole(); - PropertyAttributes meta_data; - SetEntry(thread, entry, hole, hole, meta_data); + PropertyAttributes metaData; + SetEntry(thread, entry, hole, hole, metaData); } void GlobalDictionary::UpdateValueAndAttributes(const JSThread *thread, int entry, const JSTaggedValue &value, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { UpdateValue(thread, entry, value); - SetAttributes(thread, entry, meta_data); + SetAttributes(thread, entry, metaData); } -void GlobalDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &meta_data) +void GlobalDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData) { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - Set(thread, index, meta_data.GetTaggedValue()); + Set(thread, index, metaData.GetTaggedValue()); } void GlobalDictionary::UpdateValue(const JSThread *thread, int entry, const JSTaggedValue &value) @@ -110,55 +110,55 @@ void GlobalDictionary::UpdateValue(const JSThread *thread, int entry, const JSTa SetValue(thread, entry, value); } -void GlobalDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArray *key_array) const +void GlobalDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const { - ASSERT_PRINT(offset + EntriesCount() <= static_cast(key_array->GetLength()), + ASSERT_PRINT(offset + EntriesCount() <= static_cast(keyArray->GetLength()), "key_array capacity is not enough for dictionary"); - int array_index = 0; + int arrayIndex = 0; int size = Size(); - PandaVector> sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = GetKey(hash_index); + PandaVector> sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = GetAttributes(hash_index); + PropertyAttributes attr = GetAttributes(hashIndex); std::pair pair(key, attr.GetOffset()); - sort_arr.push_back(pair); + sortArr.push_back(pair); } } - std::sort(sort_arr.begin(), sort_arr.end(), CompKey); - for (auto entry : sort_arr) { - JSTaggedValue name_key = entry.first; - key_array->Set(thread, array_index + offset, name_key); - array_index++; + std::sort(sortArr.begin(), sortArr.end(), CompKey); + for (auto entry : sortArr) { + JSTaggedValue nameKey = entry.first; + keyArray->Set(thread, arrayIndex + offset, nameKey); + arrayIndex++; } } -void GlobalDictionary::GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *key_array, uint32_t *keys) const +void GlobalDictionary::GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const { - ASSERT_PRINT(offset + EntriesCount() <= static_cast(key_array->GetLength()), + ASSERT_PRINT(offset + EntriesCount() <= static_cast(keyArray->GetLength()), "key_array capacity is not enough for dictionary"); - int array_index = 0; + int arrayIndex = 0; int size = Size(); - PandaVector> sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = GetKey(hash_index); + PandaVector> sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = GetKey(hashIndex); if (key.IsString()) { - PropertyAttributes attr = GetAttributes(hash_index); + PropertyAttributes attr = GetAttributes(hashIndex); if (attr.IsEnumerable()) { std::pair pair(key, attr.GetOffset()); - sort_arr.push_back(pair); + sortArr.push_back(pair); } } } - std::sort(sort_arr.begin(), sort_arr.end(), CompKey); - for (const auto &entry : sort_arr) { - JSTaggedValue name_key = entry.first; - key_array->Set(thread, array_index + offset, name_key); - array_index++; + std::sort(sortArr.begin(), sortArr.end(), CompKey); + for (const auto &entry : sortArr) { + JSTaggedValue nameKey = entry.first; + keyArray->Set(thread, arrayIndex + offset, nameKey); + arrayIndex++; } - *keys += array_index; + *keys += arrayIndex; } bool GlobalDictionary::CompKey(const std::pair &a, const std::pair &b) @@ -166,33 +166,33 @@ bool GlobalDictionary::CompKey(const std::pair &a, cons return a.second < b.second; } -void GlobalDictionary::InvalidatePropertyBox(JSThread *thread, const JSHandle &dict_handle, int entry, - const PropertyAttributes &meta_data) +void GlobalDictionary::InvalidatePropertyBox(JSThread *thread, const JSHandle &dictHandle, int entry, + const PropertyAttributes &metaData) { - PropertyBox *box = dict_handle->GetBox(entry); - PropertyAttributes new_attr(meta_data); + PropertyBox *box = dictHandle->GetBox(entry); + PropertyAttributes newAttr(metaData); ASSERT(!box->GetValue().IsHole()); - JSHandle old_value(thread, box->GetValue()); - dict_handle->SetAttributes(thread, entry, new_attr); - GlobalDictionary::InvalidateAndReplaceEntry(thread, dict_handle, entry, old_value); + JSHandle oldValue(thread, box->GetValue()); + dictHandle->SetAttributes(thread, entry, newAttr); + GlobalDictionary::InvalidateAndReplaceEntry(thread, dictHandle, entry, oldValue); } -void GlobalDictionary::InvalidateAndReplaceEntry(JSThread *thread, const JSHandle &dict_handle, - int entry, const JSHandle &old_value) +void GlobalDictionary::InvalidateAndReplaceEntry(JSThread *thread, const JSHandle &dictHandle, + int entry, const JSHandle &oldValue) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - PropertyAttributes attr = dict_handle->GetAttributes(entry); + PropertyAttributes attr = dictHandle->GetAttributes(entry); ASSERT_PRINT(attr.IsConfigurable(), "property must be configurable"); - ASSERT_PRINT(!dict_handle->GetBox(entry)->GetValue().IsHole(), "value must not be hole"); + ASSERT_PRINT(!dictHandle->GetBox(entry)->GetValue().IsHole(), "value must not be hole"); // Swap with a copy. - JSHandle new_box = factory->NewPropertyBox(old_value); + JSHandle newBox = factory->NewPropertyBox(oldValue); // Cell is officially mutable henceforth. attr.SetBoxType(PropertyBoxType::MUTABLE); - dict_handle->SetAttributes(thread, entry, attr); - dict_handle->GetBox(entry)->Clear(thread); - dict_handle->UpdateValue(thread, entry, new_box.GetTaggedValue()); + dictHandle->SetAttributes(thread, entry, attr); + dictHandle->GetBox(entry)->Clear(thread); + dictHandle->UpdateValue(thread, entry, newBox.GetTaggedValue()); } } // namespace panda::ecmascript diff --git a/runtime/global_dictionary.h b/runtime/global_dictionary.h index 06588efc1e80ea5bd954424175fb50174466d10b..8e62ca3f14104f00079d51b86b0f07b4e7f44512 100644 --- a/runtime/global_dictionary.h +++ b/runtime/global_dictionary.h @@ -46,11 +46,11 @@ public: static inline bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &other); static inline int Hash(const JSTaggedValue &key); - inline static void InvalidatePropertyBox(JSThread *thread, const JSHandle &dict_handle, int entry, - const PropertyAttributes &meta_data); + inline static void InvalidatePropertyBox(JSThread *thread, const JSHandle &dictHandle, int entry, + const PropertyAttributes &metaData); - inline static void InvalidateAndReplaceEntry(JSThread *thread, const JSHandle &dict_handle, - int entry, const JSHandle &old_value); + inline static void InvalidateAndReplaceEntry(JSThread *thread, const JSHandle &dictHandle, + int entry, const JSHandle &oldValue); inline PropertyBox *GetBox(int entry) const; @@ -66,22 +66,22 @@ public: inline void ClearEntry([[maybe_unused]] const JSThread *thread, int entry); inline void UpdateValueAndAttributes(const JSThread *thread, int entry, const JSTaggedValue &value, - const PropertyAttributes &meta_data); + const PropertyAttributes &metaData); inline void UpdateValue(const JSThread *thread, int entry, const JSTaggedValue &value); - inline void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &meta_data); + inline void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData); - inline void GetAllKeys(const JSThread *thread, int offset, TaggedArray *key_array) const; + inline void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const; - inline void GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *key_array, uint32_t *keys) const; + inline void GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const; static bool inline CompKey(const std::pair &a, const std::pair &b); DECL_DUMP() private: - inline int GetKeysWithFilter(const JSThread *thread, int offset, TaggedArray *key_array, + inline int GetKeysWithFilter(const JSThread *thread, int offset, TaggedArray *keyArray, const std::function &filter) const; static constexpr int ENTRY_KEY_INDEX = 0; diff --git a/runtime/global_env.cpp b/runtime/global_env.cpp index 13c788678366799de9a58a29f40ddff15a90418c..b51836e1facfe961c8b81978f65e0054cc6000eb 100644 --- a/runtime/global_env.cpp +++ b/runtime/global_env.cpp @@ -30,24 +30,24 @@ namespace panda::ecmascript { JSHandle GlobalEnv::GetSymbol(JSThread *thread, const JSHandle &string) { - JSHandle symbol_function(GetSymbolFunction()); - return JSObject::GetProperty(thread, symbol_function, string).GetValue(); + JSHandle symbolFunction(GetSymbolFunction()); + return JSObject::GetProperty(thread, symbolFunction, string).GetValue(); } JSHandle GlobalEnv::GetStringPrototypeFunctionByName(JSThread *thread, const char *name) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle string_func_obj(GetStringFunction()); - JSHandle string_func_prototype(thread, string_func_obj->GetPrototype(thread)); - JSHandle name_key(factory->NewFromString(name)); - return JSObject::GetProperty(thread, string_func_prototype, name_key).GetValue(); + JSHandle stringFuncObj(GetStringFunction()); + JSHandle stringFuncPrototype(thread, stringFuncObj->GetPrototype(thread)); + JSHandle nameKey(factory->NewFromString(name)); + return JSObject::GetProperty(thread, stringFuncPrototype, nameKey).GetValue(); } JSHandle GlobalEnv::GetStringFunctionByName(JSThread *thread, const char *name) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle string_func_obj = GetStringFunction(); - JSHandle name_key(factory->NewFromString(name)); - return JSObject::GetProperty(thread, string_func_obj, name_key).GetValue(); + JSHandle stringFuncObj = GetStringFunction(); + JSHandle nameKey(factory->NewFromString(name)); + return JSObject::GetProperty(thread, stringFuncObj, nameKey).GetValue(); } } // namespace panda::ecmascript diff --git a/runtime/global_env_constants.cpp b/runtime/global_env_constants.cpp index 51fb1b1f0a721abf7536267125783812d3eea0b3..983aebcb4302dcf6d2994799527ca6bd2fbf39cb 100644 --- a/runtime/global_env_constants.cpp +++ b/runtime/global_env_constants.cpp @@ -57,151 +57,146 @@ namespace panda::ecmascript { void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, - const JSHandle &dyn_class_class_handle) + const JSHandle &dynClassClassHandle) { // Global constants are readonly. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - SetConstant(ConstantIndex::HCLASS_CLASS_INDEX, JSTaggedValue(*dyn_class_class_handle)); + SetConstant(ConstantIndex::HCLASS_CLASS_INDEX, JSTaggedValue(*dynClassClassHandle)); SetConstant(ConstantIndex::STRING_CLASS_INDEX, - factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::STRING, HClass::STRING).GetTaggedValue()); + factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::STRING, HClass::STRING).GetTaggedValue()); SetConstant( ConstantIndex::ARRAY_CLASS_INDEX, - factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::TAGGED_ARRAY, HClass::ARRAY).GetTaggedValue()); - JSHClass *weak_array_class = - *factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::TAGGED_ARRAY, HClass::ARRAY); - weak_array_class->SetWeakContainer(true); - SetConstant(ConstantIndex::WEAK_ARRAY_CLASS_INDEX, JSTaggedValue(weak_array_class)); + factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::TAGGED_ARRAY, HClass::ARRAY).GetTaggedValue()); + JSHClass *weakArrayClass = *factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::TAGGED_ARRAY, HClass::ARRAY); + weakArrayClass->SetWeakContainer(true); + SetConstant(ConstantIndex::WEAK_ARRAY_CLASS_INDEX, JSTaggedValue(weakArrayClass)); SetConstant(ConstantIndex::BIGINT_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::BIGINT).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::BIGINT).GetTaggedValue()); SetConstant(ConstantIndex::DICTIONARY_CLASS_INDEX, factory - ->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::TAGGED_DICTIONARY, + ->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::TAGGED_DICTIONARY, HClass::ARRAY | HClass::IS_DICTIONARY_ARRAY) .GetTaggedValue()); - SetConstant(ConstantIndex::JS_NATIVE_POINTER_CLASS_INDEX, - factory - ->CreateDynClass(*dyn_class_class_handle, JSType::JS_NATIVE_POINTER, - HClass::NATIVE_POINTER) - .GetTaggedValue()); + SetConstant( + ConstantIndex::JS_NATIVE_POINTER_CLASS_INDEX, + factory + ->CreateDynClass(*dynClassClassHandle, JSType::JS_NATIVE_POINTER, HClass::NATIVE_POINTER) + .GetTaggedValue()); SetConstant( ConstantIndex::ENV_CLASS_INDEX, - factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::TAGGED_ARRAY, HClass::ARRAY).GetTaggedValue()); - JSHClass *free_object0_class = *factory->NewEcmaDynClass(*dyn_class_class_handle, FreeObject::GetTaggedNextOffset(), - JSType::FREE_OBJECT_WITH_NONE_FIELD); - free_object0_class->GetHClass()->SetNativeFieldMask(FreeObject::NATIVE_FIELDS_MASK); - SetConstant(ConstantIndex::FREE_OBJECT_WITH_NONE_FIELD_CLASS_INDEX, JSTaggedValue(free_object0_class)); - JSHClass *free_object1_class = *factory->NewEcmaDynClass(*dyn_class_class_handle, FreeObject::GetTaggedSizeOffset(), - JSType::FREE_OBJECT_WITH_ONE_FIELD); - free_object1_class->GetHClass()->SetNativeFieldMask(FreeObject::NATIVE_FIELDS_MASK); - SetConstant(ConstantIndex::FREE_OBJECT_WITH_ONE_FIELD_CLASS_INDEX, JSTaggedValue(free_object1_class)); - JSHClass *free_object2_class = *factory->CreateDynClass( - *dyn_class_class_handle, JSType::FREE_OBJECT_WITH_TWO_FIELD, HClass::IS_FREE_OBJECT); - free_object2_class->GetHClass()->SetNativeFieldMask(FreeObject::NATIVE_FIELDS_MASK); - SetConstant(ConstantIndex::FREE_OBJECT_WITH_TWO_FIELD_CLASS_INDEX, JSTaggedValue(free_object2_class)); + factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::TAGGED_ARRAY, HClass::ARRAY).GetTaggedValue()); + JSHClass *freeObject0Class = *factory->NewEcmaDynClass(*dynClassClassHandle, FreeObject::GetTaggedNextOffset(), + JSType::FREE_OBJECT_WITH_NONE_FIELD); + freeObject0Class->GetHClass()->SetNativeFieldMask(FreeObject::NATIVE_FIELDS_MASK); + SetConstant(ConstantIndex::FREE_OBJECT_WITH_NONE_FIELD_CLASS_INDEX, JSTaggedValue(freeObject0Class)); + JSHClass *freeObject1Class = *factory->NewEcmaDynClass(*dynClassClassHandle, FreeObject::GetTaggedSizeOffset(), + JSType::FREE_OBJECT_WITH_ONE_FIELD); + freeObject1Class->GetHClass()->SetNativeFieldMask(FreeObject::NATIVE_FIELDS_MASK); + SetConstant(ConstantIndex::FREE_OBJECT_WITH_ONE_FIELD_CLASS_INDEX, JSTaggedValue(freeObject1Class)); + JSHClass *freeObject2Class = *factory->CreateDynClass( + *dynClassClassHandle, JSType::FREE_OBJECT_WITH_TWO_FIELD, HClass::IS_FREE_OBJECT); + freeObject2Class->GetHClass()->SetNativeFieldMask(FreeObject::NATIVE_FIELDS_MASK); + SetConstant(ConstantIndex::FREE_OBJECT_WITH_TWO_FIELD_CLASS_INDEX, JSTaggedValue(freeObject2Class)); SetConstant(ConstantIndex::SYMBOL_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::SYMBOL).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::SYMBOL).GetTaggedValue()); SetConstant(ConstantIndex::ACCESSOE_DATA_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::ACCESSOR_DATA).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::ACCESSOR_DATA).GetTaggedValue()); SetConstant( ConstantIndex::INTERNAL_ACCESSOR_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::INTERNAL_ACCESSOR).GetTaggedValue()); - JSHClass *js_proxy_ordinary_class = *factory->CreateDynClass(*dyn_class_class_handle, JSType::JS_PROXY); - SetConstant(ConstantIndex::JS_PROXY_ORDINARY_CLASS_INDEX, JSTaggedValue(js_proxy_ordinary_class)); - SetConstant( - ConstantIndex::OBJECT_WRAPPER_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::OBJECT_WRAPPER).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::INTERNAL_ACCESSOR).GetTaggedValue()); + JSHClass *jsProxyOrdinaryClass = *factory->CreateDynClass(*dynClassClassHandle, JSType::JS_PROXY); + SetConstant(ConstantIndex::JS_PROXY_ORDINARY_CLASS_INDEX, JSTaggedValue(jsProxyOrdinaryClass)); + SetConstant(ConstantIndex::OBJECT_WRAPPER_CLASS_INDEX, + factory->CreateDynClass(*dynClassClassHandle, JSType::OBJECT_WRAPPER).GetTaggedValue()); SetConstant( ConstantIndex::COMPLETION_RECORD_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::COMPLETION_RECORD).GetTaggedValue()); - SetConstant(ConstantIndex::GENERATOR_CONTEST_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::JS_GENERATOR_CONTEXT) - .GetTaggedValue()); - SetConstant(ConstantIndex::CAPABILITY_RECORD_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PROMISE_CAPABILITY) - .GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::COMPLETION_RECORD).GetTaggedValue()); + SetConstant( + ConstantIndex::GENERATOR_CONTEST_INDEX, + factory->CreateDynClass(*dynClassClassHandle, JSType::JS_GENERATOR_CONTEXT).GetTaggedValue()); + SetConstant( + ConstantIndex::CAPABILITY_RECORD_CLASS_INDEX, + factory->CreateDynClass(*dynClassClassHandle, JSType::PROMISE_CAPABILITY).GetTaggedValue()); SetConstant( ConstantIndex::REACTIONS_RECORD_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PROMISE_REACTIONS).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::PROMISE_REACTIONS).GetTaggedValue()); SetConstant(ConstantIndex::PROMISE_ITERATOR_RECORD_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PROMISE_ITERATOR_RECORD) + factory->CreateDynClass(*dynClassClassHandle, JSType::PROMISE_ITERATOR_RECORD) .GetTaggedValue()); - SetConstant( - ConstantIndex::PROMISE_RECORD_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PROMISE_RECORD).GetTaggedValue()); + SetConstant(ConstantIndex::PROMISE_RECORD_CLASS_INDEX, + factory->CreateDynClass(*dynClassClassHandle, JSType::PROMISE_RECORD).GetTaggedValue()); SetConstant( ConstantIndex::PROMISE_RESOLVING_FUNCTIONS_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::RESOLVING_FUNCTIONS_RECORD) + factory->CreateDynClass(*dynClassClassHandle, JSType::RESOLVING_FUNCTIONS_RECORD) .GetTaggedValue()); SetConstant( ConstantIndex::MICRO_JOB_QUEUE_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::MICRO_JOB_QUEUE).GetTaggedValue()); - SetConstant( - ConstantIndex::PENDING_JOB_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PENDING_JOB).GetTaggedValue()); - JSHClass *proto_change_marker_class = - *factory->CreateDynClass(*dyn_class_class_handle, JSType::PROTO_CHANGE_MARKER); - SetConstant(ConstantIndex::PROTO_CHANGE_MARKER_CLASS_INDEX, JSTaggedValue(proto_change_marker_class)); + factory->CreateDynClass(*dynClassClassHandle, JSType::MICRO_JOB_QUEUE).GetTaggedValue()); + SetConstant(ConstantIndex::PENDING_JOB_CLASS_INDEX, + factory->CreateDynClass(*dynClassClassHandle, JSType::PENDING_JOB).GetTaggedValue()); + JSHClass *protoChangeMarkerClass = + *factory->CreateDynClass(*dynClassClassHandle, JSType::PROTO_CHANGE_MARKER); + SetConstant(ConstantIndex::PROTO_CHANGE_MARKER_CLASS_INDEX, JSTaggedValue(protoChangeMarkerClass)); SetConstant( ConstantIndex::PROTO_CHANGE_DETAILS_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PROTOTYPE_INFO).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::PROTOTYPE_INFO).GetTaggedValue()); SetConstant( ConstantIndex::PROTOTYPE_HANDLER_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PROTOTYPE_HANDLER).GetTaggedValue()); - SetConstant(ConstantIndex::TRANSITION_HANDLER_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::TRANSITION_HANDLER) - .GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::PROTOTYPE_HANDLER).GetTaggedValue()); + SetConstant( + ConstantIndex::TRANSITION_HANDLER_CLASS_INDEX, + factory->CreateDynClass(*dynClassClassHandle, JSType::TRANSITION_HANDLER).GetTaggedValue()); SetConstant(ConstantIndex::PROPERTY_BOX_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::PROPERTY_BOX).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::PROPERTY_BOX).GetTaggedValue()); SetConstant(ConstantIndex::FUNCTION_EXTRA_INFO_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::FUNCTION_EXTRA_INFO) + factory->CreateDynClass(*dynClassClassHandle, JSType::FUNCTION_EXTRA_INFO) .GetTaggedValue()); - JSHClass *program_class = *factory->CreateDynClass(*dyn_class_class_handle, JSType::PROGRAM); - SetConstant(ConstantIndex::PROGRAM_CLASS_INDEX, JSTaggedValue(program_class)); + JSHClass *programClass = *factory->CreateDynClass(*dynClassClassHandle, JSType::PROGRAM); + SetConstant(ConstantIndex::PROGRAM_CLASS_INDEX, JSTaggedValue(programClass)); SetConstant(ConstantIndex::ECMA_MODULE_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::ECMA_MODULE).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::ECMA_MODULE).GetTaggedValue()); - JSHClass *js_proxy_callable_class = - *factory->CreateDynClass(*dyn_class_class_handle, JSType::JS_PROXY, HClass::IS_CALLABLE); - SetConstant(ConstantIndex::JS_PROXY_CALLABLE_CLASS_INDEX, JSTaggedValue(js_proxy_callable_class)); + JSHClass *jsProxyCallableClass = + *factory->CreateDynClass(*dynClassClassHandle, JSType::JS_PROXY, HClass::IS_CALLABLE); + SetConstant(ConstantIndex::JS_PROXY_CALLABLE_CLASS_INDEX, JSTaggedValue(jsProxyCallableClass)); - JSHClass *js_proxy_construct_class = - *factory->CreateDynClass(*dyn_class_class_handle, JSType::JS_PROXY, HClass::IS_CALLABLE); - js_proxy_construct_class->SetConstructor(true); - SetConstant(ConstantIndex::JS_PROXY_CONSTRUCT_CLASS_INDEX, JSTaggedValue(js_proxy_construct_class)); + JSHClass *jsProxyConstructClass = + *factory->CreateDynClass(*dynClassClassHandle, JSType::JS_PROXY, HClass::IS_CALLABLE); + jsProxyConstructClass->SetConstructor(true); + SetConstant(ConstantIndex::JS_PROXY_CONSTRUCT_CLASS_INDEX, JSTaggedValue(jsProxyConstructClass)); SetConstant(ConstantIndex::JS_REALM_CLASS_INDEX, - factory->CreateDynClass(*dyn_class_class_handle, JSType::JS_REALM).GetTaggedValue()); + factory->CreateDynClass(*dynClassClassHandle, JSType::JS_REALM).GetTaggedValue()); - JSHClass *class_info_extractor_class = - *factory->CreateDynClass(*dyn_class_class_handle, JSType::CLASS_INFO_EXTRACTOR); - SetConstant(ConstantIndex::CLASS_INFO_EXTRACTOR_HCLASS_INDEX, JSTaggedValue(class_info_extractor_class)); + JSHClass *classInfoExtractorClass = + *factory->CreateDynClass(*dynClassClassHandle, JSType::CLASS_INFO_EXTRACTOR); + SetConstant(ConstantIndex::CLASS_INFO_EXTRACTOR_HCLASS_INDEX, JSTaggedValue(classInfoExtractorClass)); - JSHClass *js_regexp_iterator_class = - *factory->CreateDynClass(*dyn_class_class_handle, JSType::JS_REG_EXP_ITERATOR, 0); - SetConstant(ConstantIndex::JS_REGEXP_ITERATOR_CLASS_INDEX, JSTaggedValue(js_regexp_iterator_class)); + JSHClass *jsRegexpIteratorClass = + *factory->CreateDynClass(*dynClassClassHandle, JSType::JS_REG_EXP_ITERATOR, 0); + SetConstant(ConstantIndex::JS_REGEXP_ITERATOR_CLASS_INDEX, JSTaggedValue(jsRegexpIteratorClass)); SetConstant( ConstantIndex::LINKED_HASH_SET_CLASS_INDEX, - factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::LINKED_HASH_SET, HClass::ARRAY).GetTaggedValue()); + factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::LINKED_HASH_SET, HClass::ARRAY).GetTaggedValue()); SetConstant( ConstantIndex::LINKED_HASH_MAP_CLASS_INDEX, - factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::LINKED_HASH_MAP, HClass::ARRAY).GetTaggedValue()); + factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::LINKED_HASH_MAP, HClass::ARRAY).GetTaggedValue()); - JSHClass *js_weak_ref_class = - *factory->CreateDynClass(*dyn_class_class_handle, JSType::JS_WEAK_REF, 0, 0); - js_weak_ref_class->SetWeakContainer(true); - SetConstant(ConstantIndex::WEAK_REF_CLASS_INDEX, JSTaggedValue(js_weak_ref_class)); + JSHClass *jsWeakRefClass = *factory->CreateDynClass(*dynClassClassHandle, JSType::JS_WEAK_REF, 0, 0); + jsWeakRefClass->SetWeakContainer(true); + SetConstant(ConstantIndex::WEAK_REF_CLASS_INDEX, JSTaggedValue(jsWeakRefClass)); - JSHClass *weak_hash_set_class = - *factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::LINKED_HASH_SET, HClass::ARRAY); - weak_hash_set_class->SetWeakContainer(true); - SetConstant(ConstantIndex::WEAK_LINKED_HASH_SET_CLASS_INDEX, JSTaggedValue(weak_hash_set_class)); + JSHClass *weakHashSetClass = + *factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::LINKED_HASH_SET, HClass::ARRAY); + weakHashSetClass->SetWeakContainer(true); + SetConstant(ConstantIndex::WEAK_LINKED_HASH_SET_CLASS_INDEX, JSTaggedValue(weakHashSetClass)); - JSHClass *weak_hash_map_class = - *factory->NewEcmaDynClass(*dyn_class_class_handle, 0, JSType::LINKED_HASH_MAP, HClass::ARRAY); - weak_hash_map_class->SetWeakContainer(true); - SetConstant(ConstantIndex::WEAK_LINKED_HASH_MAP_CLASS_INDEX, JSTaggedValue(weak_hash_map_class)); + JSHClass *weakHashMapClass = + *factory->NewEcmaDynClass(*dynClassClassHandle, 0, JSType::LINKED_HASH_MAP, HClass::ARRAY); + weakHashMapClass->SetWeakContainer(true); + SetConstant(ConstantIndex::WEAK_LINKED_HASH_MAP_CLASS_INDEX, JSTaggedValue(weakHashMapClass)); } // NOLINTNEXTLINE(readability-function-size) diff --git a/runtime/global_env_constants.h b/runtime/global_env_constants.h index 652aef69b687e6f27b17124fdead2f25a8828320..cb0c1ec100a38e85cd4745ef57f21fcda458a077 100644 --- a/runtime/global_env_constants.h +++ b/runtime/global_env_constants.h @@ -361,7 +361,7 @@ public: const JSTaggedValue *EndSlot() const; - void InitRootsClass(JSThread *thread, const JSHandle &dyn_class_class_handle); + void InitRootsClass(JSThread *thread, const JSHandle &dynClassClassHandle); void InitGlobalConstant(JSThread *thread); diff --git a/runtime/handle_storage_check.h b/runtime/handle_storage_check.h index f3426c0862d6608dbff34ff37d405d0fbd21f85e..a8423753b05ab5a8ca4f6b23fe245dd5b6bb0d05 100644 --- a/runtime/handle_storage_check.h +++ b/runtime/handle_storage_check.h @@ -44,15 +44,15 @@ template <> class HandleStorageCheckT { public: explicit HandleStorageCheckT(JSThread *thread) - : thread_(thread), handle_storage_check_(thread->GetHandleScopeStorageNext()) + : thread_(thread), handleStorageCheck_(thread->GetHandleScopeStorageNext()) { } ~HandleStorageCheckT() { (void)thread_; - (void)handle_storage_check_; - ASSERT(handle_storage_check_ == thread_->GetHandleScopeStorageNext()); + (void)handleStorageCheck_; + ASSERT(handleStorageCheck_ == thread_->GetHandleScopeStorageNext()); } NO_COPY_SEMANTIC(HandleStorageCheckT); @@ -60,7 +60,7 @@ public: private: JSThread *thread_; - JSTaggedType *handle_storage_check_; + JSTaggedType *handleStorageCheck_; }; using HandleStorageCheck = HandleStorageCheckT; diff --git a/runtime/ic/ic_handler-inl.h b/runtime/ic/ic_handler-inl.h index b8bb85afa32058e174f75edd2d0f04442b6a1f78..045b0a7e91f79a217c8b36adef8e525211b79df6 100644 --- a/runtime/ic/ic_handler-inl.h +++ b/runtime/ic/ic_handler-inl.h @@ -22,11 +22,11 @@ #include "ic_handler.h" namespace panda::ecmascript { -JSHandle LoadHandler::LoadElement(const JSThread *thread, bool is_int) +JSHandle LoadHandler::LoadElement(const JSThread *thread, bool isInt) { uint32_t handler = 0; KindBit::Set(HandlerKind::ELEMENT, &handler); - IsKeyIntBit::Set(is_int, &handler); + IsKeyIntBit::Set(isInt, &handler); return JSHandle(thread, JSTaggedValue(handler)); } @@ -44,9 +44,9 @@ JSHandle LoadHandler::LoadProperty(const JSThread *thread, const if (val.IsPropertyBox()) { return JSHandle(thread, val); } - bool has_accessor = op.IsAccessorDescriptor(); - AccessorBit::Set(has_accessor, &handler); - if (!has_accessor) { + bool hasAccessor = op.IsAccessorDescriptor(); + AccessorBit::Set(hasAccessor, &handler); + if (!hasAccessor) { KindBit::Set(HandlerKind::FIELD, &handler); } @@ -68,9 +68,9 @@ JSHandle PrototypeHandler::LoadPrototype(const JSThread *thread, const JSHandle &hclass) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle handler_info = LoadHandler::LoadProperty(thread, op); + JSHandle handlerInfo = LoadHandler::LoadProperty(thread, op); JSHandle handler = factory->NewPrototypeHandler(); - handler->SetHandlerInfo(thread, handler_info); + handler->SetHandlerInfo(thread, handlerInfo); if (op.IsFound()) { handler->SetHolder(thread, op.GetHolder()); } @@ -84,20 +84,19 @@ JSHandle PrototypeHandler::StorePrototype(const JSThread *thread, { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle handler = factory->NewPrototypeHandler(); - JSHandle handler_info = StoreHandler::StoreProperty(thread, op); - handler->SetHandlerInfo(thread, handler_info); + JSHandle handlerInfo = StoreHandler::StoreProperty(thread, op); + handler->SetHandlerInfo(thread, handlerInfo); handler->SetHolder(thread, op.GetHolder()); auto result = JSHClass::EnableProtoChangeMarker(thread, hclass); handler->SetProtoCell(thread, result); return JSHandle::Cast(handler); } -JSHandle StoreHandler::StoreElement(const JSThread *thread, JSHandle receiver, - bool is_int) +JSHandle StoreHandler::StoreElement(const JSThread *thread, JSHandle receiver, bool isInt) { uint32_t handler = 0; KindBit::Set(HandlerKind::ELEMENT, &handler); - IsKeyIntBit::Set(is_int, &handler); + IsKeyIntBit::Set(isInt, &handler); if (receiver->IsJSArray()) { IsJSArrayBit::Set(true, &handler); @@ -113,9 +112,9 @@ JSHandle StoreHandler::StoreProperty(const JSThread *thread, cons if (val.IsPropertyBox()) { return JSHandle(thread, val); } - bool has_setter = op.IsAccessorDescriptor(); - AccessorBit::Set(has_setter, &handler); - if (!has_setter) { + bool hasSetter = op.IsAccessorDescriptor(); + AccessorBit::Set(hasSetter, &handler); + if (!hasSetter) { KindBit::Set(HandlerKind::FIELD, &handler); } if (op.IsInlinedProps()) { @@ -134,8 +133,8 @@ JSHandle TransitionHandler::StoreTransition(const JSThread *threa { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle handler = factory->NewTransitionHandler(); - JSHandle handler_info = StoreHandler::StoreProperty(thread, op); - handler->SetHandlerInfo(thread, handler_info); + JSHandle handlerInfo = StoreHandler::StoreProperty(thread, op); + handler->SetHandlerInfo(thread, handlerInfo); auto hclass = JSObject::Cast(op.GetReceiver()->GetHeapObject())->GetJSHClass(); handler->SetTransitionHClass(thread, JSTaggedValue(hclass)); return JSHandle::Cast(handler); diff --git a/runtime/ic/ic_handler.h b/runtime/ic/ic_handler.h index 757b0195a5d7b0cbf8bb2d2ec0916ef52217a466..62c1769e2adb33ee957a9e1a85626053d4b4fbb0 100644 --- a/runtime/ic/ic_handler.h +++ b/runtime/ic/ic_handler.h @@ -121,14 +121,14 @@ public: class LoadHandler final : public HandlerBase { public: static inline JSHandle LoadProperty(const JSThread *thread, const ObjectOperator &op); - static inline JSHandle LoadElement(const JSThread *thread, bool is_int); + static inline JSHandle LoadElement(const JSThread *thread, bool isInt); }; class StoreHandler final : public HandlerBase { public: static inline JSHandle StoreProperty(const JSThread *thread, const ObjectOperator &op); static inline JSHandle StoreElement(const JSThread *thread, JSHandle receiver, - bool is_int); + bool isInt); }; class TransitionHandler : public TaggedObject { diff --git a/runtime/ic/ic_runtime.cpp b/runtime/ic/ic_runtime.cpp index aac47f23b8a784d7df5cd9dd6e6a46cd872dcd7c..00b72fd5dbe1e0d4a8c98f7c7a3efbdc0697bbd3 100644 --- a/runtime/ic/ic_runtime.cpp +++ b/runtime/ic/ic_runtime.cpp @@ -36,37 +36,37 @@ void ICRuntime::UpdateLoadHandler(const ObjectOperator &op, JSHandle(); } - JSHandle handler_value; + JSHandle handlerValue; JSHandle hclass(GetThread(), JSHandle::Cast(receiver)->GetClass()); if (op.IsElement()) { if (!op.IsFound() && hclass->IsDictionaryElement()) { return; } - handler_value = LoadHandler::LoadElement(thread_, key.IsEmpty() ? false : key->IsInt()); + handlerValue = LoadHandler::LoadElement(thread_, key.IsEmpty() ? false : key->IsInt()); } else { if (!op.IsFound()) { - handler_value = PrototypeHandler::LoadPrototype(thread_, op, hclass); + handlerValue = PrototypeHandler::LoadPrototype(thread_, op, hclass); } else if (!op.IsOnPrototype()) { - handler_value = LoadHandler::LoadProperty(thread_, op); + handlerValue = LoadHandler::LoadProperty(thread_, op); } else { // do not support global prototype ic if (IsGlobalLoadIC(GetICKind())) { return; } - handler_value = PrototypeHandler::LoadPrototype(thread_, op, hclass); + handlerValue = PrototypeHandler::LoadPrototype(thread_, op, hclass); } } if (key.IsEmpty()) { - ic_accessor_.AddHandlerWithoutKey(JSHandle::Cast(hclass), handler_value); + icAccessor_.AddHandlerWithoutKey(JSHandle::Cast(hclass), handlerValue); } else if (op.IsElement()) { // do not support global element ic if (IsGlobalLoadIC(GetICKind())) { return; } - ic_accessor_.AddElementHandler(JSHandle::Cast(hclass), handler_value); + icAccessor_.AddElementHandler(JSHandle::Cast(hclass), handlerValue); } else { - ic_accessor_.AddHandlerWithKey(key, JSHandle::Cast(hclass), handler_value); + icAccessor_.AddHandlerWithKey(key, JSHandle::Cast(hclass), handlerValue); } } @@ -76,9 +76,9 @@ void ICRuntime::UpdateStoreHandler(const ObjectOperator &op, JSHandle(); } - JSHandle handler_value; + JSHandle handlerValue; if (op.IsElement()) { - handler_value = StoreHandler::StoreElement(thread_, receiver, key.IsEmpty() ? false : key->IsInt()); + handlerValue = StoreHandler::StoreElement(thread_, receiver, key.IsEmpty() ? false : key->IsInt()); } else { ASSERT(op.IsFound()); if (op.IsOnPrototype()) { @@ -87,24 +87,24 @@ void ICRuntime::UpdateStoreHandler(const ObjectOperator &op, JSHandle hclass(thread_, JSHandle::Cast(receiver)->GetClass()); - handler_value = PrototypeHandler::StorePrototype(thread_, op, hclass); + handlerValue = PrototypeHandler::StorePrototype(thread_, op, hclass); } else if (op.IsTransition()) { - handler_value = TransitionHandler::StoreTransition(thread_, op); + handlerValue = TransitionHandler::StoreTransition(thread_, op); } else { - handler_value = StoreHandler::StoreProperty(thread_, op); + handlerValue = StoreHandler::StoreProperty(thread_, op); } } if (key.IsEmpty()) { - ic_accessor_.AddHandlerWithoutKey(receiver_h_class_, handler_value); + icAccessor_.AddHandlerWithoutKey(receiverHClass_, handlerValue); } else if (op.IsElement()) { // do not support global element ic if (IsGlobalStoreIC(GetICKind())) { return; } - ic_accessor_.AddElementHandler(receiver_h_class_, handler_value); + icAccessor_.AddElementHandler(receiverHClass_, handlerValue); } else { - ic_accessor_.AddHandlerWithKey(key, receiver_h_class_, handler_value); + icAccessor_.AddHandlerWithKey(key, receiverHClass_, handlerValue); } } @@ -141,7 +141,7 @@ JSTaggedValue LoadICRuntime::LoadMiss(JSHandle receiver, JSHandle RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(GetThread()); // ic-switch if (!GetThread()->GetEcmaVM()->ICEnable()) { - ic_accessor_.SetAsMega(); + icAccessor_.SetAsMega(); return result.GetTaggedValue(); } #ifndef NDEBUG @@ -149,7 +149,7 @@ JSTaggedValue LoadICRuntime::LoadMiss(JSHandle receiver, JSHandle #endif // do not cache element if (!op.IsFastMode() && op.IsFound()) { - ic_accessor_.SetAsMega(); + icAccessor_.SetAsMega(); return result.GetTaggedValue(); } @@ -179,13 +179,13 @@ JSTaggedValue StoreICRuntime::StoreMiss(JSHandle receiver, JSHand UpdateReceiverHClass(JSHandle(GetThread(), JSHandle::Cast(receiver)->GetClass())); ObjectOperator op(GetThread(), receiver, key); - JSHandle old_hc(thread_, JSObject::Cast(receiver.GetTaggedValue())->GetJSHClass()); + JSHandle oldHc(thread_, JSObject::Cast(receiver.GetTaggedValue())->GetJSHClass()); bool success = JSObject::SetProperty(&op, value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); - auto new_hc = JSObject::Cast(receiver.GetTaggedValue())->GetJSHClass(); + auto newHc = JSObject::Cast(receiver.GetTaggedValue())->GetJSHClass(); // Update object operator if there was transition to dictionary mode - if (UNLIKELY(!old_hc->IsDictionaryMode() && new_hc->IsDictionaryMode())) { + if (UNLIKELY(!oldHc->IsDictionaryMode() && newHc->IsDictionaryMode())) { op = ObjectOperator(GetThread(), receiver, key); } @@ -195,7 +195,7 @@ JSTaggedValue StoreICRuntime::StoreMiss(JSHandle receiver, JSHand } // ic-switch if (!GetThread()->GetEcmaVM()->ICEnable()) { - ic_accessor_.SetAsMega(); + icAccessor_.SetAsMega(); return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } #ifndef NDEBUG @@ -203,7 +203,7 @@ JSTaggedValue StoreICRuntime::StoreMiss(JSHandle receiver, JSHand #endif // do not cache element if (!op.IsFastMode()) { - ic_accessor_.SetAsMega(); + icAccessor_.SetAsMega(); return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } if (success) { diff --git a/runtime/ic/ic_runtime.h b/runtime/ic/ic_runtime.h index 232235bf7f191544d0641561528dd44ceb43f556..29faadacd3c5f96c4cd69e618e5e7fb14d7fb7ee 100644 --- a/runtime/ic/ic_runtime.h +++ b/runtime/ic/ic_runtime.h @@ -29,8 +29,8 @@ class ObjectOperator; class ICRuntime { public: - ICRuntime(JSThread *thread, JSHandle profile_type_info, uint32_t slot_id, ICKind kind) - : thread_(thread), ic_accessor_(thread, profile_type_info, slot_id, kind) + ICRuntime(JSThread *thread, JSHandle profileTypeInfo, uint32_t slotId, ICKind kind) + : thread_(thread), icAccessor_(thread, profileTypeInfo, slotId, kind) { } @@ -44,14 +44,14 @@ public: return thread_; } - void UpdateReceiverHClass(JSHandle receiver_h_class) + void UpdateReceiverHClass(JSHandle receiverHClass) { - receiver_h_class_ = receiver_h_class; + receiverHClass_ = receiverHClass; } ICKind GetICKind() const { - return ic_accessor_.GetKind(); + return icAccessor_.GetKind(); } void TraceIC(JSHandle receiver, JSHandle key) const; @@ -60,15 +60,15 @@ public: NO_COPY_SEMANTIC(ICRuntime); protected: - JSThread *thread_; // NOLINT(misc-non-private-member-variables-in-classes) - JSHandle receiver_h_class_ {}; // NOLINT(misc-non-private-member-variables-in-classes) - ProfileTypeAccessor ic_accessor_; // NOLINT(misc-non-private-member-variables-in-classes) + JSThread *thread_; // NOLINT(misc-non-private-member-variables-in-classes) + JSHandle receiverHClass_ {}; // NOLINT(misc-non-private-member-variables-in-classes) + ProfileTypeAccessor icAccessor_; // NOLINT(misc-non-private-member-variables-in-classes) }; class LoadICRuntime : public ICRuntime { public: - LoadICRuntime(JSThread *thread, JSHandle profile_type_info, uint32_t slot_id, ICKind kind) - : ICRuntime(thread, profile_type_info, slot_id, kind) + LoadICRuntime(JSThread *thread, JSHandle profileTypeInfo, uint32_t slotId, ICKind kind) + : ICRuntime(thread, profileTypeInfo, slotId, kind) { } @@ -82,8 +82,8 @@ public: class StoreICRuntime : public ICRuntime { public: - StoreICRuntime(JSThread *thread, JSHandle profile_type_info, uint32_t slot_id, ICKind kind) - : ICRuntime(thread, profile_type_info, slot_id, kind) + StoreICRuntime(JSThread *thread, JSHandle profileTypeInfo, uint32_t slotId, ICKind kind) + : ICRuntime(thread, profileTypeInfo, slotId, kind) { } diff --git a/runtime/ic/ic_runtime_stub-inl.h b/runtime/ic/ic_runtime_stub-inl.h index f15440d2b01b9ed2befea49e5aa5cbad0a8ebded..e80b1d8ff27e31c8c79affbaee9d79fd22e1a12e 100644 --- a/runtime/ic/ic_runtime_stub-inl.h +++ b/runtime/ic/ic_runtime_stub-inl.h @@ -41,28 +41,28 @@ bool ICRuntimeStub::HaveICForFunction(JSFunction *func) return !func->GetProfileTypeInfo().IsUndefined(); } -uint32_t ICRuntimeStub::MapSlotId(JSFunction *func, uint32_t slot_id) +uint32_t ICRuntimeStub::MapSlotId(JSFunction *func, uint32_t slotId) { uint8_t *mapping = func->GetMethod()->GetICMapping(); ASSERT(mapping != nullptr); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - return mapping[slot_id]; + return mapping[slotId]; } ProfileTypeInfo *ICRuntimeStub::GetRuntimeProfileTypeInfo(JSFunction *func) { - JSTaggedValue profile_type_info = func->GetProfileTypeInfo(); - return ProfileTypeInfo::Cast(profile_type_info.GetTaggedObject()); + JSTaggedValue profileTypeInfo = func->GetProfileTypeInfo(); + return ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); } -JSTaggedValue ICRuntimeStub::LoadGlobalICByName(JSThread *thread, JSFunction *func, JSTaggedValue global_value, - JSTaggedValue key, uint32_t slot_id, bool is_try_load) +JSTaggedValue ICRuntimeStub::LoadGlobalICByName(JSThread *thread, JSFunction *func, JSTaggedValue globalValue, + JSTaggedValue key, uint32_t slotId, bool isTryLoad) { INTERPRETER_TRACE(thread, LoadGlobalICByName); ASSERT(HaveICForFunction(func)); - slot_id = MapSlotId(func, slot_id); - ProfileTypeInfo *profile_type_info = GetRuntimeProfileTypeInfo(func); - JSTaggedValue handler = profile_type_info->Get(slot_id); + slotId = MapSlotId(func, slotId); + ProfileTypeInfo *profileTypeInfo = GetRuntimeProfileTypeInfo(func); + JSTaggedValue handler = profileTypeInfo->Get(slotId); if (handler.IsHeapObject()) { auto result = LoadGlobal(handler); if (!result.IsHole()) { @@ -70,24 +70,24 @@ JSTaggedValue ICRuntimeStub::LoadGlobalICByName(JSThread *thread, JSFunction *fu } } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto key_handle = JSHandle(thread, key); - auto receiver_handle = JSHandle(thread, global_value); - auto profile_info_handle = JSHandle(thread, profile_type_info); - LoadICRuntime ic_runtime(thread, JSHandle::Cast(profile_info_handle), slot_id, - is_try_load ? ICKind::TRY_NAMED_GLOBAL_LOAD_IC : ICKind::NAMED_GLOBAL_LOAD_IC); - return ic_runtime.LoadMiss(receiver_handle, key_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto keyHandle = JSHandle(thread, key); + auto receiverHandle = JSHandle(thread, globalValue); + auto profileInfoHandle = JSHandle(thread, profileTypeInfo); + LoadICRuntime icRuntime(thread, JSHandle::Cast(profileInfoHandle), slotId, + isTryLoad ? ICKind::TRY_NAMED_GLOBAL_LOAD_IC : ICKind::NAMED_GLOBAL_LOAD_IC); + return icRuntime.LoadMiss(receiverHandle, keyHandle); } -JSTaggedValue ICRuntimeStub::StoreGlobalICByName(JSThread *thread, JSFunction *func, JSTaggedValue global_value, - JSTaggedValue key, JSTaggedValue value, uint32_t slot_id, - bool is_try_store) +JSTaggedValue ICRuntimeStub::StoreGlobalICByName(JSThread *thread, JSFunction *func, JSTaggedValue globalValue, + JSTaggedValue key, JSTaggedValue value, uint32_t slotId, + bool isTryStore) { INTERPRETER_TRACE(thread, StoreGlobalICByName); ASSERT(HaveICForFunction(func)); - slot_id = MapSlotId(func, slot_id); - ProfileTypeInfo *profile_type_info = GetRuntimeProfileTypeInfo(func); - JSTaggedValue handler = profile_type_info->Get(slot_id); + slotId = MapSlotId(func, slotId); + ProfileTypeInfo *profileTypeInfo = GetRuntimeProfileTypeInfo(func); + JSTaggedValue handler = profileTypeInfo->Get(slotId); if (handler.IsHeapObject()) { auto result = StoreGlobal(thread, value, handler); if (!result.IsHole()) { @@ -95,21 +95,21 @@ JSTaggedValue ICRuntimeStub::StoreGlobalICByName(JSThread *thread, JSFunction *f } } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto key_handle = JSHandle(thread, key); - auto receiver_handle = JSHandle(thread, global_value); - auto value_handle = JSHandle(thread, value); - auto profile_info_handle = JSHandle(thread, profile_type_info); - StoreICRuntime ic_runtime(thread, JSHandle::Cast(profile_info_handle), slot_id, - is_try_store ? ICKind::TRY_NAMED_GLOBAL_STORE_IC : ICKind::NAMED_GLOBAL_STORE_IC); - return ic_runtime.StoreMiss(receiver_handle, key_handle, value_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto keyHandle = JSHandle(thread, key); + auto receiverHandle = JSHandle(thread, globalValue); + auto valueHandle = JSHandle(thread, value); + auto profileInfoHandle = JSHandle(thread, profileTypeInfo); + StoreICRuntime icRuntime(thread, JSHandle::Cast(profileInfoHandle), slotId, + isTryStore ? ICKind::TRY_NAMED_GLOBAL_STORE_IC : ICKind::NAMED_GLOBAL_STORE_IC); + return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle); } -JSTaggedValue ICRuntimeStub::CheckPolyHClass(JSTaggedValue cached_value, JSHClass *hclass) +JSTaggedValue ICRuntimeStub::CheckPolyHClass(JSTaggedValue cachedValue, JSHClass *hclass) { - if (!cached_value.IsWeak()) { - ASSERT(cached_value.IsTaggedArray()); - TaggedArray *array = TaggedArray::Cast(cached_value.GetHeapObject()); + if (!cachedValue.IsWeak()) { + ASSERT(cachedValue.IsTaggedArray()); + TaggedArray *array = TaggedArray::Cast(cachedValue.GetHeapObject()); uint32_t length = array->GetLength(); for (uint32_t i = 0; i < length; i += 2) { // 2 means one ic, two slot auto result = array->Get(i); @@ -122,178 +122,178 @@ JSTaggedValue ICRuntimeStub::CheckPolyHClass(JSTaggedValue cached_value, JSHClas } JSTaggedValue ICRuntimeStub::LoadICByName(JSThread *thread, JSFunction *func, JSTaggedValue receiver, JSTaggedValue key, - uint32_t slot_id) + uint32_t slotId) { INTERPRETER_TRACE(thread, LoadICByName); ASSERT(HaveICForFunction(func)); - slot_id = MapSlotId(func, slot_id); - ProfileTypeInfo *profile_type_info = GetRuntimeProfileTypeInfo(func); - JSTaggedValue hclass_value = profile_type_info->Get(slot_id); - if (hclass_value.IsHole()) { + slotId = MapSlotId(func, slotId); + ProfileTypeInfo *profileTypeInfo = GetRuntimeProfileTypeInfo(func); + JSTaggedValue hclassValue = profileTypeInfo->Get(slotId); + if (hclassValue.IsHole()) { return JSTaggedValue::Hole(); } if (LIKELY(receiver.IsHeapObject())) { auto hclass = receiver.GetTaggedObject()->GetClass(); - size_t index = slot_id; + size_t index = slotId; do { - if (!hclass_value.IsHeapObject()) { + if (!hclassValue.IsHeapObject()) { break; } - if (LIKELY(hclass_value.GetTaggedObject() == hclass)) { - JSTaggedValue handler = profile_type_info->Get(index + 1); + if (LIKELY(hclassValue.GetTaggedObject() == hclass)) { + JSTaggedValue handler = profileTypeInfo->Get(index + 1); if (UNLIKELY(handler.IsUndefined())) { // handler is collected by GC. // Clear profile data to fill it again in LoadMiss. - profile_type_info->Set(thread, index, JSTaggedValue::Undefined()); + profileTypeInfo->Set(thread, index, JSTaggedValue::Undefined()); break; } return LoadICWithHandler(thread, receiver, receiver, handler); } index += 2U; - hclass_value = profile_type_info->Get(index); - } while (index < slot_id + SlotSizeForICByName()); + hclassValue = profileTypeInfo->Get(index); + } while (index < slotId + SlotSizeForICByName()); } - return LoadMissedICByName(thread, profile_type_info, receiver, key, slot_id); + return LoadMissedICByName(thread, profileTypeInfo, receiver, key, slotId); } JSTaggedValue ICRuntimeStub::LoadICByValue(JSThread *thread, JSFunction *func, JSTaggedValue receiver, - JSTaggedValue key, uint32_t slot_id) + JSTaggedValue key, uint32_t slotId) { INTERPRETER_TRACE(thread, LoadICByValue); ASSERT(HaveICForFunction(func)); - slot_id = MapSlotId(func, slot_id); - ProfileTypeInfo *profile_type_info = GetRuntimeProfileTypeInfo(func); - JSTaggedValue first_value = profile_type_info->Get(slot_id); - if (first_value.IsHole()) { + slotId = MapSlotId(func, slotId); + ProfileTypeInfo *profileTypeInfo = GetRuntimeProfileTypeInfo(func); + JSTaggedValue firstValue = profileTypeInfo->Get(slotId); + if (firstValue.IsHole()) { return JSTaggedValue::Hole(); } - if (receiver.IsHeapObject() && first_value.IsHeapObject()) { + if (receiver.IsHeapObject() && firstValue.IsHeapObject()) { auto hclass = receiver.GetTaggedObject()->GetClass(); // Check key - if (first_value == key) { - JSTaggedValue hclass_value = profile_type_info->Get(slot_id + 1); - if (hclass_value.GetTaggedObject() == hclass) { - JSTaggedValue handler = profile_type_info->Get(slot_id + 2); + if (firstValue == key) { + JSTaggedValue hclassValue = profileTypeInfo->Get(slotId + 1); + if (hclassValue.GetTaggedObject() == hclass) { + JSTaggedValue handler = profileTypeInfo->Get(slotId + 2); if (UNLIKELY(handler.IsUndefined())) { // handler is collected by GC. // Clear profile data to fill it again in LoadMiss. - profile_type_info->Set(thread, slot_id, JSTaggedValue::Undefined()); - profile_type_info->Set(thread, slot_id + 1, JSTaggedValue::Undefined()); + profileTypeInfo->Set(thread, slotId, JSTaggedValue::Undefined()); + profileTypeInfo->Set(thread, slotId + 1, JSTaggedValue::Undefined()); } else { return LoadICWithHandler(thread, receiver, receiver, handler); } } } // Check element - if (first_value.GetTaggedObject() == hclass) { - ASSERT(HandlerBase::IsElement(profile_type_info->Get(slot_id + 1).GetInt())); + if (firstValue.GetTaggedObject() == hclass) { + ASSERT(HandlerBase::IsElement(profileTypeInfo->Get(slotId + 1).GetInt())); if (!key.IsInt()) { - JSTaggedValue handler = profile_type_info->Get(slot_id + 1); - auto handler_info = static_cast(handler.GetInt()); - HandlerBase::SetKeyNotInt(handler_info); - profile_type_info->Set(thread, slot_id + 1, JSTaggedValue(handler_info)); + JSTaggedValue handler = profileTypeInfo->Get(slotId + 1); + auto handlerInfo = static_cast(handler.GetInt()); + HandlerBase::SetKeyNotInt(handlerInfo); + profileTypeInfo->Set(thread, slotId + 1, JSTaggedValue(handlerInfo)); } return LoadElement(JSObject::Cast(receiver.GetHeapObject()), key); } - size_t index = slot_id + 2; + size_t index = slotId + 2; while (index < SlotSizeForICByValue()) { - first_value = profile_type_info->Get(index); - if (first_value.GetRawData() == ToUintPtr(hclass)) { - ASSERT(HandlerBase::IsElement(profile_type_info->Get(index + 1).GetInt())); + firstValue = profileTypeInfo->Get(index); + if (firstValue.GetRawData() == ToUintPtr(hclass)) { + ASSERT(HandlerBase::IsElement(profileTypeInfo->Get(index + 1).GetInt())); if (!key.IsInt()) { - JSTaggedValue handler = profile_type_info->Get(index + 1); - auto handler_info = static_cast(handler.GetInt()); - HandlerBase::SetKeyNotInt(handler_info); - profile_type_info->Set(thread, index + 1, JSTaggedValue(handler_info)); + JSTaggedValue handler = profileTypeInfo->Get(index + 1); + auto handlerInfo = static_cast(handler.GetInt()); + HandlerBase::SetKeyNotInt(handlerInfo); + profileTypeInfo->Set(thread, index + 1, JSTaggedValue(handlerInfo)); } return LoadElement(JSObject::Cast(receiver.GetHeapObject()), key); } index += 2; } } - return LoadMissedICByValue(thread, profile_type_info, receiver, key, slot_id); + return LoadMissedICByValue(thread, profileTypeInfo, receiver, key, slotId); } JSTaggedValue ICRuntimeStub::StoreICByValue(JSThread *thread, JSFunction *func, JSTaggedValue receiver, - JSTaggedValue key, JSTaggedValue value, uint32_t slot_id) + JSTaggedValue key, JSTaggedValue value, uint32_t slotId) { INTERPRETER_TRACE(thread, StoreICByValue); ASSERT(HaveICForFunction(func)); - slot_id = MapSlotId(func, slot_id); - ProfileTypeInfo *profile_type_info = GetRuntimeProfileTypeInfo(func); - JSTaggedValue first_value = profile_type_info->Get(slot_id); - if (first_value.IsHole()) { + slotId = MapSlotId(func, slotId); + ProfileTypeInfo *profileTypeInfo = GetRuntimeProfileTypeInfo(func); + JSTaggedValue firstValue = profileTypeInfo->Get(slotId); + if (firstValue.IsHole()) { return JSTaggedValue::Hole(); } - if (receiver.IsHeapObject() && first_value.IsHeapObject()) { + if (receiver.IsHeapObject() && firstValue.IsHeapObject()) { auto hclass = receiver.GetTaggedObject()->GetClass(); // Check key - if (first_value == key) { - JSTaggedValue hclass_value = profile_type_info->Get(slot_id + 1); - if (hclass_value.GetTaggedObject() == hclass) { - JSTaggedValue handler = profile_type_info->Get(slot_id + 2); + if (firstValue == key) { + JSTaggedValue hclassValue = profileTypeInfo->Get(slotId + 1); + if (hclassValue.GetTaggedObject() == hclass) { + JSTaggedValue handler = profileTypeInfo->Get(slotId + 2); if (UNLIKELY(handler.IsUndefined())) { // handler is collected by GC. // Clear profile data to fill it again in StoreMiss. - profile_type_info->Set(thread, slot_id, JSTaggedValue::Undefined()); - profile_type_info->Set(thread, slot_id + 1, JSTaggedValue::Undefined()); + profileTypeInfo->Set(thread, slotId, JSTaggedValue::Undefined()); + profileTypeInfo->Set(thread, slotId + 1, JSTaggedValue::Undefined()); } else { return StoreICWithHandler(thread, receiver, receiver, value, handler); } } } // Check element - if (first_value.GetTaggedObject() == hclass) { - return StoreElement(thread, JSObject::Cast(receiver.GetHeapObject()), key, value, profile_type_info, - slot_id + 1); + if (firstValue.GetTaggedObject() == hclass) { + return StoreElement(thread, JSObject::Cast(receiver.GetHeapObject()), key, value, profileTypeInfo, + slotId + 1); } - size_t index = slot_id + 2; + size_t index = slotId + 2; while (index < SlotSizeForICByValue()) { - first_value = profile_type_info->Get(index); - if (first_value.GetRawData() == ToUintPtr(hclass)) { - return StoreElement(thread, JSObject::Cast(receiver.GetHeapObject()), key, value, profile_type_info, + firstValue = profileTypeInfo->Get(index); + if (firstValue.GetRawData() == ToUintPtr(hclass)) { + return StoreElement(thread, JSObject::Cast(receiver.GetHeapObject()), key, value, profileTypeInfo, index + 1); } index += 2; } } - return StoreMissedICByValue(thread, profile_type_info, receiver, key, value, slot_id); + return StoreMissedICByValue(thread, profileTypeInfo, receiver, key, value, slotId); } JSTaggedValue ICRuntimeStub::StoreICByName(JSThread *thread, JSFunction *func, JSTaggedValue receiver, - JSTaggedValue key, JSTaggedValue value, uint32_t slot_id) + JSTaggedValue key, JSTaggedValue value, uint32_t slotId) { INTERPRETER_TRACE(thread, StoreICByName); ASSERT(HaveICForFunction(func)); - slot_id = MapSlotId(func, slot_id); - ProfileTypeInfo *profile_type_info = GetRuntimeProfileTypeInfo(func); - JSTaggedValue hclass_value = profile_type_info->Get(slot_id); - if (hclass_value.IsHole()) { + slotId = MapSlotId(func, slotId); + ProfileTypeInfo *profileTypeInfo = GetRuntimeProfileTypeInfo(func); + JSTaggedValue hclassValue = profileTypeInfo->Get(slotId); + if (hclassValue.IsHole()) { return JSTaggedValue::Hole(); } if (receiver.IsHeapObject()) { auto hclass = receiver.GetTaggedObject()->GetClass(); - size_t index = slot_id; + size_t index = slotId; do { - if (!hclass_value.IsHeapObject()) { + if (!hclassValue.IsHeapObject()) { break; } - if (LIKELY(hclass_value.GetTaggedObject() == hclass)) { - JSTaggedValue handler = profile_type_info->Get(index + 1); + if (LIKELY(hclassValue.GetTaggedObject() == hclass)) { + JSTaggedValue handler = profileTypeInfo->Get(index + 1); if (UNLIKELY(handler.IsUndefined())) { // handler is collected by GC. // Clear profile data to fill it again in StoreMiss. - profile_type_info->Set(thread, index, JSTaggedValue::Undefined()); + profileTypeInfo->Set(thread, index, JSTaggedValue::Undefined()); break; } return StoreICWithHandler(thread, receiver, receiver, value, handler); } index += 2U; - hclass_value = profile_type_info->Get(index); - } while (index < slot_id + SlotSizeForICByName()); + hclassValue = profileTypeInfo->Get(index); + } while (index < slotId + SlotSizeForICByName()); } - return StoreMissedICByName(thread, profile_type_info, receiver, key, value, slot_id); + return StoreMissedICByName(thread, profileTypeInfo, receiver, key, value, slotId); } JSTaggedValue ICRuntimeStub::StoreICWithHandler(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, @@ -301,13 +301,13 @@ JSTaggedValue ICRuntimeStub::StoreICWithHandler(JSThread *thread, JSTaggedValue { INTERPRETER_TRACE(thread, StoreICWithHandler); if (handler.IsInt()) { - auto handler_info = static_cast(handler.GetInt()); - if (HandlerBase::IsField(handler_info)) { - StoreField(thread, JSObject::Cast(receiver.GetHeapObject()), value, handler_info); + auto handlerInfo = static_cast(handler.GetInt()); + if (HandlerBase::IsField(handlerInfo)) { + StoreField(thread, JSObject::Cast(receiver.GetHeapObject()), value, handlerInfo); return JSTaggedValue::Undefined(); } - ASSERT(HandlerBase::IsAccessor(handler_info) || HandlerBase::IsInternalAccessor(handler_info)); - auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handler_info); + ASSERT(HandlerBase::IsAccessor(handlerInfo) || HandlerBase::IsInternalAccessor(handlerInfo)); + auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handlerInfo); return FastRuntimeStub::CallSetter(thread, JSTaggedValue(receiver), value, accessor); } if (handler.IsTransitionHandler()) { @@ -328,54 +328,54 @@ JSTaggedValue ICRuntimeStub::StorePrototype(JSThread *thread, JSTaggedValue rece { INTERPRETER_TRACE(thread, StorePrototype); ASSERT(handler.IsPrototypeHandler()); - PrototypeHandler *prototype_handler = PrototypeHandler::Cast(handler.GetTaggedObject()); - auto cell_value = prototype_handler->GetProtoCell(); - ASSERT(cell_value.IsProtoChangeMarker()); - ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cell_value.GetHeapObject()); + PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); + auto cellValue = prototypeHandler->GetProtoCell(); + ASSERT(cellValue.IsProtoChangeMarker()); + ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetHeapObject()); if (cell->GetHasChanged()) { return JSTaggedValue::Hole(); } - auto holder = prototype_handler->GetHolder(); - JSTaggedValue handler_info = prototype_handler->GetHandlerInfo(); - return StoreICWithHandler(thread, receiver, holder, value, handler_info); + auto holder = prototypeHandler->GetHolder(); + JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(); + return StoreICWithHandler(thread, receiver, holder, value, handlerInfo); } void ICRuntimeStub::StoreWithTransition(JSThread *thread, JSObject *receiver, JSTaggedValue value, JSTaggedValue handler) { INTERPRETER_TRACE(thread, StoreWithTransition); - TransitionHandler *transition_handler = TransitionHandler::Cast(handler.GetTaggedObject()); - JSHClass *new_h_class = JSHClass::Cast(transition_handler->GetTransitionHClass().GetTaggedObject()); - receiver->SetClass(new_h_class); - uint32_t handler_info = transition_handler->GetHandlerInfo().GetInt(); - ASSERT(HandlerBase::IsField(handler_info)); + TransitionHandler *transitionHandler = TransitionHandler::Cast(handler.GetTaggedObject()); + JSHClass *newHClass = JSHClass::Cast(transitionHandler->GetTransitionHClass().GetTaggedObject()); + receiver->SetClass(newHClass); + uint32_t handlerInfo = transitionHandler->GetHandlerInfo().GetInt(); + ASSERT(HandlerBase::IsField(handlerInfo)); - if (!HandlerBase::IsInlinedProps(handler_info)) { + if (!HandlerBase::IsInlinedProps(handlerInfo)) { TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetHeapObject()); int capacity = array->GetLength(); - int index = HandlerBase::GetOffset(handler_info); + int index = HandlerBase::GetOffset(handlerInfo); if (index >= capacity) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - transition_handler->SetArrayOverflowed(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + transitionHandler->SetArrayOverflowed(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle properties; - JSHandle obj_handle(thread, receiver); - JSHandle value_handle(thread, value); + JSHandle objHandle(thread, receiver); + JSHandle valueHandle(thread, value); if (capacity == 0) { capacity = JSObject::MIN_PROPERTIES_LENGTH; properties = factory->NewTaggedArray(capacity); } else { - auto array_handle = JSHandle(thread, array); - properties = factory->CopyArray(array_handle, capacity, JSObject::ComputePropertyCapacity(capacity)); + auto arrayHandle = JSHandle(thread, array); + properties = factory->CopyArray(arrayHandle, capacity, JSObject::ComputePropertyCapacity(capacity)); } - properties->Set(thread, index, value_handle); - obj_handle->SetProperties(thread, properties); + properties->Set(thread, index, valueHandle); + objHandle->SetProperties(thread, properties); return; } array->Set(thread, index, value); return; } - StoreField(thread, receiver, value, handler_info); + StoreField(thread, receiver, value, handlerInfo); } void ICRuntimeStub::StoreField(JSThread *thread, JSObject *receiver, JSTaggedValue value, uint32_t handler) @@ -391,10 +391,10 @@ void ICRuntimeStub::StoreField(JSThread *thread, JSObject *receiver, JSTaggedVal array->Set(thread, index, value); } -JSTaggedValue ICRuntimeStub::LoadFromField(JSObject *receiver, uint32_t handler_info) +JSTaggedValue ICRuntimeStub::LoadFromField(JSObject *receiver, uint32_t handlerInfo) { - int index = HandlerBase::GetOffset(handler_info); - if (HandlerBase::IsInlinedProps(handler_info)) { + int index = HandlerBase::GetOffset(handlerInfo); + if (HandlerBase::IsInlinedProps(handlerInfo)) { return JSTaggedValue(GET_VALUE(receiver, index * JSTaggedValue::TaggedTypeSize())); } return TaggedArray::Cast(receiver->GetProperties().GetHeapObject())->Get(index); @@ -429,20 +429,20 @@ JSTaggedValue ICRuntimeStub::LoadPrototype(JSThread *thread, JSTaggedValue recei { INTERPRETER_TRACE(thread, LoadPrototype); ASSERT(handler.IsPrototypeHandler()); - PrototypeHandler *prototype_handler = PrototypeHandler::Cast(handler.GetTaggedObject()); - auto cell_value = prototype_handler->GetProtoCell(); - if (cell_value.IsFalse()) { + PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); + auto cellValue = prototypeHandler->GetProtoCell(); + if (cellValue.IsFalse()) { // property was not found and object has no prototype return JSTaggedValue::Hole(); } - ASSERT(cell_value.IsProtoChangeMarker()); - ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cell_value.GetHeapObject()); + ASSERT(cellValue.IsProtoChangeMarker()); + ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetHeapObject()); if (cell->GetHasChanged()) { return JSTaggedValue::Hole(); } - auto holder = prototype_handler->GetHolder(); - JSTaggedValue handler_info = prototype_handler->GetHandlerInfo(); - return LoadICWithHandler(thread, receiver, holder, handler_info); + auto holder = prototypeHandler->GetHolder(); + JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(); + return LoadICWithHandler(thread, receiver, holder, handlerInfo); } JSTaggedValue ICRuntimeStub::LoadICWithHandler(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, @@ -450,15 +450,15 @@ JSTaggedValue ICRuntimeStub::LoadICWithHandler(JSThread *thread, JSTaggedValue r { INTERPRETER_TRACE(thread, LoadICWithHandler); if (LIKELY(handler.IsInt())) { - auto handler_info = static_cast(handler.GetInt()); - if (LIKELY(HandlerBase::IsField(handler_info))) { - return LoadFromField(JSObject::Cast(holder.GetHeapObject()), handler_info); + auto handlerInfo = static_cast(handler.GetInt()); + if (LIKELY(HandlerBase::IsField(handlerInfo))) { + return LoadFromField(JSObject::Cast(holder.GetHeapObject()), handlerInfo); } - if (HandlerBase::IsNonExist(handler_info)) { + if (HandlerBase::IsNonExist(handlerInfo)) { return JSTaggedValue::Hole(); } - ASSERT(HandlerBase::IsAccessor(handler_info) || HandlerBase::IsInternalAccessor(handler_info)); - auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handler_info); + ASSERT(HandlerBase::IsAccessor(handlerInfo) || HandlerBase::IsInternalAccessor(handlerInfo)); + auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handlerInfo); return FastRuntimeStub::CallGetter(thread, receiver, holder, accessor); } @@ -475,58 +475,58 @@ JSTaggedValue ICRuntimeStub::LoadElement(JSObject *receiver, JSTaggedValue key) if (index >= JSObject::MAX_ELEMENT_INDEX) { return JSTaggedValue::Hole(); } - uint32_t element_index = index; + uint32_t elementIndex = index; TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetHeapObject()); - if (elements->GetLength() <= element_index) { + if (elements->GetLength() <= elementIndex) { return JSTaggedValue::Hole(); } - JSTaggedValue value = elements->Get(element_index); + JSTaggedValue value = elements->Get(elementIndex); // TaggedArray elements return value; } JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, JSTaggedValue key, JSTaggedValue value, - ProfileTypeInfo *profile_type_info, uint32_t slot_id) + ProfileTypeInfo *profileTypeInfo, uint32_t slotId) { INTERPRETER_TRACE(thread, StoreElement); - JSTaggedValue handler = profile_type_info->Get(slot_id); - auto handler_info = static_cast(handler.GetInt()); - ASSERT(HandlerBase::IsElement(handler_info)); + JSTaggedValue handler = profileTypeInfo->Get(slotId); + auto handlerInfo = static_cast(handler.GetInt()); + ASSERT(HandlerBase::IsElement(handlerInfo)); if (!key.IsInt()) { - HandlerBase::SetKeyNotInt(handler_info); - profile_type_info->Set(thread, slot_id, JSTaggedValue(handler_info)); + HandlerBase::SetKeyNotInt(handlerInfo); + profileTypeInfo->Set(thread, slotId, JSTaggedValue(handlerInfo)); } auto index = TryToElementsIndex(key); if (index >= JSObject::MAX_ELEMENT_INDEX) { return JSTaggedValue::Hole(); } - uint32_t element_index = index; - if (HandlerBase::IsJSArray(handler_info)) { + uint32_t elementIndex = index; + if (HandlerBase::IsJSArray(handlerInfo)) { JSArray *arr = JSArray::Cast(receiver); - uint32_t old_length = arr->GetArrayLength(); - if (element_index >= old_length) { - arr->SetArrayLength(thread, element_index + 1); + uint32_t oldLength = arr->GetArrayLength(); + if (elementIndex >= oldLength) { + arr->SetArrayLength(thread, elementIndex + 1); } } TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetHeapObject()); uint32_t capacity = elements->GetLength(); - if (element_index >= capacity) { - HandlerBase::SetArrayOverflowed(handler_info); - profile_type_info->Set(thread, slot_id, JSTaggedValue(handler_info)); - if (JSObject::ShouldTransToDict(capacity, element_index)) { + if (elementIndex >= capacity) { + HandlerBase::SetArrayOverflowed(handlerInfo); + profileTypeInfo->Set(thread, slotId, JSTaggedValue(handlerInfo)); + if (JSObject::ShouldTransToDict(capacity, elementIndex)) { return JSTaggedValue::Hole(); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle receiver_handle(thread, receiver); - JSHandle value_handle(thread, value); - elements = *JSObject::GrowElementsCapacity(thread, receiver_handle, - JSObject::ComputeElementCapacity(element_index + 1)); - receiver_handle->SetElements(thread, JSTaggedValue(elements)); - elements->Set(thread, element_index, value_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle receiverHandle(thread, receiver); + JSHandle valueHandle(thread, value); + elements = + *JSObject::GrowElementsCapacity(thread, receiverHandle, JSObject::ComputeElementCapacity(elementIndex + 1)); + receiverHandle->SetElements(thread, JSTaggedValue(elements)); + elements->Set(thread, elementIndex, valueHandle); return JSTaggedValue::Undefined(); } - elements->Set(thread, element_index, value); + elements->Set(thread, elementIndex, value); return JSTaggedValue::Undefined(); } diff --git a/runtime/ic/ic_runtime_stub.cpp b/runtime/ic/ic_runtime_stub.cpp index 5a86717b8d5e06c4300ebc46e95c4e2e13d5e87b..6af6ccff8dce2ab26e0d1a92c1771940ac83165d 100644 --- a/runtime/ic/ic_runtime_stub.cpp +++ b/runtime/ic/ic_runtime_stub.cpp @@ -34,60 +34,60 @@ #include "plugins/ecmascript/runtime/runtime_call_id.h" namespace panda::ecmascript { -JSTaggedValue ICRuntimeStub::LoadMissedICByName(JSThread *thread, ProfileTypeInfo *profile_type_info, - JSTaggedValue receiver, JSTaggedValue key, uint32_t slot_id) +JSTaggedValue ICRuntimeStub::LoadMissedICByName(JSThread *thread, ProfileTypeInfo *profileTypeInfo, + JSTaggedValue receiver, JSTaggedValue key, uint32_t slotId) { INTERPRETER_TRACE(thread, LoadMissedICByName); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto key_handle = JSHandle(thread, key); - auto receiver_handle = JSHandle(thread, receiver); - auto profile_info_handle = JSHandle(thread, profile_type_info); - LoadICRuntime ic_runtime(thread, profile_info_handle, slot_id, ICKind::NAMED_LOAD_IC); - return ic_runtime.LoadMiss(receiver_handle, key_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto keyHandle = JSHandle(thread, key); + auto receiverHandle = JSHandle(thread, receiver); + auto profileInfoHandle = JSHandle(thread, profileTypeInfo); + LoadICRuntime icRuntime(thread, profileInfoHandle, slotId, ICKind::NAMED_LOAD_IC); + return icRuntime.LoadMiss(receiverHandle, keyHandle); } -JSTaggedValue ICRuntimeStub::LoadMissedICByValue(JSThread *thread, ProfileTypeInfo *profile_type_info, - JSTaggedValue receiver, JSTaggedValue key, uint32_t slot_id) +JSTaggedValue ICRuntimeStub::LoadMissedICByValue(JSThread *thread, ProfileTypeInfo *profileTypeInfo, + JSTaggedValue receiver, JSTaggedValue key, uint32_t slotId) { INTERPRETER_TRACE(thread, LoadMissedICByValue); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto key_handle = JSHandle(thread, key); - auto receiver_handle = JSHandle(thread, receiver); - auto profile_info_handle = JSHandle(thread, profile_type_info); - LoadICRuntime ic_runtime(thread, JSHandle::Cast(profile_info_handle), slot_id, ICKind::LOAD_IC); - return ic_runtime.LoadMiss(receiver_handle, key_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto keyHandle = JSHandle(thread, key); + auto receiverHandle = JSHandle(thread, receiver); + auto profileInfoHandle = JSHandle(thread, profileTypeInfo); + LoadICRuntime icRuntime(thread, JSHandle::Cast(profileInfoHandle), slotId, ICKind::LOAD_IC); + return icRuntime.LoadMiss(receiverHandle, keyHandle); } -JSTaggedValue ICRuntimeStub::StoreMissedICByValue(JSThread *thread, ProfileTypeInfo *profile_type_info, +JSTaggedValue ICRuntimeStub::StoreMissedICByValue(JSThread *thread, ProfileTypeInfo *profileTypeInfo, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value, - uint32_t slot_id) + uint32_t slotId) { INTERPRETER_TRACE(thread, StoreMissedICByValue); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto key_handle = JSHandle(thread, key); - auto receiver_handle = JSHandle(thread, receiver); - auto value_handle = JSHandle(thread, value); - auto profile_info_handle = JSHandle(thread, profile_type_info); - StoreICRuntime ic_runtime(thread, JSHandle::Cast(profile_info_handle), slot_id, ICKind::STORE_IC); - return ic_runtime.StoreMiss(receiver_handle, key_handle, value_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto keyHandle = JSHandle(thread, key); + auto receiverHandle = JSHandle(thread, receiver); + auto valueHandle = JSHandle(thread, value); + auto profileInfoHandle = JSHandle(thread, profileTypeInfo); + StoreICRuntime icRuntime(thread, JSHandle::Cast(profileInfoHandle), slotId, ICKind::STORE_IC); + return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle); } -JSTaggedValue ICRuntimeStub::StoreMissedICByName(JSThread *thread, ProfileTypeInfo *profile_type_info, +JSTaggedValue ICRuntimeStub::StoreMissedICByName(JSThread *thread, ProfileTypeInfo *profileTypeInfo, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value, - uint32_t slot_id) + uint32_t slotId) { INTERPRETER_TRACE(thread, StoreMissedICByName); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto key_handle = JSHandle(thread, key); - auto receiver_handle = JSHandle(thread, receiver); - auto value_handle = JSHandle(thread, value); - auto profile_info_handle = JSHandle(thread, profile_type_info); - StoreICRuntime ic_runtime(thread, JSHandle::Cast(profile_info_handle), slot_id, - ICKind::NAMED_STORE_IC); - return ic_runtime.StoreMiss(receiver_handle, key_handle, value_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto keyHandle = JSHandle(thread, key); + auto receiverHandle = JSHandle(thread, receiver); + auto valueHandle = JSHandle(thread, value); + auto profileInfoHandle = JSHandle(thread, profileTypeInfo); + StoreICRuntime icRuntime(thread, JSHandle::Cast(profileInfoHandle), slotId, + ICKind::NAMED_STORE_IC); + return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle); } } // namespace panda::ecmascript diff --git a/runtime/ic/ic_runtime_stub.h b/runtime/ic/ic_runtime_stub.h index 3221545d1003874ace84584d597fd78eea12e40c..f4a86438ed9ededf1646ec7811f1dfb42a83e52f 100644 --- a/runtime/ic/ic_runtime_stub.h +++ b/runtime/ic/ic_runtime_stub.h @@ -45,17 +45,17 @@ public: ARK_INLINE static inline bool HaveICForFunction(JSFunction *func); ARK_INLINE static inline JSTaggedValue LoadGlobalICByName(JSThread *thread, JSFunction *func, - JSTaggedValue global_value, JSTaggedValue key, - uint32_t slot_id, bool is_try_load = false); + JSTaggedValue globalValue, JSTaggedValue key, + uint32_t slotId, bool isTryLoad = false); ARK_INLINE static inline JSTaggedValue StoreGlobalICByName(JSThread *thread, JSFunction *func, - JSTaggedValue global_value, JSTaggedValue key, - JSTaggedValue value, uint32_t slot_id, - bool is_try_store = false); + JSTaggedValue globalValue, JSTaggedValue key, + JSTaggedValue value, uint32_t slotId, + bool isTryStore = false); ARK_INLINE static inline JSTaggedValue LoadICByName(JSThread *thread, JSFunction *func, JSTaggedValue receiver, - JSTaggedValue key, uint32_t slot_id); + JSTaggedValue key, uint32_t slotId); ARK_INLINE static inline JSTaggedValue StoreICByName(JSThread *thread, JSFunction *func, JSTaggedValue receiver, - JSTaggedValue key, JSTaggedValue value, uint32_t slot_id); - ARK_INLINE static inline JSTaggedValue CheckPolyHClass(JSTaggedValue cached_value, JSHClass *hclass); + JSTaggedValue key, JSTaggedValue value, uint32_t slotId); + ARK_INLINE static inline JSTaggedValue CheckPolyHClass(JSTaggedValue cachedValue, JSHClass *hclass); static inline JSTaggedValue LoadICWithHandler(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue handler); static inline JSTaggedValue StoreICWithHandler(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, @@ -64,7 +64,7 @@ public: JSTaggedValue handler); ARK_INLINE static inline JSTaggedValue StorePrototype(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, JSTaggedValue handler); - ARK_INLINE static inline JSTaggedValue LoadFromField(JSObject *receiver, uint32_t handler_info); + ARK_INLINE static inline JSTaggedValue LoadFromField(JSObject *receiver, uint32_t handlerInfo); ARK_INLINE static inline void StoreField(JSThread *thread, JSObject *receiver, JSTaggedValue value, uint32_t handler); ARK_INLINE static inline JSTaggedValue LoadGlobal(JSTaggedValue handler); @@ -72,28 +72,28 @@ public: ARK_INLINE static inline JSTaggedValue LoadPrototype(JSThread *thread, JSTaggedValue receiver, JSTaggedValue handler); ARK_INLINE static inline JSTaggedValue LoadICByValue(JSThread *thread, JSFunction *func, JSTaggedValue receiver, - JSTaggedValue key, uint32_t slot_id); + JSTaggedValue key, uint32_t slotId); ARK_INLINE static inline JSTaggedValue StoreICByValue(JSThread *thread, JSFunction *func, JSTaggedValue receiver, - JSTaggedValue key, JSTaggedValue value, uint32_t slot_id); + JSTaggedValue key, JSTaggedValue value, uint32_t slotId); ARK_INLINE static inline JSTaggedValue LoadElement(JSObject *receiver, JSTaggedValue key); ARK_INLINE static inline JSTaggedValue StoreElement(JSThread *thread, JSObject *receiver, JSTaggedValue key, - JSTaggedValue value, ProfileTypeInfo *profile_type_info, - uint32_t slot_id); + JSTaggedValue value, ProfileTypeInfo *profileTypeInfo, + uint32_t slotId); ARK_INLINE static inline uint32_t TryToElementsIndex(JSTaggedValue key); private: - static inline uint32_t MapSlotId(JSFunction *func, uint32_t slot_id); + static inline uint32_t MapSlotId(JSFunction *func, uint32_t slotId); static inline ProfileTypeInfo *GetRuntimeProfileTypeInfo(JSFunction *func); - ARK_NOINLINE static JSTaggedValue LoadMissedICByName(JSThread *thread, ProfileTypeInfo *profile_type_array, - JSTaggedValue receiver, JSTaggedValue key, uint32_t slot_id); - ARK_NOINLINE static JSTaggedValue StoreMissedICByName(JSThread *thread, ProfileTypeInfo *profile_type_info, + ARK_NOINLINE static JSTaggedValue LoadMissedICByName(JSThread *thread, ProfileTypeInfo *profileTypeArray, + JSTaggedValue receiver, JSTaggedValue key, uint32_t slotId); + ARK_NOINLINE static JSTaggedValue StoreMissedICByName(JSThread *thread, ProfileTypeInfo *profileTypeInfo, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, uint32_t slot_id); - ARK_NOINLINE static JSTaggedValue LoadMissedICByValue(JSThread *thread, ProfileTypeInfo *profile_type_info, - JSTaggedValue receiver, JSTaggedValue key, uint32_t slot_id); - ARK_NOINLINE static JSTaggedValue StoreMissedICByValue(JSThread *thread, ProfileTypeInfo *profile_type_info, + JSTaggedValue value, uint32_t slotId); + ARK_NOINLINE static JSTaggedValue LoadMissedICByValue(JSThread *thread, ProfileTypeInfo *profileTypeInfo, + JSTaggedValue receiver, JSTaggedValue key, uint32_t slotId); + ARK_NOINLINE static JSTaggedValue StoreMissedICByValue(JSThread *thread, ProfileTypeInfo *profileTypeInfo, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, uint32_t slot_id); + JSTaggedValue value, uint32_t slotId); }; } // namespace panda::ecmascript diff --git a/runtime/ic/profile_type_info.cpp b/runtime/ic/profile_type_info.cpp index 37e20004d05d67be6db5ad24b3f5dd10c82c2eae..56ca184f0396ca38c7819c5f2596099b491a2aae 100644 --- a/runtime/ic/profile_type_info.cpp +++ b/runtime/ic/profile_type_info.cpp @@ -21,20 +21,20 @@ namespace panda::ecmascript { void ProfileTypeAccessor::AddElementHandler(JSHandle dynclass, JSHandle handler) const { - auto profile_data = profile_type_info_->Get(slot_id_); - if (profile_data.IsHole()) { + auto profileData = profileTypeInfo_->Get(slotId_); + if (profileData.IsHole()) { return; } - auto index = slot_id_; - if (profile_data.IsUndefined()) { - profile_type_info_->Set(thread_, index, dynclass.GetTaggedValue()); - profile_type_info_->Set(thread_, index + 1, handler.GetTaggedValue()); + auto index = slotId_; + if (profileData.IsUndefined()) { + profileTypeInfo_->Set(thread_, index, dynclass.GetTaggedValue()); + profileTypeInfo_->Set(thread_, index + 1, handler.GetTaggedValue()); return; } // clear key ic - if (profile_data.IsString() || profile_data.IsSymbol()) { - profile_type_info_->Set(thread_, index, dynclass.GetTaggedValue()); - profile_type_info_->Set(thread_, index + 1, handler.GetTaggedValue()); + if (profileData.IsString() || profileData.IsSymbol()) { + profileTypeInfo_->Set(thread_, index, dynclass.GetTaggedValue()); + profileTypeInfo_->Set(thread_, index + 1, handler.GetTaggedValue()); return; } AddHandlerWithoutKey(dynclass, handler); @@ -43,26 +43,26 @@ void ProfileTypeAccessor::AddElementHandler(JSHandle dynclass, JS void ProfileTypeAccessor::AddHandlerWithoutKey(JSHandle dynclass, JSHandle handler) const { if (IsNamedGlobalIC(GetKind())) { - profile_type_info_->Set(thread_, slot_id_, handler.GetTaggedValue()); + profileTypeInfo_->Set(thread_, slotId_, handler.GetTaggedValue()); return; } - auto index = slot_id_; - auto profile_data = profile_type_info_->Get(index); - if (profile_data.IsHole()) { + auto index = slotId_; + auto profileData = profileTypeInfo_->Get(index); + if (profileData.IsHole()) { return; } - while (index < slot_id_ + 4U && !profile_type_info_->Get(index).IsUndefined()) { + while (index < slotId_ + 4U && !profileTypeInfo_->Get(index).IsUndefined()) { index += 2U; } - if (index == slot_id_ + 4U) { - profile_type_info_->Set(thread_, slot_id_, JSTaggedValue::Hole()); - profile_type_info_->Set(thread_, slot_id_ + 1, JSTaggedValue::Hole()); - profile_type_info_->Set(thread_, slot_id_ + 2, JSTaggedValue::Hole()); - profile_type_info_->Set(thread_, slot_id_ + 3, JSTaggedValue::Hole()); + if (index == slotId_ + 4U) { + profileTypeInfo_->Set(thread_, slotId_, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_ + 1, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_ + 2, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_ + 3, JSTaggedValue::Hole()); return; } - profile_type_info_->Set(thread_, index, dynclass.GetTaggedValue()); - profile_type_info_->Set(thread_, index + 1, handler.GetTaggedValue()); + profileTypeInfo_->Set(thread_, index, dynclass.GetTaggedValue()); + profileTypeInfo_->Set(thread_, index + 1, handler.GetTaggedValue()); } void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandle dynclass, @@ -72,45 +72,45 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl AddGlobalHandlerKey(key, handler); return; } - auto profile_data = profile_type_info_->Get(slot_id_); - if (profile_data.IsUndefined() || profile_type_info_->Get(slot_id_ + 1).IsUndefined()) { - profile_type_info_->Set(thread_, slot_id_, key.GetTaggedValue()); - profile_type_info_->Set(thread_, slot_id_ + 1U, dynclass.GetTaggedValue()); - profile_type_info_->Set(thread_, slot_id_ + 2U, handler.GetTaggedValue()); + auto profileData = profileTypeInfo_->Get(slotId_); + if (profileData.IsUndefined() || profileTypeInfo_->Get(slotId_ + 1).IsUndefined()) { + profileTypeInfo_->Set(thread_, slotId_, key.GetTaggedValue()); + profileTypeInfo_->Set(thread_, slotId_ + 1U, dynclass.GetTaggedValue()); + profileTypeInfo_->Set(thread_, slotId_ + 2U, handler.GetTaggedValue()); return; } // for element ic, profileData may dynclass or taggedarray - if (key.GetTaggedValue() != profile_data) { - profile_type_info_->Set(thread_, slot_id_, JSTaggedValue::Hole()); - profile_type_info_->Set(thread_, slot_id_ + 1, JSTaggedValue::Hole()); - profile_type_info_->Set(thread_, slot_id_ + 2, JSTaggedValue::Hole()); + if (key.GetTaggedValue() != profileData) { + profileTypeInfo_->Set(thread_, slotId_, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_ + 1, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_ + 2, JSTaggedValue::Hole()); return; } } void ProfileTypeAccessor::AddGlobalHandlerKey(JSHandle key, JSHandle handler) const { - uint32_t index = slot_id_; - JSTaggedValue index_val = profile_type_info_->Get(index); - if (index_val.IsUndefined()) { - profile_type_info_->Set(thread_, index, key.GetTaggedValue()); - profile_type_info_->Set(thread_, index + 1, handler.GetTaggedValue()); + uint32_t index = slotId_; + JSTaggedValue indexVal = profileTypeInfo_->Get(index); + if (indexVal.IsUndefined()) { + profileTypeInfo_->Set(thread_, index, key.GetTaggedValue()); + profileTypeInfo_->Set(thread_, index + 1, handler.GetTaggedValue()); return; } index += 2U; - if (index_val.IsUndefined()) { - profile_type_info_->Set(thread_, index, key.GetTaggedValue()); - profile_type_info_->Set(thread_, index + 1, handler.GetTaggedValue()); + if (indexVal.IsUndefined()) { + profileTypeInfo_->Set(thread_, index, key.GetTaggedValue()); + profileTypeInfo_->Set(thread_, index + 1, handler.GetTaggedValue()); return; } - profile_type_info_->Set(thread_, slot_id_, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_, JSTaggedValue::Hole()); } void ProfileTypeAccessor::SetAsMega() const { - profile_type_info_->Set(thread_, slot_id_, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_, JSTaggedValue::Hole()); if (!IsNamedGlobalIC(GetKind())) { - profile_type_info_->Set(thread_, slot_id_ + 1, JSTaggedValue::Hole()); + profileTypeInfo_->Set(thread_, slotId_ + 1, JSTaggedValue::Hole()); } } @@ -162,44 +162,44 @@ std::string ProfileTypeAccessor::ICStateToString(ProfileTypeAccessor::ICState st ProfileTypeAccessor::ICState ProfileTypeAccessor::GetICState() const { - auto profile_data = profile_type_info_->Get(slot_id_); - if (profile_data.IsUndefined()) { + auto profileData = profileTypeInfo_->Get(slotId_); + if (profileData.IsUndefined()) { return ICState::UNINIT; } - if (profile_data.IsHole()) { + if (profileData.IsHole()) { return ICState::MEGA; } switch (kind_) { case ICKind::NAMED_LOAD_IC: case ICKind::NAMED_STORE_IC: - if (profile_data.IsWeak()) { + if (profileData.IsWeak()) { return ICState::MONO; } - ASSERT(profile_data.IsTaggedArray()); + ASSERT(profileData.IsTaggedArray()); return ICState::POLY; case ICKind::LOAD_IC: case ICKind::STORE_IC: { - if (profile_data.IsWeak()) { + if (profileData.IsWeak()) { return ICState::MONO; } - if (profile_data.IsTaggedArray()) { - TaggedArray *array = TaggedArray::Cast(profile_data.GetHeapObject()); + if (profileData.IsTaggedArray()) { + TaggedArray *array = TaggedArray::Cast(profileData.GetHeapObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } - profile_data = profile_type_info_->Get(slot_id_ + 1); - TaggedArray *array = TaggedArray::Cast(profile_data.GetHeapObject()); + profileData = profileTypeInfo_->Get(slotId_ + 1); + TaggedArray *array = TaggedArray::Cast(profileData.GetHeapObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } case ICKind::NAMED_GLOBAL_LOAD_IC: case ICKind::NAMED_GLOBAL_STORE_IC: - ASSERT(profile_data.IsPropertyBox()); + ASSERT(profileData.IsPropertyBox()); return ICState::MONO; case ICKind::GLOBAL_LOAD_IC: case ICKind::GLOBAL_STORE_IC: { - ASSERT(profile_data.IsTaggedArray()); - TaggedArray *array = TaggedArray::Cast(profile_data.GetHeapObject()); + ASSERT(profileData.IsTaggedArray()); + TaggedArray *array = TaggedArray::Cast(profileData.GetHeapObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } default: diff --git a/runtime/ic/profile_type_info.h b/runtime/ic/profile_type_info.h index b074be7e40ac0cf56c60582cbc8901752460bf15..7b109a04f12ddc9bdbc8a974ce72a3a15b5fbe17 100644 --- a/runtime/ic/profile_type_info.h +++ b/runtime/ic/profile_type_info.h @@ -109,8 +109,8 @@ public: MEGA, }; - ProfileTypeAccessor(JSThread *thread, JSHandle profile_type_info, uint32_t slot_id, ICKind kind) - : thread_(thread), profile_type_info_(profile_type_info), slot_id_(slot_id), kind_(kind) + ProfileTypeAccessor(JSThread *thread, JSHandle profileTypeInfo, uint32_t slotId, ICKind kind) + : thread_(thread), profileTypeInfo_(profileTypeInfo), slotId_(slotId), kind_(kind) { } ~ProfileTypeAccessor() = default; @@ -144,8 +144,8 @@ public: private: JSThread *thread_; - JSHandle profile_type_info_; - uint32_t slot_id_; + JSHandle profileTypeInfo_; + uint32_t slotId_; ICKind kind_; }; } // namespace panda::ecmascript diff --git a/runtime/ic/properties_cache-inl.h b/runtime/ic/properties_cache-inl.h index b9c1e96681fc85b2f75cf7c87a3279f228c076b7..80fb7a09b9c643c68fe09746cd673800c3ca8854 100644 --- a/runtime/ic/properties_cache-inl.h +++ b/runtime/ic/properties_cache-inl.h @@ -20,21 +20,21 @@ #include "plugins/ecmascript/runtime/js_tagged_value-inl.h" namespace panda::ecmascript { -int PropertiesCache::Get(JSHClass *js_hclass, JSTaggedValue key) +int PropertiesCache::Get(JSHClass *jsHclass, JSTaggedValue key) { - int hash = Hash(js_hclass, key); + int hash = Hash(jsHclass, key); PropertyKey &prop = keys_[hash]; - if ((prop.hclass == js_hclass) && (prop.key == key)) { + if ((prop.hclass == jsHclass) && (prop.key == key)) { return keys_[hash].results; } return NOT_FOUND; } -void PropertiesCache::Set(JSHClass *js_hclass, JSTaggedValue key, int index) +void PropertiesCache::Set(JSHClass *jsHclass, JSTaggedValue key, int index) { - int hash = Hash(js_hclass, key); + int hash = Hash(jsHclass, key); PropertyKey &prop = keys_[hash]; - prop.hclass = js_hclass; + prop.hclass = jsHclass; prop.key = key; keys_[hash].results = index; } @@ -48,9 +48,9 @@ void PropertiesCache::Clear() int PropertiesCache::Hash(JSHClass *cls, JSTaggedValue key) { - uint32_t cls_hash = JSHClass::Hash(cls); - uint32_t key_hash = key.GetKeyHashCode(); - return static_cast((cls_hash ^ key_hash) & CACHE_LENGTH_MASK); + uint32_t clsHash = JSHClass::Hash(cls); + uint32_t keyHash = key.GetKeyHashCode(); + return static_cast((clsHash ^ keyHash) & CACHE_LENGTH_MASK); } } // namespace panda::ecmascript #endif // ECMASCRIPT_IC_PROPERTIES_CACHE_INL_H diff --git a/runtime/ic/properties_cache.h b/runtime/ic/properties_cache.h index 262c2bf3556658f9a9f7373a70f0a17afa202f8d..cd536b0775886727cfae0e58079ffe766daa5250 100644 --- a/runtime/ic/properties_cache.h +++ b/runtime/ic/properties_cache.h @@ -26,8 +26,8 @@ namespace panda::ecmascript { class EcmaVM; class PropertiesCache { public: - inline int Get(JSHClass *js_hclass, JSTaggedValue key); - inline void Set(JSHClass *js_hclass, JSTaggedValue key, int index); + inline int Get(JSHClass *jsHclass, JSTaggedValue key); + inline void Set(JSHClass *jsHclass, JSTaggedValue key, int index); inline void Clear(); static const int NOT_FOUND = -1; diff --git a/runtime/ic/proto_change_details.cpp b/runtime/ic/proto_change_details.cpp index 8c227cb73eac4d5fb66cdf69e77f0f0ff2187058..6bdc3f0049310f330ecca2fa191273fb144ebec0 100644 --- a/runtime/ic/proto_change_details.cpp +++ b/runtime/ic/proto_change_details.cpp @@ -21,32 +21,32 @@ JSHandle ChangeListener::Add(const JSThread *thread, const JSHan const JSHandle &value, uint32_t *index) { if (!array->Full()) { - uint32_t array_index = array->PushBack(thread, value.GetTaggedValue()); - if (array_index != TaggedArray::MAX_ARRAY_INDEX) { + uint32_t arrayIndex = array->PushBack(thread, value.GetTaggedValue()); + if (arrayIndex != TaggedArray::MAX_ARRAY_INDEX) { if (index != nullptr) { - *index = array_index; + *index = arrayIndex; } return array; } UNREACHABLE(); } // if exist hole, use it. - uint32_t hole_index = CheckHole(array); - if (hole_index != TaggedArray::MAX_ARRAY_INDEX) { - array->Set(thread, hole_index, value.GetTaggedValue()); + uint32_t holeIndex = CheckHole(array); + if (holeIndex != TaggedArray::MAX_ARRAY_INDEX) { + array->Set(thread, holeIndex, value.GetTaggedValue()); if (index != nullptr) { - *index = hole_index; + *index = holeIndex; } return array; } // the vector is full and no hole exists. - JSHandle new_array = WeakVector::Grow(thread, JSHandle(array), array->GetCapacity() + 1); - uint32_t array_index = new_array->PushBack(thread, value.GetTaggedValue()); - ASSERT(array_index != TaggedArray::MAX_ARRAY_INDEX); + JSHandle newArray = WeakVector::Grow(thread, JSHandle(array), array->GetCapacity() + 1); + uint32_t arrayIndex = newArray->PushBack(thread, value.GetTaggedValue()); + ASSERT(arrayIndex != TaggedArray::MAX_ARRAY_INDEX); if (index != nullptr) { - *index = array_index; + *index = arrayIndex; } - return JSHandle(new_array); + return JSHandle(newArray); } uint32_t ChangeListener::CheckHole(const JSHandle &array) diff --git a/runtime/internal_call_params.cpp b/runtime/internal_call_params.cpp index 7fddcdd036bf0f5ff69fb95071c9caea0f377948..c5ccef0a1ec653690058b96a31166fc9bd67a50d 100644 --- a/runtime/internal_call_params.cpp +++ b/runtime/internal_call_params.cpp @@ -18,8 +18,8 @@ namespace panda::ecmascript { void InternalCallParams::MakeArgv(const EcmaRuntimeCallInfo *info, uint32_t position) { - int32_t may_lenth = info->GetArgsNumber() - position; - uint32_t length = may_lenth > 0 ? may_lenth : 0; + int32_t mayLenth = info->GetArgsNumber() - position; + uint32_t length = mayLenth > 0 ? mayLenth : 0; if (LIKELY(length <= InternalCallParams::RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH)) { EnableFixedModeAndSetLength(length); for (uint32_t index = 0; index < length; ++index) { @@ -73,21 +73,21 @@ void InternalCallParams::MakeArgList(const TaggedArray *argv) } } -void InternalCallParams::MakeBoundArgv(const JSThread *thread, const JSHandle &bound_func) +void InternalCallParams::MakeBoundArgv(const JSThread *thread, const JSHandle &boundFunc) { - JSHandle bound_args(thread, bound_func->GetBoundArguments()); - uint32_t bound_length = bound_args->GetLength(); - uint32_t length = IsFixedMode() ? bound_length + GetFixedLength() : bound_length + GetVariableLength(); + JSHandle boundArgs(thread, boundFunc->GetBoundArguments()); + uint32_t boundLength = boundArgs->GetLength(); + uint32_t length = IsFixedMode() ? boundLength + GetFixedLength() : boundLength + GetVariableLength(); if (LIKELY(length <= InternalCallParams::RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH)) { EnableFixedModeAndSetLength(length); // Prevent override, reverse write order - for (ArraySsizeT index = length - 1; index >= static_cast(bound_length); --index) { - SetFixedBuffer(index, GetFixedBuffer(index - bound_length)); + for (ArraySsizeT index = length - 1; index >= static_cast(boundLength); --index) { + SetFixedBuffer(index, GetFixedBuffer(index - boundLength)); } - for (uint32_t index = 0; index < bound_length; ++index) { - SetFixedBuffer(index, bound_args->Get(index)); + for (uint32_t index = 0; index < boundLength; ++index) { + SetFixedBuffer(index, boundArgs->Get(index)); } return; } @@ -96,19 +96,19 @@ void InternalCallParams::MakeBoundArgv(const JSThread *thread, const JSHandleGet(index)); + for (uint32_t index = 0; index < boundLength; ++index) { + SetVariableBuffer(index, boundArgs->Get(index)); } - for (uint32_t index = bound_length; index < length; ++index) { - SetVariableBuffer(index, GetFixedBuffer(index - bound_length)); + for (uint32_t index = boundLength; index < length; ++index) { + SetVariableBuffer(index, GetFixedBuffer(index - boundLength)); } return; } EnableVariableModeAndSetLength(length); - for (ArraySsizeT index = bound_length - 1; index >= 0; --index) { - InsertVariableBuffer(bound_args->Get(index)); + for (ArraySsizeT index = boundLength - 1; index >= 0; --index) { + InsertVariableBuffer(boundArgs->Get(index)); } } @@ -121,10 +121,10 @@ void InternalCallParams::Iterate(const RootRangeVisitor &v) const uintptr_t end = 0U; if (LIKELY(IsFixedMode())) { start = GetFixedDataAddress(); - end = start + sizeof(TaggedType) * fixed_length_; + end = start + sizeof(TaggedType) * fixedLength_; } else { start = GetVariableDataAddress(); - end = start + sizeof(TaggedType) * variable_length_; + end = start + sizeof(TaggedType) * variableLength_; } v(Root::ROOT_INTERNAL_CALL_PARAMS, ObjectSlot(start), ObjectSlot(end)); } diff --git a/runtime/internal_call_params.h b/runtime/internal_call_params.h index ce21fa49f3b5a34c3b98d035ba28d5497694f008..0bf10feac7c2060b374a02f3c5ad5cc98a3786f9 100644 --- a/runtime/internal_call_params.h +++ b/runtime/internal_call_params.h @@ -33,45 +33,45 @@ public: inline const JSTaggedType *GetArgv() const { if (IsFixedMode()) { - return &fixed_data_.front(); + return &fixedData_.front(); } - ASSERT_PRINT(variable_length_ > RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH, "internal call params mode error"); - return variable_data_.data(); + ASSERT_PRINT(variableLength_ > RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH, "internal call params mode error"); + return variableData_.data(); } inline uint32_t GetLength() const { if (IsFixedMode()) { - return fixed_length_; + return fixedLength_; } - ASSERT_PRINT(variable_length_ > RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH, "internal call params mode error"); - return variable_length_; + ASSERT_PRINT(variableLength_ > RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH, "internal call params mode error"); + return variableLength_; } template inline void MakeArgv(const JSHandle &arg) { EnableFixedModeAndSetLength(1); - fixed_data_[0] = arg.GetTaggedType(); + fixedData_[0] = arg.GetTaggedType(); } template inline void MakeArgv(const JSHandle &arg0, const JSHandle &arg1) { EnableFixedModeAndSetLength(2); - fixed_data_[0] = arg0.GetTaggedType(); - fixed_data_[1] = arg1.GetTaggedType(); + fixedData_[0] = arg0.GetTaggedType(); + fixedData_[1] = arg1.GetTaggedType(); } template inline void MakeArgv(const JSHandle &arg0, const JSHandle &arg1, const JSHandle &arg2) { EnableFixedModeAndSetLength(3); - fixed_data_[0] = arg0.GetTaggedType(); - fixed_data_[1] = arg1.GetTaggedType(); - fixed_data_[2] = arg2.GetTaggedType(); + fixedData_[0] = arg0.GetTaggedType(); + fixedData_[1] = arg1.GetTaggedType(); + fixedData_[2] = arg2.GetTaggedType(); } template @@ -79,10 +79,10 @@ public: const JSHandle &arg3) { EnableFixedModeAndSetLength(4); - fixed_data_[0] = arg0.GetTaggedType(); - fixed_data_[1] = arg1.GetTaggedType(); - fixed_data_[2] = arg2.GetTaggedType(); - fixed_data_[3] = arg3.GetTaggedType(); + fixedData_[0] = arg0.GetTaggedType(); + fixedData_[1] = arg1.GetTaggedType(); + fixedData_[2] = arg2.GetTaggedType(); + fixedData_[3] = arg3.GetTaggedType(); } inline void MakeEmptyArgv() @@ -93,32 +93,32 @@ public: inline void MakeArgv(const JSTaggedValue arg) { EnableFixedModeAndSetLength(1); - fixed_data_[0] = arg.GetRawData(); + fixedData_[0] = arg.GetRawData(); } inline void MakeArgv(const JSTaggedValue arg0, const JSTaggedValue arg1) { EnableFixedModeAndSetLength(2); - fixed_data_[0] = arg0.GetRawData(); - fixed_data_[1] = arg1.GetRawData(); + fixedData_[0] = arg0.GetRawData(); + fixedData_[1] = arg1.GetRawData(); } inline void MakeArgv(const JSTaggedValue arg0, const JSTaggedValue arg1, const JSTaggedValue arg2) { EnableFixedModeAndSetLength(3); - fixed_data_[0] = arg0.GetRawData(); - fixed_data_[1] = arg1.GetRawData(); - fixed_data_[2] = arg2.GetRawData(); + fixedData_[0] = arg0.GetRawData(); + fixedData_[1] = arg1.GetRawData(); + fixedData_[2] = arg2.GetRawData(); } inline void MakeArgv(const JSTaggedValue arg0, const JSTaggedValue arg1, const JSTaggedValue arg2, const JSTaggedValue arg3) { EnableFixedModeAndSetLength(4); - fixed_data_[0] = arg0.GetRawData(); - fixed_data_[1] = arg1.GetRawData(); - fixed_data_[2] = arg2.GetRawData(); - fixed_data_[3] = arg3.GetRawData(); + fixedData_[0] = arg0.GetRawData(); + fixedData_[1] = arg1.GetRawData(); + fixedData_[2] = arg2.GetRawData(); + fixedData_[3] = arg3.GetRawData(); } void MakeArgv(const EcmaRuntimeCallInfo *info, uint32_t position); @@ -126,7 +126,7 @@ public: void MakeArgList(const TaggedArray *argv); void MakeArgListWithHole(const TaggedArray *argv, uint32_t length); - void MakeBoundArgv(const JSThread *thread, const JSHandle &bound_func); + void MakeBoundArgv(const JSThread *thread, const JSHandle &boundFunc); void Iterate(const RootRangeVisitor &v) const; @@ -136,95 +136,95 @@ private: inline bool IsFixedMode() const { - return !variable_mode_; + return !variableMode_; } inline void EnableFixedModeAndSetLength(uint32_t length) { - variable_mode_ = false; - variable_data_.clear(); - variable_length_ = 0; - fixed_length_ = length; + variableMode_ = false; + variableData_.clear(); + variableLength_ = 0; + fixedLength_ = length; } inline uint32_t GetFixedLength() const { - return fixed_length_; + return fixedLength_; } inline uintptr_t GetFixedDataAddress() const { - return ToUintPtr(&fixed_data_); + return ToUintPtr(&fixedData_); } inline JSTaggedType GetFixedBuffer(uint32_t idx) const { - return fixed_data_[idx]; + return fixedData_[idx]; } inline void SetFixedBuffer(uint32_t idx, JSHandle val) { - fixed_data_[idx] = val.GetTaggedType(); + fixedData_[idx] = val.GetTaggedType(); } inline void SetFixedBuffer(uint32_t idx, JSTaggedValue val) { - fixed_data_[idx] = val.GetRawData(); + fixedData_[idx] = val.GetRawData(); } inline void SetFixedBuffer(uint32_t idx, JSTaggedType val) { - fixed_data_[idx] = val; + fixedData_[idx] = val; } inline void EnableVariableModeAndSetLength(uint32_t length) { - variable_mode_ = true; - fixed_length_ = 0; - variable_length_ = length; - variable_data_.resize(variable_length_); + variableMode_ = true; + fixedLength_ = 0; + variableLength_ = length; + variableData_.resize(variableLength_); } inline uint32_t GetVariableLength() const { - return variable_length_; + return variableLength_; } inline uintptr_t GetVariableDataAddress() const { - return ToUintPtr(variable_data_.data()); + return ToUintPtr(variableData_.data()); } inline JSTaggedType GetVariableBuffer(uint32_t idx) const { - return variable_data_[idx]; + return variableData_[idx]; } inline void SetVariableBuffer(uint32_t idx, JSHandle val) { - variable_data_[idx] = val.GetTaggedType(); + variableData_[idx] = val.GetTaggedType(); } inline void SetVariableBuffer(uint32_t idx, JSTaggedValue val) { - variable_data_[idx] = val.GetRawData(); + variableData_[idx] = val.GetRawData(); } inline void SetVariableBuffer(uint32_t idx, JSTaggedType val) { - variable_data_[idx] = val; + variableData_[idx] = val; } inline void InsertVariableBuffer(JSTaggedValue val) { - variable_data_.insert(variable_data_.begin(), val.GetRawData()); + variableData_.insert(variableData_.begin(), val.GetRawData()); } - std::array fixed_data_ {}; - PandaVector variable_data_ {}; - uint32_t fixed_length_ {0}; - uint32_t variable_length_ {0}; - bool variable_mode_ {false}; + std::array fixedData_ {}; + PandaVector variableData_ {}; + uint32_t fixedLength_ {0}; + uint32_t variableLength_ {0}; + bool variableMode_ {false}; }; } // namespace panda::ecmascript diff --git a/runtime/interpreter/ecma-interpreter-inl.h b/runtime/interpreter/ecma-interpreter-inl.h index 3bd6527fa645a9ddcadca84022e003d479074483..abe83e8b464d9d7175e3deb8b1e067b02a6b672d 100644 --- a/runtime/interpreter/ecma-interpreter-inl.h +++ b/runtime/interpreter/ecma-interpreter-inl.h @@ -132,31 +132,31 @@ template class JSFrameHelper { public: template - ALWAYS_INLINE static uint32_t GetNumberActualArgsDyn([[maybe_unused]] InstructionHandler *instr_handler) + ALWAYS_INLINE static uint32_t GetNumberActualArgsDyn([[maybe_unused]] InstructionHandler *instrHandler) { - return JSGetNumberActualArgsDyn(instr_handler->GetInst()); + return JSGetNumberActualArgsDyn(instrHandler->GetInst()); } template - ALWAYS_INLINE static void CopyArgumentsDyn(InstructionHandler *instr_handler, Frame *new_frame, uint32_t num_vregs, - uint32_t num_actual_args) + ALWAYS_INLINE static void CopyArgumentsDyn(InstructionHandler *instrHandler, Frame *newFrame, uint32_t numVregs, + uint32_t numActualArgs) { - Frame *prev_frame = instr_handler->GetFrame(); - BytecodeInstruction prev_inst = instr_handler->GetInst(); - auto *thread = JSThread::Cast(instr_handler->GetThread()); + Frame *prevFrame = instrHandler->GetFrame(); + BytecodeInstruction prevInst = instrHandler->GetInst(); + auto *thread = JSThread::Cast(instrHandler->GetThread()); - uint64_t prev_raw_func_obj = JSGetCalleDyn(prev_frame, prev_inst); + uint64_t prevRawFuncObj = JSGetCalleDyn(prevFrame, prevInst); - JSCopyArgumets(thread, prev_frame, prev_raw_func_obj, prev_inst, new_frame, - num_vregs, num_actual_args); + JSCopyArgumets(thread, prevFrame, prevRawFuncObj, prevInst, newFrame, numVregs, + numActualArgs); } template - ALWAYS_INLINE static Frame *CreateFrame(ManagedThread *thread, uint32_t nregs_size, Method *method, Frame *prev, - uint32_t nregs, uint32_t num_actual_args) + ALWAYS_INLINE static Frame *CreateFrame(ManagedThread *thread, uint32_t nregsSize, Method *method, Frame *prev, + uint32_t nregs, uint32_t numActualArgs) { - return ::panda::CreateFrame(thread->GetStackFrameAllocator(), nregs_size, method, prev, nregs, - num_actual_args); + return ::panda::CreateFrame(thread->GetStackFrameAllocator(), nregsSize, method, prev, nregs, + numActualArgs); } }; @@ -189,32 +189,32 @@ public: return VRegAsTaggedValue(this->GetAcc()); } - JSTaggedType *GetStkArgs(uint16_t first_arg_idx) + JSTaggedType *GetStkArgs(uint16_t firstArgIdx) { static_assert(sizeof(interpreter::VRegister) == sizeof(JSTaggedType)); auto thread = JSThread::Cast(this->GetThread()); - return reinterpret_cast(&thread->GetCurrentFrame()->GetVReg(first_arg_idx)); + return reinterpret_cast(&thread->GetCurrentFrame()->GetVReg(firstArgIdx)); } JSTaggedValue GetCurrentFunction() { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto num_vregs = this->GetFrame()->GetMethod()->GetNumVregs(); - return GetRegAsTaggedValue(num_vregs + js_method_args::FUNC_IDX); + auto numVregs = this->GetFrame()->GetMethod()->GetNumVregs(); + return GetRegAsTaggedValue(numVregs + js_method_args::FUNC_IDX); } JSTaggedValue GetCurrentNewTarget() { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto num_vregs = this->GetFrame()->GetMethod()->GetNumVregs(); - return GetRegAsTaggedValue(num_vregs + js_method_args::NEW_TARGET_IDX); + auto numVregs = this->GetFrame()->GetMethod()->GetNumVregs(); + return GetRegAsTaggedValue(numVregs + js_method_args::NEW_TARGET_IDX); } JSTaggedValue GetCurrentThis() { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto num_vregs = this->GetFrame()->GetMethod()->GetNumVregs(); - return GetRegAsTaggedValue(num_vregs + js_method_args::THIS_IDX); + auto numVregs = this->GetFrame()->GetMethod()->GetNumVregs(); + return GetRegAsTaggedValue(numVregs + js_method_args::THIS_IDX); } JSTaggedValue GetGlobalObject() @@ -250,11 +250,11 @@ public: this->GetAcc() = this->GetFrame()->GetAcc(); } - JSHandle GetMethodName(JSHandle call_target) + JSHandle GetMethodName(JSHandle callTarget) { auto thread = JSThread::Cast(this->GetThread()); - JSHandle this_func = JSHandle::Cast(call_target); - return JSFunctionBase::GetFunctionName(thread, JSHandle(this_func)); + JSHandle thisFunc = JSHandle::Cast(callTarget); + return JSFunctionBase::GetFunctionName(thread, JSHandle(thisFunc)); } ALWAYS_INLINE EcmascriptEnvironment *GetCurrentEnv() @@ -292,9 +292,9 @@ public: return JSTaggedValue(GetCurrentEnv()->GetLexicalEnv()).GetRawData(); } - ALWAYS_INLINE void SetLexicalEnv(JSTaggedValue lex_env) + ALWAYS_INLINE void SetLexicalEnv(JSTaggedValue lexEnv) { - return GetCurrentEnv()->SetLexicalEnv(lex_env.GetTaggedObject()); + return GetCurrentEnv()->SetLexicalEnv(lexEnv.GetTaggedObject()); } template @@ -305,14 +305,14 @@ public: auto frame = this->GetFrame(); if (UNLIKELY(frame->IsInitobj())) { - auto acc_in = GetAccAsTaggedValue(); + auto accIn = GetAccAsTaggedValue(); JSFunction *func = JSFunction::Cast(GetCurrentFunction().GetTaggedObject()); - if (LIKELY(acc_in.IsECMAObject())) { + if (LIKELY(accIn.IsECMAObject())) { // preserve current value - } else if (LIKELY(func->IsBase() || acc_in.IsUndefined())) { + } else if (LIKELY(func->IsBase() || accIn.IsUndefined())) { SetAccFromTaggedValue(GetCurrentThis()); } else { - [[maybe_unused]] EcmaHandleScope handle_scope(this->GetJSThread()); + [[maybe_unused]] EcmaHandleScope handleScope(this->GetJSThread()); ASSERT(func->IsDerivedConstructor()); JSHandle error = GetFactory()->GetJSError( ErrorType::TYPE_ERROR, "Derived constructor must return object or undefined"); @@ -332,12 +332,12 @@ public: auto frame = this->GetFrame(); if (UNLIKELY(frame->IsInitobj())) { - auto acc_in = GetAccAsTaggedValue(); + auto accIn = GetAccAsTaggedValue(); JSFunction *func = JSFunction::Cast(GetCurrentFunction().GetTaggedObject()); - if (LIKELY(func->IsBase() || acc_in.IsUndefined())) { + if (LIKELY(func->IsBase() || accIn.IsUndefined())) { SetAccFromTaggedValue(GetCurrentThis()); } else { - [[maybe_unused]] EcmaHandleScope handle_scope(this->GetJSThread()); + [[maybe_unused]] EcmaHandleScope handleScope(this->GetJSThread()); ASSERT(func->IsDerivedConstructor()); JSHandle error = GetFactory()->GetJSError( ErrorType::TYPE_ERROR, "Derived constructor must return object or undefined"); @@ -363,73 +363,73 @@ public: this->UpdateBytecodeOffset(); this->SaveAccToFrame(); - JSThread *js_thread = this->GetJSThread(); - [[maybe_unused]] HandleStorageCheck handle_storage_check(js_thread); - uint64_t function = JSGetCalleDyn(js_thread->GetCurrentFrame(), this->GetInst()); + JSThread *jsThread = this->GetJSThread(); + [[maybe_unused]] HandleStorageCheck handleStorageCheck(jsThread); + uint64_t function = JSGetCalleDyn(jsThread->GetCurrentFrame(), this->GetInst()); if (UNLIKELY(!JSTaggedValue(function).IsCallable())) { - [[maybe_unused]] EcmaHandleScope handle_scope(js_thread); + [[maybe_unused]] EcmaHandleScope handleScope(jsThread); JSHandle error = GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "is not callable"); - js_thread->SetException(error.GetTaggedValue()); + jsThread->SetException(error.GetTaggedValue()); this->MoveToExceptionHandler(); return; } - ECMAObject *this_func = ECMAObject::Cast(JSTaggedValue(function).GetHeapObject()); - Method *method = this_func->GetCallTarget(); + ECMAObject *thisFunc = ECMAObject::Cast(JSTaggedValue(function).GetHeapObject()); + Method *method = thisFunc->GetCallTarget(); if (method->IsNative()) { // Native ASSERT(method->GetNumVregs() == 0); - UPDATE_CALL_PROFILE(this_func); + UPDATE_CALL_PROFILE(thisFunc); - uint32_t num_actual_args = JSGetNumberActualArgsDyn(this->GetInst()); - uint32_t num_args = std::max(method->GetNumArgs(), num_actual_args); + uint32_t numActualArgs = JSGetNumberActualArgsDyn(this->GetInst()); + uint32_t numArgs = std::max(method->GetNumArgs(), numActualArgs); - Frame *prev_frame = this->GetFrame(); - BytecodeInstruction prev_inst = this->GetInst(); + Frame *prevFrame = this->GetFrame(); + BytecodeInstruction prevInst = this->GetInst(); Frame *frame = - JSFrame::CreateNativeFrame(js_thread, method, js_thread->GetCurrentFrame(), num_args, num_actual_args); + JSFrame::CreateNativeFrame(jsThread, method, jsThread->GetCurrentFrame(), numArgs, numActualArgs); - JSCopyArgumets(this->GetJSThread(), prev_frame, function, prev_inst, frame, 0, - num_actual_args); + JSCopyArgumets(this->GetJSThread(), prevFrame, function, prevInst, frame, 0, + numActualArgs); // Call native method - js_thread->SetCurrentFrame(frame); - JSTaggedValue ret_value = JSFrame::ExecuteNativeMethod(js_thread, frame, method, num_actual_args); - ASSERT(js_thread->GetCurrentFrame() == frame); - js_thread->SetCurrentFrameIsCompiled(false); - js_thread->SetCurrentFrame(prev_frame); - - JSFrame::DestroyNativeFrame(js_thread, frame); - if (UNLIKELY(js_thread->HasPendingException())) { + jsThread->SetCurrentFrame(frame); + JSTaggedValue retValue = JSFrame::ExecuteNativeMethod(jsThread, frame, method, numActualArgs); + ASSERT(jsThread->GetCurrentFrame() == frame); + jsThread->SetCurrentFrameIsCompiled(false); + jsThread->SetCurrentFrame(prevFrame); + + JSFrame::DestroyNativeFrame(jsThread, frame); + if (UNLIKELY(jsThread->HasPendingException())) { this->MoveToExceptionHandler(); return; } - ASSERT(JSTaggedValue(ret_value).IsException() == false); - SetAccFromTaggedValue(ret_value); + ASSERT(JSTaggedValue(retValue).IsException() == false); + SetAccFromTaggedValue(retValue); this->template MoveToNextInst(); return; } - JSFunction *js_function = JSFunction::Cast(this_func); - if (UNLIKELY(js_function->IsClassConstructor())) { - [[maybe_unused]] EcmaHandleScope handle_scope(js_thread); + JSFunction *jsFunction = JSFunction::Cast(thisFunc); + if (UNLIKELY(jsFunction->IsClassConstructor())) { + [[maybe_unused]] EcmaHandleScope handleScope(jsThread); JSHandle error = GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "class constructor cannot be called without 'new'"); - js_thread->SetException(error.GetTaggedValue()); + jsThread->SetException(error.GetTaggedValue()); this->MoveToExceptionHandler(); return; } - UPDATE_CALL_PROFILE(this_func); + UPDATE_CALL_PROFILE(thisFunc); if (method->HasCompiledCode()) { // AOT, JIT this->template CallCompiledCode(method); } else { // Interpreter - [[maybe_unused]] EcmaHandleScope scope(js_thread); - JSHandle function_handle(js_thread, js_function); + [[maybe_unused]] EcmaHandleScope scope(jsThread); + JSHandle functionHandle(jsThread, jsFunction); method->DecrementHotnessCounter(0, nullptr, false, JSTaggedValue(function)); - if (UNLIKELY(js_thread->HasPendingException())) { + if (UNLIKELY(jsThread->HasPendingException())) { return; } @@ -438,16 +438,16 @@ public: /* is_dynamic = */ true, /* is_range= */ false, /* accept_acc= */ false, /* initobj= */ false, /* call= */ true>(method); - if (UNLIKELY(js_thread->HasPendingException())) { + if (UNLIKELY(jsThread->HasPendingException())) { return; } - ConstantPool *constant_pool = ConstantPool::Cast(function_handle->GetConstantPool().GetHeapObject()); - JSTaggedValue lexical_env = function_handle->GetLexicalEnv(); + ConstantPool *constantPool = ConstantPool::Cast(functionHandle->GetConstantPool().GetHeapObject()); + JSTaggedValue lexicalEnv = functionHandle->GetLexicalEnv(); // Init EcmascriptEnvironment - EcmascriptEnvironment *new_env = JSFrame::GetJSEnv(this->GetFrame()); - new (new_env) EcmascriptEnvironment(constant_pool, lexical_env.GetHeapObject(), *function_handle); + EcmascriptEnvironment *newEnv = JSFrame::GetJSEnv(this->GetFrame()); + new (newEnv) EcmascriptEnvironment(constantPool, lexicalEnv.GetHeapObject(), *functionHandle); } } @@ -456,65 +456,65 @@ public: { auto constexpr OPCODE = BytecodeInstruction::Opcode::ECMA_NEWOBJDYNRANGE_PREF_IMM16_V8_PROF16; - auto first_arg_reg_idx = this->GetInst().template GetVReg(); - auto num_range_args = this->GetInst().template GetImm(); + auto firstArgRegIdx = this->GetInst().template GetVReg(); + auto numRangeArgs = this->GetInst().template GetImm(); - LOG_INST() << "newobjDynrange " << num_range_args << " v" << first_arg_reg_idx; + LOG_INST() << "newobjDynrange " << numRangeArgs << " v" << firstArgRegIdx; this->UpdateBytecodeOffset(); // acc: out, thus dead - auto range_args = GetStkArgs(first_arg_reg_idx); + auto rangeArgs = GetStkArgs(firstArgRegIdx); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto ctor_handle = JSHandle(ToUintPtr(&range_args[0])); + auto ctorHandle = JSHandle(ToUintPtr(&rangeArgs[0])); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto new_target_handle = JSHandle(ToUintPtr(&range_args[1])); + auto newTargetHandle = JSHandle(ToUintPtr(&rangeArgs[1])); - auto ctor = ctor_handle.GetTaggedValue(); - auto new_target = new_target_handle.GetTaggedValue(); + auto ctor = ctorHandle.GetTaggedValue(); + auto newTarget = newTargetHandle.GetTaggedValue(); auto thread = this->GetJSThread(); if (LIKELY(ctor.IsJSFunction() && ctor.IsConstructor())) { - auto ctor_func = JSFunction::Cast(ctor.GetTaggedObject()); - auto method = ctor_func->GetMethod(); - - UPDATE_CALL_PROFILE(ctor_func); - - if (LIKELY(!method->IsNative() && (ctor_func->IsBase() || ctor_func->IsDerivedConstructor()))) { - JSTaggedValue this_obj; - if (ctor_func->IsBase()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - this_obj = GetFactory() - ->NewJSObjectByConstructor(JSHandle(ctor_handle), new_target_handle) - .GetTaggedValue(); - INTERPRETER_RETURN_IF_ABRUPT(this_obj); + auto ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); + auto method = ctorFunc->GetMethod(); + + UPDATE_CALL_PROFILE(ctorFunc); + + if (LIKELY(!method->IsNative() && (ctorFunc->IsBase() || ctorFunc->IsDerivedConstructor()))) { + JSTaggedValue thisObj; + if (ctorFunc->IsBase()) { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + thisObj = GetFactory() + ->NewJSObjectByConstructor(JSHandle(ctorHandle), newTargetHandle) + .GetTaggedValue(); + INTERPRETER_RETURN_IF_ABRUPT(thisObj); // gc may fire - ctor = ctor_handle.GetTaggedValue(); - ctor_func = JSFunction::Cast(ctor.GetTaggedObject()); - new_target = new_target_handle.GetTaggedValue(); + ctor = ctorHandle.GetTaggedValue(); + ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); + newTarget = newTargetHandle.GetTaggedValue(); } else { - this_obj = JSTaggedValue::Undefined(); + thisObj = JSTaggedValue::Undefined(); } - SetAccFromTaggedValue(this_obj); + SetAccFromTaggedValue(thisObj); if (UNLIKELY(method->HasCompiledCode())) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle(thread, this_obj); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisHandle(thread, thisObj); // 'this' object to be set from acc in i2c this->template CallCompiledCode(method); - auto acc_in = GetAccAsTaggedValue(); + auto accIn = GetAccAsTaggedValue(); // gc may fire - ctor = ctor_handle.GetTaggedValue(); - ctor_func = JSFunction::Cast(ctor.GetTaggedObject()); - if (LIKELY(acc_in.IsECMAObject())) { + ctor = ctorHandle.GetTaggedValue(); + ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); + if (LIKELY(accIn.IsECMAObject())) { // preserve current value - } else if (LIKELY(ctor_func->IsBase() || acc_in.IsUndefined())) { - SetAccFromTaggedValue(this_handle.GetTaggedValue()); + } else if (LIKELY(ctorFunc->IsBase() || accIn.IsUndefined())) { + SetAccFromTaggedValue(thisHandle.GetTaggedValue()); } else { - ASSERT(ctor_func->IsDerivedConstructor()); + ASSERT(ctorFunc->IsDerivedConstructor()); JSHandle error = GetFactory()->GetJSError( ErrorType::TYPE_ERROR, "Derived constructor must return object or undefined"); this->GetJSThread()->SetException(error.GetTaggedValue()); @@ -537,46 +537,45 @@ public: } this->GetFrame() ->GetVReg(method->GetNumVregs() + js_method_args::THIS_IDX) - .SetValue(this_obj.GetRawData()); + .SetValue(thisObj.GetRawData()); // Init EcmascriptEnvironment - auto ctor_func_handle = JSHandle(ctor_handle); - ConstantPool *constant_pool = - ConstantPool::Cast(ctor_func_handle->GetConstantPool().GetHeapObject()); - JSTaggedValue lexical_env = ctor_func_handle->GetLexicalEnv(); - EcmascriptEnvironment *new_env = JSFrame::GetJSEnv(this->GetFrame()); - new (new_env) EcmascriptEnvironment(constant_pool, lexical_env.GetHeapObject(), *ctor_func_handle); + auto ctorFuncHandle = JSHandle(ctorHandle); + ConstantPool *constantPool = ConstantPool::Cast(ctorFuncHandle->GetConstantPool().GetHeapObject()); + JSTaggedValue lexicalEnv = ctorFuncHandle->GetLexicalEnv(); + EcmascriptEnvironment *newEnv = JSFrame::GetJSEnv(this->GetFrame()); + new (newEnv) EcmascriptEnvironment(constantPool, lexicalEnv.GetHeapObject(), *ctorFuncHandle); } return; } - if (LIKELY(ctor_func->IsBuiltinConstructor())) { + if (LIKELY(ctorFunc->IsBuiltinConstructor())) { ASSERT(method->IsNative() && method->GetNumVregs() == 0); - uint32_t num_actual_args = JSGetNumberActualArgsDyn(this->GetInst()); - uint32_t num_args = std::max(method->GetNumArgs(), num_actual_args); + uint32_t numActualArgs = JSGetNumberActualArgsDyn(this->GetInst()); + uint32_t numArgs = std::max(method->GetNumArgs(), numActualArgs); - Frame *prev_frame = this->GetFrame(); - BytecodeInstruction prev_inst = this->GetInst(); + Frame *prevFrame = this->GetFrame(); + BytecodeInstruction prevInst = this->GetInst(); Frame *frame = - JSFrame::CreateNativeFrame(thread, method, thread->GetCurrentFrame(), num_args, num_actual_args); + JSFrame::CreateNativeFrame(thread, method, thread->GetCurrentFrame(), numArgs, numActualArgs); - JSTaggedValue ret_value; + JSTaggedValue retValue; if (UNLIKELY(frame == nullptr)) { - ret_value = JSTaggedValue::Exception(); + retValue = JSTaggedValue::Exception(); } else { - JSCopyArgumets(this->GetJSThread(), prev_frame, ctor.GetRawData(), - prev_inst, frame, 0, num_actual_args); + JSCopyArgumets(this->GetJSThread(), prevFrame, ctor.GetRawData(), + prevInst, frame, 0, numActualArgs); frame->GetVReg(0 + js_method_args::THIS_IDX).SetValue(JSTaggedValue::VALUE_UNDEFINED); // Call native method thread->SetCurrentFrame(frame); - ret_value = JSFrame::ExecuteNativeMethod(thread, frame, method, num_actual_args); + retValue = JSFrame::ExecuteNativeMethod(thread, frame, method, numActualArgs); ASSERT(thread->GetCurrentFrame() == frame); thread->SetCurrentFrameIsCompiled(false); - thread->SetCurrentFrame(prev_frame); + thread->SetCurrentFrame(prevFrame); JSFrame::DestroyNativeFrame(thread, frame); } @@ -584,16 +583,16 @@ public: this->MoveToExceptionHandler(); return; } - ASSERT(JSTaggedValue(ret_value).IsException() == false); - SetAccFromTaggedValue(ret_value); + ASSERT(JSTaggedValue(retValue).IsException() == false); + SetAccFromTaggedValue(retValue); this->template MoveToNextInst(); return; } } // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic) - INTRINSIC_CALL_CHECK_SETACC(intrinsics::NewobjDynrange(thread, num_range_args - 2U, ctor.GetRawData(), - new_target.GetRawData(), range_args + 2U)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::NewobjDynrange(thread, numRangeArgs - 2U, ctor.GetRawData(), + newTarget.GetRawData(), rangeArgs + 2U)); // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic) this->template MoveToNextInst(); } @@ -691,11 +690,11 @@ public: ALWAYS_INLINE void HandleEcmaCallirangedyn() { auto v0 = this->GetInst().template GetVReg(); - auto num_args = this->GetInst().template GetImm(); + auto numArgs = this->GetInst().template GetImm(); auto func = GetRegAsTaggedValue(v0); - LOG_INST() << "calli.rangedyn " << num_args + 3 << ", v" << v0 << " , func:" << func.GetRawData(); + LOG_INST() << "calli.rangedyn " << numArgs + 3 << ", v" << v0 << " , func:" << func.GetRawData(); this->template DoEcmaCallDyn(); } @@ -704,9 +703,9 @@ public: ALWAYS_INLINE void HandleEcmaCallithisrangedyn() { auto v0 = this->GetInst().template GetVReg(); - auto num_args = this->GetInst().template GetImm(); + auto numArgs = this->GetInst().template GetImm(); - LOG_INST() << "calli.dyn.this.range " << num_args + 2 << ", v" << v0; + LOG_INST() << "calli.dyn.this.range " << numArgs + 2 << ", v" << v0; this->template DoEcmaCallDyn(); @@ -837,11 +836,11 @@ public: template ALWAYS_INLINE void HandleEcmaLdbigint() { - auto big_int = this->GetInst().template GetId(); - LOG_INST() << "ld.bigint " << big_int << "n"; + auto bigInt = this->GetInst().template GetId(); + LOG_INST() << "ld.bigint " << bigInt << "n"; auto thread = this->GetJSThread(); - INTRINSIC_CALL_SETACC(intrinsics::Ldbigint(thread, LoadFromConstantPool(big_int))); + INTRINSIC_CALL_SETACC(intrinsics::Ldbigint(thread, LoadFromConstantPool(bigInt))); this->template MoveToNextInst(); } @@ -858,12 +857,12 @@ public: { LOG_INST() << "getunmappedargs"; - uint32_t actual_num_args = + uint32_t actualNumArgs = this->GetFrame()->GetNumActualArgs() - js_method_args::NUM_MANDATORY_ARGS; // not compile-time - uint32_t start_idx = this->GetFrame()->GetMethod()->GetNumVregs() + js_method_args::NUM_MANDATORY_ARGS; + uint32_t startIdx = this->GetFrame()->GetMethod()->GetNumVregs() + js_method_args::NUM_MANDATORY_ARGS; auto thread = JSThread::Cast(this->GetThread()); - JSTaggedValue res = SlowRuntimeStub::GetUnmappedArgs(thread, actual_num_args, GetStkArgs(start_idx)); + JSTaggedValue res = SlowRuntimeStub::GetUnmappedArgs(thread, actualNumArgs, GetStkArgs(startIdx)); INTERPRETER_RETURN_IF_ABRUPT(res); SetAccFromTaggedValue(res); @@ -1149,8 +1148,8 @@ public: template ALWAYS_INLINE void HandleEcmaThrowconstassignment() { - auto string_id = this->GetInst().template GetId(); - auto prop = JSTaggedValue(LoadFromConstantPool(string_id)); + auto stringId = this->GetInst().template GetId(); + auto prop = JSTaggedValue(LoadFromConstantPool(stringId)); LOG_INST() << "throwconstassignment " << "string_id:" << ConvertToPandaString(EcmaString::Cast(prop.GetHeapObject())); @@ -1530,14 +1529,14 @@ public: template ALWAYS_INLINE void HandleEcmaDefinefuncdyn() { - auto method_id = this->GetInst().template GetId(); + auto methodId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); LOG_INST() << "definefuncDyn" - << " v" << v0 << std::hex << method_id; + << " v" << v0 << std::hex << methodId; uint64_t env = GetRegAsTaggedValue(v0).GetRawData(); auto cp = GetConstantPool(); - uint64_t method = cp->GetObjectFromCache(method_id.AsIndex()).GetRawData(); + uint64_t method = cp->GetObjectFromCache(methodId.AsIndex()).GetRawData(); INTRINSIC_CALL_CHECK_SETACC( intrinsics::DefinefuncDyn(this->GetJSThread(), method, env, JSTaggedValue(cp).GetRawData())); this->template MoveToNextInst(); @@ -1546,36 +1545,36 @@ public: template ALWAYS_INLINE void HandleEcmaDefinencfuncdyn() { - auto method_id = this->GetInst().template GetId(); + auto methodId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); LOG_INST() << "definencfuncDyn" - << " v" << v0 << ", method_id: " << std::hex << method_id; + << " v" << v0 << ", method_id: " << std::hex << methodId; uint64_t env = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t home_object = GetAccAsTaggedValue().GetRawData(); + uint64_t homeObject = GetAccAsTaggedValue().GetRawData(); auto cp = GetConstantPool(); - uint64_t method = cp->GetObjectFromCache(method_id.AsIndex()).GetRawData(); + uint64_t method = cp->GetObjectFromCache(methodId.AsIndex()).GetRawData(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::DefineNCFuncDyn(this->GetJSThread(), method, env, home_object, JSTaggedValue(cp).GetRawData())); + intrinsics::DefineNCFuncDyn(this->GetJSThread(), method, env, homeObject, JSTaggedValue(cp).GetRawData())); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaDefinemethod() { - auto method_id = this->GetInst().template GetId(); + auto methodId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); LOG_INST() << "definemethod" - << " v" << v0 << std::hex << method_id; + << " v" << v0 << std::hex << methodId; - uint64_t tagged_cur_env = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t home_object = GetAccAsTaggedValue().GetRawData(); + uint64_t taggedCurEnv = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t homeObject = GetAccAsTaggedValue().GetRawData(); SaveAccToFrame(); auto cp = GetConstantPool(); - uint64_t method = cp->GetObjectFromCache(method_id.AsIndex()).GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::DefineMethod(this->GetJSThread(), method, tagged_cur_env, home_object, + uint64_t method = cp->GetObjectFromCache(methodId.AsIndex()).GetRawData(); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::DefineMethod(this->GetJSThread(), method, taggedCurEnv, homeObject, JSTaggedValue(cp).GetRawData())); this->template MoveToNextInst(); } @@ -1675,24 +1674,24 @@ public: auto slot = this->GetInst().template GetImm(); LOG_INST() << "ldlexvardyn" << " level:" << level << " slot:" << slot; - auto lex_env = GetLexicalEnvRawValue(); - INTRINSIC_CALL_SETACC(intrinsics::LdLexVarDyn(this->GetJSThread(), level, slot, lex_env)); + auto lexEnv = GetLexicalEnvRawValue(); + INTRINSIC_CALL_SETACC(intrinsics::LdLexVarDyn(this->GetJSThread(), level, slot, lexEnv)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaLdlexdyn() { - auto string_id = this->GetInst().template GetId(); - auto prop = LoadFromConstantPool(string_id); + auto stringId = this->GetInst().template GetId(); + auto prop = LoadFromConstantPool(stringId); auto level = this->GetInst().template GetImm(); auto slot = this->GetInst().template GetImm(); LOG_INST() << "ldlexdyn" << " string_id:" << ConvertToPandaString(EcmaString::Cast(JSTaggedValue(prop).GetHeapObject())) << " level:" << level << " slot:" << slot; - auto lex_env = GetLexicalEnvRawValue(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdLexDyn(this->GetJSThread(), prop, level, slot, lex_env)); + auto lexEnv = GetLexicalEnvRawValue(); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdLexDyn(this->GetJSThread(), prop, level, slot, lexEnv)); this->template MoveToNextInst(); } @@ -1706,8 +1705,8 @@ public: << " level:" << level << " slot:" << slot; uint64_t value = GetAccAsTaggedValue().GetRawData(); - uint64_t lex_env = GetLexicalEnvRawValue(); - intrinsics::StLexVarDyn(this->GetJSThread(), level, slot, value, lex_env); + uint64_t lexEnv = GetLexicalEnvRawValue(); + intrinsics::StLexVarDyn(this->GetJSThread(), level, slot, value, lexEnv); this->template MoveToNextInst(); } @@ -1715,8 +1714,8 @@ public: template ALWAYS_INLINE void HandleEcmaStlexdyn() { - auto string_id = this->GetInst().template GetId(); - auto prop = LoadFromConstantPool(string_id); + auto stringId = this->GetInst().template GetId(); + auto prop = LoadFromConstantPool(stringId); auto level = this->GetInst().template GetImm(); auto slot = this->GetInst().template GetImm(); LOG_INST() << "stlexdyn" @@ -1724,8 +1723,8 @@ public: << " level:" << level << " slot:" << slot; uint64_t value = GetAccAsTaggedValue().GetRawData(); - uint64_t lex_env = GetLexicalEnvRawValue(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::StLexDyn(this->GetJSThread(), prop, level, slot, value, lex_env)); + uint64_t lexEnv = GetLexicalEnvRawValue(); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::StLexDyn(this->GetJSThread(), prop, level, slot, value, lexEnv)); this->template MoveToNextInst(); } @@ -1733,13 +1732,13 @@ public: template ALWAYS_INLINE void HandleEcmaNewlexenvdyn() { - auto num_vars = this->GetInst().template GetImm(); + auto numVars = this->GetInst().template GetImm(); LOG_INST() << "newlexenvdyn" - << " imm " << num_vars; + << " imm " << numVars; - auto lex_env = GetLexicalEnvRawValue(); - INTRINSIC_CALL_CHECK_SETACC_SETENV(intrinsics::NewlexenvDyn(this->GetJSThread(), num_vars, lex_env)); + auto lexEnv = GetLexicalEnvRawValue(); + INTRINSIC_CALL_CHECK_SETACC_SETENV(intrinsics::NewlexenvDyn(this->GetJSThread(), numVars, lexEnv)); this->template MoveToNextInst(); } @@ -1748,8 +1747,8 @@ public: { LOG_INST() << "copylexenvdyn"; - auto lex_env = GetLexicalEnvRawValue(); - INTRINSIC_CALL_CHECK_SETACC_SETENV(intrinsics::CopylexenvDyn(lex_env)); + auto lexEnv = GetLexicalEnvRawValue(); + INTRINSIC_CALL_CHECK_SETACC_SETENV(intrinsics::CopylexenvDyn(lexEnv)); this->template MoveToNextInst(); } @@ -1773,14 +1772,14 @@ public: LOG_INST() << "suspendgenerator" << " v" << v0; - auto gen_obj = GetRegAsTaggedValue(v0); + auto genObj = GetRegAsTaggedValue(v0); auto value = GetAccAsTaggedValue(); // SuspendGenerator preserves BCOffset and acc this->GetFrame()->SetBytecodeOffset(this->GetBytecodeOffset()); SaveAccToFrame(); auto thread = JSThread::Cast(this->GetThread()); - auto res = SlowRuntimeStub::SuspendGenerator(thread, gen_obj, value); + auto res = SlowRuntimeStub::SuspendGenerator(thread, genObj, value); LOG(DEBUG, INTERPRETER) << "Exit: SuspendGenerator: res - " << res.GetRawData(); @@ -1797,14 +1796,14 @@ public: LOG_INST() << "suspendasyncgenerator" << " v" << v0; - auto gen_obj = GetRegAsTaggedValue(v0); + auto genObj = GetRegAsTaggedValue(v0); auto value = GetAccAsTaggedValue(); // SuspendAsyncGenerator preserves BCOffset and acc this->GetFrame()->SetBytecodeOffset(this->GetBytecodeOffset()); SaveAccToFrame(); auto thread = JSThread::Cast(this->GetThread()); - auto res = SlowRuntimeStub::SuspendAsyncGenerator(thread, gen_obj, value); + auto res = SlowRuntimeStub::SuspendAsyncGenerator(thread, genObj, value); LOG(DEBUG, INTERPRETER) << "Exit: SuspendAsyncGenerator: res - " << res.GetRawData(); @@ -1823,10 +1822,10 @@ public: LOG_INST() << "asyncfunctionawait" << " v" << v0; - uint64_t async_func_obj = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t asyncFuncObj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncFunctionAwait(this->GetJSThread(), async_func_obj, value)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncFunctionAwait(this->GetJSThread(), asyncFuncObj, value)); this->template MoveToNextInst(); } @@ -1837,10 +1836,10 @@ public: LOG_INST() << "asyncfunctionresolve" << " v" << v0; - uint64_t async_func_obj = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t asyncFuncObj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncFunctionResolve(this->GetJSThread(), async_func_obj, value)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncFunctionResolve(this->GetJSThread(), asyncFuncObj, value)); this->template MoveToNextInst(); } @@ -1851,10 +1850,10 @@ public: LOG_INST() << "asyncfunctionreject" << " v" << v0; - uint64_t async_func_obj = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t asyncFuncObj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncFunctionReject(this->GetJSThread(), async_func_obj, value)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncFunctionReject(this->GetJSThread(), asyncFuncObj, value)); this->template MoveToNextInst(); } @@ -1865,10 +1864,10 @@ public: LOG_INST() << "asyncgeneratorresolve" << " v" << v0; - uint64_t async_func_obj = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t asyncFuncObj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncGeneratorResolve(this->GetJSThread(), async_func_obj, value)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncGeneratorResolve(this->GetJSThread(), asyncFuncObj, value)); this->template MoveToNextInst(); } @@ -1879,10 +1878,10 @@ public: LOG_INST() << "asyncgeneratorreject" << " v" << v0; - uint64_t async_func_obj = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t asyncFuncObj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncGeneratorReject(this->GetJSThread(), async_func_obj, value)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::AsyncGeneratorReject(this->GetJSThread(), asyncFuncObj, value)); this->template MoveToNextInst(); } @@ -1895,18 +1894,18 @@ public: << " v" << v0 << " v" << v1; uint64_t func = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t new_target = GetRegAsTaggedValue(v1).GetRawData(); + uint64_t newTarget = GetRegAsTaggedValue(v1).GetRawData(); uint64_t array = GetAccAsTaggedValue().GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::NewobjspreadDyn(this->GetJSThread(), func, new_target, array)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::NewobjspreadDyn(this->GetJSThread(), func, newTarget, array)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaThrowtdz() { - auto string_id = this->GetInst().template GetId(); - auto prop = JSTaggedValue(LoadFromConstantPool(string_id)); + auto stringId = this->GetInst().template GetId(); + auto prop = JSTaggedValue(LoadFromConstantPool(stringId)); LOG_INST() << "intrinsic::throwundefinedifhole " << "string_id:" << ConvertToPandaString(EcmaString::Cast(prop.GetHeapObject())); @@ -1954,62 +1953,62 @@ public: template ALWAYS_INLINE void HandleEcmaCreateobjectwithbuffer() { - auto literalarray_id = this->GetInst().template GetId(); + auto literalarrayId = this->GetInst().template GetId(); LOG_INST() << "createobjectwithbuffer" - << " literalArrayId:" << literalarray_id.AsIndex(); + << " literalArrayId:" << literalarrayId.AsIndex(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::CreateObjectWithBuffer(this->GetJSThread(), LoadFromConstantPool(literalarray_id))); + intrinsics::CreateObjectWithBuffer(this->GetJSThread(), LoadFromConstantPool(literalarrayId))); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaCreatearraywithbuffer() { - auto literalarray_id = this->GetInst().template GetId(); + auto literalarrayId = this->GetInst().template GetId(); LOG_INST() << "createarraywithbuffer" - << " literalArrayId:" << literalarray_id.AsIndex(); + << " literalArrayId:" << literalarrayId.AsIndex(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::CreateArrayWithBuffer(this->GetJSThread(), LoadFromConstantPool(literalarray_id))); + intrinsics::CreateArrayWithBuffer(this->GetJSThread(), LoadFromConstantPool(literalarrayId))); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaCreateregexpwithliteral() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); auto flags = this->GetInst().template GetImm(); LOG_INST() << "createregexpwithliteral" - << " string_id: " << string_id << " flags:" << flags; + << " string_id: " << stringId << " flags:" << flags; INTRINSIC_CALL_CHECK_SETACC( - intrinsics::CreateRegExpWithLiteral(this->GetJSThread(), LoadFromConstantPool(string_id), flags)); + intrinsics::CreateRegExpWithLiteral(this->GetJSThread(), LoadFromConstantPool(stringId), flags)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaImportmodule() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "importmodule " - << "string_id:" << std::hex << string_id.AsIndex(); + << "string_id:" << std::hex << stringId.AsIndex(); - INTRINSIC_CALL_SETACC(intrinsics::ImportModule(this->GetJSThread(), LoadFromConstantPool(string_id))); + INTRINSIC_CALL_SETACC(intrinsics::ImportModule(this->GetJSThread(), LoadFromConstantPool(stringId))); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaStmodulevar() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "stmodulevar " - << "string_id:" << string_id; + << "string_id:" << stringId; uint64_t value = GetAccAsTaggedValue().GetRawData(); SaveAccToFrame(); - intrinsics::StModuleVar(this->GetJSThread(), LoadFromConstantPool(string_id), value); + intrinsics::StModuleVar(this->GetJSThread(), LoadFromConstantPool(stringId), value); RestoreAccFromFrame(); this->template MoveToNextInst(); } @@ -2021,9 +2020,9 @@ public: LOG_INST() << "copymodule " << " v" << v0; - uint64_t src_module = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t srcModule = GetRegAsTaggedValue(v0).GetRawData(); SaveAccToFrame(); - intrinsics::CopyModule(this->GetJSThread(), src_module); + intrinsics::CopyModule(this->GetJSThread(), srcModule); RestoreAccFromFrame(); this->template MoveToNextInst(); } @@ -2032,15 +2031,15 @@ public: ALWAYS_INLINE void HandleEcmaLdmodvarbyname() { auto v0 = this->GetInst().template GetVReg(); - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "ldmodvarbyname " - << "string_id:" << string_id.AsIndex(); + << "string_id:" << stringId.AsIndex(); - uint64_t module_obj = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t moduleObj = GetRegAsTaggedValue(v0).GetRawData(); INTRINSIC_CALL_SETACC( - intrinsics::LdModvarByName(this->GetJSThread(), LoadFromConstantPool(string_id), module_obj)); + intrinsics::LdModvarByName(this->GetJSThread(), LoadFromConstantPool(stringId), moduleObj)); this->template MoveToNextInst(); } @@ -2048,12 +2047,12 @@ public: ALWAYS_INLINE void HandleEcmaGetmethod() { auto v0 = this->GetInst().template GetVReg(); - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); - LOG_INST() << "getmethod v" << v0 << " string_id:" << string_id; + LOG_INST() << "getmethod v" << v0 << " string_id:" << stringId; uint64_t obj = GetRegAsTaggedValue(v0).GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::GetMethod(this->GetJSThread(), LoadFromConstantPool(string_id), obj)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::GetMethod(this->GetJSThread(), LoadFromConstantPool(stringId), obj)); this->template MoveToNextInst(); } @@ -2124,11 +2123,11 @@ public: << " v" << v0 << " v" << v1; uint64_t receiver = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t prop_key = GetRegAsTaggedValue(v1).GetRawData(); + uint64_t propKey = GetRegAsTaggedValue(v1).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); SaveAccToFrame(); - INTRINSIC_CALL_CHECK(intrinsics::StOwnByValue(this->GetJSThread(), receiver, prop_key, value)); + INTRINSIC_CALL_CHECK(intrinsics::StOwnByValue(this->GetJSThread(), receiver, propKey, value)); RestoreAccFromFrame(); this->template MoveToNextInst(); } @@ -2136,15 +2135,15 @@ public: template ALWAYS_INLINE void HandleEcmaCreateobjectwithexcludedkeys() { - auto num_keys = this->GetInst().template GetImm(); + auto numKeys = this->GetInst().template GetImm(); auto v0 = this->GetInst().template GetVReg(); - uint16_t first_arg_reg_idx = this->GetInst().template GetVReg(); - LOG_INST() << "createobjectwithexcludedkeys " << num_keys << " v" << v0 << std::hex << first_arg_reg_idx; + uint16_t firstArgRegIdx = this->GetInst().template GetVReg(); + LOG_INST() << "createobjectwithexcludedkeys " << numKeys << " v" << v0 << std::hex << firstArgRegIdx; auto obj = GetRegAsTaggedValue(v0); auto thread = JSThread::Cast(this->GetThread()); - auto res = SlowRuntimeStub::CreateObjectWithExcludedKeys(thread, num_keys, obj, GetStkArgs(first_arg_reg_idx)); + auto res = SlowRuntimeStub::CreateObjectWithExcludedKeys(thread, numKeys, obj, GetStkArgs(firstArgRegIdx)); INTERPRETER_RETURN_IF_ABRUPT(res); SetAccFromTaggedValue(res); @@ -2155,13 +2154,13 @@ public: ALWAYS_INLINE void HandleEcmaDefinegeneratorfunc() { auto v0 = this->GetInst().template GetVReg(); - auto method_id = this->GetInst().template GetId(); + auto methodId = this->GetInst().template GetId(); LOG_INST() << "define generator function" << " v" << v0; uint64_t env = GetRegAsTaggedValue(v0).GetRawData(); auto cp = GetConstantPool(); - uint64_t method = cp->GetObjectFromCache(method_id.AsIndex()).GetRawData(); + uint64_t method = cp->GetObjectFromCache(methodId.AsIndex()).GetRawData(); INTRINSIC_CALL_CHECK_SETACC( intrinsics::DefineGeneratorFunc(this->GetJSThread(), method, env, JSTaggedValue(cp).GetRawData())); this->template MoveToNextInst(); @@ -2171,13 +2170,13 @@ public: ALWAYS_INLINE void HandleEcmaDefineasyncfunc() { auto v0 = this->GetInst().template GetVReg(); - auto method_id = this->GetInst().template GetId(); + auto methodId = this->GetInst().template GetId(); LOG_INST() << "define async function" << " v" << v0; uint64_t env = GetRegAsTaggedValue(v0).GetRawData(); auto cp = GetConstantPool(); - uint64_t method = cp->GetObjectFromCache(method_id.AsIndex()).GetRawData(); + uint64_t method = cp->GetObjectFromCache(methodId.AsIndex()).GetRawData(); INTRINSIC_CALL_CHECK_SETACC( intrinsics::DefineAsyncFunc(this->GetJSThread(), method, env, JSTaggedValue(cp).GetRawData())); this->template MoveToNextInst(); @@ -2187,13 +2186,13 @@ public: ALWAYS_INLINE void HandleEcmaDefineasyncgeneratorfunc() { auto v0 = this->GetInst().template GetVReg(); - auto method_id = this->GetInst().template GetId(); + auto methodId = this->GetInst().template GetId(); LOG_INST() << "define async generator function" << " v" << v0; uint64_t env = GetRegAsTaggedValue(v0).GetRawData(); auto cp = GetConstantPool(); - uint64_t method = cp->GetObjectFromCache(method_id.AsIndex()).GetRawData(); + uint64_t method = cp->GetObjectFromCache(methodId.AsIndex()).GetRawData(); INTRINSIC_CALL_CHECK_SETACC( intrinsics::DefineAsyncGeneratorFunc(this->GetJSThread(), method, env, JSTaggedValue(cp).GetRawData())); this->template MoveToNextInst(); @@ -2211,20 +2210,20 @@ public: template ALWAYS_INLINE void HandleEcmaCopyrestargs() { - auto rest_idx = this->GetInst().template GetImm(); + auto restIdx = this->GetInst().template GetImm(); LOG_INST() << "copyrestargs" - << " index: " << rest_idx; + << " index: " << restIdx; auto *state = this->GetFrame(); - uint32_t num_vregs = state->GetMethod()->GetNumVregs(); + uint32_t numVregs = state->GetMethod()->GetNumVregs(); // Exclude func, new_target and "this" - int32_t actual_num_args = state->GetNumActualArgs() - js_method_args::NUM_MANDATORY_ARGS; - int32_t tmp = actual_num_args - rest_idx; - uint32_t rest_num_args = (tmp > 0) ? tmp : 0; - uint32_t start_idx = num_vregs + js_method_args::NUM_MANDATORY_ARGS + rest_idx; + int32_t actualNumArgs = state->GetNumActualArgs() - js_method_args::NUM_MANDATORY_ARGS; + int32_t tmp = actualNumArgs - restIdx; + uint32_t restNumArgs = (tmp > 0) ? tmp : 0; + uint32_t startIdx = numVregs + js_method_args::NUM_MANDATORY_ARGS + restIdx; auto thread = JSThread::Cast(this->GetThread()); - JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, rest_num_args, GetStkArgs(start_idx)); + JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, restNumArgs, GetStkArgs(startIdx)); INTERPRETER_RETURN_IF_ABRUPT(res); SetAccFromTaggedValue(res); this->template MoveToNextInst(); @@ -2259,9 +2258,9 @@ public: << " imm" << idx; uint64_t obj = GetAccAsTaggedValue().GetRawData(); - void *prof_address; - GET_PROFILE_ADDRESS(prof_address); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdObjByIndex(this->GetJSThread(), idx, obj, prof_address)); + void *profAddress; + GET_PROFILE_ADDRESS(profAddress); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdObjByIndex(this->GetJSThread(), idx, obj, profAddress)); this->template MoveToNextInst(); } @@ -2275,10 +2274,10 @@ public: uint64_t obj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); - void *prof_address; - GET_PROFILE_ADDRESS(prof_address); + void *profAddress; + GET_PROFILE_ADDRESS(profAddress); SaveAccToFrame(); - INTRINSIC_CALL_CHECK(intrinsics::StObjByIndex(this->GetJSThread(), idx, obj, value, prof_address)); + INTRINSIC_CALL_CHECK(intrinsics::StObjByIndex(this->GetJSThread(), idx, obj, value, profAddress)); RestoreAccFromFrame(); this->template MoveToNextInst(); } @@ -2291,10 +2290,10 @@ public: << " v" << v0; uint64_t receiver = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t prop_key = GetAccAsTaggedValue().GetRawData(); + uint64_t propKey = GetAccAsTaggedValue().GetRawData(); uint64_t func = GetThisFuncRawValue(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::LdObjByValue(this->GetJSThread(), receiver, prop_key, this->GetBytecodeOffset(), func)); + intrinsics::LdObjByValue(this->GetJSThread(), receiver, propKey, this->GetBytecodeOffset(), func)); this->template MoveToNextInst(); } @@ -2307,13 +2306,13 @@ public: << " v" << v0 << " v" << v1; uint64_t receiver = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t prop_key = GetRegAsTaggedValue(v1).GetRawData(); + uint64_t propKey = GetRegAsTaggedValue(v1).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); SaveAccToFrame(); auto func = GetThisFuncRawValue(); INTRINSIC_CALL_CHECK( - intrinsics::StObjByValue(this->GetJSThread(), receiver, prop_key, value, this->GetBytecodeOffset(), func)); + intrinsics::StObjByValue(this->GetJSThread(), receiver, propKey, value, this->GetBytecodeOffset(), func)); RestoreAccFromFrame(); this->template MoveToNextInst(); } @@ -2326,9 +2325,9 @@ public: << " v" << v0; uint64_t receiver = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t prop_key = GetAccAsTaggedValue().GetRawData(); + uint64_t propKey = GetAccAsTaggedValue().GetRawData(); uint64_t func = GetThisFuncRawValue(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdSuperByValue(this->GetJSThread(), receiver, prop_key, func)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdSuperByValue(this->GetJSThread(), receiver, propKey, func)); this->template MoveToNextInst(); } @@ -2341,12 +2340,12 @@ public: << " v" << v0 << " v" << v1; uint64_t receiver = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t prop_key = GetRegAsTaggedValue(v1).GetRawData(); + uint64_t propKey = GetRegAsTaggedValue(v1).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); uint64_t func = GetThisFuncRawValue(); SaveAccToFrame(); - INTRINSIC_CALL_CHECK(intrinsics::StSuperByValue(this->GetJSThread(), receiver, prop_key, value, func)); + INTRINSIC_CALL_CHECK(intrinsics::StSuperByValue(this->GetJSThread(), receiver, propKey, value, func)); RestoreAccFromFrame(); this->template MoveToNextInst(); } @@ -2354,9 +2353,9 @@ public: template ALWAYS_INLINE void HandleEcmaTryldglobalbyname() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); auto func = GetThisFuncRawValue(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::TryLdGlobalByName(this->GetJSThread(), LoadFromConstantPool(string_id), + INTRINSIC_CALL_CHECK_SETACC(intrinsics::TryLdGlobalByName(this->GetJSThread(), LoadFromConstantPool(stringId), this->GetBytecodeOffset(), func)); this->template MoveToNextInst(); } @@ -2364,15 +2363,15 @@ public: template ALWAYS_INLINE void HandleEcmaTrystglobalbyname() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "trystglobalbyname" - << " string_id:" << string_id; + << " string_id:" << stringId; uint64_t value = GetAccAsTaggedValue().GetRawData(); SaveAccToFrame(); auto func = GetThisFuncRawValue(); - INTRINSIC_CALL_CHECK(intrinsics::TryStGlobalByName(this->GetJSThread(), LoadFromConstantPool(string_id), value, + INTRINSIC_CALL_CHECK(intrinsics::TryStGlobalByName(this->GetJSThread(), LoadFromConstantPool(stringId), value, this->GetBytecodeOffset(), func)); RestoreAccFromFrame(); this->template MoveToNextInst(); @@ -2381,13 +2380,13 @@ public: template ALWAYS_INLINE void HandleEcmaLdglobalvar() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "ldglobalvar " - << " string_id:" << string_id; + << " string_id:" << stringId; auto func = GetThisFuncRawValue(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdGlobalVar(this->GetJSThread(), LoadFromConstantPool(string_id), + INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdGlobalVar(this->GetJSThread(), LoadFromConstantPool(stringId), this->GetBytecodeOffset(), func)); this->template MoveToNextInst(); } @@ -2395,14 +2394,14 @@ public: template ALWAYS_INLINE void HandleEcmaLdobjbyname() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "ldobjbyname" - << " string_id:" << string_id; + << " string_id:" << stringId; uint64_t obj = GetAccAsTaggedValue().GetRawData(); auto func = GetThisFuncRawValue(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdObjByName(this->GetJSThread(), LoadFromConstantPool(string_id), obj, + INTRINSIC_CALL_CHECK_SETACC(intrinsics::LdObjByName(this->GetJSThread(), LoadFromConstantPool(stringId), obj, this->GetBytecodeOffset(), func)); this->template MoveToNextInst(); } @@ -2411,17 +2410,17 @@ public: ALWAYS_INLINE void HandleEcmaStobjbyname() { auto v0 = this->GetInst().template GetVReg(); - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "stobjbyname " - << "v" << v0 << " string_id:" << string_id.AsIndex(); + << "v" << v0 << " string_id:" << stringId.AsIndex(); uint64_t obj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); SaveAccToFrame(); auto func = GetThisFuncRawValue(); - INTRINSIC_CALL_CHECK(intrinsics::StObjByName(this->GetJSThread(), LoadFromConstantPool(string_id), obj, value, + INTRINSIC_CALL_CHECK(intrinsics::StObjByName(this->GetJSThread(), LoadFromConstantPool(stringId), obj, value, this->GetBytecodeOffset(), func)); RestoreAccFromFrame(); this->template MoveToNextInst(); @@ -2430,26 +2429,26 @@ public: template ALWAYS_INLINE void HandleEcmaLdsuperbyname() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "ldsuperbyname" - << " string_id:" << string_id.AsIndex(); + << " string_id:" << stringId.AsIndex(); uint64_t obj = GetAccAsTaggedValue().GetRawData(); auto func = GetThisFuncRawValue(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::LdSuperByName(this->GetJSThread(), LoadFromConstantPool(string_id), obj, func)); + intrinsics::LdSuperByName(this->GetJSThread(), LoadFromConstantPool(stringId), obj, func)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaStsuperbyname() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); LOG_INST() << "stsuperbyname" - << "v" << v0 << " string_id:" << string_id.AsIndex(); + << "v" << v0 << " string_id:" << stringId.AsIndex(); uint64_t obj = GetRegAsTaggedValue(v0).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); @@ -2457,7 +2456,7 @@ public: SaveAccToFrame(); auto func = GetThisFuncRawValue(); INTRINSIC_CALL_CHECK( - intrinsics::StSuperByName(this->GetJSThread(), LoadFromConstantPool(string_id), obj, value, func)); + intrinsics::StSuperByName(this->GetJSThread(), LoadFromConstantPool(stringId), obj, value, func)); RestoreAccFromFrame(); this->template MoveToNextInst(); } @@ -2465,16 +2464,16 @@ public: template ALWAYS_INLINE void HandleEcmaStglobalvar() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); LOG_INST() << "stglobalvar " - << "string_id:" << string_id.AsIndex() << ", "; + << "string_id:" << stringId.AsIndex() << ", "; uint64_t value = GetAccAsTaggedValue().GetRawData(); SaveAccToFrame(); auto func = GetThisFuncRawValue(); - INTRINSIC_CALL_CHECK(intrinsics::StGlobalVar(this->GetJSThread(), LoadFromConstantPool(string_id), value, + INTRINSIC_CALL_CHECK(intrinsics::StGlobalVar(this->GetJSThread(), LoadFromConstantPool(stringId), value, this->GetBytecodeOffset(), func)); RestoreAccFromFrame(); this->template MoveToNextInst(); @@ -2487,9 +2486,9 @@ public: LOG_INST() << "creategeneratorobj" << " v" << v0; - uint64_t gen_func = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t genFunc = GetRegAsTaggedValue(v0).GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::CreateGeneratorObj(this->GetJSThread(), gen_func)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::CreateGeneratorObj(this->GetJSThread(), genFunc)); this->template MoveToNextInst(); } @@ -2501,9 +2500,9 @@ public: LOG_INST() << "setgeneratorstate" << " v" << v0 << " state" << state; - uint64_t gen_func = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t genFunc = GetRegAsTaggedValue(v0).GetRawData(); - intrinsics::SetGeneratorState(this->GetJSThread(), gen_func, state); + intrinsics::SetGeneratorState(this->GetJSThread(), genFunc, state); this->template MoveToNextInst(); } @@ -2514,9 +2513,9 @@ public: LOG_INST() << "createasyncgeneratorobj" << " v" << v0; - uint64_t gen_func = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t genFunc = GetRegAsTaggedValue(v0).GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::CreateAsyncGeneratorObj(this->GetJSThread(), gen_func)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::CreateAsyncGeneratorObj(this->GetJSThread(), genFunc)); this->template MoveToNextInst(); } @@ -2557,27 +2556,27 @@ public: LOG_INST() << "setclasscomputedfields" << " class_reg v:" << v0 << " computed_fields v:" << v1; - uint64_t class_reg = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t computed_fields = GetRegAsTaggedValue(v1).GetRawData(); + uint64_t classReg = GetRegAsTaggedValue(v0).GetRawData(); + uint64_t computedFields = GetRegAsTaggedValue(v1).GetRawData(); - intrinsics::SetClassComputedFields(this->GetJSThread(), class_reg, computed_fields); + intrinsics::SetClassComputedFields(this->GetJSThread(), classReg, computedFields); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaDefineclasswithbuffer() { - auto method_id = this->GetInst().template GetId().AsIndex(); + auto methodId = this->GetInst().template GetId().AsIndex(); auto imm = this->GetInst().template GetImm(); auto v0 = this->GetInst().template GetVReg(); auto v1 = this->GetInst().template GetVReg(); LOG_INST() << "defineclasswithbuffer" - << " method id:" << method_id << " literal id:" << imm << " lexenv: v" << v0 << " parent: v" << v1; + << " method id:" << methodId << " literal id:" << imm << " lexenv: v" << v0 << " parent: v" << v1; uint64_t lexenv = GetRegAsTaggedValue(v0).GetRawData(); uint64_t proto = GetRegAsTaggedValue(v1).GetRawData(); auto cp = GetConstantPool(); - uint64_t method = cp->GetObjectFromCache(method_id).GetRawData(); + uint64_t method = cp->GetObjectFromCache(methodId).GetRawData(); // uint64_t buffer = cp->GetObjectFromCache(imm).GetRawData(); INTRINSIC_CALL_CHECK_SETACC(intrinsics::DefineClassWithBuffer(this->GetJSThread(), method, imm, lexenv, proto, JSTaggedValue(cp).GetRawData())); @@ -2603,19 +2602,19 @@ public: template ALWAYS_INLINE void HandleEcmaDefineclassprivatefields() { - auto literalarray_id = this->GetInst().template GetId(); + auto literalarrayId = this->GetInst().template GetId(); LOG_INST() << "ldevalbindings" - << " literalArrayId:" << literalarray_id.AsIndex(); + << " literalArrayId:" << literalarrayId.AsIndex(); auto v0 = this->GetInst().template GetVReg(); LOG_INST() << "defineclassprivatefields" - << " literalArrayId:" << literalarray_id.AsIndex() << " v0:" << v0; + << " literalArrayId:" << literalarrayId.AsIndex() << " v0:" << v0; uint64_t env = GetRegAsTaggedValue(v0).GetRawData(); uint64_t ctor = GetAccAsTaggedValue().GetRawData(); auto cp = GetConstantPool(); - uint64_t private_buf = cp->GetObjectFromCache(literalarray_id.AsIndex()).GetRawData(); - intrinsics::DefineClassPrivateFields(this->GetJSThread(), private_buf, env, ctor, + uint64_t privateBuf = cp->GetObjectFromCache(literalarrayId.AsIndex()).GetRawData(); + intrinsics::DefineClassPrivateFields(this->GetJSThread(), privateBuf, env, ctor, JSTaggedValue(cp).GetRawData()); this->template MoveToNextInst(); } @@ -2638,65 +2637,65 @@ public: template ALWAYS_INLINE void HandleEcmaClassprivatefieldadd() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); auto v1 = this->GetInst().template GetVReg(); LOG_INST() << "classprivatefieldadd" - << " string id:" << string_id << " ctor: v" << v0 << " obj: v" << v1; + << " string id:" << stringId << " ctor: v" << v0 << " obj: v" << v1; uint64_t ctor = GetRegAsTaggedValue(v0).GetRawData(); uint64_t obj = GetRegAsTaggedValue(v1).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::ClassPrivateFieldAdd(this->GetJSThread(), LoadFromConstantPool(string_id), ctor, obj, value)); + intrinsics::ClassPrivateFieldAdd(this->GetJSThread(), LoadFromConstantPool(stringId), ctor, obj, value)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaClassprivatefieldget() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); auto v1 = this->GetInst().template GetVReg(); LOG_INST() << "classprivatefieldadd" - << " string id:" << string_id << " private contexts: v" << v0 << " obj: v" << v1; + << " string id:" << stringId << " private contexts: v" << v0 << " obj: v" << v1; uint64_t ctor = GetRegAsTaggedValue(v0).GetRawData(); uint64_t obj = GetRegAsTaggedValue(v1).GetRawData(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::ClassPrivateFieldGet(this->GetJSThread(), LoadFromConstantPool(string_id), ctor, obj)); + intrinsics::ClassPrivateFieldGet(this->GetJSThread(), LoadFromConstantPool(stringId), ctor, obj)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaClassprivatefieldset() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); auto v1 = this->GetInst().template GetVReg(); LOG_INST() << "classprivatefieldset" - << " string id:" << string_id << " private contexts: v" << v0 << " obj: v" << v1; + << " string id:" << stringId << " private contexts: v" << v0 << " obj: v" << v1; uint64_t ctor = GetRegAsTaggedValue(v0).GetRawData(); uint64_t obj = GetRegAsTaggedValue(v1).GetRawData(); uint64_t value = GetAccAsTaggedValue().GetRawData(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::ClassPrivateFieldSet(this->GetJSThread(), LoadFromConstantPool(string_id), ctor, obj, value)); + intrinsics::ClassPrivateFieldSet(this->GetJSThread(), LoadFromConstantPool(stringId), ctor, obj, value)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaClassprivatefieldin() { - auto string_id = this->GetInst().template GetId(); + auto stringId = this->GetInst().template GetId(); auto v0 = this->GetInst().template GetVReg(); LOG_INST() << "classprivatefieldin" - << " string id:" << string_id << " private contexts: v" << v0; + << " string id:" << stringId << " private contexts: v" << v0; uint64_t ctor = GetRegAsTaggedValue(v0).GetRawData(); uint64_t obj = GetAccAsTaggedValue().GetRawData(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::ClassPrivateFieldIn(this->GetJSThread(), LoadFromConstantPool(string_id), ctor, obj)); + intrinsics::ClassPrivateFieldIn(this->GetJSThread(), LoadFromConstantPool(stringId), ctor, obj)); this->template MoveToNextInst(); } @@ -2708,13 +2707,13 @@ public: LOG_INST() << "supercall" << "range: " << range << " v" << v0; - auto num_vregs = this->GetFrame()->GetMethod()->GetNumVregs(); + auto numVregs = this->GetFrame()->GetMethod()->GetNumVregs(); - auto this_func = GetAccAsTaggedValue(); - auto new_target = GetRegAsTaggedValue(num_vregs + 1); + auto thisFunc = GetAccAsTaggedValue(); + auto newTarget = GetRegAsTaggedValue(numVregs + 1); auto thread = JSThread::Cast(this->GetThread()); - auto res = SlowRuntimeStub::SuperCall(thread, this_func, new_target, range, GetStkArgs(v0)); + auto res = SlowRuntimeStub::SuperCall(thread, thisFunc, newTarget, range, GetStkArgs(v0)); INTERPRETER_RETURN_IF_ABRUPT(res); SetAccFromTaggedValue(res); @@ -2729,25 +2728,25 @@ public: << " array: v" << v0; uint64_t array = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t this_func = GetAccAsTaggedValue().GetRawData(); + uint64_t thisFunc = GetAccAsTaggedValue().GetRawData(); - auto num_vregs = this->GetFrame()->GetMethod()->GetNumVregs(); - uint64_t new_target = GetRegAsTaggedValue(num_vregs + 1).GetRawData(); + auto numVregs = this->GetFrame()->GetMethod()->GetNumVregs(); + uint64_t newTarget = GetRegAsTaggedValue(numVregs + 1).GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::SuperCallSpread(this->GetJSThread(), array, new_target, this_func)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::SuperCallSpread(this->GetJSThread(), array, newTarget, thisFunc)); this->template MoveToNextInst(); } template ALWAYS_INLINE void HandleEcmaCreateobjecthavingmethod() { - auto literalarray_id = this->GetInst().template GetId(); + auto literalarrayId = this->GetInst().template GetId(); LOG_INST() << "createobjecthavingmethod" - << " literalArrayId:" << literalarray_id.AsIndex(); + << " literalArrayId:" << literalarrayId.AsIndex(); uint64_t env = GetAccAsTaggedValue().GetRawData(); auto cp = GetConstantPool(); - uint64_t literal = cp->GetObjectFromCache(literalarray_id.AsIndex()).GetRawData(); + uint64_t literal = cp->GetObjectFromCache(literalarrayId.AsIndex()).GetRawData(); INTRINSIC_CALL_CHECK_SETACC( intrinsics::CreateObjectHavingMethod(this->GetJSThread(), literal, env, JSTaggedValue(cp).GetRawData())); this->template MoveToNextInst(); @@ -2767,11 +2766,11 @@ public: ALWAYS_INLINE void HandleEcmaThrowifsupernotcorrectcall() { uint16_t imm = this->GetInst().template GetImm(); - JSTaggedValue this_value = GetAccAsTaggedValue(); + JSTaggedValue thisValue = GetAccAsTaggedValue(); LOG_INST() << "intrinsic::throwifsupernotcorrectcall" << " imm:" << imm; auto thread = JSThread::Cast(this->GetThread()); - JSTaggedValue res = SlowRuntimeStub::ThrowIfSuperNotCorrectCall(thread, imm, this_value); + JSTaggedValue res = SlowRuntimeStub::ThrowIfSuperNotCorrectCall(thread, imm, thisValue); INTERPRETER_RETURN_IF_ABRUPT(res); this->template MoveToNextInst(); } @@ -2798,8 +2797,8 @@ public: ALWAYS_INLINE void HandleEcmaPoplexenvdyn() { auto thread = this->GetJSThread(); - auto lex_env = GetLexicalEnvRawValue(); - auto res = JSTaggedValue(intrinsics::PopLexenvDyn(thread, lex_env)); + auto lexEnv = GetLexicalEnvRawValue(); + auto res = JSTaggedValue(intrinsics::PopLexenvDyn(thread, lexEnv)); SetLexicalEnv(res); this->template MoveToNextInst(); } @@ -2825,10 +2824,10 @@ public: template ALWAYS_INLINE void HandleEcmaLdevalbindings() { - auto literalarray_id = this->GetInst().template GetId(); + auto literalarrayId = this->GetInst().template GetId(); LOG_INST() << "ldevalbindings" - << " literalArrayId:" << literalarray_id.AsIndex(); - INTRINSIC_CALL_SETACC(intrinsics::LdEvalBindings(this->GetJSThread(), LoadFromConstantPool(literalarray_id))); + << " literalArrayId:" << literalarrayId.AsIndex(); + INTRINSIC_CALL_SETACC(intrinsics::LdEvalBindings(this->GetJSThread(), LoadFromConstantPool(literalarrayId))); this->template MoveToNextInst(); } @@ -2843,9 +2842,9 @@ public: << " status:" << imm << " v0:" << v0 << " v1:" << v1; uint64_t arg0 = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t eval_bindings = GetRegAsTaggedValue(v1).GetRawData(); + uint64_t evalBindings = GetRegAsTaggedValue(v1).GetRawData(); - INTRINSIC_CALL_CHECK_SETACC(intrinsics::DirectEval(this->GetJSThread(), imm, arg0, eval_bindings)); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::DirectEval(this->GetJSThread(), imm, arg0, evalBindings)); this->template MoveToNextInst(); } @@ -2857,9 +2856,9 @@ public: LOG_INST() << "ldevalvar" << " name:" << id.AsIndex(); - uint64_t lexical_context = GetAccAsTaggedValue().GetRawData(); + uint64_t lexicalContext = GetAccAsTaggedValue().GetRawData(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::LdEvalVar(this->GetJSThread(), LoadFromConstantPool(id), lexical_context)); + intrinsics::LdEvalVar(this->GetJSThread(), LoadFromConstantPool(id), lexicalContext)); this->template MoveToNextInst(); } @@ -2873,9 +2872,9 @@ public: << " name:" << id.AsIndex() << " v0:" << v0; uint64_t value = GetRegAsTaggedValue(v0).GetRawData(); - uint64_t lexical_context = GetAccAsTaggedValue().GetRawData(); + uint64_t lexicalContext = GetAccAsTaggedValue().GetRawData(); INTRINSIC_CALL_CHECK_SETACC( - intrinsics::StEvalVar(this->GetJSThread(), LoadFromConstantPool(id), value, lexical_context)); + intrinsics::StEvalVar(this->GetJSThread(), LoadFromConstantPool(id), value, lexicalContext)); this->template MoveToNextInst(); } @@ -2898,14 +2897,14 @@ public: if (method->GetProfileSize() == 0) { return nullptr; } - auto prof_data = method->GetProfilingVector(); - auto prof_id = this->GetInst().GetProfileId(); - ASSERT(prof_id >= 0); - ASSERT(method->GetProfileSize() > helpers::ToUnsigned(prof_id)); + auto profData = method->GetProfilingVector(); + auto profId = this->GetInst().GetProfileId(); + ASSERT(profId >= 0); + ASSERT(method->GetProfileSize() > helpers::ToUnsigned(profId)); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto prof_value = reinterpret_cast(&prof_data[prof_id]); + auto profValue = reinterpret_cast(&profData[profId]); - return prof_value; + return profValue; } void UpdateTypeOfProfile(coretypes::TaggedType value) @@ -2915,13 +2914,13 @@ public: if (method->GetProfileSize() == 0) { return; } - auto prof_data = method->GetProfilingVector(); - auto prof_id = this->GetInst().GetProfileId(); - ASSERT(prof_id >= 0); - ASSERT(method->GetProfileSize() > helpers::ToUnsigned(prof_id)); + auto profData = method->GetProfilingVector(); + auto profId = this->GetInst().GetProfileId(); + ASSERT(profId >= 0); + ASSERT(method->GetProfileSize() > helpers::ToUnsigned(profId)); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto prof_value = reinterpret_cast(&prof_data[prof_id]); - TypeOfOperationProfile::Update(prof_value, JSTaggedValue(value)); + auto profValue = reinterpret_cast(&profData[profId]); + TypeOfOperationProfile::Update(profValue, JSTaggedValue(value)); } void UpdateUnaryArithProfile(coretypes::TaggedType value) @@ -2931,13 +2930,13 @@ public: if (method->GetProfileSize() == 0) { return; } - auto prof_data = method->GetProfilingVector(); - auto prof_id = this->GetInst().GetProfileId(); - ASSERT(prof_id >= 0); - ASSERT(method->GetProfileSize() > helpers::ToUnsigned(prof_id)); + auto profData = method->GetProfilingVector(); + auto profId = this->GetInst().GetProfileId(); + ASSERT(profId >= 0); + ASSERT(method->GetProfileSize() > helpers::ToUnsigned(profId)); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto prof_value = reinterpret_cast(&prof_data[prof_id]); - UnaryOperationProfile::Update(prof_value, JSTaggedValue(value)); + auto profValue = reinterpret_cast(&profData[profId]); + UnaryOperationProfile::Update(profValue, JSTaggedValue(value)); } template @@ -2950,34 +2949,34 @@ public: if (method->GetProfileSize() == 0) { return; } - auto prof_data = method->GetProfilingVector(); - auto prof_id = this->GetInst().GetProfileId(); - ASSERT(prof_id >= 0); - ASSERT(method->GetProfileSize() > helpers::ToUnsigned(prof_id)); + auto profData = method->GetProfilingVector(); + auto profId = this->GetInst().GetProfileId(); + ASSERT(profId >= 0); + ASSERT(method->GetProfileSize() > helpers::ToUnsigned(profId)); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto prof_value = reinterpret_cast(&prof_data[prof_id]); + auto profValue = reinterpret_cast(&profData[profId]); // NOLINTNEXTLINE(readability-braces-around-statements,bugprone-suspicious-semicolon) if constexpr (IS_MOD) { - BinaryOperationProfile::UpdateMod(prof_value, left, right); + BinaryOperationProfile::UpdateMod(profValue, left, right); } else { - BinaryOperationProfile::Update(prof_value, left, right); + BinaryOperationProfile::Update(profValue, left, right); } } void UpdateCallProfile(ECMAObject *func) { - auto js_method = (JSMethod *)this->GetFrame()->GetMethod(); - if (js_method->GetProfileSize() == 0) { + auto jsMethod = (JSMethod *)this->GetFrame()->GetMethod(); + if (jsMethod->GetProfileSize() == 0) { return; } - auto prof_id = this->GetInst().GetProfileId(); - ASSERT(prof_id != -1); - ASSERT(static_cast(prof_id) < js_method->GetProfileSize()); + auto profId = this->GetInst().GetProfileId(); + ASSERT(profId != -1); + ASSERT(static_cast(profId) < jsMethod->GetProfileSize()); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto profile = CallProfile::FromBuffer(js_method->GetProfilingVector() + prof_id); + auto profile = CallProfile::FromBuffer(jsMethod->GetProfilingVector() + profId); ASSERT(profile != nullptr); - auto *profile_table = this->GetJSThread()->GetEcmaVM()->GetEcmaCallProfileTable(); - profile->Update(func, profile_table); + auto *profileTable = this->GetJSThread()->GetEcmaVM()->GetEcmaCallProfileTable(); + profile->Update(func, profileTable); } }; // InstructionHandler diff --git a/runtime/interpreter/fast_runtime_stub-inl.h b/runtime/interpreter/fast_runtime_stub-inl.h index b4171640245eb172c64ec11068cc4cb4db31b2ac..16aa04257238216d7baff65eaadaf3f1bfa07a84 100644 --- a/runtime/interpreter/fast_runtime_stub-inl.h +++ b/runtime/interpreter/fast_runtime_stub-inl.h @@ -71,16 +71,16 @@ JSTaggedValue FastRuntimeStub::FastMul(JSTaggedValue left, JSTaggedValue right) JSTaggedValue FastRuntimeStub::FastDiv(JSTaggedValue left, JSTaggedValue right) { if (left.IsNumber() && right.IsNumber()) { - double d_left = left.IsInt() ? left.GetInt() : left.GetDouble(); - double d_right = right.IsInt() ? right.GetInt() : right.GetDouble(); - if (UNLIKELY(d_right == 0.0)) { - if (d_left == 0.0 || std::isnan(d_left)) { + double dLeft = left.IsInt() ? left.GetInt() : left.GetDouble(); + double dRight = right.IsInt() ? right.GetInt() : right.GetDouble(); + if (UNLIKELY(dRight == 0.0)) { + if (dLeft == 0.0 || std::isnan(dLeft)) { return JSTaggedValue(base::NAN_VALUE); } - uint64_t flag_bit = ((bit_cast(d_left)) ^ (bit_cast(d_right))) & base::DOUBLE_SIGN_MASK; - return JSTaggedValue(bit_cast(flag_bit ^ (bit_cast(base::POSITIVE_INFINITY)))); + uint64_t flagBit = ((bit_cast(dLeft)) ^ (bit_cast(dRight))) & base::DOUBLE_SIGN_MASK; + return JSTaggedValue(bit_cast(flagBit ^ (bit_cast(base::POSITIVE_INFINITY)))); } - return JSTaggedValue(d_left / d_right); + return JSTaggedValue(dLeft / dRight); } return JSTaggedValue::Hole(); } @@ -88,22 +88,22 @@ JSTaggedValue FastRuntimeStub::FastDiv(JSTaggedValue left, JSTaggedValue right) JSTaggedValue FastRuntimeStub::FastMod(JSTaggedValue left, JSTaggedValue right) { if (right.IsInt() && left.IsInt()) { - int i_right = right.GetInt(); - int i_left = left.GetInt(); - if (i_right > 0 && i_left >= 0) { - return JSTaggedValue(i_left % i_right); + int iRight = right.GetInt(); + int iLeft = left.GetInt(); + if (iRight > 0 && iLeft >= 0) { + return JSTaggedValue(iLeft % iRight); } } if (left.IsNumber() && right.IsNumber()) { - double d_left = left.IsInt() ? left.GetInt() : left.GetDouble(); - double d_right = right.IsInt() ? right.GetInt() : right.GetDouble(); - if (d_right == 0.0 || std::isnan(d_right) || std::isnan(d_left) || std::isinf(d_left)) { + double dLeft = left.IsInt() ? left.GetInt() : left.GetDouble(); + double dRight = right.IsInt() ? right.GetInt() : right.GetDouble(); + if (dRight == 0.0 || std::isnan(dRight) || std::isnan(dLeft) || std::isinf(dLeft)) { return JSTaggedValue(base::NAN_VALUE); } - if (d_left == 0.0 || std::isinf(d_right)) { - return JSTaggedValue(d_left); + if (dLeft == 0.0 || std::isinf(dRight)) { + return JSTaggedValue(dLeft); } - return JSTaggedValue(std::fmod(d_left, d_right)); + return JSTaggedValue(std::fmod(dLeft, dRight)); } return JSTaggedValue::Hole(); } @@ -141,9 +141,9 @@ bool FastRuntimeStub::FastStrictEqual(JSThread *thread, JSTaggedValue left, JSTa { if (left.IsNumber()) { if (right.IsNumber()) { - double d_left = left.IsInt() ? left.GetInt() : left.GetDouble(); - double d_right = right.IsInt() ? right.GetInt() : right.GetDouble(); - return JSTaggedValue::StrictNumberEquals(d_left, d_right); + double dLeft = left.IsInt() ? left.GetInt() : left.GetDouble(); + double dRight = right.IsInt() ? right.GetInt() : right.GetDouble(); + return JSTaggedValue::StrictNumberEquals(dLeft, dRight); } return false; } @@ -163,19 +163,19 @@ bool FastRuntimeStub::FastStrictEqual(JSThread *thread, JSTaggedValue left, JSTa return false; } -bool FastRuntimeStub::IsSpecialIndexedObj(JSType js_type) +bool FastRuntimeStub::IsSpecialIndexedObj(JSType jsType) { - return js_type > JSType::JS_ARRAY; + return jsType > JSType::JS_ARRAY; } -bool FastRuntimeStub::IsSpecialReceiverObj(JSType js_type) +bool FastRuntimeStub::IsSpecialReceiverObj(JSType jsType) { - return js_type > JSType::JS_PRIMITIVE_REF; + return jsType > JSType::JS_PRIMITIVE_REF; } -bool FastRuntimeStub::IsSpecialContainer(JSType js_type) +bool FastRuntimeStub::IsSpecialContainer(JSType jsType) { - return js_type >= JSType::JS_ARRAY_LIST && js_type <= JSType::JS_QUEUE; + return jsType >= JSType::JS_ARRAY_LIST && jsType <= JSType::JS_QUEUE; } uint32_t FastRuntimeStub::TryToElementsIndex(JSTaggedValue key) @@ -203,34 +203,34 @@ JSTaggedValue FastRuntimeStub::CallGetter(JSThread *thread, JSTaggedValue receiv { INTERPRETER_TRACE(thread, CallGetter); // Accessor - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); AccessorData *accessor = AccessorData::Cast(value.GetTaggedObject()); if (UNLIKELY(accessor->IsInternal())) { - JSHandle obj_handle(thread, holder); - return accessor->CallInternalGet(thread, obj_handle); + JSHandle objHandle(thread, holder); + return accessor->CallInternalGet(thread, objHandle); } - JSHandle obj_handle(thread, receiver); - return JSObject::CallGetter(thread, accessor, obj_handle); + JSHandle objHandle(thread, receiver); + return JSObject::CallGetter(thread, accessor, objHandle); } JSTaggedValue FastRuntimeStub::CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, - JSTaggedValue accessor_value) + JSTaggedValue accessorValue) { INTERPRETER_TRACE(thread, CallSetter); // Accessor - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, receiver); - JSHandle value_handle(thread, value); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle objHandle(thread, receiver); + JSHandle valueHandle(thread, value); - auto accessor = AccessorData::Cast(accessor_value.GetTaggedObject()); - bool success = JSObject::CallSetter(thread, *accessor, obj_handle, value_handle, true); + auto accessor = AccessorData::Cast(accessorValue.GetTaggedObject()); + bool success = JSObject::CallSetter(thread, *accessor, objHandle, valueHandle, true); return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } -bool FastRuntimeStub::ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessor_value, +bool FastRuntimeStub::ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessorValue, PropertyAttributes attr) { - if (!AccessorData::Cast(accessor_value.GetTaggedObject())->IsInternal()) { + if (!AccessorData::Cast(accessorValue.GetTaggedObject())->IsInternal()) { return true; } if (receiver != holder) { @@ -239,46 +239,46 @@ bool FastRuntimeStub::ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue hol return attr.IsWritable(); } -PropertyAttributes FastRuntimeStub::AddPropertyByName(JSThread *thread, JSHandle obj_handle, - JSHandle key_handle, - JSHandle value_handle, PropertyAttributes attr) +PropertyAttributes FastRuntimeStub::AddPropertyByName(JSThread *thread, JSHandle objHandle, + JSHandle keyHandle, + JSHandle valueHandle, PropertyAttributes attr) { INTERPRETER_TRACE(thread, AddPropertyByName); - if (obj_handle->IsJSArray() && key_handle.GetTaggedValue() == thread->GlobalConstants()->GetConstructorString()) { - obj_handle->GetJSHClass()->SetHasConstructor(true); + if (objHandle->IsJSArray() && keyHandle.GetTaggedValue() == thread->GlobalConstants()->GetConstructorString()) { + objHandle->GetJSHClass()->SetHasConstructor(true); } - int32_t next_inlined_props_index = obj_handle->GetJSHClass()->GetNextInlinedPropsIndex(); - if (next_inlined_props_index >= 0) { - obj_handle->SetPropertyInlinedProps(thread, next_inlined_props_index, value_handle.GetTaggedValue()); - attr.SetOffset(next_inlined_props_index); + int32_t nextInlinedPropsIndex = objHandle->GetJSHClass()->GetNextInlinedPropsIndex(); + if (nextInlinedPropsIndex >= 0) { + objHandle->SetPropertyInlinedProps(thread, nextInlinedPropsIndex, valueHandle.GetTaggedValue()); + attr.SetOffset(nextInlinedPropsIndex); attr.SetIsInlinedProps(true); - JSHClass::AddProperty(thread, obj_handle, key_handle, attr); + JSHClass::AddProperty(thread, objHandle, keyHandle, attr); return attr; } - JSMutableHandle array(thread, obj_handle->GetProperties()); + JSMutableHandle array(thread, objHandle->GetProperties()); uint32_t length = array->GetLength(); if (length == 0) { length = JSObject::MIN_PROPERTIES_LENGTH; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); array.Update(factory->NewTaggedArray(length).GetTaggedValue()); - obj_handle->SetProperties(thread, array.GetTaggedValue()); + objHandle->SetProperties(thread, array.GetTaggedValue()); } if (!array->IsDictionaryMode()) { attr.SetIsInlinedProps(false); - uint32_t non_inlined_props = obj_handle->GetJSHClass()->GetNextNonInlinedPropsIndex(); - ASSERT(length >= non_inlined_props); + uint32_t nonInlinedProps = objHandle->GetJSHClass()->GetNextNonInlinedPropsIndex(); + ASSERT(length >= nonInlinedProps); // if array is full, grow array or change to dictionary mode - if (length == non_inlined_props) { + if (length == nonInlinedProps) { if (UNLIKELY(length == JSHClass::MAX_CAPACITY_OF_OUT_OBJECTS)) { // change to dictionary and add one. - JSHandle dict(JSObject::TransitionToDictionary(thread, obj_handle)); - JSHandle new_dict = - NameDictionary::PutIfAbsent(thread, dict, key_handle, value_handle, attr); - obj_handle->SetProperties(thread, new_dict); + JSHandle dict(JSObject::TransitionToDictionary(thread, objHandle)); + JSHandle newDict = + NameDictionary::PutIfAbsent(thread, dict, keyHandle, valueHandle, attr); + objHandle->SetProperties(thread, newDict); // index is not essential when fastMode is false; return attr; } @@ -286,17 +286,17 @@ PropertyAttributes FastRuntimeStub::AddPropertyByName(JSThread *thread, JSHandle uint32_t capacity = JSObject::ComputePropertyCapacity(length); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); array.Update(factory->CopyArray(array, length, capacity).GetTaggedValue()); - obj_handle->SetProperties(thread, array.GetTaggedValue()); + objHandle->SetProperties(thread, array.GetTaggedValue()); } - attr.SetOffset(non_inlined_props + obj_handle->GetJSHClass()->GetInlinedProperties()); - JSHClass::AddProperty(thread, obj_handle, key_handle, attr); - array->Set(thread, non_inlined_props, value_handle.GetTaggedValue()); + attr.SetOffset(nonInlinedProps + objHandle->GetJSHClass()->GetInlinedProperties()); + JSHClass::AddProperty(thread, objHandle, keyHandle, attr); + array->Set(thread, nonInlinedProps, valueHandle.GetTaggedValue()); } else { - JSHandle dict_handle(array); - JSHandle new_dict = - NameDictionary::PutIfAbsent(thread, dict_handle, key_handle, value_handle, attr); - obj_handle->SetProperties(thread, new_dict); + JSHandle dictHandle(array); + JSHandle newDict = + NameDictionary::PutIfAbsent(thread, dictHandle, keyHandle, valueHandle, attr); + objHandle->SetProperties(thread, newDict); } return attr; } @@ -305,7 +305,7 @@ JSTaggedValue FastRuntimeStub::AddPropertyByIndex(JSThread *thread, JSTaggedValu JSTaggedValue value) { INTERPRETER_TRACE(thread, AddPropertyByIndex); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", JSTaggedValue::Exception()); } @@ -319,15 +319,15 @@ template JSTaggedValue FastRuntimeStub::GetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, void *prof) { INTERPRETER_TRACE(thread, GetPropertyByIndex); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSTaggedValue holder = receiver; do { auto *hclass = holder.GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - if (IsSpecialIndexedObj(js_type)) { + JSType jsType = hclass->GetObjectType(); + if (IsSpecialIndexedObj(jsType)) { SET_PROFILING_ACCESS(ProfilingIndexedAccessBits::OBJECT_ACCESS); - if (IsSpecialContainer(js_type)) { - return GetContainerProperty(thread, holder, index, js_type); + if (IsSpecialContainer(jsType)) { + return GetContainerProperty(thread, holder, index, jsType); } return JSTaggedValue::Hole(); } @@ -383,12 +383,12 @@ JSTaggedValue FastRuntimeStub::GetPropertyByValue(JSThread *thread, JSHandle(thread, receiver.GetTaggedValue(), index); } if (!key->IsNumber()) { - JSTaggedValue raw_key = key.GetTaggedValue(); - if (raw_key.IsString() && !EcmaString::Cast(raw_key.GetTaggedObject())->IsInternString()) { + JSTaggedValue rawKey = key.GetTaggedValue(); + if (rawKey.IsString() && !EcmaString::Cast(rawKey.GetTaggedObject())->IsInternString()) { // update string stable - raw_key = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); + rawKey = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); } - return FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), raw_key); + return FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), rawKey); } return JSTaggedValue::Hole(); } @@ -402,19 +402,19 @@ JSTaggedValue FastRuntimeStub::GetPropertyByName(JSThread *thread, JSTaggedValue JSTaggedValue holder = receiver; do { auto *hclass = holder.GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - if (IsSpecialIndexedObj(js_type)) { + JSType jsType = hclass->GetObjectType(); + if (IsSpecialIndexedObj(jsType)) { return JSTaggedValue::Hole(); } if (LIKELY(!hclass->IsDictionaryMode())) { ASSERT(!TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject())->IsDictionaryMode()); - LayoutInfo *layout_info = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - int props_number = hclass->NumberOfProps(); - int entry = layout_info->FindElementWithCache(thread, hclass, key, props_number); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + int propsNumber = hclass->NumberOfProps(); + int entry = layoutInfo->FindElementWithCache(thread, hclass, key, propsNumber); if (entry != -1) { - PropertyAttributes attr(layout_info->GetAttr(entry)); + PropertyAttributes attr(layoutInfo->GetAttr(entry)); ASSERT(static_cast(attr.GetOffset()) == entry); auto value = JSObject::Cast(holder)->GetProperty(hclass, attr); if (UNLIKELY(attr.IsAccessor())) { @@ -456,9 +456,9 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue JSTaggedValue holder = receiver; do { auto *hclass = holder.GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - if (IsSpecialIndexedObj(js_type)) { - if (IsSpecialContainer(js_type)) { + JSType jsType = hclass->GetObjectType(); + if (IsSpecialIndexedObj(jsType)) { + if (IsSpecialContainer(jsType)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set property on Container", JSTaggedValue::Exception()); } return JSTaggedValue::Hole(); @@ -467,12 +467,12 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue if (LIKELY(!hclass->IsDictionaryMode())) { ASSERT(!TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject())->IsDictionaryMode()); - LayoutInfo *layout_info = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - int props_number = hclass->NumberOfProps(); - int entry = layout_info->FindElementWithCache(thread, hclass, key, props_number); + int propsNumber = hclass->NumberOfProps(); + int entry = layoutInfo->FindElementWithCache(thread, hclass, key, propsNumber); if (entry != -1) { - PropertyAttributes attr(layout_info->GetAttr(entry)); + PropertyAttributes attr(layoutInfo->GetAttr(entry)); ASSERT(static_cast(attr.GetOffset()) == entry); if (UNLIKELY(attr.IsAccessor())) { auto accessor = JSObject::Cast(holder)->GetProperty(hclass, attr); @@ -481,7 +481,7 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue } } if (UNLIKELY(!attr.IsWritable())) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", JSTaggedValue::Exception()); } if (UNLIKELY(holder != receiver)) { @@ -504,7 +504,7 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue } } if (UNLIKELY(!attr.IsWritable())) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", JSTaggedValue::Exception()); } if (UNLIKELY(holder != receiver)) { @@ -520,15 +520,15 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue holder = hclass->GetPrototype(); } while (holder.IsHeapObject()); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, receiver); - JSHandle key_handle(thread, key); - JSHandle value_handle(thread, value); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle objHandle(thread, receiver); + JSHandle keyHandle(thread, key); + JSHandle valueHandle(thread, value); if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", JSTaggedValue::Exception()); } - AddPropertyByName(thread, obj_handle, key_handle, value_handle, PropertyAttributes::Default()); + AddPropertyByName(thread, objHandle, keyHandle, valueHandle, PropertyAttributes::Default()); return JSTaggedValue::Undefined(); } @@ -540,12 +540,12 @@ JSTaggedValue FastRuntimeStub::SetPropertyByIndex(JSThread *thread, JSTaggedValu JSTaggedValue holder = receiver; do { auto *hclass = holder.GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - if (IsSpecialIndexedObj(js_type)) { + JSType jsType = hclass->GetObjectType(); + if (IsSpecialIndexedObj(jsType)) { SET_PROFILING_ACCESS(ProfilingIndexedAccessBits::OBJECT_ACCESS); - if (IsSpecialContainer(js_type)) { - return SetContainerProperty(thread, holder, index, value, js_type); + if (IsSpecialContainer(jsType)) { + return SetContainerProperty(thread, holder, index, value, jsType); } return JSTaggedValue::Hole(); } @@ -590,12 +590,12 @@ JSTaggedValue FastRuntimeStub::SetPropertyByValue(JSThread *thread, JSHandle(thread, receiver.GetTaggedValue(), index, value.GetTaggedValue()); } if (!key->IsNumber()) { - JSTaggedValue raw_key = key.GetTaggedValue(); - if (raw_key.IsString() && !EcmaString::Cast(raw_key.GetTaggedObject())->IsInternString()) { + JSTaggedValue rawKey = key.GetTaggedValue(); + if (rawKey.IsString() && !EcmaString::Cast(rawKey.GetTaggedObject())->IsInternString()) { // update string stable - raw_key = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); + rawKey = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); } - return FastRuntimeStub::SetPropertyByName(thread, receiver.GetTaggedValue(), raw_key, + return FastRuntimeStub::SetPropertyByName(thread, receiver.GetTaggedValue(), rawKey, value.GetTaggedValue()); } return JSTaggedValue::Hole(); @@ -618,53 +618,53 @@ JSTaggedValue FastRuntimeStub::GetGlobalOwnProperty(JSTaggedValue receiver, JSTa JSTaggedValue FastRuntimeStub::FastTypeOf(JSThread *thread, JSTaggedValue obj) { INTERPRETER_TRACE(thread, FastTypeOf); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); switch (obj.GetRawData()) { case JSTaggedValue::VALUE_TRUE: case JSTaggedValue::VALUE_FALSE: - return global_const->GetBooleanString(); + return globalConst->GetBooleanString(); case JSTaggedValue::VALUE_NULL: - return global_const->GetObjectString(); + return globalConst->GetObjectString(); case JSTaggedValue::VALUE_UNDEFINED: - return global_const->GetUndefinedString(); + return globalConst->GetUndefinedString(); default: if (obj.IsHeapObject()) { if (obj.IsString()) { - return global_const->GetStringString(); + return globalConst->GetStringString(); } if (obj.IsSymbol()) { - return global_const->GetSymbolString(); + return globalConst->GetSymbolString(); } if (obj.IsBigInt()) { - return global_const->GetBigIntString(); + return globalConst->GetBigIntString(); } if (obj.IsCallable()) { - return global_const->GetFunctionString(); + return globalConst->GetFunctionString(); } - return global_const->GetObjectString(); + return globalConst->GetObjectString(); } if (obj.IsNumber()) { - return global_const->GetNumberString(); + return globalConst->GetNumberString(); } } - return global_const->GetUndefinedString(); + return globalConst->GetUndefinedString(); } bool FastRuntimeStub::FastSetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value) { INTERPRETER_TRACE(thread, FastSetPropertyByIndex); - JSTaggedType raw_receiver = receiver.GetRawData(); - JSTaggedType raw_value = value.GetRawData(); + JSTaggedType rawReceiver = receiver.GetRawData(); + JSTaggedType rawValue = value.GetRawData(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); JSTaggedValue result = FastRuntimeStub::SetPropertyByIndex(thread, receiver, index, value); if (!result.IsHole()) { return result != JSTaggedValue::Exception(); } ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - receiver = JSTaggedValue(raw_receiver); - value = JSTaggedValue(raw_value); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + receiver = JSTaggedValue(rawReceiver); + value = JSTaggedValue(rawValue); return JSTaggedValue::SetProperty(thread, JSHandle(thread, receiver), index, JSHandle(thread, value), true); } @@ -686,17 +686,16 @@ JSTaggedValue FastRuntimeStub::FastGetPropertyByName(JSThread *thread, JSHandle< { INTERPRETER_TRACE(thread, FastGetPropertyByName); ASSERT(key->IsStringOrSymbol()); - JSTaggedType raw_key = key->GetRawData(); + JSTaggedType rawKey = key->GetRawData(); if (key->IsString() && !EcmaString::Cast(key->GetTaggedObject())->IsInternString()) { - raw_key = ToUintPtr(thread->GetEcmaVM()->GetFactory()->InternString(key)); + rawKey = ToUintPtr(thread->GetEcmaVM()->GetFactory()->InternString(key)); } [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); - JSTaggedValue result = - FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), JSTaggedValue(raw_key)); + JSTaggedValue result = FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), JSTaggedValue(rawKey)); if (result.IsHole()) { ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - return JSTaggedValue::GetProperty(thread, receiver, JSHandle(thread, JSTaggedValue(raw_key))) + [[maybe_unused]] EcmaHandleScope handleScope(thread); + return JSTaggedValue::GetProperty(thread, receiver, JSHandle(thread, JSTaggedValue(rawKey))) .GetValue() .GetTaggedValue(); } @@ -718,13 +717,13 @@ template // UseHole is only for Array::Sort() which requires Ho JSTaggedValue FastRuntimeStub::FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index) { INTERPRETER_TRACE(thread, FastGetPropertyByIndex); - JSTaggedType raw_receiver = receiver.GetRawData(); + JSTaggedType rawReceiver = receiver.GetRawData(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); JSTaggedValue result = FastRuntimeStub::GetPropertyByIndex(thread, receiver, index); if (result.IsHole() && !USE_HOLE) { ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - receiver = JSTaggedValue(raw_receiver); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + receiver = JSTaggedValue(rawReceiver); return JSTaggedValue::GetProperty(thread, JSHandle(thread, receiver), index) .GetValue() .GetTaggedValue(); @@ -732,27 +731,27 @@ JSTaggedValue FastRuntimeStub::FastGetPropertyByIndex(JSThread *thread, JSTagged return result; } -JSTaggedValue FastRuntimeStub::NewLexicalEnvDyn(JSThread *thread, ObjectFactory *factory, uint16_t num_vars) +JSTaggedValue FastRuntimeStub::NewLexicalEnvDyn(JSThread *thread, ObjectFactory *factory, uint16_t numVars) { INTERPRETER_TRACE(thread, NewLexicalEnvDyn); - LexicalEnv *new_env = factory->InlineNewLexicalEnv(num_vars); - if (UNLIKELY(new_env == nullptr)) { + LexicalEnv *newEnv = factory->InlineNewLexicalEnv(numVars); + if (UNLIKELY(newEnv == nullptr)) { return JSTaggedValue::Hole(); } - return JSTaggedValue(new_env); + return JSTaggedValue(newEnv); } // Those interface below is discarded bool FastRuntimeStub::IsSpecialIndexedObjForGet(JSTaggedValue obj) { - JSType js_type = obj.GetTaggedObject()->GetClass()->GetObjectType(); - return js_type > JSType::JS_ARRAY && js_type <= JSType::JS_PRIMITIVE_REF; + JSType jsType = obj.GetTaggedObject()->GetClass()->GetObjectType(); + return jsType > JSType::JS_ARRAY && jsType <= JSType::JS_PRIMITIVE_REF; } bool FastRuntimeStub::IsSpecialIndexedObjForSet(JSTaggedValue obj) { - JSType js_type = obj.GetTaggedObject()->GetClass()->GetObjectType(); - return js_type >= JSType::JS_ARRAY && js_type <= JSType::JS_PRIMITIVE_REF; + JSType jsType = obj.GetTaggedObject()->GetClass()->GetObjectType(); + return jsType >= JSType::JS_ARRAY && jsType <= JSType::JS_PRIMITIVE_REF; } JSTaggedValue FastRuntimeStub::GetElement(JSTaggedValue receiver, uint32_t index) @@ -792,22 +791,22 @@ JSTaggedValue FastRuntimeStub::GetElementWithArray(JSTaggedValue receiver, uint3 } bool FastRuntimeStub::SetElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value, - bool may_throw) + bool mayThrow) { INTERPRETER_TRACE(thread, SetElement); JSTaggedValue holder = receiver; - bool on_prototype = false; + bool onPrototype = false; while (true) { PropertyAttributes attr; - uint32_t index_or_entry = 0; + uint32_t indexOrEntry = 0; TaggedArray *elements = TaggedArray::Cast(JSObject::Cast(holder)->GetElements().GetHeapObject()); - bool is_dict = elements->IsDictionaryMode(); - JSTaggedValue val = FindOwnElement(elements, index, is_dict, &attr, &index_or_entry); + bool isDict = elements->IsDictionaryMode(); + JSTaggedValue val = FindOwnElement(elements, index, isDict, &attr, &indexOrEntry); if (!val.IsHole()) { - if (UNLIKELY(on_prototype)) { + if (UNLIKELY(onPrototype)) { if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); } return false; @@ -820,33 +819,33 @@ bool FastRuntimeStub::SetElement(JSThread *thread, JSTaggedValue receiver, uint3 if (!attr.IsAccessor()) { if (attr.IsWritable()) { elements = TaggedArray::Cast(JSObject::Cast(receiver)->GetElements().GetHeapObject()); - if (!is_dict) { - elements->Set(thread, index_or_entry, value); + if (!isDict) { + elements->Set(thread, indexOrEntry, value); JSObject::Cast(receiver)->GetJSHClass()->UpdateRepresentation(value); return true; } - NumberDictionary::Cast(elements)->UpdateValueAndAttributes(thread, index_or_entry, value, attr); + NumberDictionary::Cast(elements)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); return true; } - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", false); } return false; } // Accessor - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, receiver); - JSHandle value_handle(thread, value); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle objHandle(thread, receiver); + JSHandle valueHandle(thread, value); AccessorData *access = AccessorData::Cast(val.GetHeapObject()); - return JSObject::CallSetter(thread, *access, obj_handle, value_handle, may_throw); + return JSObject::CallSetter(thread, *access, objHandle, valueHandle, mayThrow); } holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); if (!holder.IsHeapObject()) { if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); } return false; @@ -858,35 +857,35 @@ bool FastRuntimeStub::SetElement(JSThread *thread, JSTaggedValue receiver, uint3 if (holder.IsJSProxy()) { return JSProxy::SetProperty( thread, JSHandle(thread, holder), JSHandle(thread, JSTaggedValue(index)), - JSHandle(thread, value), JSHandle(thread, receiver), may_throw); + JSHandle(thread, value), JSHandle(thread, receiver), mayThrow); } - on_prototype = true; + onPrototype = true; } } bool FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool may_throw) + JSTaggedValue value, bool mayThrow) { INTERPRETER_TRACE(thread, SetPropertyByName); // property JSTaggedValue holder = receiver; - bool on_prototype = false; + bool onPrototype = false; while (true) { TaggedArray *properties = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetHeapObject()); PropertyAttributes attr; - uint32_t index_or_entry = 0; - JSTaggedValue val = FindOwnProperty(thread, JSObject::Cast(holder), properties, key, &attr, &index_or_entry); + uint32_t indexOrEntry = 0; + JSTaggedValue val = FindOwnProperty(thread, JSObject::Cast(holder), properties, key, &attr, &indexOrEntry); if (!val.IsHole()) { if (!attr.IsAccessor()) { - if (UNLIKELY(on_prototype)) { + if (UNLIKELY(onPrototype)) { if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible() || !attr.IsWritable())) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); } return false; } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectOperator::FastAdd(thread, receiver, key, JSHandle(thread, value), PropertyAttributes::Default()); @@ -904,119 +903,118 @@ bool FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue receiver JSObject::Cast(receiver)->GetJSHClass()->UpdatePropertyMetaData(thread, key, attr); if (UNLIKELY(val.IsInternalAccessor())) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); AccessorData::Cast(val.GetHeapObject()) ->CallInternalSet(thread, JSHandle(thread, receiver), - JSHandle(thread, value), may_throw); + JSHandle(thread, value), mayThrow); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); return true; } if (attr.IsInlinedProps()) { - JSObject::Cast(receiver)->SetPropertyInlinedProps(thread, index_or_entry, value); + JSObject::Cast(receiver)->SetPropertyInlinedProps(thread, indexOrEntry, value); } else { - properties->Set(thread, index_or_entry, value); + properties->Set(thread, indexOrEntry, value); } return true; } if (receiver.IsJSGlobalObject()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle dict_handle(thread, properties); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle dictHandle(thread, properties); // globalobj have no internal accessor - GlobalDictionary::InvalidatePropertyBox(thread, dict_handle, index_or_entry, attr); + GlobalDictionary::InvalidatePropertyBox(thread, dictHandle, indexOrEntry, attr); return true; } if (UNLIKELY(val.IsInternalAccessor())) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); AccessorData::Cast(val.GetHeapObject()) ->CallInternalSet(thread, JSHandle(thread, receiver), - JSHandle(thread, value), may_throw); + JSHandle(thread, value), mayThrow); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); return true; } - NameDictionary::Cast(properties)->UpdateValueAndAttributes(thread, index_or_entry, value, attr); + NameDictionary::Cast(properties)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); return true; } - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", false); } return false; } // Accessor - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, receiver); - JSHandle value_handle(thread, value); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle objHandle(thread, receiver); + JSHandle valueHandle(thread, value); AccessorData *access = AccessorData::Cast(val.GetHeapObject()); - return JSObject::CallSetter(thread, *access, obj_handle, value_handle, may_throw); + return JSObject::CallSetter(thread, *access, objHandle, valueHandle, mayThrow); } if (holder.IsTypedArray()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle holder_handle(thread, holder); - JSHandle value_handle(thread, value); - JSHandle receiver_handle(thread, receiver); - JSHandle key_handle = JSTypedArray::ToPropKey(thread, JSHandle(thread, key)); - return JSTypedArray::SetProperty(thread, holder_handle, key_handle, value_handle, receiver_handle, - may_throw); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle holderHandle(thread, holder); + JSHandle valueHandle(thread, value); + JSHandle receiverHandle(thread, receiver); + JSHandle keyHandle = JSTypedArray::ToPropKey(thread, JSHandle(thread, key)); + return JSTypedArray::SetProperty(thread, holderHandle, keyHandle, valueHandle, receiverHandle, mayThrow); } holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); if (!holder.IsHeapObject()) { if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); } return false; } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectOperator::FastAdd(thread, receiver, key, JSHandle(thread, value), PropertyAttributes::Default()); return true; } if (holder.IsJSProxy()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); return JSProxy::SetProperty(thread, JSHandle(thread, holder), JSHandle(thread, key), JSHandle(thread, value), - JSHandle(thread, receiver), may_throw); + JSHandle(thread, receiver), mayThrow); } - on_prototype = true; + onPrototype = true; } } bool FastRuntimeStub::SetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool may_throw) + JSTaggedValue value, bool mayThrow) { INTERPRETER_TRACE(thread, SetGlobalOwnProperty); uint32_t index = 0; if (JSTaggedValue::ToElementIndex(key, &index)) { - return SetElement(thread, receiver, index, value, may_throw); + return SetElement(thread, receiver, index, value, mayThrow); } JSObject *obj = JSObject::Cast(receiver); GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties().GetTaggedObject()); PropertyAttributes attr = PropertyAttributes::Default(); if (UNLIKELY(dict->GetLength() == 0)) { - JSHandle key_handle(thread, key); - JSHandle val_handle(thread, value); - JSHandle obj_handle(thread, obj); - JSHandle dict_handle(GlobalDictionary::Create(thread)); + JSHandle keyHandle(thread, key); + JSHandle valHandle(thread, value); + JSHandle objHandle(thread, obj); + JSHandle dictHandle(GlobalDictionary::Create(thread)); // Add PropertyBox to global dictionary ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle box_handle = factory->NewPropertyBox(val_handle); - box_handle->SetValue(thread, val_handle.GetTaggedValue()); - PropertyBoxType box_type = val_handle->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; - attr.SetBoxType(box_type); + JSHandle boxHandle = factory->NewPropertyBox(valHandle); + boxHandle->SetValue(thread, valHandle.GetTaggedValue()); + PropertyBoxType boxType = valHandle->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; + attr.SetBoxType(boxType); JSHandle properties = - GlobalDictionary::PutIfAbsent(thread, dict_handle, key_handle, JSHandle(box_handle), attr); - obj_handle->SetProperties(thread, properties); + GlobalDictionary::PutIfAbsent(thread, dictHandle, keyHandle, JSHandle(boxHandle), attr); + objHandle->SetProperties(thread, properties); return true; } @@ -1027,8 +1025,8 @@ bool FastRuntimeStub::SetGlobalOwnProperty(JSThread *thread, JSTaggedValue recei if (!attr.IsAccessor()) { if (attr.IsWritable()) { // globalobj have no internal accessor - JSHandle dict_handle(thread, dict); - GlobalDictionary::InvalidatePropertyBox(thread, dict_handle, entry, attr); + JSHandle dictHandle(thread, dict); + GlobalDictionary::InvalidatePropertyBox(thread, dictHandle, entry, attr); return true; } } @@ -1036,16 +1034,16 @@ bool FastRuntimeStub::SetGlobalOwnProperty(JSThread *thread, JSTaggedValue recei // Accessor JSTaggedValue setter = AccessorData::Cast(val.GetHeapObject())->GetSetter(); if (setter.IsUndefined()) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set property when setter is undefined", false); } return false; } - JSHandle obj_handle(thread, receiver); - JSHandle set_func(thread, setter); + JSHandle objHandle(thread, receiver); + JSHandle setFunc(thread, setter); - auto info = NewRuntimeCallInfo(thread, set_func, obj_handle, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread, setFunc, objHandle, JSTaggedValue::Undefined(), 1); info->SetCallArgs(value); JSFunction::Call(info.Get()); // 10. ReturnIfAbrupt(setterResult). @@ -1053,21 +1051,21 @@ bool FastRuntimeStub::SetGlobalOwnProperty(JSThread *thread, JSTaggedValue recei return true; } - JSHandle key_handle(thread, key); - JSHandle val_handle(thread, value); - JSHandle obj_handle(thread, obj); - JSHandle dict_handle(thread, dict); + JSHandle keyHandle(thread, key); + JSHandle valHandle(thread, value); + JSHandle objHandle(thread, obj); + JSHandle dictHandle(thread, dict); // Add PropertyBox to global dictionary ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle box_handle = factory->NewPropertyBox(key_handle); - box_handle->SetValue(thread, val_handle.GetTaggedValue()); - PropertyBoxType box_type = val_handle->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; - attr.SetBoxType(box_type); + JSHandle boxHandle = factory->NewPropertyBox(keyHandle); + boxHandle->SetValue(thread, valHandle.GetTaggedValue()); + PropertyBoxType boxType = valHandle->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; + attr.SetBoxType(boxType); JSHandle properties = - GlobalDictionary::PutIfAbsent(thread, dict_handle, key_handle, JSHandle(box_handle), attr); - obj_handle->SetProperties(thread, properties); + GlobalDictionary::PutIfAbsent(thread, dictHandle, keyHandle, JSHandle(boxHandle), attr); + objHandle->SetProperties(thread, properties); return true; } @@ -1078,8 +1076,8 @@ void FastRuntimeStub::SetOwnPropertyByName(JSThread *thread, JSTaggedValue recei INTERPRETER_TRACE(thread, SetOwnPropertyByName); TaggedArray *properties = TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties().GetHeapObject()); PropertyAttributes attr; - uint32_t index_or_entry = 0; - JSTaggedValue val = FindOwnProperty(thread, JSObject::Cast(receiver), properties, key, &attr, &index_or_entry); + uint32_t indexOrEntry = 0; + JSTaggedValue val = FindOwnProperty(thread, JSObject::Cast(receiver), properties, key, &attr, &indexOrEntry); if (!val.IsHole()) { ASSERT(!attr.IsAccessor() && attr.IsWritable()); if (!properties->IsDictionaryMode()) { @@ -1091,17 +1089,17 @@ void FastRuntimeStub::SetOwnPropertyByName(JSThread *thread, JSTaggedValue recei JSObject::Cast(receiver)->GetJSHClass()->UpdatePropertyMetaData(thread, key, attr); if (attr.IsInlinedProps()) { - JSObject::Cast(receiver)->SetPropertyInlinedProps(thread, index_or_entry, value); + JSObject::Cast(receiver)->SetPropertyInlinedProps(thread, indexOrEntry, value); } else { - properties->Set(thread, index_or_entry, value); + properties->Set(thread, indexOrEntry, value); } return; } - NameDictionary::Cast(properties)->UpdateValueAndAttributes(thread, index_or_entry, value, attr); + NameDictionary::Cast(properties)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); return; } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectOperator::FastAdd(thread, receiver, key, JSHandle(thread, value), PropertyAttributes::Default()); @@ -1111,20 +1109,20 @@ void FastRuntimeStub::SetOwnPropertyByName(JSThread *thread, JSTaggedValue recei bool FastRuntimeStub::SetOwnElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value) { INTERPRETER_TRACE(thread, SetOwnElement); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); PropertyAttributes attr; - uint32_t index_or_entry = 0; + uint32_t indexOrEntry = 0; TaggedArray *elements = TaggedArray::Cast(JSObject::Cast(receiver)->GetElements().GetHeapObject()); - bool is_dict = elements->IsDictionaryMode(); - [[maybe_unused]] JSTaggedValue val = FindOwnElement(elements, index, is_dict, &attr, &index_or_entry); + bool isDict = elements->IsDictionaryMode(); + [[maybe_unused]] JSTaggedValue val = FindOwnElement(elements, index, isDict, &attr, &indexOrEntry); if (!val.IsHole()) { ASSERT(!attr.IsAccessor() && attr.IsWritable()); - if (!is_dict) { - elements->Set(thread, index_or_entry, value); + if (!isDict) { + elements->Set(thread, indexOrEntry, value); JSObject::Cast(receiver)->GetJSHClass()->UpdateRepresentation(value); return true; } - NumberDictionary::Cast(elements)->UpdateValueAndAttributes(thread, index_or_entry, value, attr); + NumberDictionary::Cast(elements)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); return true; } @@ -1133,7 +1131,7 @@ bool FastRuntimeStub::SetOwnElement(JSThread *thread, JSTaggedValue receiver, ui } bool FastRuntimeStub::FastSetProperty(JSThread *thread, JSHandle receiver, JSHandle key, - JSHandle value, bool may_throw) + JSHandle value, bool mayThrow) { INTERPRETER_TRACE(thread, FastSetProperty); if (receiver->IsJSObject() && !receiver->IsTypedArray() && (key->IsStringOrSymbol())) { @@ -1143,16 +1141,16 @@ bool FastRuntimeStub::FastSetProperty(JSThread *thread, JSHandle return FastRuntimeStub::SetElement(thread, receiver.GetTaggedValue(), index, value.GetTaggedValue(), true); } - return JSTaggedValue::SetProperty(thread, receiver, key, value, may_throw); + return JSTaggedValue::SetProperty(thread, receiver, key, value, mayThrow); } - JSTaggedValue raw_key = key.GetTaggedValue(); - if (raw_key.IsString()) { - raw_key = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); + JSTaggedValue rawKey = key.GetTaggedValue(); + if (rawKey.IsString()) { + rawKey = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); } - return FastRuntimeStub::SetPropertyByName(thread, receiver.GetTaggedValue(), raw_key, value.GetTaggedValue(), - may_throw); + return FastRuntimeStub::SetPropertyByName(thread, receiver.GetTaggedValue(), rawKey, value.GetTaggedValue(), + mayThrow); } - return JSTaggedValue::SetProperty(thread, receiver, key, value, may_throw); + return JSTaggedValue::SetProperty(thread, receiver, key, value, mayThrow); } JSTaggedValue FastRuntimeStub::FastGetProperty(JSThread *thread, JSHandle receiver, @@ -1170,11 +1168,11 @@ JSTaggedValue FastRuntimeStub::FastGetProperty(JSThread *thread, JSHandleGetEcmaVM()->GetFactory()->InternString(key)); + JSTaggedValue rawKey = key.GetTaggedValue(); + if (rawKey.IsString()) { + rawKey = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); } - result = FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), raw_key); + result = FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), rawKey); } } if (!result.IsHole()) { @@ -1187,25 +1185,25 @@ JSTaggedValue FastRuntimeStub::FastGetProperty(JSThread *thread, JSHandleIsDictionaryMode()) { JSHClass *cls = obj->GetJSHClass(); JSTaggedValue attrs = cls->GetLayout(); if (!attrs.IsNull()) { - LayoutInfo *layout_info = LayoutInfo::Cast(attrs.GetHeapObject()); - int prop_number = cls->NumberOfProps(); - int entry = layout_info->FindElementWithCache(thread, cls, key, prop_number); + LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetHeapObject()); + int propNumber = cls->NumberOfProps(); + int entry = layoutInfo->FindElementWithCache(thread, cls, key, propNumber); if (entry != -1) { - *attr = layout_info->GetAttr(entry); + *attr = layoutInfo->GetAttr(entry); ASSERT(entry == static_cast(attr->GetOffset())); - *index_or_entry = entry; + *indexOrEntry = entry; if (attr->IsInlinedProps()) { return obj->GetPropertyInlinedProps(entry); } - *index_or_entry -= cls->GetInlinedProperties(); - return properties->Get(*index_or_entry); + *indexOrEntry -= cls->GetInlinedProperties(); + return properties->Get(*indexOrEntry); } } return JSTaggedValue::Hole(); // properties == empty properties will return here. @@ -1215,7 +1213,7 @@ JSTaggedValue FastRuntimeStub::FindOwnProperty(JSThread *thread, JSObject *obj, GlobalDictionary *dict = GlobalDictionary::Cast(properties); int entry = dict->FindEntry(key); if (entry != -1) { - *index_or_entry = entry; + *indexOrEntry = entry; *attr = dict->GetAttributes(entry); return dict->GetValue(entry); } @@ -1225,7 +1223,7 @@ JSTaggedValue FastRuntimeStub::FindOwnProperty(JSThread *thread, JSObject *obj, NameDictionary *dict = NameDictionary::Cast(properties); int entry = dict->FindEntry(key); if (entry != -1) { - *index_or_entry = entry; + *indexOrEntry = entry; *attr = dict->GetAttributes(entry); return dict->GetValue(entry); } @@ -1233,10 +1231,10 @@ JSTaggedValue FastRuntimeStub::FindOwnProperty(JSThread *thread, JSObject *obj, return JSTaggedValue::Hole(); } -JSTaggedValue FastRuntimeStub::FindOwnElement(TaggedArray *elements, uint32_t index, bool is_dict, - PropertyAttributes *attr, uint32_t *index_or_entry) +JSTaggedValue FastRuntimeStub::FindOwnElement(TaggedArray *elements, uint32_t index, bool isDict, + PropertyAttributes *attr, uint32_t *indexOrEntry) { - if (!is_dict) { + if (!isDict) { if (elements->GetLength() <= index) { return JSTaggedValue::Hole(); } @@ -1244,14 +1242,14 @@ JSTaggedValue FastRuntimeStub::FindOwnElement(TaggedArray *elements, uint32_t in JSTaggedValue value = elements->Get(index); if (!value.IsHole()) { *attr = PropertyAttributes::Default(); - *index_or_entry = index; + *indexOrEntry = index; return value; } } else { NumberDictionary *dict = NumberDictionary::Cast(elements); int entry = dict->FindEntry(JSTaggedValue(static_cast(index))); if (entry != -1) { - *index_or_entry = entry; + *indexOrEntry = entry; *attr = dict->GetAttributes(entry); return dict->GetValue(entry); } @@ -1267,11 +1265,11 @@ JSTaggedValue FastRuntimeStub::FindOwnProperty(JSThread *thread, JSObject *obj, JSHClass *cls = obj->GetJSHClass(); JSTaggedValue attrs = cls->GetLayout(); if (!attrs.IsNull()) { - LayoutInfo *layout_info = LayoutInfo::Cast(attrs.GetHeapObject()); - int props_number = cls->NumberOfProps(); - int entry = layout_info->FindElementWithCache(thread, cls, key, props_number); + LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetHeapObject()); + int propsNumber = cls->NumberOfProps(); + int entry = layoutInfo->FindElementWithCache(thread, cls, key, propsNumber); if (entry != -1) { - PropertyAttributes attr(layout_info->GetAttr(entry)); + PropertyAttributes attr(layoutInfo->GetAttr(entry)); ASSERT(static_cast(attr.GetOffset()) == entry); return attr.IsInlinedProps() ? obj->GetPropertyInlinedProps(entry) : array->Get(entry - cls->GetInlinedProperties()); @@ -1333,10 +1331,10 @@ JSTaggedValue FastRuntimeStub::HasOwnProperty(JSThread *thread, JSObject *obj, J } JSTaggedValue FastRuntimeStub::GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSType js_type) + JSType jsType) { JSTaggedValue res = JSTaggedValue::Undefined(); - switch (js_type) { + switch (jsType) { case JSType::JS_ARRAY_LIST: res = JSArrayList::Cast(receiver.GetTaggedObject())->Get(thread, index); break; @@ -1347,10 +1345,10 @@ JSTaggedValue FastRuntimeStub::GetContainerProperty(JSThread *thread, JSTaggedVa } JSTaggedValue FastRuntimeStub::SetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value, JSType js_type) + JSTaggedValue value, JSType jsType) { JSTaggedValue res = JSTaggedValue::Undefined(); - switch (js_type) { + switch (jsType) { case JSType::JS_ARRAY_LIST: res = JSArrayList::Cast(receiver.GetTaggedObject())->Set(thread, index, value); break; diff --git a/runtime/interpreter/fast_runtime_stub.h b/runtime/interpreter/fast_runtime_stub.h index 41a5c4e84caf2b45c1937e24a69f3eb75b15a0b5..f0f1bc58555a10c11b23d1bac5127649fa1e93d5 100644 --- a/runtime/interpreter/fast_runtime_stub.h +++ b/runtime/interpreter/fast_runtime_stub.h @@ -35,7 +35,7 @@ public: static inline JSTaggedValue FastEqual(JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue FastTypeOf(JSThread *thread, JSTaggedValue obj); static inline bool FastStrictEqual(JSThread *thread, JSTaggedValue left, JSTaggedValue right); - static inline JSTaggedValue NewLexicalEnvDyn(JSThread *thread, ObjectFactory *factory, uint16_t num_vars); + static inline JSTaggedValue NewLexicalEnvDyn(JSThread *thread, ObjectFactory *factory, uint16_t numVars); static inline JSTaggedValue GetGlobalOwnProperty(JSTaggedValue receiver, JSTaggedValue key, bool *found); /* -------------- Special API For Multi-Language VM Begin ----------------- */ static inline bool IsSpecialIndexedObjForGet(JSTaggedValue obj); @@ -43,11 +43,11 @@ public: static inline JSTaggedValue GetElement(JSTaggedValue receiver, uint32_t index); static inline JSTaggedValue GetElementWithArray(JSTaggedValue receiver, uint32_t index); static inline bool SetElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value, - bool may_throw); + bool mayThrow); static inline bool SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool may_throw); + JSTaggedValue value, bool mayThrow); static inline bool SetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool may_throw); + JSTaggedValue value, bool mayThrow); // set property that is not accessor and is writable static inline void SetOwnPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, @@ -55,13 +55,13 @@ public: // set element that is not accessor and is writable static inline bool SetOwnElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value); static inline bool FastSetProperty(JSThread *thread, JSHandle receiver, JSHandle key, - JSHandle value, bool may_throw); + JSHandle value, bool mayThrow); static inline JSTaggedValue FastGetProperty(JSThread *thread, JSHandle receiver, JSHandle key); static inline JSTaggedValue FindOwnProperty(JSThread *thread, JSObject *obj, TaggedArray *properties, - JSTaggedValue key, PropertyAttributes *attr, uint32_t *index_or_entry); - static inline JSTaggedValue FindOwnElement(TaggedArray *elements, uint32_t index, bool is_dict, - PropertyAttributes *attr, uint32_t *index_or_entry); + JSTaggedValue key, PropertyAttributes *attr, uint32_t *indexOrEntry); + static inline JSTaggedValue FindOwnElement(TaggedArray *elements, uint32_t index, bool isDict, + PropertyAttributes *attr, uint32_t *indexOrEntry); static inline JSTaggedValue FindOwnProperty(JSThread *thread, JSObject *obj, JSTaggedValue key); static inline JSTaggedValue FindOwnElement(JSObject *obj, uint32_t index); @@ -98,28 +98,28 @@ public: JSHandle key); template static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index); - static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle obj_handle, - JSHandle key_handle, - JSHandle value_handle, PropertyAttributes attr); + static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle objHandle, + JSHandle keyHandle, + JSHandle valueHandle, PropertyAttributes attr); private: friend class ICRuntimeStub; - static inline bool IsSpecialIndexedObj(JSType js_type); - static inline bool IsSpecialReceiverObj(JSType js_type); - static inline bool IsSpecialContainer(JSType js_type); + static inline bool IsSpecialIndexedObj(JSType jsType); + static inline bool IsSpecialReceiverObj(JSType jsType); + static inline bool IsSpecialContainer(JSType jsType); static inline uint32_t TryToElementsIndex(JSTaggedValue key); static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue value); static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, - JSTaggedValue accessor_value); - static inline bool ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessor_value, + JSTaggedValue accessorValue); + static inline bool ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessorValue, PropertyAttributes attr); static inline JSTaggedValue AddPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value); static inline JSTaggedValue GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSType js_type); + JSType jsType); static inline JSTaggedValue SetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value, JSType js_type); + JSTaggedValue value, JSType jsType); }; } // namespace panda::ecmascript diff --git a/runtime/interpreter/interpreter-inl.h b/runtime/interpreter/interpreter-inl.h index 9c19dcd3bd5893f931e8cfd97b9e2cce2119a9b7..ed15ffebef9f19b3ce4f4a1c1e3083dcd752847b 100644 --- a/runtime/interpreter/interpreter-inl.h +++ b/runtime/interpreter/interpreter-inl.h @@ -39,127 +39,127 @@ class JSInvokeHelper : public InvokeHelperDynamic { public: ALWAYS_INLINE inline static void InterpreterExecute(ManagedThread *thread, const uint8_t *pc, Frame *frame) { - JSThread *js_thread = JSThread::Cast(thread); + JSThread *jsThread = JSThread::Cast(thread); // Get current functional object - JSTaggedValue func = js_thread->GetFunctionalObject(); - ObjectHeader *lexical_env = js_thread->GetInvocationLexicalEnv().GetHeapObject(); + JSTaggedValue func = jsThread->GetFunctionalObject(); + ObjectHeader *lexicalEnv = jsThread->GetInvocationLexicalEnv().GetHeapObject(); - JSFunction *js_function = JSFunction::Cast(func.GetHeapObject()); - ObjectHeader *constant_pool = js_function->GetConstantPool().GetHeapObject(); + JSFunction *jsFunction = JSFunction::Cast(func.GetHeapObject()); + ObjectHeader *constantPool = jsFunction->GetConstantPool().GetHeapObject(); // Init EcmascriptEnvironment - EcmascriptEnvironment *new_env = JSFrame::GetJSEnv(frame); - new (new_env) EcmascriptEnvironment(constant_pool, lexical_env, func.GetHeapObject()); + EcmascriptEnvironment *newEnv = JSFrame::GetJSEnv(frame); + new (newEnv) EcmascriptEnvironment(constantPool, lexicalEnv, func.GetHeapObject()); InvokeHelperDynamic::InterpreterExecute(thread, pc, frame); } ALWAYS_INLINE inline static coretypes::TaggedValue CompiledCodeExecute(ManagedThread *thread, Method *method, - uint32_t num_args, + uint32_t numArgs, coretypes::TaggedValue *args) { - auto ret = InvokeHelperDynamic::CompiledCodeExecute(thread, method, num_args, args); + auto ret = InvokeHelperDynamic::CompiledCodeExecute(thread, method, numArgs, args); return ret; } - ALWAYS_INLINE static Frame *CreateFrame(ManagedThread *thread, uint32_t nregs_size, Method *method, Frame *prev, - uint32_t nregs, uint32_t num_actual_args) + ALWAYS_INLINE static Frame *CreateFrame(ManagedThread *thread, uint32_t nregsSize, Method *method, Frame *prev, + uint32_t nregs, uint32_t numActualArgs) { - return ::panda::CreateFrame(thread->GetStackFrameAllocator(), nregs_size, method, prev, nregs, - num_actual_args); + return ::panda::CreateFrame(thread->GetStackFrameAllocator(), nregsSize, method, prev, nregs, + numActualArgs); } }; JSTaggedValue EcmaInterpreter::ExecuteNative(EcmaRuntimeCallInfo *info) { JSThread *thread = info->GetThread(); - uint32_t num_args = info->GetInternalArgsNum(); - JSTaggedValue fn_object = info->GetFunction().GetTaggedValue(); + uint32_t numArgs = info->GetInternalArgsNum(); + JSTaggedValue fnObject = info->GetFunction().GetTaggedValue(); ASSERT(!thread->HasPendingException()); - Frame *current_frame = thread->GetCurrentFrame(); - bool is_compiled = thread->IsCurrentFrameCompiled(); + Frame *currentFrame = thread->GetCurrentFrame(); + bool isCompiled = thread->IsCurrentFrameCompiled(); // Boundary frame expected for c2i call - ASSERT(!is_compiled || StackWalker::IsBoundaryFrame(current_frame)); + ASSERT(!isCompiled || StackWalker::IsBoundaryFrame(currentFrame)); - Method *method = ECMAObject::Cast(fn_object.GetHeapObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(fnObject.GetHeapObject())->GetCallTarget(); ASSERT(method->GetNumVregs() == 0); - uint32_t num_declared_args = method->GetNumArgs(); - uint32_t nregs = std::max(num_declared_args, num_args); - Frame *frame = JSFrame::CreateNativeFrame(thread, method, current_frame, nregs, num_args); - JSFrame::InitNativeFrameArgs(frame, num_args, info->GetInternalArgs()); + uint32_t numDeclaredArgs = method->GetNumArgs(); + uint32_t nregs = std::max(numDeclaredArgs, numArgs); + Frame *frame = JSFrame::CreateNativeFrame(thread, method, currentFrame, nregs, numArgs); + JSFrame::InitNativeFrameArgs(frame, numArgs, info->GetInternalArgs()); thread->SetCurrentFrameIsCompiled(false); thread->SetCurrentFrame(frame); - JSTaggedValue ret_value = JSFrame::ExecuteNativeMethod(thread, frame, method, num_args); + JSTaggedValue retValue = JSFrame::ExecuteNativeMethod(thread, frame, method, numArgs); ASSERT(thread->GetCurrentFrame() == frame); - thread->SetCurrentFrameIsCompiled(is_compiled); + thread->SetCurrentFrameIsCompiled(isCompiled); thread->SetCurrentFrame(frame->GetPrevFrame()); JSFrame::DestroyNativeFrame(thread, frame); - return ret_value; + return retValue; } -JSTaggedValue EcmaInterpreter::ExecuteInvoke(EcmaRuntimeCallInfo *info, JSTaggedValue fn_object) +JSTaggedValue EcmaInterpreter::ExecuteInvoke(EcmaRuntimeCallInfo *info, JSTaggedValue fnObject) { JSThread *thread = info->GetThread(); ASSERT(!thread->HasPendingException()); - ASSERT(fn_object.IsJSFunction()); + ASSERT(fnObject.IsJSFunction()); - JSFunction *js_function = JSFunction::Cast(fn_object.GetHeapObject()); - Method *method = js_function->GetCallTarget(); + JSFunction *jsFunction = JSFunction::Cast(fnObject.GetHeapObject()); + Method *method = jsFunction->GetCallTarget(); // Set current functional object to thread so we can get it from InvokeHelper - thread->SetFunctionalObject(fn_object); - thread->SetInvocationLexicalEnv(js_function->GetLexicalEnv()); - TaggedValue ret_value = + thread->SetFunctionalObject(fnObject); + thread->SetInvocationLexicalEnv(jsFunction->GetLexicalEnv()); + TaggedValue retValue = method->InvokeDyn(thread, info->GetInternalArgsNum(), info->GetInternalArgs()); - return JSTaggedValue(ret_value); + return JSTaggedValue(retValue); } -JSTaggedValue EcmaInterpreter::ExecuteInEnv(EcmaRuntimeCallInfo *info, JSTaggedValue fn_object) +JSTaggedValue EcmaInterpreter::ExecuteInEnv(EcmaRuntimeCallInfo *info, JSTaggedValue fnObject) { JSThread *thread = info->GetThread(); - [[maybe_unused]] HandleStorageCheck handle_storage_check(thread); + [[maybe_unused]] HandleStorageCheck handleStorageCheck(thread); if (UNLIKELY(thread->HasPendingException())) { // NOTE(vpukhov): replace with assert return JSTaggedValue::Undefined(); } - if (UNLIKELY(!fn_object.IsCallable())) { // NOTE(vpukhov): replace with assert + if (UNLIKELY(!fnObject.IsCallable())) { // NOTE(vpukhov): replace with assert JSHandle error = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "is not callable"); thread->SetException(error.GetTaggedValue()); return JSTaggedValue::Exception(); } - Method *method = ECMAObject::Cast(fn_object.GetHeapObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(fnObject.GetHeapObject())->GetCallTarget(); if (method->IsNative()) { - auto current_frame = thread->GetCurrentFrame(); + auto currentFrame = thread->GetCurrentFrame(); - if (thread->IsCurrentFrameCompiled() && !StackWalker::IsBoundaryFrame(current_frame)) { - C2IBridge bridge {0, reinterpret_cast(current_frame), COMPILED_CODE_TO_INTERPRETER, + if (thread->IsCurrentFrameCompiled() && !StackWalker::IsBoundaryFrame(currentFrame)) { + C2IBridge bridge {0, reinterpret_cast(currentFrame), COMPILED_CODE_TO_INTERPRETER, thread->GetNativePc()}; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) thread->SetCurrentFrame(reinterpret_cast(&bridge.v[1])); - JSTaggedValue ret_val = ExecuteNative(info); + JSTaggedValue retVal = ExecuteNative(info); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ASSERT(thread->GetCurrentFrame() == reinterpret_cast(&bridge.v[1])); thread->SetCurrentFrameIsCompiled(true); - thread->SetCurrentFrame(current_frame); - return ret_val; + thread->SetCurrentFrame(currentFrame); + return retVal; } return ExecuteNative(info); } - return ExecuteInvoke(info, fn_object); + return ExecuteInvoke(info, fnObject); } JSTaggedValue EcmaInterpreter::Execute(EcmaRuntimeCallInfo *info) @@ -176,23 +176,23 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH JSHandle func = JSHandle::Cast(JSHandle(thread, context->GetMethod())); Method *method = func->GetCallTarget(); - JSTaggedValue pc_offset = context->GetBCOffset(); - auto format = method->GetPandaFile()->GetHeader()->quickened_flag != 0U ? BytecodeInstruction::Format::V8 - : BytecodeInstruction::Format::PREF_V8; - const uint8_t *resume_pc = + JSTaggedValue pcOffset = context->GetBCOffset(); + auto format = method->GetPandaFile()->GetHeader()->quickenedFlag != 0U ? BytecodeInstruction::Format::V8 + : BytecodeInstruction::Format::PREF_V8; + const uint8_t *resumePc = // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - method->GetInstructions() + static_cast(pc_offset.GetInt()) + BytecodeInstruction::Size(format); + method->GetInstructions() + static_cast(pcOffset.GetInt()) + BytecodeInstruction::Size(format); auto *acc = reinterpret_cast(ToUintPtr(*context) + context->GetAccOffset()); uint32_t nregs = context->GetNRegs().GetInt(); - TaggedArray *regs_array = TaggedArray::Cast(context->GetRegsArray().GetHeapObject()); - auto *regs = reinterpret_cast(regs_array->GetData()); - ASSERT(nregs == regs_array->GetLength()); + TaggedArray *regsArray = TaggedArray::Cast(context->GetRegsArray().GetHeapObject()); + auto *regs = reinterpret_cast(regsArray->GetData()); + ASSERT(nregs == regsArray->GetLength()); // Set current functional object to thread so we can get it from InvokeHelper thread->SetFunctionalObject(func.GetTaggedValue()); thread->SetInvocationLexicalEnv(context->GetLexicalEnv()); - TaggedValue value = method->InvokeContext(thread, resume_pc, acc, nregs, regs); + TaggedValue value = method->InvokeContext(thread, resumePc, acc, nregs, regs); return JSTaggedValue(value); } diff --git a/runtime/interpreter/interpreter.h b/runtime/interpreter/interpreter.h index 73627f02ade39454c8a6ff21befe6780c39e4cb5..1565e1ed8e10cc57654c747c86ae5e0f0a066e93 100644 --- a/runtime/interpreter/interpreter.h +++ b/runtime/interpreter/interpreter.h @@ -30,8 +30,8 @@ class GeneratorContext; class EcmaInterpreter { public: static inline JSTaggedValue Execute(EcmaRuntimeCallInfo *info); - static inline JSTaggedValue ExecuteInEnv(EcmaRuntimeCallInfo *info, JSTaggedValue fn_object); - static inline JSTaggedValue ExecuteInvoke(EcmaRuntimeCallInfo *info, JSTaggedValue fn_object); + static inline JSTaggedValue ExecuteInEnv(EcmaRuntimeCallInfo *info, JSTaggedValue fnObject); + static inline JSTaggedValue ExecuteInvoke(EcmaRuntimeCallInfo *info, JSTaggedValue fnObject); static inline JSTaggedValue ExecuteNative(EcmaRuntimeCallInfo *info); static inline JSTaggedValue GeneratorReEnterInterpreter(JSThread *thread, JSHandle context); static inline void ChangeGenContext(JSThread *thread, JSHandle context); @@ -40,16 +40,16 @@ public: static inline uint8_t ReadU8(const uint8_t *pc, uint32_t offset); static inline void InitStackFrame(JSThread *thread); static inline uint32_t FindCatchBlock(JSMethod *caller, uint32_t pc); - static inline size_t GetJumpSizeAfterCall(const uint8_t *prev_pc); + static inline size_t GetJumpSizeAfterCall(const uint8_t *prevPc); static inline JSTaggedValue GetRuntimeProfileTypeInfo(JSTaggedType *sp); static inline bool UpdateHotnessCounter(JSThread *thread, JSTaggedType *sp, JSTaggedValue acc, int32_t offset); - static inline void InterpreterFrameCopyArgs(JSTaggedType *new_sp, uint32_t num_vregs, uint32_t num_actual_args, - uint32_t num_declared_args, bool have_extra_args = true); + static inline void InterpreterFrameCopyArgs(JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs, + uint32_t numDeclaredArgs, bool haveExtraArgs = true); static inline void NotifyBytecodePcChanged(JSThread *thread); static inline JSTaggedValue GetThisFunction(JSTaggedType *sp); static inline JSTaggedValue GetNewTarget(JSTaggedType *sp); - static inline uint32_t GetNumArgs(JSTaggedType *sp, uint32_t rest_idx, uint32_t &start_idx); + static inline uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); }; enum EcmaOpcode { diff --git a/runtime/interpreter/js_decode_call_instr.h b/runtime/interpreter/js_decode_call_instr.h index b78da21b6c4306586f764ef5f9be5e7ce501937b..babdf7655b113a1a362d075fdd196defa5a44fc3 100644 --- a/runtime/interpreter/js_decode_call_instr.h +++ b/runtime/interpreter/js_decode_call_instr.h @@ -100,9 +100,9 @@ ALWAYS_INLINE inline uint16_t JSGetCalleRangeStartDyn([[maybe_unused]] BytecodeI } template -ALWAYS_INLINE inline static void JSCopyArgumets(JSThread *thread, Frame *prev_frame, uint64_t raw_fn_object, - BytecodeInstruction prev_inst, Frame *new_frame, uint32_t num_vregs, - uint32_t num_actual_args) +ALWAYS_INLINE inline static void JSCopyArgumets(JSThread *thread, Frame *prevFrame, uint64_t rawFnObject, + BytecodeInstruction prevInst, Frame *newFrame, uint32_t numVregs, + uint32_t numActualArgs) { // ecma.call0dyn // ecma.call1dyn @@ -145,10 +145,10 @@ ALWAYS_INLINE inline static void JSCopyArgumets(JSThread *thread, Frame *prev_fr using R = BytecodeInstructionResolver; constexpr auto OP = R::template Get(); - ASSERT(num_actual_args >= js_method_args::FIRST_ARG_IDX); - new_frame->GetVReg(num_vregs + js_method_args::FUNC_IDX).SetValue(raw_fn_object); + ASSERT(numActualArgs >= js_method_args::FIRST_ARG_IDX); + newFrame->GetVReg(numVregs + js_method_args::FUNC_IDX).SetValue(rawFnObject); if constexpr (OP != R::template Get()) { - new_frame->GetVReg(num_vregs + js_method_args::NEW_TARGET_IDX).SetValue(JSTaggedValue::VALUE_UNDEFINED); + newFrame->GetVReg(numVregs + js_method_args::NEW_TARGET_IDX).SetValue(JSTaggedValue::VALUE_UNDEFINED); } if constexpr (OP == R::template Get() || @@ -156,92 +156,86 @@ ALWAYS_INLINE inline static void JSCopyArgumets(JSThread *thread, Frame *prev_fr OP == R::template Get() || OP == R::template Get() || OP == R::template Get()) { - JSTaggedValue fn_object(raw_fn_object); - uint64_t this_arg = JSTaggedValue::VALUE_UNDEFINED; - if (fn_object.IsJSFunction() && !JSFunction::Cast(fn_object.GetHeapObject())->IsStrict()) { - this_arg = thread->GetGlobalObject().GetRawData(); + JSTaggedValue fnObject(rawFnObject); + uint64_t thisArg = JSTaggedValue::VALUE_UNDEFINED; + if (fnObject.IsJSFunction() && !JSFunction::Cast(fnObject.GetHeapObject())->IsStrict()) { + thisArg = thread->GetGlobalObject().GetRawData(); } - new_frame->GetVReg(num_vregs + js_method_args::THIS_IDX).SetValue(this_arg); + newFrame->GetVReg(numVregs + js_method_args::THIS_IDX).SetValue(thisArg); } if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX); // Do nothing } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX + 1); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 0) - .SetValue(prev_frame->GetAccAsVReg().GetValue()); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX + 1); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 0).SetValue(prevFrame->GetAccAsVReg().GetValue()); } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX + 2); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 0) = prev_frame->GetVReg(prev_inst.GetVReg(1)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 1) - .SetValue(prev_frame->GetAccAsVReg().GetValue()); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX + 2); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 0) = prevFrame->GetVReg(prevInst.GetVReg(1)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 1).SetValue(prevFrame->GetAccAsVReg().GetValue()); } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX + 3); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 0) = prev_frame->GetVReg(prev_inst.GetVReg(1)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 1) = prev_frame->GetVReg(prev_inst.GetVReg(2)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 2) - .SetValue(prev_frame->GetAccAsVReg().GetValue()); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX + 3); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 0) = prevFrame->GetVReg(prevInst.GetVReg(1)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 1) = prevFrame->GetVReg(prevInst.GetVReg(2)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 2).SetValue(prevFrame->GetAccAsVReg().GetValue()); } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - uint16_t prev_v0 = JSGetCalleRangeStartDyn(prev_inst); - for (size_t i = 0; i < (num_actual_args - js_method_args::FIRST_ARG_IDX); ++i) { - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + i) = prev_frame->GetVReg(prev_v0 + 1 + i); + uint16_t prevV0 = JSGetCalleRangeStartDyn(prevInst); + for (size_t i = 0; i < (numActualArgs - js_method_args::FIRST_ARG_IDX); ++i) { + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + i) = prevFrame->GetVReg(prevV0 + 1 + i); } } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX); - new_frame->GetVReg(num_vregs + js_method_args::THIS_IDX).SetValue(prev_frame->GetAccAsVReg().GetValue()); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX); + newFrame->GetVReg(numVregs + js_method_args::THIS_IDX).SetValue(prevFrame->GetAccAsVReg().GetValue()); } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX + 1); - new_frame->GetVReg(num_vregs + js_method_args::THIS_IDX) = prev_frame->GetVReg(prev_inst.GetVReg(1)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 0) - .SetValue(prev_frame->GetAccAsVReg().GetValue()); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX + 1); + newFrame->GetVReg(numVregs + js_method_args::THIS_IDX) = prevFrame->GetVReg(prevInst.GetVReg(1)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 0).SetValue(prevFrame->GetAccAsVReg().GetValue()); } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX + 2); - new_frame->GetVReg(num_vregs + js_method_args::THIS_IDX) = prev_frame->GetVReg(prev_inst.GetVReg(1)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 0) = prev_frame->GetVReg(prev_inst.GetVReg(2)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 1) - .SetValue(prev_frame->GetAccAsVReg().GetValue()); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX + 2); + newFrame->GetVReg(numVregs + js_method_args::THIS_IDX) = prevFrame->GetVReg(prevInst.GetVReg(1)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 0) = prevFrame->GetVReg(prevInst.GetVReg(2)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 1).SetValue(prevFrame->GetAccAsVReg().GetValue()); } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - ASSERT(num_actual_args == js_method_args::FIRST_ARG_IDX + 3); - new_frame->GetVReg(num_vregs + js_method_args::THIS_IDX) = prev_frame->GetVReg(prev_inst.GetVReg(1)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 0) = prev_frame->GetVReg(prev_inst.GetVReg(2)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 1) = prev_frame->GetVReg(prev_inst.GetVReg(3)); - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + 2) - .SetValue(prev_frame->GetAccAsVReg().GetValue()); + ASSERT(numActualArgs == js_method_args::FIRST_ARG_IDX + 3); + newFrame->GetVReg(numVregs + js_method_args::THIS_IDX) = prevFrame->GetVReg(prevInst.GetVReg(1)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 0) = prevFrame->GetVReg(prevInst.GetVReg(2)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 1) = prevFrame->GetVReg(prevInst.GetVReg(3)); + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + 2).SetValue(prevFrame->GetAccAsVReg().GetValue()); } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - uint16_t prev_v0 = JSGetCalleRangeStartDyn(prev_inst); - new_frame->GetVReg(num_vregs + js_method_args::THIS_IDX) = prev_frame->GetVReg(prev_v0 + 1); - for (size_t i = 0; i < (num_actual_args - js_method_args::FIRST_ARG_IDX); ++i) { - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + i) = prev_frame->GetVReg(prev_v0 + 2 + i); + uint16_t prevV0 = JSGetCalleRangeStartDyn(prevInst); + newFrame->GetVReg(numVregs + js_method_args::THIS_IDX) = prevFrame->GetVReg(prevV0 + 1); + for (size_t i = 0; i < (numActualArgs - js_method_args::FIRST_ARG_IDX); ++i) { + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + i) = prevFrame->GetVReg(prevV0 + 2 + i); } } else if constexpr (OP == R::template Get()) { static_assert(FORMAT == R::template Get()); - uint16_t prev_v0 = JSGetCalleRangeStartDyn(prev_inst); - new_frame->GetVReg(num_vregs + js_method_args::NEW_TARGET_IDX) = prev_frame->GetVReg(prev_v0 + 1); - for (size_t i = 0; i < (num_actual_args - js_method_args::FIRST_ARG_IDX); ++i) { - new_frame->GetVReg(num_vregs + js_method_args::FIRST_ARG_IDX + i) = prev_frame->GetVReg(prev_v0 + 2 + i); + uint16_t prevV0 = JSGetCalleRangeStartDyn(prevInst); + newFrame->GetVReg(numVregs + js_method_args::NEW_TARGET_IDX) = prevFrame->GetVReg(prevV0 + 1); + for (size_t i = 0; i < (numActualArgs - js_method_args::FIRST_ARG_IDX); ++i) { + newFrame->GetVReg(numVregs + js_method_args::FIRST_ARG_IDX + i) = prevFrame->GetVReg(prevV0 + 2 + i); } } else { enum { IMPOSSIBLE_CASE = false }; static_assert(IMPOSSIBLE_CASE, "Impossible case"); } - for (size_t i = num_vregs + num_actual_args; i < new_frame->GetSize(); ++i) { - new_frame->GetVReg(i).SetValue(JSTaggedValue::VALUE_UNDEFINED); + for (size_t i = numVregs + numActualArgs; i < newFrame->GetSize(); ++i) { + newFrame->GetVReg(i).SetValue(JSTaggedValue::VALUE_UNDEFINED); } } } // namespace panda::ecmascript diff --git a/runtime/interpreter/js_frame-inl.h b/runtime/interpreter/js_frame-inl.h index 3f529b5e348afba1cd2eb5bca810e94bb62f1b6b..2407339cc84d555ff5fc40da2d31374990b35279 100644 --- a/runtime/interpreter/js_frame-inl.h +++ b/runtime/interpreter/js_frame-inl.h @@ -13,59 +13,58 @@ namespace panda::ecmascript { /* static */ -inline Frame *JSFrame::CreateNativeFrame(JSThread *js_thread, Method *method, Frame *prev_frame, uint32_t nregs, - uint32_t num_actual_args) +inline Frame *JSFrame::CreateNativeFrame(JSThread *jsThread, Method *method, Frame *prevFrame, uint32_t nregs, + uint32_t numActualArgs) { - ASSERT(js_thread == JSThread::GetCurrent()); + ASSERT(jsThread == JSThread::GetCurrent()); - Frame *new_frame = - CreateFrame(js_thread->GetStackFrameAllocator(), nregs, method, prev_frame, nregs, num_actual_args); - if (UNLIKELY(new_frame == nullptr)) { + Frame *newFrame = CreateFrame(jsThread->GetStackFrameAllocator(), nregs, method, prevFrame, nregs, numActualArgs); + if (UNLIKELY(newFrame == nullptr)) { return nullptr; } - LOG_IF(new_frame == nullptr, FATAL, ECMASCRIPT) << "Cannot allocate native frame"; - new_frame->SetInvoke(); - new_frame->SetDynamic(); - return new_frame; + LOG_IF(newFrame == nullptr, FATAL, ECMASCRIPT) << "Cannot allocate native frame"; + newFrame->SetInvoke(); + newFrame->SetDynamic(); + return newFrame; } /* static */ -inline void JSFrame::DestroyNativeFrame(JSThread *js_thread, Frame *frame) +inline void JSFrame::DestroyNativeFrame(JSThread *jsThread, Frame *frame) { - ASSERT(js_thread == JSThread::GetCurrent()); - DestroyFrame(js_thread->GetStackFrameAllocator(), frame); + ASSERT(jsThread == JSThread::GetCurrent()); + DestroyFrame(jsThread->GetStackFrameAllocator(), frame); } /* static */ -inline void JSFrame::InitNativeFrameArgs(Frame *frame, uint32_t num_args, const JSTaggedValue *args) +inline void JSFrame::InitNativeFrameArgs(Frame *frame, uint32_t numArgs, const JSTaggedValue *args) { - uint32_t num_actual_args = frame->GetNumActualArgs(); - ASSERT(num_args <= num_actual_args); + uint32_t numActualArgs = frame->GetNumActualArgs(); + ASSERT(numArgs <= numActualArgs); - for (uint32_t i = 0; i < num_args; ++i) { + for (uint32_t i = 0; i < numArgs; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) frame->GetVReg(i).SetValue(args[i].GetRawData()); } - for (uint32_t i = num_args; i < num_actual_args; ++i) { + for (uint32_t i = numArgs; i < numActualArgs; ++i) { frame->GetVReg(i).SetValue(JSTaggedValue::VALUE_UNDEFINED); } frame->SetInvoke(); } /* static */ -inline JSTaggedValue JSFrame::ExecuteNativeMethod(JSThread *js_thread, Frame *frame, Method *method, - uint32_t num_actual_args) +inline JSTaggedValue JSFrame::ExecuteNativeMethod(JSThread *jsThread, Frame *frame, Method *method, + uint32_t numActualArgs) { - ASSERT(js_thread == JSThread::GetCurrent()); - if (UNLIKELY((!js_thread->StackOverflowCheck()))) { + ASSERT(jsThread == JSThread::GetCurrent()); + if (UNLIKELY((!jsThread->StackOverflowCheck()))) { return JSTaggedValue::Exception(); } - [[maybe_unused]] HandleStorageCheck handle_storage_check(js_thread); - EcmaRuntimeCallInfo call_info(js_thread, num_actual_args, reinterpret_cast(&frame->GetVReg(0))); - auto ecma_entry_point = reinterpret_cast(method->GetNativePointer()); - JSTaggedValue ret_value = ecma_entry_point(&call_info); + [[maybe_unused]] HandleStorageCheck handleStorageCheck(jsThread); + EcmaRuntimeCallInfo callInfo(jsThread, numActualArgs, reinterpret_cast(&frame->GetVReg(0))); + auto ecmaEntryPoint = reinterpret_cast(method->GetNativePointer()); + JSTaggedValue retValue = ecmaEntryPoint(&callInfo); - return ret_value; + return retValue; } } // namespace panda::ecmascript diff --git a/runtime/interpreter/js_frame.h b/runtime/interpreter/js_frame.h index df13b36d5382d61301507583bfeb5c8d71c684bb..3c548212401e0ba4387ff46112d95b7dcc30aa9a 100644 --- a/runtime/interpreter/js_frame.h +++ b/runtime/interpreter/js_frame.h @@ -22,13 +22,12 @@ using JSEnv = EcmascriptEnvironment; class JSFrame { public: - static Frame *CreateNativeFrame(JSThread *js_thread, Method *method, Frame *prev_frame, uint32_t nregs, - uint32_t num_actual_args); - static void DestroyNativeFrame(JSThread *js_thread, Frame *frame); + static Frame *CreateNativeFrame(JSThread *jsThread, Method *method, Frame *prevFrame, uint32_t nregs, + uint32_t numActualArgs); + static void DestroyNativeFrame(JSThread *jsThread, Frame *frame); - static void InitNativeFrameArgs(Frame *frame, uint32_t num_args, const JSTaggedValue *args); - static JSTaggedValue ExecuteNativeMethod(JSThread *js_thread, Frame *frame, Method *method, - uint32_t num_actual_args); + static void InitNativeFrameArgs(Frame *frame, uint32_t numArgs, const JSTaggedValue *args); + static JSTaggedValue ExecuteNativeMethod(JSThread *jsThread, Frame *frame, Method *method, uint32_t numActualArgs); static JSEnv *GetJSEnv(const Frame *frame) { diff --git a/runtime/interpreter/slow_runtime_helper.cpp b/runtime/interpreter/slow_runtime_helper.cpp index cf74c0c217b93d4d5a6845c2d87c1f921f6e1f15..b57ad109c8483c61e1d0c67607ad0af85eeb43eb 100644 --- a/runtime/interpreter/slow_runtime_helper.cpp +++ b/runtime/interpreter/slow_runtime_helper.cpp @@ -36,30 +36,30 @@ JSTaggedValue GetGlobalObject(JSThread *thread) JSTaggedValue SlowRuntimeHelper::CallBoundFunction(EcmaRuntimeCallInfo *info) { JSThread *thread = info->GetThread(); - JSHandle bound_func(info->GetFunction()); - JSHandle target_func(thread, bound_func->GetBoundTarget()); - if (target_func->IsClassConstructor()) { + JSHandle boundFunc(info->GetFunction()); + JSHandle targetFunc(thread, boundFunc->GetBoundTarget()); + if (targetFunc->IsClassConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "class constructor cannot called without 'new'", JSTaggedValue::Exception()); } - JSHandle bound_args(thread, bound_func->GetBoundArguments()); - const uint32_t bound_length = bound_args->GetLength(); - const uint32_t args_length = info->GetArgsNumber(); + JSHandle boundArgs(thread, boundFunc->GetBoundArguments()); + const uint32_t boundLength = boundArgs->GetLength(); + const uint32_t argsLength = info->GetArgsNumber(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - auto runtime_info = NewRuntimeCallInfo(thread, JSHandle(target_func), info->GetThis(), undefined, - bound_length + args_length); + auto runtimeInfo = NewRuntimeCallInfo(thread, JSHandle(targetFunc), info->GetThis(), undefined, + boundLength + argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (bound_length != 0) { + if (boundLength != 0) { // 0 ~ boundLength is boundArgs; boundLength ~ argsLength is args of EcmaRuntimeCallInfo. - runtime_info->SetCallArg(bound_length, bound_args->GetData()); + runtimeInfo->SetCallArg(boundLength, boundArgs->GetData()); } - if (args_length != 0) { - runtime_info->SetCallArg( - args_length, reinterpret_cast(info->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS)), - bound_length); + if (argsLength != 0) { + runtimeInfo->SetCallArg( + argsLength, reinterpret_cast(info->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS)), + boundLength); } - return EcmaInterpreter::Execute(runtime_info.Get()); + return EcmaInterpreter::Execute(runtimeInfo.Get()); } JSTaggedValue SlowRuntimeHelper::NewObject(EcmaRuntimeCallInfo *info) @@ -78,9 +78,9 @@ JSTaggedValue SlowRuntimeHelper::NewObject(EcmaRuntimeCallInfo *info) } if (func->IsJSProxy()) { - JSTaggedValue js_obj = JSProxy::ConstructInternal(info); + JSTaggedValue jsObj = JSProxy::ConstructInternal(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return js_obj; + return jsObj; } THROW_TYPE_ERROR_AND_RETURN(thread, "Constructed NonConstructable", JSTaggedValue::Exception()); } @@ -95,15 +95,15 @@ void SlowRuntimeHelper::SaveFrameToContext(JSThread *thread, JSHandleGetCurrentFrame(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); uint32_t nregs = frame->GetSize(); - JSHandle regs_array = factory->NewTaggedArray(nregs); + JSHandle regsArray = factory->NewTaggedArray(nregs); for (uint32_t i = 0; i < nregs; i++) { - regs_array->Set(thread, i, VRegAsTaggedValue(frame->GetVReg(i))); + regsArray->Set(thread, i, VRegAsTaggedValue(frame->GetVReg(i))); } - auto num_vregs = frame->GetMethod()->GetNumVregs(); - auto func = VRegAsTaggedValue(frame->GetVReg(num_vregs)); + auto numVregs = frame->GetMethod()->GetNumVregs(); + auto func = VRegAsTaggedValue(frame->GetVReg(numVregs)); auto acc = VRegAsTaggedValue(frame->GetAcc()); - context->SetRegsArray(thread, regs_array.GetTaggedValue()); + context->SetRegsArray(thread, regsArray.GetTaggedValue()); context->SetMethod(thread, func); context->SetAcc(thread, acc); @@ -112,8 +112,8 @@ void SlowRuntimeHelper::SaveFrameToContext(JSThread *thread, JSHandleSetLexicalEnv(thread, JSTaggedValue(JSFrame::GetJSEnv(frame)->GetLexicalEnv())); } -JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHandle new_tgt, - JSHandle pre_args, uint32_t args_count, JSTaggedType *stkargs) +JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHandle newTgt, + JSHandle preArgs, uint32_t argsCount, JSTaggedType *stkargs) { if (!ctor->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is false", JSTaggedValue::Exception()); @@ -122,67 +122,67 @@ JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHa JSHandle obj(thread, JSTaggedValue::Undefined()); if (ctor->IsBase()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - obj = JSHandle(factory->NewJSObjectByConstructor(ctor, new_tgt)); + obj = JSHandle(factory->NewJSObjectByConstructor(ctor, newTgt)); } ASSERT(ctor->GetCallTarget()); - uint32_t pre_args_size = pre_args->IsUndefined() ? 0 : JSHandle::Cast(pre_args)->GetLength(); - const uint32_t size = pre_args_size + args_count; - auto info = NewRuntimeCallInfo(thread, ctor, obj, new_tgt, size); + uint32_t preArgsSize = preArgs->IsUndefined() ? 0 : JSHandle::Cast(preArgs)->GetLength(); + const uint32_t size = preArgsSize + argsCount; + auto info = NewRuntimeCallInfo(thread, ctor, obj, newTgt, size); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // add preArgs when boundfunction is encountered - uint32_t arg_idx = 0; - if (pre_args_size > 0) { - JSHandle tga_pre_args = JSHandle::Cast(pre_args); - for (uint32_t i = 0; i < pre_args_size; ++i) { - info->SetCallArg(arg_idx++, tga_pre_args->Get(i)); + uint32_t argIdx = 0; + if (preArgsSize > 0) { + JSHandle tgaPreArgs = JSHandle::Cast(preArgs); + for (uint32_t i = 0; i < preArgsSize; ++i) { + info->SetCallArg(argIdx++, tgaPreArgs->Get(i)); } } - for (uint32_t i = 0; i < args_count; ++i) { + for (uint32_t i = 0; i < argsCount; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - info->SetCallArg(arg_idx++, JSTaggedValue(stkargs[i])); + info->SetCallArg(argIdx++, JSTaggedValue(stkargs[i])); } - JSTaggedValue result_value = EcmaInterpreter::Execute(info.Get()); + JSTaggedValue resultValue = EcmaInterpreter::Execute(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9.3.2 [[Construct]] (argumentsList, new_target) - if (result_value.IsECMAObject()) { - return result_value; + if (resultValue.IsECMAObject()) { + return resultValue; } if (ctor->IsBase()) { return obj.GetTaggedValue(); } - if (!result_value.IsUndefined()) { + if (!resultValue.IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "function is non-constructor", JSTaggedValue::Exception()); } return obj.GetTaggedValue(); } -JSTaggedValue ConstructBoundFunction(JSThread *thread, JSHandle ctor, JSHandle new_tgt, - JSHandle pre_args, uint32_t args_count, JSTaggedType *stkargs) +JSTaggedValue ConstructBoundFunction(JSThread *thread, JSHandle ctor, JSHandle newTgt, + JSHandle preArgs, uint32_t argsCount, JSTaggedType *stkargs) { JSHandle target(thread, ctor->GetBoundTarget()); ASSERT(target->IsConstructor()); - JSHandle bound_args(thread, ctor->GetBoundArguments()); - JSMutableHandle new_pre_args(thread, pre_args.GetTaggedValue()); - if (new_pre_args->IsUndefined()) { - new_pre_args.Update(bound_args.GetTaggedValue()); + JSHandle boundArgs(thread, ctor->GetBoundArguments()); + JSMutableHandle newPreArgs(thread, preArgs.GetTaggedValue()); + if (newPreArgs->IsUndefined()) { + newPreArgs.Update(boundArgs.GetTaggedValue()); } else { - new_pre_args.Update( - TaggedArray::Append(thread, bound_args, JSHandle::Cast(pre_args)).GetTaggedValue()); + newPreArgs.Update( + TaggedArray::Append(thread, boundArgs, JSHandle::Cast(preArgs)).GetTaggedValue()); } - JSMutableHandle new_target_mutable(thread, new_tgt.GetTaggedValue()); - if (JSTaggedValue::SameValue(ctor.GetTaggedValue(), new_tgt.GetTaggedValue())) { - new_target_mutable.Update(target.GetTaggedValue()); + JSMutableHandle newTargetMutable(thread, newTgt.GetTaggedValue()); + if (JSTaggedValue::SameValue(ctor.GetTaggedValue(), newTgt.GetTaggedValue())) { + newTargetMutable.Update(target.GetTaggedValue()); } - return SlowRuntimeHelper::Construct(thread, target, new_target_mutable, new_pre_args, args_count, stkargs); + return SlowRuntimeHelper::Construct(thread, target, newTargetMutable, newPreArgs, argsCount, stkargs); } -JSTaggedValue ConstructProxy(JSThread *thread, JSHandle ctor, JSHandle new_tgt, - JSHandle pre_args, uint32_t args_count, JSTaggedType *stkargs) +JSTaggedValue ConstructProxy(JSThread *thread, JSHandle ctor, JSHandle newTgt, + JSHandle preArgs, uint32_t argsCount, JSTaggedType *stkargs) { // step 1 ~ 4 get ProxyHandler and ProxyTarget JSHandle handler(thread, ctor->GetHandler()); @@ -203,75 +203,74 @@ JSTaggedValue ConstructProxy(JSThread *thread, JSHandle ctor, JSHandle< // b.Return Construct(target, argumentsList, new_target). if (method->IsUndefined()) { ASSERT(target->IsConstructor()); - return SlowRuntimeHelper::Construct(thread, target, new_tgt, pre_args, args_count, stkargs); + return SlowRuntimeHelper::Construct(thread, target, newTgt, preArgs, argsCount, stkargs); } // 8.Let argArray be CreateArrayFromList(argumentsList). - uint32_t pre_args_size = pre_args->IsUndefined() ? 0 : JSHandle::Cast(pre_args)->GetLength(); - const uint32_t size = pre_args_size + args_count; + uint32_t preArgsSize = preArgs->IsUndefined() ? 0 : JSHandle::Cast(preArgs)->GetLength(); + const uint32_t size = preArgsSize + argsCount; JSHandle args = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(size); - if (pre_args_size > 0) { - JSHandle tga_pre_args = JSHandle::Cast(pre_args); - for (uint32_t i = 0; i < pre_args_size; ++i) { - JSTaggedValue value = tga_pre_args->Get(i); + if (preArgsSize > 0) { + JSHandle tgaPreArgs = JSHandle::Cast(preArgs); + for (uint32_t i = 0; i < preArgsSize; ++i) { + JSTaggedValue value = tgaPreArgs->Get(i); args->Set(thread, i, value); } } - for (ArraySizeT i = 0; i < args_count; ++i) { + for (ArraySizeT i = 0; i < argsCount; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - args->Set(thread, i + pre_args_size, JSTaggedValue(stkargs[i])); + args->Set(thread, i + preArgsSize, JSTaggedValue(stkargs[i])); } // step 8 ~ 9 Call(trap, handler, «target, argArray, new_target »). auto info = NewRuntimeCallInfo(thread, method, handler, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(target, JSHandle(args), new_tgt); - JSTaggedValue new_obj_value = JSFunction::Call(info.Get()); // 3: «target, argArray, new_target » + info->SetCallArgs(target, JSHandle(args), newTgt); + JSTaggedValue newObjValue = JSFunction::Call(info.Get()); // 3: «target, argArray, new_target » // 10.ReturnIfAbrupt(newObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11.If Type(newObj) is not Object, throw a TypeError exception. - if (!new_obj_value.IsECMAObject()) { + if (!newObjValue.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new object is not object", JSTaggedValue::Exception()); } // 12.Return newObj. - return new_obj_value; + return newObjValue; } JSTaggedValue SlowRuntimeHelper::Construct(JSThread *thread, JSHandle ctor, - JSHandle new_target, JSHandle pre_args, - uint32_t args_count, JSTaggedType *stkargs) + JSHandle newTarget, JSHandle preArgs, + uint32_t argsCount, JSTaggedType *stkargs) { - if (new_target->IsUndefined()) { - new_target = ctor; + if (newTarget->IsUndefined()) { + newTarget = ctor; } - if (!(new_target->IsConstructor() && ctor->IsConstructor())) { + if (!(newTarget->IsConstructor() && ctor->IsConstructor())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is false", JSTaggedValue::Exception()); } if (ctor->IsJSFunction()) { - return ConstructGeneric(thread, JSHandle::Cast(ctor), new_target, pre_args, args_count, stkargs); + return ConstructGeneric(thread, JSHandle::Cast(ctor), newTarget, preArgs, argsCount, stkargs); } if (ctor->IsBoundFunction()) { - return ConstructBoundFunction(thread, JSHandle::Cast(ctor), new_target, pre_args, args_count, + return ConstructBoundFunction(thread, JSHandle::Cast(ctor), newTarget, preArgs, argsCount, stkargs); } if (ctor->IsJSProxy()) { - return ConstructProxy(thread, JSHandle::Cast(ctor), new_target, pre_args, args_count, stkargs); + return ConstructProxy(thread, JSHandle::Cast(ctor), newTarget, preArgs, argsCount, stkargs); } THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor NonConstructor", JSTaggedValue::Exception()); } -JSTaggedValue SlowRuntimeHelper::FindPrivateKey(JSThread *thread, - const JSHandle &private_context, +JSTaggedValue SlowRuntimeHelper::FindPrivateKey(JSThread *thread, const JSHandle &privateContext, const JSHandle &obj, const JSHandle &key, - PropertyDescriptor &prop_desc, PrivateFieldKind &kind) + PropertyDescriptor &propDesc, PrivateFieldKind &kind) { - JSHandle desc(thread, private_context->GetPrivateFields()); + JSHandle desc(thread, privateContext->GetPrivateFields()); for (ArraySizeT i = 0; i < desc->GetLength();) { - JSHandle kind_value(thread, desc->Get(thread, i++)); - kind = static_cast(kind_value->GetInt()); - JSHandle private_symbol(thread, desc->Get(thread, i++)); + JSHandle kindValue(thread, desc->Get(thread, i++)); + kind = static_cast(kindValue->GetInt()); + JSHandle privateSymbol(thread, desc->Get(thread, i++)); switch (kind) { case PrivateFieldKind::FIELD: @@ -283,20 +282,20 @@ JSTaggedValue SlowRuntimeHelper::FindPrivateKey(JSThread *thread, } } - if (!JSTaggedValue::Equal(thread, JSHandle(thread, private_symbol->GetDescription()), key)) { + if (!JSTaggedValue::Equal(thread, JSHandle(thread, privateSymbol->GetDescription()), key)) { continue; } - bool exists = JSObject::GetOwnProperty(thread, obj, JSHandle::Cast(private_symbol), prop_desc); + bool exists = JSObject::GetOwnProperty(thread, obj, JSHandle::Cast(privateSymbol), propDesc); if (!exists) { - prop_desc.SetValue(JSHandle(thread, JSTaggedValue::Hole())); + propDesc.SetValue(JSHandle(thread, JSTaggedValue::Hole())); } - return private_symbol.GetTaggedValue(); + return privateSymbol.GetTaggedValue(); } - prop_desc.SetValue(JSHandle(thread, JSTaggedValue::Hole())); + propDesc.SetValue(JSHandle(thread, JSTaggedValue::Hole())); return JSTaggedValue::Undefined(); } diff --git a/runtime/interpreter/slow_runtime_helper.h b/runtime/interpreter/slow_runtime_helper.h index e5b7e9fb8de077d327d8beb6000ecb54f9cb8a79..9989fe7db0f82ff666607d30f34d750414949249 100644 --- a/runtime/interpreter/slow_runtime_helper.h +++ b/runtime/interpreter/slow_runtime_helper.h @@ -29,13 +29,13 @@ public: static void SaveFrameToContext(JSThread *thread, JSHandle context); - static JSTaggedValue Construct(JSThread *thread, JSHandle ctor, JSHandle new_target, - JSHandle pre_args, uint32_t args_count, JSTaggedType *stkargs); + static JSTaggedValue Construct(JSThread *thread, JSHandle ctor, JSHandle newTarget, + JSHandle preArgs, uint32_t argsCount, JSTaggedType *stkargs); using PrivateFieldKind = JSConstructorFunction::PrivateFieldKind; - static JSTaggedValue FindPrivateKey(JSThread *thread, const JSHandle &private_context, + static JSTaggedValue FindPrivateKey(JSThread *thread, const JSHandle &privateContext, const JSHandle &obj, const JSHandle &key, - PropertyDescriptor &prop_desc, PrivateFieldKind &kind); + PropertyDescriptor &propDesc, PrivateFieldKind &kind); }; } // namespace panda::ecmascript diff --git a/runtime/interpreter/slow_runtime_stub.cpp b/runtime/interpreter/slow_runtime_stub.cpp index 14633c1455bbe9bddf07748a436b4760266786aa..bc5755082056bd37e6ffd80f22bca9d1bc85a176 100644 --- a/runtime/interpreter/slow_runtime_stub.cpp +++ b/runtime/interpreter/slow_runtime_stub.cpp @@ -58,43 +58,42 @@ JSTaggedValue SlowRuntimeStub::CallSpreadDyn(JSThread *thread, JSTaggedValue fun if ((!obj.IsUndefined() && !obj.IsECMAObject()) || !func.IsJSFunction() || !array.IsJSArray()) { THROW_TYPE_ERROR_AND_RETURN(thread, "cannot Callspread", JSTaggedValue::Exception()); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle js_func(thread, func); - JSHandle js_array(thread, array); - JSHandle tagged_obj(thread, obj); + JSHandle jsFunc(thread, func); + JSHandle jsArray(thread, array); + JSHandle taggedObj(thread, obj); - JSHandle coretypes_array(thread, GetCallSpreadArgs(thread, js_array.GetTaggedValue())); + JSHandle coretypesArray(thread, GetCallSpreadArgs(thread, jsArray.GetTaggedValue())); - auto info = - NewRuntimeCallInfo(thread, js_func, tagged_obj, JSTaggedValue::Undefined(), coretypes_array->GetLength()); - info->SetCallArg(coretypes_array->GetLength(), coretypes_array->GetData()); + auto info = NewRuntimeCallInfo(thread, jsFunc, taggedObj, JSTaggedValue::Undefined(), coretypesArray->GetLength()); + info->SetCallArg(coretypesArray->GetLength(), coretypesArray->GetData()); return InvokeJsFunction(info.Get()); } JSTaggedValue SlowRuntimeStub::NegDyn(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, NegDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle input(thread, value); - JSHandle input_val = JSTaggedValue::ToNumeric(thread, input); + JSHandle inputVal = JSTaggedValue::ToNumeric(thread, input); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (input_val->IsBigInt()) { - JSHandle big_value(input_val); - return BigInt::UnaryMinus(thread, big_value).GetTaggedValue(); + if (inputVal->IsBigInt()) { + JSHandle bigValue(inputVal); + return BigInt::UnaryMinus(thread, bigValue).GetTaggedValue(); } - if (input_val->IsInt()) { - int32_t int_value = input_val->GetInt(); - if (int_value == 0) { + if (inputVal->IsInt()) { + int32_t intValue = inputVal->GetInt(); + if (intValue == 0) { return JSTaggedValue(-0.0); } - return JSTaggedValue(-int_value); + return JSTaggedValue(-intValue); } - if (input_val->IsDouble()) { - return JSTaggedValue(-input_val->GetDouble()); + if (inputVal->IsDouble()) { + return JSTaggedValue(-inputVal->GetDouble()); } UNREACHABLE(); @@ -104,34 +103,34 @@ JSTaggedValue SlowRuntimeStub::AsyncFunctionEnter(JSThread *thread) { INTERPRETER_TRACE(thread, AsyncFunctionEnter); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. create promise - JSHandle global_env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle promise_func = global_env->GetPromiseFunction(); + JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle promiseFunc = globalEnv->GetPromiseFunction(); - JSHandle promise_object = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promise_func), promise_func)); - promise_object->SetPromiseState(thread, JSTaggedValue(static_cast(PromiseStatus::PENDING))); + JSHandle promiseObject = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promiseFunc), promiseFunc)); + promiseObject->SetPromiseState(thread, JSTaggedValue(static_cast(PromiseStatus::PENDING))); // 2. create asyncfuncobj - JSHandle async_func_obj = factory->NewJSAsyncFuncObject(); - async_func_obj->SetPromise(thread, promise_object); + JSHandle asyncFuncObj = factory->NewJSAsyncFuncObject(); + asyncFuncObj->SetPromise(thread, promiseObject); JSHandle context = factory->NewGeneratorContext(); - context->SetGeneratorObject(thread, async_func_obj); + context->SetGeneratorObject(thread, asyncFuncObj); // change state to EXECUTING - async_func_obj->SetState(thread, JSGeneratorState::EXECUTING); - async_func_obj->SetGeneratorContext(thread, context); + asyncFuncObj->SetState(thread, JSGeneratorState::EXECUTING); + asyncFuncObj->SetGeneratorContext(thread, context); // 3. return asyncfuncobj RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return async_func_obj.GetTaggedValue(); + return asyncFuncObj.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::ToNumber(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, Tonumber); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle number(thread, value); // may return exception @@ -141,48 +140,48 @@ JSTaggedValue SlowRuntimeStub::ToNumber(JSThread *thread, JSTaggedValue value) JSTaggedValue SlowRuntimeStub::NotDyn(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, NotDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle input_tag(thread, value); - JSHandle input_val = JSTaggedValue::ToNumeric(thread, input_tag); + JSHandle inputTag(thread, value); + JSHandle inputVal = JSTaggedValue::ToNumeric(thread, inputTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (input_val->IsBigInt()) { - JSHandle big_value(input_val); - return BigInt::BitwiseNOT(thread, big_value).GetTaggedValue(); + if (inputVal->IsBigInt()) { + JSHandle bigValue(inputVal); + return BigInt::BitwiseNOT(thread, bigValue).GetTaggedValue(); } - int32_t number = JSTaggedValue::ToInt32(thread, input_val); + int32_t number = JSTaggedValue::ToInt32(thread, inputVal); return JSTaggedValue(~number); // NOLINT(hicpp-signed-bitwise) } JSTaggedValue SlowRuntimeStub::IncDyn(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, IncDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle input_tag(thread, value); - JSHandle input_val = JSTaggedValue::ToNumeric(thread, input_tag); + JSHandle inputTag(thread, value); + JSHandle inputVal = JSTaggedValue::ToNumeric(thread, inputTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (input_val->IsBigInt()) { - JSHandle big_value(input_val); - return BigInt::BigIntAddOne(thread, big_value).GetTaggedValue(); + if (inputVal->IsBigInt()) { + JSHandle bigValue(inputVal); + return BigInt::BigIntAddOne(thread, bigValue).GetTaggedValue(); } - JSTaggedNumber number(input_val.GetTaggedValue()); + JSTaggedNumber number(inputVal.GetTaggedValue()); return (++number); } JSTaggedValue SlowRuntimeStub::DecDyn(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, DecDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle input_tag(thread, value); - JSHandle input_val = JSTaggedValue::ToNumeric(thread, input_tag); + JSHandle inputTag(thread, value); + JSHandle inputVal = JSTaggedValue::ToNumeric(thread, inputTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (input_val->IsBigInt()) { - JSHandle big_value(input_val); - return BigInt::BigIntSubOne(thread, big_value).GetTaggedValue(); + if (inputVal->IsBigInt()) { + JSHandle bigValue(inputVal); + return BigInt::BigIntSubOne(thread, bigValue).GetTaggedValue(); } - JSTaggedNumber number(input_val.GetTaggedValue()); + JSTaggedNumber number(inputVal.GetTaggedValue()); return (--number); } @@ -190,31 +189,31 @@ void SlowRuntimeStub::ThrowDyn(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, ThrowDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj(thread, value); - JSHandle wrapper_object = factory->NewObjectWrapper(obj); + JSHandle wrapperObject = factory->NewObjectWrapper(obj); - thread->SetException(wrapper_object.GetTaggedValue()); + thread->SetException(wrapperObject.GetTaggedValue()); } JSTaggedValue SlowRuntimeStub::GetPropIterator(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, GetPropIterator); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, value); - JSHandle iterator_handle = JSObject::EnumerateObjectProperties(thread, obj_handle); + JSHandle objHandle(thread, value); + JSHandle iteratorHandle = JSObject::EnumerateObjectProperties(thread, objHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - iterator_handle->SetFastRemainingIndex(JSTaggedNumber(0)); - return iterator_handle.GetTaggedValue(); + iteratorHandle->SetFastRemainingIndex(JSTaggedNumber(0)); + return iteratorHandle.GetTaggedValue(); } void SlowRuntimeStub::ThrowConstAssignment(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, ThrowConstAssignment); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -225,190 +224,190 @@ void SlowRuntimeStub::ThrowConstAssignment(JSThread *thread, JSTaggedValue value THROW_NEW_ERROR_AND_RETURN(thread, factory->NewJSError(base::ErrorType::TYPE_ERROR, msg).GetTaggedValue()); } -JSTaggedValue SlowRuntimeStub::Add2Dyn(JSThread *thread, EcmaVM *ecma_vm, JSTaggedValue left, JSTaggedValue right) +JSTaggedValue SlowRuntimeStub::Add2Dyn(JSThread *thread, EcmaVM *ecmaVm, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, Add2Dyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); - if (left_value->IsString() && right_value->IsString()) { - EcmaString *new_string = - EcmaString::Concat(JSHandle(left_value), JSHandle(right_value), ecma_vm); - return JSTaggedValue(new_string); + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); + if (leftValue->IsString() && rightValue->IsString()) { + EcmaString *newString = + EcmaString::Concat(JSHandle(leftValue), JSHandle(rightValue), ecmaVm); + return JSTaggedValue(newString); } - JSHandle primitive_a0(thread, JSTaggedValue::ToPrimitive(thread, left_value)); + JSHandle primitiveA0(thread, JSTaggedValue::ToPrimitive(thread, leftValue)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle primitive_a1(thread, JSTaggedValue::ToPrimitive(thread, right_value)); + JSHandle primitiveA1(thread, JSTaggedValue::ToPrimitive(thread, rightValue)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // contain string - if (primitive_a0->IsString() || primitive_a1->IsString()) { - JSHandle string_a0 = JSTaggedValue::ToString(thread, primitive_a0); + if (primitiveA0->IsString() || primitiveA1->IsString()) { + JSHandle stringA0 = JSTaggedValue::ToString(thread, primitiveA0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string_a1 = JSTaggedValue::ToString(thread, primitive_a1); + JSHandle stringA1 = JSTaggedValue::ToString(thread, primitiveA1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *new_string = EcmaString::Concat(string_a0, string_a1, ecma_vm); - return JSTaggedValue(new_string); + EcmaString *newString = EcmaString::Concat(stringA0, stringA1, ecmaVm); + return JSTaggedValue(newString); } - JSHandle val_left = JSTaggedValue::ToNumeric(thread, primitive_a0); + JSHandle valLeft = JSTaggedValue::ToNumeric(thread, primitiveA0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle val_right = JSTaggedValue::ToNumeric(thread, primitive_a1); + JSHandle valRight = JSTaggedValue::ToNumeric(thread, primitiveA1); - if (val_left->IsBigInt() || val_right->IsBigInt()) { - if (val_left->IsBigInt() && val_right->IsBigInt()) { - JSHandle big_left(val_left); - JSHandle big_right(val_right); - return BigInt::Add(thread, big_left, big_right).GetTaggedValue(); + if (valLeft->IsBigInt() || valRight->IsBigInt()) { + if (valLeft->IsBigInt() && valRight->IsBigInt()) { + JSHandle bigLeft(valLeft); + JSHandle bigRight(valRight); + return BigInt::Add(thread, bigLeft, bigRight).GetTaggedValue(); } return ThrowTypeError(thread, "Cannot mix BigInt and other types, use explicit conversions"); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double a0_double = val_left->GetNumber(); - double a1_double = val_right->GetNumber(); - return JSTaggedValue(a0_double + a1_double); + double a0Double = valLeft->GetNumber(); + double a1Double = valRight->GetNumber(); + return JSTaggedValue(a0Double + a1Double); } JSTaggedValue SlowRuntimeStub::Sub2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, Sub2Dyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_handle(thread, left); - JSHandle right_handle(thread, right); + JSHandle leftHandle(thread, left); + JSHandle rightHandle(thread, right); - JSHandle val_left = JSTaggedValue::ToNumeric(thread, left_handle); + JSHandle valLeft = JSTaggedValue::ToNumeric(thread, leftHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle val_right = JSTaggedValue::ToNumeric(thread, right_handle); + JSHandle valRight = JSTaggedValue::ToNumeric(thread, rightHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (val_left->IsBigInt() || val_right->IsBigInt()) { - if (val_left->IsBigInt() && val_right->IsBigInt()) { - JSHandle big_left(val_left); - JSHandle big_right(val_right); - return BigInt::Subtract(thread, big_left, big_right).GetTaggedValue(); + if (valLeft->IsBigInt() || valRight->IsBigInt()) { + if (valLeft->IsBigInt() && valRight->IsBigInt()) { + JSHandle bigLeft(valLeft); + JSHandle bigRight(valRight); + return BigInt::Subtract(thread, bigLeft, bigRight).GetTaggedValue(); } return ThrowTypeError(thread, "Cannot mix BigInt and other types, use explicit conversions"); } - JSTaggedNumber number0(val_left.GetTaggedValue()); - JSTaggedNumber number1(val_right.GetTaggedValue()); + JSTaggedNumber number0(valLeft.GetTaggedValue()); + JSTaggedNumber number1(valRight.GetTaggedValue()); return number0 - number1; } JSTaggedValue SlowRuntimeStub::Mul2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, Mul2Dyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); // 6. Let lnum be ToNumeric(leftValue). - JSHandle val_left = JSTaggedValue::ToNumeric(thread, left_value); + JSHandle valLeft = JSTaggedValue::ToNumeric(thread, leftValue); // 7. ReturnIfAbrupt(lnum). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Let rnum be ToNumeric(rightValue). - JSHandle val_right = JSTaggedValue::ToNumeric(thread, right_value); + JSHandle valRight = JSTaggedValue::ToNumeric(thread, rightValue); // 9. ReturnIfAbrupt(rnum). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (val_left->IsBigInt() || val_right->IsBigInt()) { - if (val_left->IsBigInt() && val_right->IsBigInt()) { - JSHandle big_left(val_left); - JSHandle big_right(val_right); - return BigInt::Multiply(thread, big_left, big_right).GetTaggedValue(); + if (valLeft->IsBigInt() || valRight->IsBigInt()) { + if (valLeft->IsBigInt() && valRight->IsBigInt()) { + JSHandle bigLeft(valLeft); + JSHandle bigRight(valRight); + return BigInt::Multiply(thread, bigLeft, bigRight).GetTaggedValue(); } return ThrowTypeError(thread, "Cannot mix BigInt and other types, use explicit conversions"); } // 12.6.3.1 Applying the * Operator - JSTaggedNumber number0(val_left.GetTaggedValue()); - JSTaggedNumber number1(val_right.GetTaggedValue()); + JSTaggedNumber number0(valLeft.GetTaggedValue()); + JSTaggedNumber number1(valRight.GetTaggedValue()); return number0 * number1; } JSTaggedValue SlowRuntimeStub::Div2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, Div2Dyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_handle(thread, left); - JSHandle right_handle(thread, right); + JSHandle leftHandle(thread, left); + JSHandle rightHandle(thread, right); - JSHandle val_left = JSTaggedValue::ToNumeric(thread, left_handle); + JSHandle valLeft = JSTaggedValue::ToNumeric(thread, leftHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle val_right = JSTaggedValue::ToNumeric(thread, right_handle); + JSHandle valRight = JSTaggedValue::ToNumeric(thread, rightHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (val_left->IsBigInt() || val_right->IsBigInt()) { - if (val_left->IsBigInt() && val_right->IsBigInt()) { - JSHandle big_left(val_left); - JSHandle big_right(val_right); - return BigInt::Divide(thread, big_left, big_right).GetTaggedValue(); + if (valLeft->IsBigInt() || valRight->IsBigInt()) { + if (valLeft->IsBigInt() && valRight->IsBigInt()) { + JSHandle bigLeft(valLeft); + JSHandle bigRight(valRight); + return BigInt::Divide(thread, bigLeft, bigRight).GetTaggedValue(); } return ThrowTypeError(thread, "Cannot mix BigInt and other types, use explicit conversions"); } - double d_left = val_left->GetNumber(); - double d_right = val_right->GetNumber(); + double dLeft = valLeft->GetNumber(); + double dRight = valRight->GetNumber(); - if (d_right == 0) { - if (d_left == 0 || std::isnan(d_left)) { + if (dRight == 0) { + if (dLeft == 0 || std::isnan(dLeft)) { return JSTaggedValue(base::NAN_VALUE); } - bool positive = (((bit_cast(d_right)) & base::DOUBLE_SIGN_MASK) == - ((bit_cast(d_left)) & base::DOUBLE_SIGN_MASK)); + bool positive = (((bit_cast(dRight)) & base::DOUBLE_SIGN_MASK) == + ((bit_cast(dLeft)) & base::DOUBLE_SIGN_MASK)); return JSTaggedValue(positive ? base::POSITIVE_INFINITY : -base::POSITIVE_INFINITY); } - return JSTaggedValue(d_left / d_right); + return JSTaggedValue(dLeft / dRight); } JSTaggedValue SlowRuntimeStub::Mod2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, Mod2Dyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_handle(thread, left); - JSHandle right_handle(thread, right); + JSHandle leftHandle(thread, left); + JSHandle rightHandle(thread, right); - JSHandle val_left = JSTaggedValue::ToNumeric(thread, left_handle); + JSHandle valLeft = JSTaggedValue::ToNumeric(thread, leftHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle val_right = JSTaggedValue::ToNumeric(thread, right_handle); + JSHandle valRight = JSTaggedValue::ToNumeric(thread, rightHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (val_left->IsBigInt() || val_right->IsBigInt()) { - if (val_left->IsBigInt() && val_right->IsBigInt()) { - JSHandle left_bigint(val_left); - JSHandle right_bigint(val_right); - return BigInt::Remainder(thread, left_bigint, right_bigint).GetTaggedValue(); + if (valLeft->IsBigInt() || valRight->IsBigInt()) { + if (valLeft->IsBigInt() && valRight->IsBigInt()) { + JSHandle leftBigint(valLeft); + JSHandle rightBigint(valRight); + return BigInt::Remainder(thread, leftBigint, rightBigint).GetTaggedValue(); } return ThrowTypeError(thread, "Cannot mix BigInt and other types, use explicit conversions"); } - double d_left = val_left->GetNumber(); - double d_right = val_right->GetNumber(); + double dLeft = valLeft->GetNumber(); + double dRight = valRight->GetNumber(); // 12.6.3.3 Applying the % Operator - if ((d_right == 0.0) || std::isnan(d_right) || std::isnan(d_left) || std::isinf(d_left)) { + if ((dRight == 0.0) || std::isnan(dRight) || std::isnan(dLeft) || std::isinf(dLeft)) { return JSTaggedValue(base::NAN_VALUE); } - if ((d_left == 0.0) || std::isinf(d_right)) { - return JSTaggedValue(d_left); + if ((dLeft == 0.0) || std::isinf(dRight)) { + return JSTaggedValue(dLeft); } - return JSTaggedValue(std::fmod(d_left, d_right)); + return JSTaggedValue(std::fmod(dLeft, dRight)); } JSTaggedValue SlowRuntimeStub::EqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, EqDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); - bool ret = JSTaggedValue::Equal(thread, left_value, right_value); + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); + bool ret = JSTaggedValue::Equal(thread, leftValue, rightValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return (ret ? JSTaggedValue::True() : JSTaggedValue::False()); } @@ -416,11 +415,11 @@ JSTaggedValue SlowRuntimeStub::EqDyn(JSThread *thread, JSTaggedValue left, JSTag JSTaggedValue SlowRuntimeStub::NotEqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, NotEqDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); - bool ret = JSTaggedValue::Equal(thread, left_value, right_value); + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); + bool ret = JSTaggedValue::Equal(thread, leftValue, rightValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return (ret ? JSTaggedValue::False() : JSTaggedValue::True()); } @@ -428,11 +427,11 @@ JSTaggedValue SlowRuntimeStub::NotEqDyn(JSThread *thread, JSTaggedValue left, JS JSTaggedValue SlowRuntimeStub::LessDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, LessDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); - bool ret = JSTaggedValue::Compare(thread, left_value, right_value) == ComparisonResult::LESS; + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); + bool ret = JSTaggedValue::Compare(thread, leftValue, rightValue) == ComparisonResult::LESS; RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return (ret ? JSTaggedValue::True() : JSTaggedValue::False()); } @@ -440,11 +439,11 @@ JSTaggedValue SlowRuntimeStub::LessDyn(JSThread *thread, JSTaggedValue left, JST JSTaggedValue SlowRuntimeStub::LessEqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, LessEqDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); - bool ret = JSTaggedValue::Compare(thread, left_value, right_value) <= ComparisonResult::EQUAL; + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); + bool ret = JSTaggedValue::Compare(thread, leftValue, rightValue) <= ComparisonResult::EQUAL; RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return (ret ? JSTaggedValue::True() : JSTaggedValue::False()); } @@ -452,11 +451,11 @@ JSTaggedValue SlowRuntimeStub::LessEqDyn(JSThread *thread, JSTaggedValue left, J JSTaggedValue SlowRuntimeStub::GreaterDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, GreaterDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); - bool ret = JSTaggedValue::Compare(thread, left_value, right_value) == ComparisonResult::GREAT; + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); + bool ret = JSTaggedValue::Compare(thread, leftValue, rightValue) == ComparisonResult::GREAT; RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return (ret ? JSTaggedValue::True() : JSTaggedValue::False()); } @@ -464,11 +463,11 @@ JSTaggedValue SlowRuntimeStub::GreaterDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue SlowRuntimeStub::GreaterEqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { INTERPRETER_TRACE(thread, GreaterEqDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle left_value(thread, left); - JSHandle right_value(thread, right); - ComparisonResult comparison = JSTaggedValue::Compare(thread, left_value, right_value); + JSHandle leftValue(thread, left); + JSHandle rightValue(thread, right); + ComparisonResult comparison = JSTaggedValue::Compare(thread, leftValue, rightValue); bool ret = (comparison == ComparisonResult::GREAT) || (comparison == ComparisonResult::EQUAL); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return (ret ? JSTaggedValue::True() : JSTaggedValue::False()); @@ -477,9 +476,9 @@ JSTaggedValue SlowRuntimeStub::GreaterEqDyn(JSThread *thread, JSTaggedValue left JSTaggedValue SlowRuntimeStub::ToJSTaggedValueWithInt32(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, ToJSTaggedValueWithInt32); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle value_handle(thread, value); - int32_t res = JSTaggedValue::ToInt32(thread, value_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle valueHandle(thread, value); + int32_t res = JSTaggedValue::ToInt32(thread, valueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue(res); } @@ -487,9 +486,9 @@ JSTaggedValue SlowRuntimeStub::ToJSTaggedValueWithInt32(JSThread *thread, JSTagg JSTaggedValue SlowRuntimeStub::ToJSTaggedValueWithUint32(JSThread *thread, JSTaggedValue value) { INTERPRETER_TRACE(thread, ToJSTaggedValueWithUint32); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle value_handle(thread, value); - int32_t res = JSTaggedValue::ToUint32(thread, value_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle valueHandle(thread, value); + int32_t res = JSTaggedValue::ToUint32(thread, valueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue(res); } @@ -497,68 +496,68 @@ JSTaggedValue SlowRuntimeStub::ToJSTaggedValueWithUint32(JSThread *thread, JSTag JSTaggedValue SlowRuntimeStub::DelObjProp(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop) { INTERPRETER_TRACE(thread, Delobjprop); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, prop); - JSHandle js_obj(JSTaggedValue::ToObject(thread, obj_handle)); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, prop); + JSHandle jsObj(JSTaggedValue::ToObject(thread, objHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle prop_key = JSTaggedValue::ToPropertyKey(thread, prop_handle); + JSHandle propKey = JSTaggedValue::ToPropertyKey(thread, propHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool ret = JSTaggedValue::DeletePropertyOrThrow(thread, js_obj, prop_key); + bool ret = JSTaggedValue::DeletePropertyOrThrow(thread, jsObj, propKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue(ret); } -JSTaggedValue SlowRuntimeStub::NewObjDynRange(JSThread *thread, uint16_t args_count, JSTaggedValue func, - JSTaggedValue new_target, JSTaggedType *stkargs) +JSTaggedValue SlowRuntimeStub::NewObjDynRange(JSThread *thread, uint16_t argsCount, JSTaggedValue func, + JSTaggedValue newTarget, JSTaggedType *stkargs) { INTERPRETER_TRACE(thread, NewobjDynrange); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle func_handle(thread, JSTaggedValue(func)); - JSHandle new_target_handle(thread, JSTaggedValue(new_target)); + JSHandle funcHandle(thread, JSTaggedValue(func)); + JSHandle newTargetHandle(thread, JSTaggedValue(newTarget)); - JSHandle pre_args(thread, JSTaggedValue::Undefined()); - auto tagged = SlowRuntimeHelper::Construct(thread, func_handle, new_target_handle, pre_args, args_count, stkargs); + JSHandle preArgs(thread, JSTaggedValue::Undefined()); + auto tagged = SlowRuntimeHelper::Construct(thread, funcHandle, newTargetHandle, preArgs, argsCount, stkargs); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return tagged; } -JSTaggedValue SlowRuntimeStub::CreateObjectWithExcludedKeys(JSThread *thread, uint16_t num_keys, JSTaggedValue obj_val, +JSTaggedValue SlowRuntimeStub::CreateObjectWithExcludedKeys(JSThread *thread, uint16_t numKeys, JSTaggedValue objVal, JSTaggedType *stkargs) { INTERPRETER_TRACE(thread, CreateObjectWithExcludedKeys); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_tval(thread, obj_val); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle objTval(thread, objVal); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle from_value(thread, obj_val); + JSHandle fromValue(thread, objVal); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If source is undefined or null, return target. - if (from_value->IsNull() || from_value->IsUndefined()) { - return obj_val; + if (fromValue->IsNull() || fromValue->IsUndefined()) { + return objVal; } // 4. Let from be ! ToObject(source). - JSHandle from = JSTaggedValue::ToObject(thread, from_value); + JSHandle from = JSTaggedValue::ToObject(thread, fromValue); ASSERT_NO_ABRUPT_COMPLETION(thread); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSTaggedValue vreg(stkargs[0]); - ArraySizeT num_excluded_keys = vreg.IsUndefined() ? 0 : num_keys + 1; + ArraySizeT numExcludedKeys = vreg.IsUndefined() ? 0 : numKeys + 1; // 5.Let keys be obj.[[OwnPropertyKeys]](). - JSHandle from_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(from)); + JSHandle fromKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(from)); // 6. For each element nextKey of keys, do - JSHandle new_obj = factory->NewEmptyJSObject(); + JSHandle newObj = factory->NewEmptyJSObject(); bool excluded = true; - for (ArraySizeT i = 0; i < from_keys->GetLength(); i++) { - JSMutableHandle key(thread, from_keys->Get(i)); + for (ArraySizeT i = 0; i < fromKeys->GetLength(); i++) { + JSMutableHandle key(thread, fromKeys->Get(i)); // a. Let excluded be false. excluded = false; // b. For each element e of excludedItems, do - for (ArraySizeT e = 0; e < num_excluded_keys; e++) { + for (ArraySizeT e = 0; e < numExcludedKeys; e++) { // i. If SameValue(e, nextKey) is true, then // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSTaggedValue ereg(stkargs[e]); @@ -576,55 +575,55 @@ JSTaggedValue SlowRuntimeStub::CreateObjectWithExcludedKeys(JSThread *thread, ui RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // ii. If desc is not undefined and desc.[[Enumerable]] is true, then if (status && desc.IsEnumerable()) { - JSHandle prop_value = + JSHandle propValue = JSTaggedValue::GetProperty(thread, JSHandle(from), key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, new_obj, key, prop_value); + JSObject::CreateDataPropertyOrThrow(thread, newObj, key, propValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } } - return new_obj.GetTaggedValue(); + return newObj.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::ExpDyn(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent) { INTERPRETER_TRACE(thread, ExpDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle base_tag(thread, base); - JSHandle exponent_tag(thread, exponent); - JSHandle val_base = JSTaggedValue::ToNumeric(thread, base_tag); + JSHandle baseTag(thread, base); + JSHandle exponentTag(thread, exponent); + JSHandle valBase = JSTaggedValue::ToNumeric(thread, baseTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle val_exponent = JSTaggedValue::ToNumeric(thread, exponent_tag); + JSHandle valExponent = JSTaggedValue::ToNumeric(thread, exponentTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (val_base->IsBigInt() || val_exponent->IsBigInt()) { - if (val_base->IsBigInt() && val_exponent->IsBigInt()) { - JSHandle big_base_value(val_base); - JSHandle big_exponent_value(val_exponent); - return BigInt::Exponentiate(thread, big_base_value, big_exponent_value).GetTaggedValue(); + if (valBase->IsBigInt() || valExponent->IsBigInt()) { + if (valBase->IsBigInt() && valExponent->IsBigInt()) { + JSHandle bigBaseValue(valBase); + JSHandle bigExponentValue(valExponent); + return BigInt::Exponentiate(thread, bigBaseValue, bigExponentValue).GetTaggedValue(); } THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot mix BigInt and other types, use explicit conversions", JSTaggedValue::Exception()); } - return base::NumberHelper::Pow(base_tag->GetNumber(), exponent.GetNumber()); + return base::NumberHelper::Pow(baseTag->GetNumber(), exponent.GetNumber()); } JSTaggedValue SlowRuntimeStub::IsInDyn(JSThread *thread, JSTaggedValue prop, JSTaggedValue obj) { INTERPRETER_TRACE(thread, IsInDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle prop_handle(thread, prop); - JSHandle obj_handle(thread, obj); - if (!obj_handle->IsECMAObject()) { + JSHandle propHandle(thread, prop); + JSHandle objHandle(thread, obj); + if (!objHandle->IsECMAObject()) { return ThrowTypeError(thread, "Cannot use 'in' operator in Non-Object"); } - JSHandle prop_key = JSTaggedValue::ToPropertyKey(thread, prop_handle); + JSHandle propKey = JSTaggedValue::ToPropertyKey(thread, propHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool ret = JSTaggedValue::HasProperty(thread, obj_handle, prop_key); + bool ret = JSTaggedValue::HasProperty(thread, objHandle, propKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue(ret); } @@ -632,46 +631,46 @@ JSTaggedValue SlowRuntimeStub::IsInDyn(JSThread *thread, JSTaggedValue prop, JST JSTaggedValue SlowRuntimeStub::InstanceofDyn(JSThread *thread, JSTaggedValue obj, JSTaggedValue target) { INTERPRETER_TRACE(thread, InstanceofDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); - JSHandle target_handle(thread, target); - bool ret = JSObject::InstanceOf(thread, obj_handle, target_handle); + JSHandle objHandle(thread, obj); + JSHandle targetHandle(thread, target); + bool ret = JSObject::InstanceOf(thread, objHandle, targetHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue(ret); } -JSTaggedValue SlowRuntimeStub::NewLexicalEnvDyn(JSThread *thread, uint16_t num_vars) +JSTaggedValue SlowRuntimeStub::NewLexicalEnvDyn(JSThread *thread, uint16_t numVars) { INTERPRETER_TRACE(thread, NewlexenvDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_env = factory->NewLexicalEnv(num_vars); + JSHandle newEnv = factory->NewLexicalEnv(numVars); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return new_env.GetTaggedValue(); + return newEnv.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::CreateIterResultObj(JSThread *thread, JSTaggedValue value, bool done) { INTERPRETER_TRACE(thread, CreateIterResultObj); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle value_handle(thread, value); - JSHandle iter = JSIterator::CreateIterResultObject(thread, value_handle, done); + JSHandle valueHandle(thread, value); + JSHandle iter = JSIterator::CreateIterResultObject(thread, valueHandle, done); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return iter.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::CreateGeneratorObj(JSThread *thread, JSTaggedValue gen_func) +JSTaggedValue SlowRuntimeStub::CreateGeneratorObj(JSThread *thread, JSTaggedValue genFunc) { INTERPRETER_TRACE(thread, CreateGeneratorObj); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle generator_function(thread, gen_func); - JSHandle obj = factory->NewJSGeneratorObject(generator_function); + JSHandle generatorFunction(thread, genFunc); + JSHandle obj = factory->NewJSGeneratorObject(generatorFunction); JSHandle context = factory->NewGeneratorContext(); context->SetGeneratorObject(thread, obj.GetTaggedValue()); @@ -683,107 +682,107 @@ JSTaggedValue SlowRuntimeStub::CreateGeneratorObj(JSThread *thread, JSTaggedValu return obj.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::SetGeneratorState(JSThread *thread, JSTaggedValue gen_obj, uint8_t state) +JSTaggedValue SlowRuntimeStub::SetGeneratorState(JSThread *thread, JSTaggedValue genObj, uint8_t state) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle generator_object_handle(thread, gen_obj); - generator_object_handle->SetState(thread, static_cast(state)); + JSHandle generatorObjectHandle(thread, genObj); + generatorObjectHandle->SetState(thread, static_cast(state)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Undefined(); } -JSTaggedValue SlowRuntimeStub::CreateAsyncGeneratorObj(JSThread *thread, JSTaggedValue gen_func) +JSTaggedValue SlowRuntimeStub::CreateAsyncGeneratorObj(JSThread *thread, JSTaggedValue genFunc) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle generator_function(thread, gen_func); - JSHandle obj = factory->NewJSAsyncGeneratorObject(generator_function); + JSHandle generatorFunction(thread, genFunc); + JSHandle obj = factory->NewJSAsyncGeneratorObject(generatorFunction); JSHandle context = factory->NewGeneratorContext(); - JSHandle async_queue = factory->NewTaggedQueue(0); + JSHandle asyncQueue = factory->NewTaggedQueue(0); context->SetGeneratorObject(thread, obj.GetTaggedValue()); // change state to SUSPENDED_START obj->SetState(thread, JSGeneratorState::SUSPENDED_START); obj->SetGeneratorContext(thread, context); - obj->SetAsyncGeneratorQueue(thread, async_queue); + obj->SetAsyncGeneratorQueue(thread, asyncQueue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return obj.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::SuspendGenerator(JSThread *thread, JSTaggedValue gen_obj, JSTaggedValue value) +JSTaggedValue SlowRuntimeStub::SuspendGenerator(JSThread *thread, JSTaggedValue genObj, JSTaggedValue value) { INTERPRETER_TRACE(thread, SuspendGenerator); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle generator_object_handle(thread, gen_obj); - JSHandle gen_context_handle(thread, generator_object_handle->GetGeneratorContext()); - JSHandle value_handle(thread, value); + JSHandle generatorObjectHandle(thread, genObj); + JSHandle genContextHandle(thread, generatorObjectHandle->GetGeneratorContext()); + JSHandle valueHandle(thread, value); // save stack, should copy cur_frame, function execute over will free cur_frame - SlowRuntimeHelper::SaveFrameToContext(thread, gen_context_handle); + SlowRuntimeHelper::SaveFrameToContext(thread, genContextHandle); - return value_handle.GetTaggedValue(); + return valueHandle.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::SuspendAsyncGenerator(JSThread *thread, JSTaggedValue async_gen_obj, JSTaggedValue value) +JSTaggedValue SlowRuntimeStub::SuspendAsyncGenerator(JSThread *thread, JSTaggedValue asyncGenObj, JSTaggedValue value) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle async_generator_object_handle(thread, async_gen_obj); - JSHandle async_generator_handle(thread, async_gen_obj); - JSHandle gen_context_handle(thread, async_generator_object_handle->GetGeneratorContext()); - JSHandle value_handle(thread, value); + JSHandle asyncGeneratorObjectHandle(thread, asyncGenObj); + JSHandle asyncGeneratorHandle(thread, asyncGenObj); + JSHandle genContextHandle(thread, asyncGeneratorObjectHandle->GetGeneratorContext()); + JSHandle valueHandle(thread, value); // save stack, should copy cur_frame, function execute over will free cur_frame - SlowRuntimeHelper::SaveFrameToContext(thread, gen_context_handle); + SlowRuntimeHelper::SaveFrameToContext(thread, genContextHandle); - return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, async_generator_handle, value_handle, false) + return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, asyncGeneratorHandle, valueHandle, false) .GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::AsyncFunctionAwait(JSThread *thread, JSTaggedValue async_func_obj, JSTaggedValue value) +JSTaggedValue SlowRuntimeStub::AsyncFunctionAwait(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value) { INTERPRETER_TRACE(thread, AsyncFunctionAwait); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle async_func_obj_handle(thread, async_func_obj); - JSHandle value_handle(thread, value); - JSAsyncFuncObject::AsyncFunctionAwait(thread, async_func_obj_handle, value_handle); - JSHandle promise(thread, async_func_obj_handle->GetPromise()); + JSHandle asyncFuncObjHandle(thread, asyncFuncObj); + JSHandle valueHandle(thread, value); + JSAsyncFuncObject::AsyncFunctionAwait(thread, asyncFuncObjHandle, valueHandle); + JSHandle promise(thread, asyncFuncObjHandle->GetPromise()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return promise.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::AsyncFunctionResolveOrReject(JSThread *thread, JSTaggedValue async_func_obj, - JSTaggedValue value, bool is_resolve) +JSTaggedValue SlowRuntimeStub::AsyncFunctionResolveOrReject(JSThread *thread, JSTaggedValue asyncFuncObj, + JSTaggedValue value, bool isResolve) { - if (is_resolve) { + if (isResolve) { INTERPRETER_TRACE(thread, AsyncFunctionResolve); } else { INTERPRETER_TRACE(thread, AsyncFunctionReject); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle async_func_obj_handle(thread, async_func_obj); - JSHandle promise(thread, async_func_obj_handle->GetPromise()); - JSHandle value_handle(thread, value); + JSHandle asyncFuncObjHandle(thread, asyncFuncObj); + JSHandle promise(thread, asyncFuncObjHandle->GetPromise()); + JSHandle valueHandle(thread, value); // ActivePromise JSHandle reactions = JSPromise::CreateResolvingFunctions(thread, promise); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle this_arg = global_const->GetHandledUndefined(); - JSHandle active_func; - if (is_resolve) { - active_func = JSHandle(thread, reactions->GetResolveFunction()); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle thisArg = globalConst->GetHandledUndefined(); + JSHandle activeFunc; + if (isResolve) { + activeFunc = JSHandle(thread, reactions->GetResolveFunction()); } else { - active_func = JSHandle(thread, reactions->GetRejectFunction()); + activeFunc = JSHandle(thread, reactions->GetRejectFunction()); } - auto info = NewRuntimeCallInfo(thread, active_func, this_arg, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(value_handle); + auto info = NewRuntimeCallInfo(thread, activeFunc, thisArg, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(valueHandle); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -791,83 +790,83 @@ JSTaggedValue SlowRuntimeStub::AsyncFunctionResolveOrReject(JSThread *thread, JS } // 27.6.3.2 AsyncGeneratorStart (generator, generatorBody) -JSTaggedValue SlowRuntimeStub::AsyncGeneratorResolve(JSThread *thread, JSTaggedValue async_gen_obj, JSTaggedValue value) +JSTaggedValue SlowRuntimeStub::AsyncGeneratorResolve(JSThread *thread, JSTaggedValue asyncGenObj, JSTaggedValue value) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle async_generator_handle(thread, async_gen_obj); - JSHandle value_handle(thread, value); + JSHandle asyncGeneratorHandle(thread, asyncGenObj); + JSHandle valueHandle(thread, value); // e. Set generator.[[AsyncGeneratorState]] to completed. - JSAsyncGeneratorObject::Cast(async_gen_obj.GetHeapObject())->SetState(thread, JSGeneratorState::COMPLETED); + JSAsyncGeneratorObject::Cast(asyncGenObj.GetHeapObject())->SetState(thread, JSGeneratorState::COMPLETED); // f. If result is a normal completion, let resultValue be undefined. // i. Let resultValue be result.[[Value]]. // h. Return ! AsyncGeneratorResolve(generator, resultValue, true). - return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, async_generator_handle, value_handle, true) + return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, asyncGeneratorHandle, valueHandle, true) .GetTaggedValue(); } // 27.6.3.2 AsyncGeneratorStart (generator, generatorBody) -JSTaggedValue SlowRuntimeStub::AsyncGeneratorReject(JSThread *thread, JSTaggedValue async_gen_obj, JSTaggedValue value) +JSTaggedValue SlowRuntimeStub::AsyncGeneratorReject(JSThread *thread, JSTaggedValue asyncGenObj, JSTaggedValue value) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle async_generator_handle(thread, async_gen_obj); - JSHandle value_handle(thread, value); + JSHandle asyncGeneratorHandle(thread, asyncGenObj); + JSHandle valueHandle(thread, value); // e. Set generator.[[AsyncGeneratorState]] to completed. - JSAsyncGeneratorObject::Cast(async_gen_obj.GetHeapObject())->SetState(thread, JSGeneratorState::COMPLETED); + JSAsyncGeneratorObject::Cast(asyncGenObj.GetHeapObject())->SetState(thread, JSGeneratorState::COMPLETED); // ii. ii. If result.[[Type]] is not return, then // 1. Return ! AsyncGeneratorReject(generator, resultValue). // 1. 1. Return ! AsyncGeneratorReject(generator, resultValue). - return JSAsyncGeneratorObject::AsyncGeneratorReject(thread, async_generator_handle, value_handle).GetTaggedValue(); + return JSAsyncGeneratorObject::AsyncGeneratorReject(thread, asyncGeneratorHandle, valueHandle).GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::NewObjSpreadDyn(JSThread *thread, JSTaggedValue func, JSTaggedValue new_target, +JSTaggedValue SlowRuntimeStub::NewObjSpreadDyn(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, JSTaggedValue array) { INTERPRETER_TRACE(thread, NewobjspreadDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle js_array(thread, array); - if (!js_array->IsJSArray()) { + JSHandle jsArray(thread, array); + if (!jsArray->IsJSArray()) { return ThrowTypeError(thread, "Cannot Newobjspread"); } - uint32_t length = JSHandle::Cast(js_array)->GetArrayLength(); - auto info = NewRuntimeCallInfo(thread, func, JSTaggedValue::Undefined(), new_target, length); + uint32_t length = JSHandle::Cast(jsArray)->GetArrayLength(); + auto info = NewRuntimeCallInfo(thread, func, JSTaggedValue::Undefined(), newTarget, length); for (uint32_t i = 0; i < length; ++i) { - auto prop = JSTaggedValue::GetProperty(thread, js_array, i).GetValue(); + auto prop = JSTaggedValue::GetProperty(thread, jsArray, i).GetValue(); info->SetCallArg(i, prop.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } return SlowRuntimeHelper::NewObject(info.Get()); } -void SlowRuntimeStub::ThrowTdz(JSThread *thread, JSTaggedValue binding_name) +void SlowRuntimeStub::ThrowTdz(JSThread *thread, JSTaggedValue bindingName) { INTERPRETER_TRACE(thread, ThrowTdz); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle name(thread, binding_name); + JSHandle name(thread, bindingName); JSHandle info = factory->NewFromCanBeCompressString(" is not initialized"); JSHandle msg = factory->ConcatFromString(name, info); THROW_NEW_ERROR_AND_RETURN(thread, factory->NewJSError(base::ErrorType::REFERENCE_ERROR, msg).GetTaggedValue()); } -JSTaggedValue SlowRuntimeStub::ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, JSTaggedValue this_value) +JSTaggedValue SlowRuntimeStub::ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, JSTaggedValue thisValue) { INTERPRETER_TRACE(thread, ThrowIfSuperNotCorrectCall); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - if (index == 0 && (this_value.IsUndefined() || this_value.IsHole())) { + if (index == 0 && (thisValue.IsUndefined() || thisValue.IsHole())) { return ThrowReferenceError(thread, JSTaggedValue::Undefined(), "sub-class must call super before use 'this'"); } - if (index == 1 && !this_value.IsUndefined() && !this_value.IsHole()) { + if (index == 1 && !thisValue.IsUndefined() && !thisValue.IsHole()) { return ThrowReferenceError(thread, JSTaggedValue::Undefined(), "super() forbidden re-bind 'this'"); } return JSTaggedValue::True(); @@ -876,7 +875,7 @@ JSTaggedValue SlowRuntimeStub::ThrowIfSuperNotCorrectCall(JSThread *thread, uint void SlowRuntimeStub::ThrowIfNotObject(JSThread *thread) { INTERPRETER_TRACE(thread, ThrowIfNotObject); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); THROW_TYPE_ERROR(thread, "Inner return result is not object"); } @@ -884,7 +883,7 @@ void SlowRuntimeStub::ThrowIfNotObject(JSThread *thread) void SlowRuntimeStub::ThrowThrowNotExists(JSThread *thread) { INTERPRETER_TRACE(thread, ThrowThrowNotExists); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); THROW_TYPE_ERROR(thread, "Throw method is not defined"); } @@ -892,7 +891,7 @@ void SlowRuntimeStub::ThrowThrowNotExists(JSThread *thread) void SlowRuntimeStub::ThrowPatternNonCoercible(JSThread *thread) { INTERPRETER_TRACE(thread, ThrowPatternNonCoercible); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle msg(thread->GlobalConstants()->GetHandledObjNotCoercibleString()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -902,24 +901,24 @@ void SlowRuntimeStub::ThrowPatternNonCoercible(JSThread *thread) JSTaggedValue SlowRuntimeStub::StOwnByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value) { INTERPRETER_TRACE(thread, StOwnByNameDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, prop); - JSHandle value_handle(thread, value); - ASSERT(prop_handle->IsStringOrSymbol()); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, prop); + JSHandle valueHandle(thread, value); + ASSERT(propHandle->IsStringOrSymbol()); - if (obj_handle->IsClassConstructor() && - JSTaggedValue::SameValue(prop_handle, global_const->GetHandledPrototypeString())) { + if (objHandle->IsClassConstructor() && + JSTaggedValue::SameValue(propHandle, globalConst->GetHandledPrototypeString())) { return ThrowTypeError(thread, "In a class, static property named 'prototype' throw a TypeError"); } // property in class is non-enumerable - bool enumerable = !(obj_handle->IsClassPrototype() || obj_handle->IsClassConstructor()); + bool enumerable = !(objHandle->IsClassPrototype() || objHandle->IsClassConstructor()); - PropertyDescriptor desc(thread, value_handle, true, enumerable, true); - bool ret = JSTaggedValue::DefineOwnProperty(thread, obj_handle, prop_handle, desc); + PropertyDescriptor desc(thread, valueHandle, true, enumerable, true); + bool ret = JSTaggedValue::DefineOwnProperty(thread, objHandle, propHandle, desc); if (!ret) { return ThrowTypeError(thread, "SetOwnByName failed"); } @@ -930,24 +929,24 @@ JSTaggedValue SlowRuntimeStub::StOwnByNameWithNameSet(JSThread *thread, JSTagged JSTaggedValue value) { INTERPRETER_TRACE(thread, StOwnByNameDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, prop); - JSHandle value_handle(thread, value); - ASSERT(prop_handle->IsStringOrSymbol()); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, prop); + JSHandle valueHandle(thread, value); + ASSERT(propHandle->IsStringOrSymbol()); - JSHandle prop_key = JSTaggedValue::ToPropertyKey(thread, prop_handle); + JSHandle propKey = JSTaggedValue::ToPropertyKey(thread, propHandle); // property in class is non-enumerable - bool enumerable = !(obj_handle->IsClassPrototype() || obj_handle->IsClassConstructor()); + bool enumerable = !(objHandle->IsClassPrototype() || objHandle->IsClassConstructor()); - PropertyDescriptor desc(thread, value_handle, true, enumerable, true); - bool ret = JSTaggedValue::DefineOwnProperty(thread, obj_handle, prop_handle, desc); + PropertyDescriptor desc(thread, valueHandle, true, enumerable, true); + bool ret = JSTaggedValue::DefineOwnProperty(thread, objHandle, propHandle, desc); if (!ret) { return ThrowTypeError(thread, "SetOwnByNameWithNameSet failed"); } - JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(value_handle), prop_key, + JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(valueHandle), propKey, JSHandle(thread, JSTaggedValue::Undefined())); return JSTaggedValue::True(); } @@ -955,17 +954,17 @@ JSTaggedValue SlowRuntimeStub::StOwnByNameWithNameSet(JSThread *thread, JSTagged JSTaggedValue SlowRuntimeStub::StOwnByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value) { INTERPRETER_TRACE(thread, StOwnByIdDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); - JSHandle idx_handle(thread, JSTaggedValue(idx)); - JSHandle value_handle(thread, value); + JSHandle objHandle(thread, obj); + JSHandle idxHandle(thread, JSTaggedValue(idx)); + JSHandle valueHandle(thread, value); // property in class is non-enumerable - bool enumerable = !(obj_handle->IsClassPrototype() || obj_handle->IsClassConstructor()); + bool enumerable = !(objHandle->IsClassPrototype() || objHandle->IsClassConstructor()); - PropertyDescriptor desc(thread, value_handle, true, enumerable, true); - bool ret = JSTaggedValue::DefineOwnProperty(thread, obj_handle, idx_handle, desc); + PropertyDescriptor desc(thread, valueHandle, true, enumerable, true); + bool ret = JSTaggedValue::DefineOwnProperty(thread, objHandle, idxHandle, desc); if (!ret) { return ThrowTypeError(thread, "SetOwnByIndex failed"); } @@ -975,12 +974,12 @@ JSTaggedValue SlowRuntimeStub::StOwnByIndex(JSThread *thread, JSTaggedValue obj, JSTaggedValue SlowRuntimeStub::StOwnByValue(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); INTERPRETER_TRACE(thread, StOwnByValueDyn); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - if (obj->IsClassConstructor() && JSTaggedValue::SameValue(key, global_const->GetHandledPrototypeString())) { + if (obj->IsClassConstructor() && JSTaggedValue::SameValue(key, globalConst->GetHandledPrototypeString())) { return ThrowTypeError(thread, "In a class, static property named 'prototype' throw a TypeError"); } @@ -988,16 +987,16 @@ JSTaggedValue SlowRuntimeStub::StOwnByValue(JSThread *thread, const JSHandleIsClassPrototype() || obj->IsClassConstructor()); PropertyDescriptor desc(thread, value, true, enumerable, true); - JSMutableHandle prop_key(JSTaggedValue::ToPropertyKey(thread, key)); - bool ret = JSTaggedValue::DefineOwnProperty(thread, obj, prop_key, desc); + JSMutableHandle propKey(JSTaggedValue::ToPropertyKey(thread, key)); + bool ret = JSTaggedValue::DefineOwnProperty(thread, obj, propKey, desc); if (!ret) { return ThrowTypeError(thread, "StOwnByValue failed"); } if (value->IsJSFunction()) { - if (prop_key->IsNumber()) { - prop_key.Update(base::NumberHelper::NumberToString(thread, prop_key.GetTaggedValue()).GetTaggedValue()); + if (propKey->IsNumber()) { + propKey.Update(base::NumberHelper::NumberToString(thread, propKey.GetTaggedValue()).GetTaggedValue()); } - JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(value), prop_key, + JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(value), propKey, JSHandle(thread, JSTaggedValue::Undefined())); } return JSTaggedValue::True(); @@ -1006,11 +1005,11 @@ JSTaggedValue SlowRuntimeStub::StOwnByValue(JSThread *thread, const JSHandle obj, JSHandle key, JSHandle value) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); INTERPRETER_TRACE(thread, StOwnByValueDyn); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - if (obj->IsClassConstructor() && JSTaggedValue::SameValue(key, global_const->GetHandledPrototypeString())) { + if (obj->IsClassConstructor() && JSTaggedValue::SameValue(key, globalConst->GetHandledPrototypeString())) { return ThrowTypeError(thread, "In a class, static property named 'prototype' throw a TypeError"); } @@ -1018,80 +1017,79 @@ JSTaggedValue SlowRuntimeStub::StOwnByValueWithNameSet(JSThread *thread, JSHandl bool enumerable = !(obj->IsClassPrototype() || obj->IsClassConstructor()); PropertyDescriptor desc(thread, value, true, enumerable, true); - JSMutableHandle prop_key(JSTaggedValue::ToPropertyKey(thread, key)); - bool ret = JSTaggedValue::DefineOwnProperty(thread, obj, prop_key, desc); + JSMutableHandle propKey(JSTaggedValue::ToPropertyKey(thread, key)); + bool ret = JSTaggedValue::DefineOwnProperty(thread, obj, propKey, desc); if (!ret) { return ThrowTypeError(thread, "StOwnByValueWithNameSet failed"); } if (value->IsJSFunction()) { - if (prop_key->IsNumber()) { - prop_key.Update(base::NumberHelper::NumberToString(thread, prop_key.GetTaggedValue()).GetTaggedValue()); + if (propKey->IsNumber()) { + propKey.Update(base::NumberHelper::NumberToString(thread, propKey.GetTaggedValue()).GetTaggedValue()); } - JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(value), prop_key, + JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(value), propKey, JSHandle(thread, JSTaggedValue::Undefined())); } return JSTaggedValue::True(); } -JSTaggedValue SlowRuntimeStub::CreateEmptyArray(JSThread *thread, ObjectFactory *factory, - JSHandle global_env) +JSTaggedValue SlowRuntimeStub::CreateEmptyArray(JSThread *thread, ObjectFactory *factory, JSHandle globalEnv) { INTERPRETER_TRACE(thread, CreateEmptyArray); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle builtin_obj(global_env->GetArrayFunction()); - JSHandle arr = factory->NewJSObjectByConstructor(builtin_obj, JSHandle(builtin_obj)); + JSHandle builtinObj(globalEnv->GetArrayFunction()); + JSHandle arr = factory->NewJSObjectByConstructor(builtinObj, JSHandle(builtinObj)); return arr.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::CreateEmptyObject(JSThread *thread, ObjectFactory *factory, - JSHandle global_env) + JSHandle globalEnv) { INTERPRETER_TRACE(thread, CreateEmptyObject); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle builtin_obj(global_env->GetObjectFunction()); - JSHandle obj = factory->NewJSObjectByConstructor(builtin_obj, JSHandle(builtin_obj)); + JSHandle builtinObj(globalEnv->GetObjectFunction()); + JSHandle obj = factory->NewJSObjectByConstructor(builtinObj, JSHandle(builtinObj)); return obj.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::CreateObjectWithBuffer(JSThread *thread, ObjectFactory *factory, JSObject *literal) { INTERPRETER_TRACE(thread, CreateObjectWithBuffer); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle obj(thread, literal); - JSHandle obj_literal = factory->CloneObjectLiteral(obj); + JSHandle objLiteral = factory->CloneObjectLiteral(obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return obj_literal.GetTaggedValue(); + return objLiteral.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::CreateObjectHavingMethod(JSThread *thread, ObjectFactory *factory, JSObject *literal, JSTaggedValue env, ConstantPool *constpool) { INTERPRETER_TRACE(thread, CreateObjectHavingMethod); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle obj(thread, literal); - JSHandle obj_literal = factory->CloneObjectLiteral( + JSHandle objLiteral = factory->CloneObjectLiteral( obj, JSHandle(thread, env), JSHandle(thread, JSTaggedValue(constpool))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return obj_literal.GetTaggedValue(); + return objLiteral.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::SetObjectWithProto(JSThread *thread, JSTaggedValue proto, JSTaggedValue obj) { INTERPRETER_TRACE(thread, SetObjectWithProto); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); if (!proto.IsECMAObject() && !proto.IsNull()) { return JSTaggedValue::False(); } - JSHandle proto_handle(thread, proto); - JSHandle obj_handle(thread, obj); - JSObject::SetPrototype(thread, obj_handle, proto_handle); + JSHandle protoHandle(thread, proto); + JSHandle objHandle(thread, obj); + JSObject::SetPrototype(thread, objHandle, protoHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::True(); } @@ -1099,85 +1097,85 @@ JSTaggedValue SlowRuntimeStub::SetObjectWithProto(JSThread *thread, JSTaggedValu JSTaggedValue SlowRuntimeStub::CloseIterator(JSThread *thread, JSTaggedValue iter) { INTERPRETER_TRACE(thread, CloseIterator); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle iter_handle(thread, iter); + JSHandle iterHandle(thread, iter); JSHandle record; if (UNLIKELY(thread->HasPendingException())) { JSHandle exception(thread, ObjectWrapper::Cast(thread->GetException().GetTaggedObject())->GetValue()); record = JSHandle(factory->NewCompletionRecord(CompletionRecord::THROW, exception)); } else { - JSHandle undefined_val = global_const->GetHandledUndefined(); - record = JSHandle(factory->NewCompletionRecord(CompletionRecord::NORMAL, undefined_val)); + JSHandle undefinedVal = globalConst->GetHandledUndefined(); + record = JSHandle(factory->NewCompletionRecord(CompletionRecord::NORMAL, undefinedVal)); } - JSHandle result = JSIterator::IteratorClose(thread, iter_handle, record); + JSHandle result = JSIterator::IteratorClose(thread, iterHandle, record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::ImportModule([[maybe_unused]] JSThread *thread, - [[maybe_unused]] JSTaggedValue module_name) + [[maybe_unused]] JSTaggedValue moduleName) { INTERPRETER_TRACE(thread, ImportModule); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle name(thread, module_name); + JSHandle name(thread, moduleName); JSHandle module = thread->GetEcmaVM()->GetModuleByName(name); return module.GetTaggedValue(); // return moduleRef } -void SlowRuntimeStub::StModuleVar([[maybe_unused]] JSThread *thread, [[maybe_unused]] JSTaggedValue export_name, - [[maybe_unused]] JSTaggedValue export_obj) +void SlowRuntimeStub::StModuleVar([[maybe_unused]] JSThread *thread, [[maybe_unused]] JSTaggedValue exportName, + [[maybe_unused]] JSTaggedValue exportObj) { INTERPRETER_TRACE(thread, StModuleVar); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle name(thread, export_name); - JSHandle value(thread, export_obj); + JSHandle name(thread, exportName); + JSHandle value(thread, exportObj); thread->GetEcmaVM()->GetModuleManager()->AddModuleItem(thread, name, value); } -void SlowRuntimeStub::CopyModule(JSThread *thread, JSTaggedValue src_module) +void SlowRuntimeStub::CopyModule(JSThread *thread, JSTaggedValue srcModule) { INTERPRETER_TRACE(thread, CopyModule); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle src_module_obj(thread, src_module); - thread->GetEcmaVM()->GetModuleManager()->CopyModule(thread, src_module_obj); + JSHandle srcModuleObj(thread, srcModule); + thread->GetEcmaVM()->GetModuleManager()->CopyModule(thread, srcModuleObj); } JSTaggedValue SlowRuntimeStub::LdModvarByName([[maybe_unused]] JSThread *thread, - [[maybe_unused]] JSTaggedValue module_obj, - [[maybe_unused]] JSTaggedValue item_name) + [[maybe_unused]] JSTaggedValue moduleObj, + [[maybe_unused]] JSTaggedValue itemName) { INTERPRETER_TRACE(thread, LdModvarByName); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle module(thread, module_obj); - JSHandle item(thread, item_name); - JSHandle module_var = thread->GetEcmaVM()->GetModuleManager()->GetModuleItem(thread, module, item); - return module_var.GetTaggedValue(); + JSHandle module(thread, moduleObj); + JSHandle item(thread, itemName); + JSHandle moduleVar = thread->GetEcmaVM()->GetModuleManager()->GetModuleItem(thread, module, item); + return moduleVar.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::ClassFieldAdd(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop_name, +JSTaggedValue SlowRuntimeStub::ClassFieldAdd(JSThread *thread, JSTaggedValue obj, JSTaggedValue propName, JSTaggedValue value) { INTERPRETER_TRACE(thread, ClassFieldAdd); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *global_consts = thread->GlobalConstants(); - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, prop_name); - JSHandle value_handle(thread, value); - ASSERT(prop_handle->IsStringOrSymbol()); + const GlobalEnvConstants *globalConsts = thread->GlobalConstants(); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, propName); + JSHandle valueHandle(thread, value); + ASSERT(propHandle->IsStringOrSymbol()); - if (obj_handle->IsClassConstructor() && - JSTaggedValue::SameValue(prop_handle, global_consts->GetHandledPrototypeString())) { + if (objHandle->IsClassConstructor() && + JSTaggedValue::SameValue(propHandle, globalConsts->GetHandledPrototypeString())) { return ThrowTypeError(thread, "In a class, static property named 'prototype' throw a TypeError"); } - PropertyDescriptor desc(thread, value_handle, true, true, true); - bool ret = JSTaggedValue::DefineOwnProperty(thread, obj_handle, prop_handle, desc); + PropertyDescriptor desc(thread, valueHandle, true, true, true); + bool ret = JSTaggedValue::DefineOwnProperty(thread, objHandle, propHandle, desc); if (!ret) { return ThrowTypeError(thread, "ClassFieldAdd failed"); } @@ -1187,46 +1185,46 @@ JSTaggedValue SlowRuntimeStub::ClassFieldAdd(JSThread *thread, JSTaggedValue obj using PrivateFieldKind = JSConstructorFunction::PrivateFieldKind; void SlowRuntimeStub::DefineClassPrivateFields(JSThread *thread, ConstantPool *constpool, JSTaggedValue env, - JSTaggedValue ctor, JSTaggedValue private_buf) + JSTaggedValue ctor, JSTaggedValue privateBuf) { INTERPRETER_TRACE(thread, DefineClassPrivateFields); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); auto factory = thread->GetEcmaVM()->GetFactory(); - JSHandle desc_template(thread, private_buf); - JSHandle constpool_handle(thread, constpool); - JSHandle lexical_env(thread, env); - JSHandle ctor_handle(thread, ctor); - JSHandle new_desc = factory->NewTaggedArray(desc_template->GetLength()); - JSHandle accessor_keys = LinkedHashMap::Create(thread); - - for (ArraySizeT i = 0; i < desc_template->GetLength();) { - JSHandle kind_value(thread, desc_template->Get(thread, i)); - auto kind = static_cast(kind_value->GetInt()); - new_desc->Set(thread, i++, kind_value); + JSHandle descTemplate(thread, privateBuf); + JSHandle constpoolHandle(thread, constpool); + JSHandle lexicalEnv(thread, env); + JSHandle ctorHandle(thread, ctor); + JSHandle newDesc = factory->NewTaggedArray(descTemplate->GetLength()); + JSHandle accessorKeys = LinkedHashMap::Create(thread); + + for (ArraySizeT i = 0; i < descTemplate->GetLength();) { + JSHandle kindValue(thread, descTemplate->Get(thread, i)); + auto kind = static_cast(kindValue->GetInt()); + newDesc->Set(thread, i++, kindValue); switch (kind) { case PrivateFieldKind::FIELD: case PrivateFieldKind::STATIC_FIELD: case PrivateFieldKind::METHOD: case PrivateFieldKind::STATIC_METHOD: { - JSHandle name(thread, desc_template->Get(thread, i)); - JSHandle private_key = factory->NewPrivateNameSymbol(name); - new_desc->Set(thread, i++, private_key.GetTaggedValue()); + JSHandle name(thread, descTemplate->Get(thread, i)); + JSHandle privateKey = factory->NewPrivateNameSymbol(name); + newDesc->Set(thread, i++, privateKey.GetTaggedValue()); break; } default: { - JSHandle name(thread, desc_template->Get(thread, i)); + JSHandle name(thread, descTemplate->Get(thread, i)); int hash = LinkedHash::Hash(name.GetTaggedValue()); - JSTaggedValue private_key = accessor_keys->Get(name.GetTaggedValue(), hash); + JSTaggedValue privateKey = accessorKeys->Get(name.GetTaggedValue(), hash); - if (private_key.IsUndefined()) { - JSHandle shared_private_key = factory->NewPrivateNameSymbol(name); - LinkedHashMap::Set(thread, accessor_keys, name, JSHandle::Cast(shared_private_key)); - private_key = shared_private_key.GetTaggedValue(); + if (privateKey.IsUndefined()) { + JSHandle sharedPrivateKey = factory->NewPrivateNameSymbol(name); + LinkedHashMap::Set(thread, accessorKeys, name, JSHandle::Cast(sharedPrivateKey)); + privateKey = sharedPrivateKey.GetTaggedValue(); } - new_desc->Set(thread, i++, private_key); + newDesc->Set(thread, i++, privateKey); break; } } @@ -1237,37 +1235,37 @@ void SlowRuntimeStub::DefineClassPrivateFields(JSThread *thread, ConstantPool *c break; } default: { - JSHandle value_handle(thread, desc_template->Get(thread, i)); - JSHandle new_func = factory->CloneJSFuction(value_handle, value_handle->GetFunctionKind()); - new_func->SetLexicalEnv(thread, lexical_env.GetTaggedValue()); - new_func->SetConstantPool(thread, constpool_handle.GetTaggedValue()); - new_desc->Set(thread, i++, new_func.GetTaggedValue()); + JSHandle valueHandle(thread, descTemplate->Get(thread, i)); + JSHandle newFunc = factory->CloneJSFuction(valueHandle, valueHandle->GetFunctionKind()); + newFunc->SetLexicalEnv(thread, lexicalEnv.GetTaggedValue()); + newFunc->SetConstantPool(thread, constpoolHandle.GetTaggedValue()); + newDesc->Set(thread, i++, newFunc.GetTaggedValue()); break; } } } - JSConstructorFunction::Cast(ctor_handle->GetHeapObject())->SetPrivateFields(new_desc.GetTaggedValue()); + JSConstructorFunction::Cast(ctorHandle->GetHeapObject())->SetPrivateFields(newDesc.GetTaggedValue()); } JSTaggedValue SlowRuntimeStub::ClassPrivateMethodOrAccessorAdd(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj) { INTERPRETER_TRACE(thread, ClassPrivateMethodOrAccessorAdd); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); auto factory = thread->GetEcmaVM()->GetFactory(); - JSHandle ctor_handle(thread, ctor); - JSHandle obj_handle(thread, obj); + JSHandle ctorHandle(thread, ctor); + JSHandle objHandle(thread, obj); - bool is_static = JSTaggedValue::Equal(thread, JSHandle::Cast(ctor_handle), - JSHandle::Cast(obj_handle)); + bool isStatic = JSTaggedValue::Equal(thread, JSHandle::Cast(ctorHandle), + JSHandle::Cast(objHandle)); - JSHandle desc = JSHandle(thread, ctor_handle->GetPrivateFields()); - JSHandle accessor_pairs = LinkedHashMap::Create(thread); + JSHandle desc = JSHandle(thread, ctorHandle->GetPrivateFields()); + JSHandle accessorPairs = LinkedHashMap::Create(thread); for (ArraySizeT i = 0; i < desc->GetLength();) { - JSHandle kind_value(thread, desc->Get(thread, i++)); - auto kind = static_cast(kind_value->GetInt()); + JSHandle kindValue(thread, desc->Get(thread, i++)); + auto kind = static_cast(kindValue->GetInt()); switch (kind) { case PrivateFieldKind::FIELD: @@ -1278,7 +1276,7 @@ JSTaggedValue SlowRuntimeStub::ClassPrivateMethodOrAccessorAdd(JSThread *thread, case PrivateFieldKind::METHOD: case PrivateFieldKind::GET: case PrivateFieldKind::SET: { - if (is_static) { + if (isStatic) { i += 2; // 2: skip key + value continue; } @@ -1287,7 +1285,7 @@ JSTaggedValue SlowRuntimeStub::ClassPrivateMethodOrAccessorAdd(JSThread *thread, case PrivateFieldKind::STATIC_METHOD: case PrivateFieldKind::STATIC_GET: case PrivateFieldKind::STATIC_SET: { - if (!is_static) { + if (!isStatic) { i += 2; // 2: skip key + value continue; } @@ -1295,11 +1293,11 @@ JSTaggedValue SlowRuntimeStub::ClassPrivateMethodOrAccessorAdd(JSThread *thread, } } - JSHandle private_symbol(thread, desc->Get(thread, i++)); + JSHandle privateSymbol(thread, desc->Get(thread, i++)); JSHandle value(thread, desc->Get(thread, i++)); - PropertyDescriptor prop_desc(thread); - bool exists = JSObject::GetOwnProperty(thread, obj_handle, private_symbol, prop_desc); + PropertyDescriptor propDesc(thread); + bool exists = JSObject::GetOwnProperty(thread, objHandle, privateSymbol, propDesc); switch (kind) { case PrivateFieldKind::METHOD: @@ -1309,20 +1307,20 @@ JSTaggedValue SlowRuntimeStub::ClassPrivateMethodOrAccessorAdd(JSThread *thread, JSTaggedValue::Exception()); } - prop_desc = PropertyDescriptor(thread, value, false, false, false); - JSObject::DefineOwnProperty(thread, obj_handle, private_symbol, prop_desc); + propDesc = PropertyDescriptor(thread, value, false, false, false); + JSObject::DefineOwnProperty(thread, objHandle, privateSymbol, propDesc); continue; } case PrivateFieldKind::GET: case PrivateFieldKind::STATIC_GET: { - int hash = LinkedHash::Hash(private_symbol.GetTaggedValue()); - JSTaggedValue pair = accessor_pairs->Get(private_symbol.GetTaggedValue(), hash); + int hash = LinkedHash::Hash(privateSymbol.GetTaggedValue()); + JSTaggedValue pair = accessorPairs->Get(privateSymbol.GetTaggedValue(), hash); if (pair.IsUndefined()) { JSHandle arr = factory->NewTaggedArray(2); // 2: getter-setter pair arr->Set(thread, 0, value); arr->Set(thread, 1, JSTaggedValue::Undefined()); - LinkedHashMap::Set(thread, accessor_pairs, private_symbol, JSHandle::Cast(arr)); + LinkedHashMap::Set(thread, accessorPairs, privateSymbol, JSHandle::Cast(arr)); continue; } TaggedArray::Cast(pair.GetHeapObject())->Set(thread, 0, value); @@ -1330,14 +1328,14 @@ JSTaggedValue SlowRuntimeStub::ClassPrivateMethodOrAccessorAdd(JSThread *thread, } case PrivateFieldKind::SET: case PrivateFieldKind::STATIC_SET: { - int hash = LinkedHash::Hash(private_symbol.GetTaggedValue()); - JSTaggedValue pair = accessor_pairs->Get(private_symbol.GetTaggedValue(), hash); + int hash = LinkedHash::Hash(privateSymbol.GetTaggedValue()); + JSTaggedValue pair = accessorPairs->Get(privateSymbol.GetTaggedValue(), hash); if (pair.IsUndefined()) { JSHandle arr = factory->NewTaggedArray(2); // 2: getter-setter pair arr->Set(thread, 0, JSTaggedValue::Undefined()); arr->Set(thread, 1, value); - LinkedHashMap::Set(thread, accessor_pairs, private_symbol, JSHandle::Cast(arr)); + LinkedHashMap::Set(thread, accessorPairs, privateSymbol, JSHandle::Cast(arr)); continue; } TaggedArray::Cast(pair.GetHeapObject())->Set(thread, 1, value); @@ -1350,186 +1348,186 @@ JSTaggedValue SlowRuntimeStub::ClassPrivateMethodOrAccessorAdd(JSThread *thread, } } - PropertyDescriptor prop_desc(thread); - for (int i = 0; i < accessor_pairs->NumberOfElements(); i++) { - JSHandle private_symbol(thread, accessor_pairs->GetKey(i)); + PropertyDescriptor propDesc(thread); + for (int i = 0; i < accessorPairs->NumberOfElements(); i++) { + JSHandle privateSymbol(thread, accessorPairs->GetKey(i)); - int hash = LinkedHash::Hash(private_symbol.GetTaggedValue()); - JSHandle accessor_pair(thread, accessor_pairs->Get(private_symbol.GetTaggedValue(), hash)); - JSHandle getter(thread, accessor_pair->Get(0)); - JSHandle setter(thread, accessor_pair->Get(1)); + int hash = LinkedHash::Hash(privateSymbol.GetTaggedValue()); + JSHandle accessorPair(thread, accessorPairs->Get(privateSymbol.GetTaggedValue(), hash)); + JSHandle getter(thread, accessorPair->Get(0)); + JSHandle setter(thread, accessorPair->Get(1)); - prop_desc.SetGetter(getter); - prop_desc.SetSetter(setter); - prop_desc.SetConfigurable(false); - prop_desc.SetEnumerable(false); - JSObject::DefineOwnProperty(thread, obj_handle, private_symbol, prop_desc); + propDesc.SetGetter(getter); + propDesc.SetSetter(setter); + propDesc.SetConfigurable(false); + propDesc.SetEnumerable(false); + JSObject::DefineOwnProperty(thread, objHandle, privateSymbol, propDesc); } return JSTaggedValue::Undefined(); } JSTaggedValue SlowRuntimeStub::ClassPrivateFieldAdd(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name, JSTaggedValue value) + JSTaggedValue propName, JSTaggedValue value) { INTERPRETER_TRACE(thread, ClassPrivateFieldAdd); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - PropertyDescriptor prop_desc(thread); + PropertyDescriptor propDesc(thread); [[maybe_unused]] PrivateFieldKind kind; - JSHandle obj_handle(thread, obj); - JSHandle prop_name_handle(thread, prop_name); - JSHandle value_handle(thread, value); + JSHandle objHandle(thread, obj); + JSHandle propNameHandle(thread, propName); + JSHandle valueHandle(thread, value); - JSHandle private_symbol( - thread, SlowRuntimeHelper::FindPrivateKey(thread, JSHandle(thread, ctor), obj_handle, - prop_name_handle, prop_desc, kind)); + JSHandle privateSymbol( + thread, SlowRuntimeHelper::FindPrivateKey(thread, JSHandle(thread, ctor), objHandle, + propNameHandle, propDesc, kind)); - if (!prop_desc.GetValue()->IsHole()) { + if (!propDesc.GetValue()->IsHole()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot declare same private field twice", JSTaggedValue::Exception()); } - prop_desc = PropertyDescriptor(thread, value_handle, true, false, false); - JSObject::DefineOwnProperty(thread, obj_handle, private_symbol, prop_desc); + propDesc = PropertyDescriptor(thread, valueHandle, true, false, false); + JSObject::DefineOwnProperty(thread, objHandle, privateSymbol, propDesc); return JSTaggedValue::Undefined(); } JSTaggedValue SlowRuntimeStub::ClassPrivateFieldGet(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name) + JSTaggedValue propName) { INTERPRETER_TRACE(thread, ClassPrivateFieldGet); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - PropertyDescriptor prop_desc(thread); + PropertyDescriptor propDesc(thread); [[maybe_unused]] PrivateFieldKind kind; - JSHandle ctor_handle(thread, ctor); - JSHandle obj_handle(thread, obj); - JSHandle prop_name_handle(thread, prop_name); - JSHandle js_obj(JSTaggedValue::ToObject(thread, obj_handle)); + JSHandle ctorHandle(thread, ctor); + JSHandle objHandle(thread, obj); + JSHandle propNameHandle(thread, propName); + JSHandle jsObj(JSTaggedValue::ToObject(thread, objHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle private_symbol( - thread, SlowRuntimeHelper::FindPrivateKey(thread, ctor_handle, js_obj, prop_name_handle, prop_desc, kind)); + JSHandle privateSymbol( + thread, SlowRuntimeHelper::FindPrivateKey(thread, ctorHandle, jsObj, propNameHandle, propDesc, kind)); - if (prop_desc.GetValue()->IsHole()) { + if (propDesc.GetValue()->IsHole()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot read private member to an object whose class did not declare it", JSTaggedValue::Exception()); } - if (prop_desc.HasValue()) { - return prop_desc.GetValue().GetTaggedValue(); + if (propDesc.HasValue()) { + return propDesc.GetValue().GetTaggedValue(); } - if (!prop_desc.HasGetter()) { + if (!propDesc.HasGetter()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Private field was defined without a getter", JSTaggedValue::Exception()); } - auto info = NewRuntimeCallInfo(thread, prop_desc.GetGetter(), obj_handle, JSTaggedValue::Undefined(), 0); + auto info = NewRuntimeCallInfo(thread, propDesc.GetGetter(), objHandle, JSTaggedValue::Undefined(), 0); JSTaggedValue res = JSFunction::Call(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res; } JSTaggedValue SlowRuntimeStub::ClassPrivateFieldSet(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name, JSTaggedValue value) + JSTaggedValue propName, JSTaggedValue value) { INTERPRETER_TRACE(thread, ClassPrivateFieldSet); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - PropertyDescriptor prop_desc(thread); + PropertyDescriptor propDesc(thread); [[maybe_unused]] PrivateFieldKind kind; - JSHandle ctor_handle(thread, ctor); - JSHandle obj_handle(thread, obj); - JSHandle prop_name_handle(thread, prop_name); - JSHandle value_handle(thread, value); - JSHandle js_obj(JSTaggedValue::ToObject(thread, obj_handle)); + JSHandle ctorHandle(thread, ctor); + JSHandle objHandle(thread, obj); + JSHandle propNameHandle(thread, propName); + JSHandle valueHandle(thread, value); + JSHandle jsObj(JSTaggedValue::ToObject(thread, objHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle private_symbol( - thread, SlowRuntimeHelper::FindPrivateKey(thread, ctor_handle, js_obj, prop_name_handle, prop_desc, kind)); + JSHandle privateSymbol( + thread, SlowRuntimeHelper::FindPrivateKey(thread, ctorHandle, jsObj, propNameHandle, propDesc, kind)); - if (prop_desc.GetValue()->IsHole()) { + if (propDesc.GetValue()->IsHole()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot read private member to an object whose class did not declare it", JSTaggedValue::Exception()); } - if (prop_desc.HasValue()) { + if (propDesc.HasValue()) { if (kind == PrivateFieldKind::METHOD || kind == PrivateFieldKind::STATIC_METHOD) { THROW_TYPE_ERROR_AND_RETURN(thread, "Private method is not writable", JSTaggedValue::Exception()); } - prop_desc.SetValue(value_handle); - JSObject::DefineOwnProperty(thread, js_obj, private_symbol, prop_desc); + propDesc.SetValue(valueHandle); + JSObject::DefineOwnProperty(thread, jsObj, privateSymbol, propDesc); return JSTaggedValue::Undefined(); } - if (!prop_desc.HasSetter()) { + if (!propDesc.HasSetter()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Private field was defined without a setter", JSTaggedValue::Exception()); } - auto info = NewRuntimeCallInfo(thread, prop_desc.GetSetter(), obj_handle, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(value_handle); + auto info = NewRuntimeCallInfo(thread, propDesc.GetSetter(), objHandle, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(valueHandle); JSTaggedValue res = JSFunction::Call(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res; } JSTaggedValue SlowRuntimeStub::ClassPrivateFieldIn(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name) + JSTaggedValue propName) { INTERPRETER_TRACE(thread, ClassPrivateFieldIn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - PropertyDescriptor prop_desc(thread); + PropertyDescriptor propDesc(thread); [[maybe_unused]] PrivateFieldKind kind; if (!obj.IsECMAObject()) { return ThrowTypeError(thread, "Cannot use 'in' operator in Non-Object"); } - JSHandle obj_handle(thread, obj); - JSHandle prop_name_handle(thread, prop_name); + JSHandle objHandle(thread, obj); + JSHandle propNameHandle(thread, propName); - JSHandle private_symbol( - thread, SlowRuntimeHelper::FindPrivateKey(thread, JSHandle(thread, ctor), obj_handle, - prop_name_handle, prop_desc, kind)); + JSHandle privateSymbol( + thread, SlowRuntimeHelper::FindPrivateKey(thread, JSHandle(thread, ctor), objHandle, + propNameHandle, propDesc, kind)); - return JSTaggedValue(!prop_desc.GetValue()->IsHole()); + return JSTaggedValue(!propDesc.GetValue()->IsHole()); } JSTaggedValue SlowRuntimeStub::CreateRegExpWithLiteral(JSThread *thread, JSTaggedValue pattern, uint8_t flags) { INTERPRETER_TRACE(thread, CreateRegExpWithLiteral); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle pattern_handle(thread, pattern); - JSHandle flags_handle(thread, JSTaggedValue(flags)); + JSHandle patternHandle(thread, pattern); + JSHandle flagsHandle(thread, JSTaggedValue(flags)); - return builtins::reg_exp::RegExpCreate(thread, pattern_handle, flags_handle); + return builtins::reg_exp::RegExpCreate(thread, patternHandle, flagsHandle); } JSTaggedValue SlowRuntimeStub::CreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory, JSArray *literal) { INTERPRETER_TRACE(thread, CreateArrayWithBuffer); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle array(thread, literal); - JSHandle arr_literal = factory->CloneArrayLiteral(array); + JSHandle arrLiteral = factory->CloneArrayLiteral(array); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return arr_literal.GetTaggedValue(); + return arrLiteral.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::GetMethod(JSThread *thread, JSTaggedValue object, JSTaggedValue prop_key) +JSTaggedValue SlowRuntimeStub::GetMethod(JSThread *thread, JSTaggedValue object, JSTaggedValue propKey) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle obj(thread, object); - JSHandle key(thread, prop_key); + JSHandle key(thread, propKey); JSHandle method = JSObject::GetMethod(thread, obj, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1539,18 +1537,18 @@ JSTaggedValue SlowRuntimeStub::GetMethod(JSThread *thread, JSTaggedValue object, JSTaggedValue SlowRuntimeStub::GetTemplateObject(JSThread *thread, JSTaggedValue literal) { INTERPRETER_TRACE(thread, GetTemplateObject); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle template_literal(thread, literal); - JSHandle template_obj = TemplateString::GetTemplateObject(thread, template_literal); + JSHandle templateLiteral(thread, literal); + JSHandle templateObj = TemplateString::GetTemplateObject(thread, templateLiteral); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return template_obj.GetTaggedValue(); + return templateObj.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::GetNextPropName(JSThread *thread, JSTaggedValue iter) { INTERPRETER_TRACE(thread, GetNextPropName); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle iterator(thread, iter); ASSERT(iterator->IsForinIterator()); @@ -1563,45 +1561,45 @@ JSTaggedValue SlowRuntimeStub::GetNextPropName(JSThread *thread, JSTaggedValue i JSTaggedValue SlowRuntimeStub::CopyDataProperties(JSThread *thread, JSTaggedValue dst, JSTaggedValue src) { INTERPRETER_TRACE(thread, CopyDataProperties); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle dst_handle(thread, dst); - JSHandle src_handle(thread, src); - if (!src_handle->IsNull() && !src_handle->IsUndefined()) { - JSHandle keys = JSTaggedValue::GetOwnPropertyKeys(thread, src_handle); + JSHandle dstHandle(thread, dst); + JSHandle srcHandle(thread, src); + if (!srcHandle->IsNull() && !srcHandle->IsUndefined()) { + JSHandle keys = JSTaggedValue::GetOwnPropertyKeys(thread, srcHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSMutableHandle key(thread, JSTaggedValue::Undefined()); - uint32_t keys_len = keys->GetLength(); - for (uint32_t i = 0; i < keys_len; i++) { + uint32_t keysLen = keys->GetLength(); + for (uint32_t i = 0; i < keysLen; i++) { PropertyDescriptor desc(thread); key.Update(keys->Get(i)); - bool success = JSTaggedValue::GetOwnProperty(thread, src_handle, key, desc); + bool success = JSTaggedValue::GetOwnProperty(thread, srcHandle, key, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (success && desc.IsEnumerable()) { - JSTaggedValue::DefineOwnProperty(thread, dst_handle, key, desc); + JSTaggedValue::DefineOwnProperty(thread, dstHandle, key, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } } - return dst_handle.GetTaggedValue(); + return dstHandle.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::GetUnmappedArgs(JSThread *thread, uint32_t actual_num_args, JSTaggedType *stkargs) +JSTaggedValue SlowRuntimeStub::GetUnmappedArgs(JSThread *thread, uint32_t actualNumArgs, JSTaggedType *stkargs) { INTERPRETER_TRACE(thread, GetUnmapedArgs); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle global_env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle arguments_list = factory->NewTaggedArray(actual_num_args); - for (uint32_t i = 0; i < actual_num_args; ++i) { - arguments_list->Set(thread, i, - JSTaggedValue(stkargs[i])); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle argumentsList = factory->NewTaggedArray(actualNumArgs); + for (uint32_t i = 0; i < actualNumArgs; ++i) { + argumentsList->Set(thread, i, + JSTaggedValue(stkargs[i])); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } // 1. Let len be the number of elements in argumentsList - int32_t len = arguments_list->GetLength(); + int32_t len = argumentsList->GetLength(); // 2. Let obj be ObjectCreate(%ObjectPrototype%, «[[ParameterMap]]»). // 3. Set obj’s [[ParameterMap]] internal slot to undefined. JSHandle obj = factory->NewJSArguments(); @@ -1613,90 +1611,89 @@ JSTaggedValue SlowRuntimeStub::GetUnmappedArgs(JSThread *thread, uint32_t actual // a. Let val be argumentsList[index]. // b. Perform CreateDataProperty(obj, ToString(index), val). // c. Let index be index + 1 - obj->SetElements(thread, arguments_list.GetTaggedValue()); + obj->SetElements(thread, argumentsList.GetTaggedValue()); // 7. Perform DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor // {[[Value]]:%ArrayProto_values%, // [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}). obj->SetPropertyInlinedProps(thread, JSArguments::ITERATOR_INLINE_PROPERTY_INDEX, - global_env->GetArrayProtoValuesFunction().GetTaggedValue()); + globalEnv->GetArrayProtoValuesFunction().GetTaggedValue()); // 9. Perform DefinePropertyOrThrow(obj, "callee", PropertyDescriptor {[[Get]]: %ThrowTypeError%, // [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false}). - JSHandle throw_function = global_env->GetThrowTypeError(); + JSHandle throwFunction = globalEnv->GetThrowTypeError(); JSHandle accessor = factory->NewAccessorData(); - accessor->SetGetter(thread, throw_function); - accessor->SetSetter(thread, throw_function); + accessor->SetGetter(thread, throwFunction); + accessor->SetSetter(thread, throwFunction); obj->SetPropertyInlinedProps(thread, JSArguments::CALLEE_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Return obj return obj.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::CopyRestArgs(JSThread *thread, uint32_t rest_num_args, JSTaggedType *stkargs) +JSTaggedValue SlowRuntimeStub::CopyRestArgs(JSThread *thread, uint32_t restNumArgs, JSTaggedType *stkargs) { INTERPRETER_TRACE(thread, Copyrestargs); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle rest_array = JSArray::ArrayCreate(thread, JSTaggedNumber(rest_num_args)); + JSHandle restArray = JSArray::ArrayCreate(thread, JSTaggedNumber(restNumArgs)); JSMutableHandle element(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 0; i < rest_num_args; ++i) { + for (uint32_t i = 0; i < restNumArgs; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) element.Update(JSTaggedValue(stkargs[i])); - JSObject::SetProperty(thread, rest_array, i, element, true); + JSObject::SetProperty(thread, restArray, i, element, true); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return rest_array.GetTaggedValue(); + return restArray.GetTaggedValue(); } // 7.4.1 GetIterator JSTaggedValue SlowRuntimeStub::GetIterator(JSThread *thread, JSTaggedValue obj, bool async, JSTaggedValue method) { INTERPRETER_TRACE(thread, GetIterator); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); EcmaVM *vm = thread->GetEcmaVM(); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); JSHandle env = vm->GetGlobalEnv(); - JSHandle obj_handle(thread, obj); - JSMutableHandle method_handle(thread, global_const->GetHandledUndefined()); + JSHandle objHandle(thread, obj); + JSMutableHandle methodHandle(thread, globalConst->GetHandledUndefined()); // 3. If method is not present, then if (method.IsHole()) { // a. If hint is async, then if (async) { // i. Set method to ? GetMethod(obj, @@asyncIterator). - method_handle.Update(JSObject::GetMethod(thread, obj_handle, env->GetAsyncIteratorSymbol())); + methodHandle.Update(JSObject::GetMethod(thread, objHandle, env->GetAsyncIteratorSymbol())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (method_handle->IsUndefined()) { + if (methodHandle->IsUndefined()) { // 1. Let syncMethod be ? GetMethod(obj, @@iterator). - JSHandle sync_method = JSObject::GetMethod(thread, obj_handle, env->GetIteratorSymbol()); + JSHandle syncMethod = JSObject::GetMethod(thread, objHandle, env->GetIteratorSymbol()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod). - JSHandle sync_iterator( - thread, SlowRuntimeStub::GetIterator(thread, obj_handle.GetTaggedValue(), false, - sync_method.GetTaggedValue())); + JSHandle syncIterator(thread, + SlowRuntimeStub::GetIterator(thread, objHandle.GetTaggedValue(), + false, syncMethod.GetTaggedValue())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Let nextMethod be ? GetV(iterator, "next"). - JSHandle sync_next_method = - JSTaggedValue::GetProperty(thread, sync_iterator, global_const->GetHandledNextString()).GetValue(); + JSHandle syncNextMethod = + JSTaggedValue::GetProperty(thread, syncIterator, globalConst->GetHandledNextString()).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ! CreateAsyncFromSyncIterator(syncIteratorRecord). - return JSAsyncFromSyncIteratorObject::CreateAsyncFromSyncIterator(thread, sync_iterator, - sync_next_method); + return JSAsyncFromSyncIteratorObject::CreateAsyncFromSyncIterator(thread, syncIterator, syncNextMethod); } } else { - method_handle.Update(JSTaggedValue::GetProperty(thread, obj_handle, env->GetIteratorSymbol()).GetValue()); + methodHandle.Update(JSTaggedValue::GetProperty(thread, objHandle, env->GetIteratorSymbol()).GetValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } else { - method_handle.Update(method); + methodHandle.Update(method); } // 4. Let iterator be ? Call(method, obj). - auto info = NewRuntimeCallInfo(thread, method_handle, obj_handle, JSTaggedValue::Undefined(), 0); + auto info = NewRuntimeCallInfo(thread, methodHandle, objHandle, JSTaggedValue::Undefined(), 0); JSTaggedValue iterator = JSFunction::Call(info.Get()); // 5. If Type(iterator) is not Object, throw a TypeError exception. @@ -1711,71 +1708,71 @@ JSTaggedValue SlowRuntimeStub::DefineGetterSetterByValue(JSThread *thread, JSTag JSTaggedValue getter, JSTaggedValue setter, bool flag) { INTERPRETER_TRACE(thread, DefineGetterSetterByValue); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, prop); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, prop); - JSHandle getter_handle(thread, getter); - JSHandle setter_handle(thread, setter); - JSHandle prop_key = JSTaggedValue::ToPropertyKey(thread, prop_handle); + JSHandle getterHandle(thread, getter); + JSHandle setterHandle(thread, setter); + JSHandle propKey = JSTaggedValue::ToPropertyKey(thread, propHandle); - auto global_const = thread->GlobalConstants(); - if (obj_handle.GetTaggedValue().IsClassConstructor() && - JSTaggedValue::SameValue(prop_key, global_const->GetHandledPrototypeString())) { + auto globalConst = thread->GlobalConstants(); + if (objHandle.GetTaggedValue().IsClassConstructor() && + JSTaggedValue::SameValue(propKey, globalConst->GetHandledPrototypeString())) { return ThrowTypeError( thread, "In a class, computed property names for static getter that are named 'prototype' throw a TypeError"); } if (flag) { - if (!getter_handle->IsUndefined()) { - if (prop_key->IsNumber()) { - prop_key = JSHandle::Cast( - base::NumberHelper::NumberToString(thread, prop_key.GetTaggedValue())); + if (!getterHandle->IsUndefined()) { + if (propKey->IsNumber()) { + propKey = + JSHandle::Cast(base::NumberHelper::NumberToString(thread, propKey.GetTaggedValue())); } - JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(getter_handle), prop_key, - JSHandle(thread, global_const->GetGetString())); + JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(getterHandle), propKey, + JSHandle(thread, globalConst->GetGetString())); } - if (!setter_handle->IsUndefined()) { - if (prop_key->IsNumber()) { - prop_key = JSHandle::Cast( - base::NumberHelper::NumberToString(thread, prop_key.GetTaggedValue())); + if (!setterHandle->IsUndefined()) { + if (propKey->IsNumber()) { + propKey = + JSHandle::Cast(base::NumberHelper::NumberToString(thread, propKey.GetTaggedValue())); } - JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(setter_handle), prop_key, - JSHandle(thread, global_const->GetSetString())); + JSFunctionBase::SetFunctionName(thread, JSHandle::Cast(setterHandle), propKey, + JSHandle(thread, globalConst->GetSetString())); } } // set accessor bool enumerable = - !(obj_handle.GetTaggedValue().IsClassPrototype() || obj_handle.GetTaggedValue().IsClassConstructor()); + !(objHandle.GetTaggedValue().IsClassPrototype() || objHandle.GetTaggedValue().IsClassConstructor()); PropertyDescriptor desc(thread, true, enumerable, true); - if (!getter_handle->IsUndefined()) { - JSHandle::Cast(getter_handle)->SetFunctionKind(thread, FunctionKind::GETTER_FUNCTION); - desc.SetGetter(getter_handle); + if (!getterHandle->IsUndefined()) { + JSHandle::Cast(getterHandle)->SetFunctionKind(thread, FunctionKind::GETTER_FUNCTION); + desc.SetGetter(getterHandle); } - if (!setter_handle->IsUndefined()) { - JSHandle::Cast(setter_handle)->SetFunctionKind(thread, FunctionKind::SETTER_FUNCTION); - desc.SetSetter(setter_handle); + if (!setterHandle->IsUndefined()) { + JSHandle::Cast(setterHandle)->SetFunctionKind(thread, FunctionKind::SETTER_FUNCTION); + desc.SetSetter(setterHandle); } - JSObject::DefineOwnProperty(thread, obj_handle, prop_key, desc); + JSObject::DefineOwnProperty(thread, objHandle, propKey, desc); - return obj_handle.GetTaggedValue(); + return objHandle.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::LdObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, bool call_getter, +JSTaggedValue SlowRuntimeStub::LdObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, bool callGetter, JSTaggedValue receiver) { INTERPRETER_TRACE(thread, LdObjByIndexDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSTaggedValue res; - JSHandle obj_handle(thread, obj); - if (call_getter) { - res = JSObject::CallGetter(thread, AccessorData::Cast(receiver.GetTaggedObject()), obj_handle); + JSHandle objHandle(thread, obj); + if (callGetter) { + res = JSObject::CallGetter(thread, AccessorData::Cast(receiver.GetTaggedObject()), objHandle); } else { - res = JSTaggedValue::GetProperty(thread, obj_handle, idx).GetValue().GetTaggedValue(); + res = JSTaggedValue::GetProperty(thread, objHandle, idx).GetValue().GetTaggedValue(); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res; @@ -1784,7 +1781,7 @@ JSTaggedValue SlowRuntimeStub::LdObjByIndex(JSThread *thread, JSTaggedValue obj, JSTaggedValue SlowRuntimeStub::StObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value) { INTERPRETER_TRACE(thread, StObjByIndexDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSTaggedValue::SetProperty(thread, JSHandle(thread, obj), idx, JSHandle(thread, value), true); @@ -1792,19 +1789,19 @@ JSTaggedValue SlowRuntimeStub::StObjByIndex(JSThread *thread, JSTaggedValue obj, return JSTaggedValue::True(); } -JSTaggedValue SlowRuntimeStub::LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool call_getter, +JSTaggedValue SlowRuntimeStub::LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter, JSTaggedValue receiver) { INTERPRETER_TRACE(thread, LdObjByNameDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); + JSHandle objHandle(thread, obj); JSTaggedValue res; - if (call_getter) { - res = JSObject::CallGetter(thread, AccessorData::Cast(receiver.GetTaggedObject()), obj_handle); + if (callGetter) { + res = JSObject::CallGetter(thread, AccessorData::Cast(receiver.GetTaggedObject()), objHandle); } else { - JSHandle prop_handle(thread, prop); - res = JSTaggedValue::GetProperty(thread, obj_handle, prop_handle).GetValue().GetTaggedValue(); + JSHandle propHandle(thread, prop); + res = JSTaggedValue::GetProperty(thread, objHandle, propHandle).GetValue().GetTaggedValue(); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res; @@ -1813,30 +1810,30 @@ JSTaggedValue SlowRuntimeStub::LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue SlowRuntimeStub::StObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value) { INTERPRETER_TRACE(thread, StObjByNameDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, prop); - JSHandle value_handle(thread, value); - JSTaggedValue::SetProperty(thread, obj_handle, prop_handle, value_handle, true); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, prop); + JSHandle valueHandle(thread, value); + JSTaggedValue::SetProperty(thread, objHandle, propHandle, valueHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::True(); } -JSTaggedValue SlowRuntimeStub::LdObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool call_getter, +JSTaggedValue SlowRuntimeStub::LdObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter, JSTaggedValue receiver) { INTERPRETER_TRACE(thread, LdObjByValueDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); + JSHandle objHandle(thread, obj); JSTaggedValue res; - if (call_getter) { - res = JSObject::CallGetter(thread, AccessorData::Cast(receiver.GetTaggedObject()), obj_handle); + if (callGetter) { + res = JSObject::CallGetter(thread, AccessorData::Cast(receiver.GetTaggedObject()), objHandle); } else { - JSHandle prop_key = JSTaggedValue::ToPropertyKey(thread, JSHandle(thread, prop)); + JSHandle propKey = JSTaggedValue::ToPropertyKey(thread, JSHandle(thread, prop)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - res = JSTaggedValue::GetProperty(thread, obj_handle, prop_key).GetValue().GetTaggedValue(); + res = JSTaggedValue::GetProperty(thread, objHandle, propKey).GetValue().GetTaggedValue(); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res; @@ -1846,15 +1843,15 @@ JSTaggedValue SlowRuntimeStub::StObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue value) { INTERPRETER_TRACE(thread, StObjByValueDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, prop); - JSHandle value_handle(thread, value); - JSHandle prop_key(JSTaggedValue::ToPropertyKey(thread, prop_handle)); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, prop); + JSHandle valueHandle(thread, value); + JSHandle propKey(JSTaggedValue::ToPropertyKey(thread, propHandle)); // strict mode is true - JSTaggedValue::SetProperty(thread, obj_handle, prop_key, value_handle, true); + JSTaggedValue::SetProperty(thread, objHandle, propKey, valueHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::True(); } @@ -1862,13 +1859,13 @@ JSTaggedValue SlowRuntimeStub::StObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue SlowRuntimeStub::TryLdGlobalByName(JSThread *thread, JSTaggedValue global, JSTaggedValue prop) { INTERPRETER_TRACE(thread, Trygetobjprop); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle obj(thread, global.GetTaggedObject()->GetClass()->GetPrototype()); - JSHandle prop_handle(thread, prop); - OperationResult res = JSTaggedValue::GetProperty(thread, obj, prop_handle); + JSHandle propHandle(thread, prop); + OperationResult res = JSTaggedValue::GetProperty(thread, obj, propHandle); if (!res.GetPropertyMetaData().IsFound()) { - return ThrowReferenceError(thread, prop_handle.GetTaggedValue(), " is not defined"); + return ThrowReferenceError(thread, propHandle.GetTaggedValue(), " is not defined"); } return res.GetValue().GetTaggedValue(); } @@ -1876,11 +1873,11 @@ JSTaggedValue SlowRuntimeStub::TryLdGlobalByName(JSThread *thread, JSTaggedValue JSTaggedValue SlowRuntimeStub::LdGlobalVar(JSThread *thread, JSTaggedValue global, JSTaggedValue prop) { INTERPRETER_TRACE(thread, LdGlobalVar); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj_handle(thread, global.GetTaggedObject()->GetClass()->GetPrototype()); - JSHandle prop_handle(thread, prop); - OperationResult res = JSTaggedValue::GetProperty(thread, obj_handle, prop_handle); + JSHandle objHandle(thread, global.GetTaggedObject()->GetClass()->GetPrototype()); + JSHandle propHandle(thread, prop); + OperationResult res = JSTaggedValue::GetProperty(thread, objHandle, propHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res.GetValue().GetTaggedValue(); } @@ -1888,13 +1885,13 @@ JSTaggedValue SlowRuntimeStub::LdGlobalVar(JSThread *thread, JSTaggedValue globa JSTaggedValue SlowRuntimeStub::StGlobalVar(JSThread *thread, JSTaggedValue prop, JSTaggedValue value) { INTERPRETER_TRACE(thread, StGlobalVar); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle global(thread, thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject()); - JSHandle prop_handle(thread, prop); - JSHandle value_handle(thread, value); + JSHandle propHandle(thread, prop); + JSHandle valueHandle(thread, value); - JSObject::GlobalSetProperty(thread, prop_handle, value_handle, true); + JSObject::GlobalSetProperty(thread, propHandle, valueHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::True(); } @@ -1902,12 +1899,12 @@ JSTaggedValue SlowRuntimeStub::StGlobalVar(JSThread *thread, JSTaggedValue prop, JSTaggedValue SlowRuntimeStub::ThrowReferenceError(JSThread *thread, JSTaggedValue prop, const char *desc) { INTERPRETER_TRACE(thread, ThrowReferenceError); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle prop_name = JSTaggedValue::ToString(thread, JSHandle(thread, prop)); + JSHandle propName = JSTaggedValue::ToString(thread, JSHandle(thread, prop)); ASSERT_NO_ABRUPT_COMPLETION(thread); JSHandle info = factory->NewFromString(desc); - JSHandle msg = factory->ConcatFromString(prop_name, info); + JSHandle msg = factory->ConcatFromString(propName, info); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, factory->NewJSError(base::ErrorType::REFERENCE_ERROR, msg).GetTaggedValue(), JSTaggedValue::Exception()); @@ -1923,7 +1920,7 @@ JSTaggedValue SlowRuntimeStub::ThrowTypeError(JSThread *thread, const char *mess JSTaggedValue SlowRuntimeStub::ThrowSyntaxError(JSThread *thread, const char *message) { INTERPRETER_TRACE(thread, ThrowSyntaxError); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ASSERT_NO_ABRUPT_COMPLETION(thread); THROW_SYNTAX_ERROR_AND_RETURN(thread, message, JSTaggedValue::Exception()); } @@ -1932,204 +1929,201 @@ JSTaggedValue SlowRuntimeStub::StArraySpread(JSThread *thread, JSTaggedValue dst JSTaggedValue src) { INTERPRETER_TRACE(thread, StArraySpread); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle dst_handle(thread, dst); - JSHandle src_handle(thread, src); - JSMutableHandle index_handle(thread, index); + JSHandle dstHandle(thread, dst); + JSHandle srcHandle(thread, src); + JSMutableHandle indexHandle(thread, index); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - if (src_handle->IsUndefined()) { + if (srcHandle->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "undefined is not iterable", JSTaggedValue::Exception()); } - if (src_handle->IsNull()) { + if (srcHandle->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "null is not iterable", JSTaggedValue::Exception()); } - ASSERT(dst_handle->IsJSArray()); - if (src_handle->IsString()) { - JSHandle src_string = JSTaggedValue::ToString(thread, src_handle); + ASSERT(dstHandle->IsJSArray()); + if (srcHandle->IsString()) { + JSHandle srcString = JSTaggedValue::ToString(thread, srcHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t dst_len = index_handle.GetTaggedValue().GetInt(); - uint32_t str_len = src_string->GetLength(); - uint32_t prop_counter = 0; - for (uint32_t i = 0; i < str_len; i++, prop_counter++) { - uint16_t res = src_string->At(i); + uint32_t dstLen = indexHandle.GetTaggedValue().GetInt(); + uint32_t strLen = srcString->GetLength(); + uint32_t propCounter = 0; + for (uint32_t i = 0; i < strLen; i++, propCounter++) { + uint16_t res = srcString->At(i); if (UNLIKELY(utf::IsUTF16SurrogatePair(res))) { - std::array res_surrogate_pair {}; - res_surrogate_pair[0] = src_string->At(i); - res_surrogate_pair[1] = src_string->At(i + 1); - JSHandle str_value_surrogate_pair( - factory->NewFromUtf16Literal(res_surrogate_pair.data(), 2)); - JSTaggedValue::SetProperty(thread, dst_handle, dst_len + prop_counter, str_value_surrogate_pair, true); + std::array resSurrogatePair {}; + resSurrogatePair[0] = srcString->At(i); + resSurrogatePair[1] = srcString->At(i + 1); + JSHandle strValueSurrogatePair(factory->NewFromUtf16Literal(resSurrogatePair.data(), 2)); + JSTaggedValue::SetProperty(thread, dstHandle, dstLen + propCounter, strValueSurrogatePair, true); i++; } else { - JSHandle str_value(factory->NewFromUtf16Literal(&res, 1)); - JSTaggedValue::SetProperty(thread, dst_handle, dst_len + prop_counter, str_value, true); + JSHandle strValue(factory->NewFromUtf16Literal(&res, 1)); + JSTaggedValue::SetProperty(thread, dstHandle, dstLen + propCounter, strValue, true); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - return JSTaggedValue(dst_len + prop_counter); + return JSTaggedValue(dstLen + propCounter); } JSHandle iter; - auto global_const = thread->GlobalConstants(); - if (src_handle->IsJSArrayIterator() || src_handle->IsJSMapIterator() || src_handle->IsJSSetIterator() || - src_handle->IsIterator()) { - iter = src_handle; - } else if (src_handle->IsJSArray() || src_handle->IsJSMap() || src_handle->IsTypedArray() || - src_handle->IsJSSet()) { - JSHandle values_str = global_const->GetHandledValuesString(); - JSHandle values_method = JSObject::GetMethod(thread, src_handle, values_str); - iter = JSIterator::GetIterator(thread, src_handle, values_method); + auto globalConst = thread->GlobalConstants(); + if (srcHandle->IsJSArrayIterator() || srcHandle->IsJSMapIterator() || srcHandle->IsJSSetIterator() || + srcHandle->IsIterator()) { + iter = srcHandle; + } else if (srcHandle->IsJSArray() || srcHandle->IsJSMap() || srcHandle->IsTypedArray() || srcHandle->IsJSSet()) { + JSHandle valuesStr = globalConst->GetHandledValuesString(); + JSHandle valuesMethod = JSObject::GetMethod(thread, srcHandle, valuesStr); + iter = JSIterator::GetIterator(thread, srcHandle, valuesMethod); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - iter = JSIterator::GetIterator(thread, src_handle); + iter = JSIterator::GetIterator(thread, srcHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - JSHandle value_str = global_const->GetHandledValueString(); + JSHandle valueStr = globalConst->GetHandledValueString(); PropertyDescriptor desc(thread); - JSHandle iter_result; + JSHandle iterResult; do { - iter_result = JSIterator::IteratorStep(thread, iter); + iterResult = JSIterator::IteratorStep(thread, iter); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (iter_result->IsFalse()) { + if (iterResult->IsFalse()) { break; } - bool success = JSTaggedValue::GetOwnProperty(thread, iter_result, value_str, desc); + bool success = JSTaggedValue::GetOwnProperty(thread, iterResult, valueStr, desc); if (success && desc.IsEnumerable()) { - JSTaggedValue::DefineOwnProperty(thread, dst_handle, index_handle, desc); - int tmp = index_handle->GetInt(); - index_handle.Update(JSTaggedValue(tmp + 1)); + JSTaggedValue::DefineOwnProperty(thread, dstHandle, indexHandle, desc); + int tmp = indexHandle->GetInt(); + indexHandle.Update(JSTaggedValue(tmp + 1)); } } while (true); - return index_handle.GetTaggedValue(); + return indexHandle.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::DefineGeneratorFunc(JSThread *thread, JSMethod *method) { INTERPRETER_TRACE(thread, DefineGeneratorFunc); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle js_func = factory->NewJSGeneratorFunction(method); + JSHandle jsFunc = factory->NewJSGeneratorFunction(method); ASSERT_NO_ABRUPT_COMPLETION(thread); // 26.3.4.3 prototype // Whenever a GeneratorFunction instance is created another ordinary object is also created and // is the initial value of the generator function's "prototype" property. - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle initial_generator_func_prototype = - factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSObject::SetPrototype(thread, initial_generator_func_prototype, env->GetGeneratorPrototype()); + JSHandle objFun = env->GetObjectFunction(); + JSHandle initialGeneratorFuncPrototype = + factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetGeneratorPrototype()); ASSERT_NO_ABRUPT_COMPLETION(thread); - js_func->SetProtoOrDynClass(thread, initial_generator_func_prototype); - js_func->SetupFunctionLength(thread); + jsFunc->SetProtoOrDynClass(thread, initialGeneratorFuncPrototype); + jsFunc->SetupFunctionLength(thread); - return js_func.GetTaggedValue(); + return jsFunc.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::DefineAsyncGeneratorFunc(JSThread *thread, JSMethod *method) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle js_func = factory->NewJSAsyncGeneratorFunction(method); + JSHandle jsFunc = factory->NewJSAsyncGeneratorFunction(method); ASSERT_NO_ABRUPT_COMPLETION(thread); // 27.4.4.3 prototype // Whenever a AsyncGeneratorFunction instance is created another ordinary object is also created and // is the initial value of the generator function's "prototype" property. - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle initial_async_generator_func_prototype = - factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSObject::SetPrototype(thread, initial_async_generator_func_prototype, env->GetAsyncGeneratorPrototype()); + JSHandle objFun = env->GetObjectFunction(); + JSHandle initialAsyncGeneratorFuncPrototype = + factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetPrototype(thread, initialAsyncGeneratorFuncPrototype, env->GetAsyncGeneratorPrototype()); ASSERT_NO_ABRUPT_COMPLETION(thread); - js_func->SetProtoOrDynClass(thread, initial_async_generator_func_prototype); - js_func->SetupFunctionLength(thread); + jsFunc->SetProtoOrDynClass(thread, initialAsyncGeneratorFuncPrototype); + jsFunc->SetupFunctionLength(thread); - return js_func.GetTaggedValue(); + return jsFunc.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::DefineAsyncFunc(JSThread *thread, JSMethod *method) { INTERPRETER_TRACE(thread, DefineAsyncFunc); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dynclass = JSHandle::Cast(env->GetAsyncFunctionClass()); - JSHandle js_func = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::ASYNC_FUNCTION); + JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::ASYNC_FUNCTION); ASSERT_NO_ABRUPT_COMPLETION(thread); - return js_func.GetTaggedValue(); + return jsFunc.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::DefineNCFuncDyn(JSThread *thread, JSMethod *method) { INTERPRETER_TRACE(thread, DefineNCFuncDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); - JSHandle js_func = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::ARROW_FUNCTION); - js_func->SetupFunctionLength(thread); + JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::ARROW_FUNCTION); + jsFunc->SetupFunctionLength(thread); ASSERT_NO_ABRUPT_COMPLETION(thread); - return js_func.GetTaggedValue(); + return jsFunc.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::DefinefuncDyn(JSThread *thread, JSMethod *method) { INTERPRETER_TRACE(thread, DefinefuncDyn); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dynclass = JSHandle::Cast(env->GetFunctionClassWithProto()); - JSHandle js_func = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR); - js_func->SetupFunctionLength(thread); + JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR); + jsFunc->SetupFunctionLength(thread); ASSERT_NO_ABRUPT_COMPLETION(thread); - return js_func.GetTaggedValue(); + return jsFunc.GetTaggedValue(); } -JSTaggedValue SlowRuntimeStub::SuperCall(JSThread *thread, JSTaggedValue func, JSTaggedValue new_target, - uint16_t args_count, JSTaggedType *stkargs) +JSTaggedValue SlowRuntimeStub::SuperCall(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, + uint16_t argsCount, JSTaggedType *stkargs) { INTERPRETER_TRACE(thread, SuperCall); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle func_handle(thread, func); - JSHandle new_target_handle(thread, new_target); + JSHandle funcHandle(thread, func); + JSHandle newTargetHandle(thread, newTarget); - JSHandle super_func(thread, JSHandle::Cast(func_handle)->GetPrototype(thread)); - ASSERT(super_func->IsJSFunction()); - auto info = NewRuntimeCallInfo(thread, super_func, JSTaggedValue::Undefined(), new_target_handle, args_count); - info->SetCallArg(args_count, stkargs); + JSHandle superFunc(thread, JSHandle::Cast(funcHandle)->GetPrototype(thread)); + ASSERT(superFunc->IsJSFunction()); + auto info = NewRuntimeCallInfo(thread, superFunc, JSTaggedValue::Undefined(), newTargetHandle, argsCount); + info->SetCallArg(argsCount, stkargs); JSTaggedValue result = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result; } -JSTaggedValue SlowRuntimeStub::SuperCallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue new_target, +JSTaggedValue SlowRuntimeStub::SuperCallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, JSTaggedValue array) { INTERPRETER_TRACE(thread, SuperCallSpread); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle func_handle(thread, func); - JSHandle new_target_handle(thread, new_target); - JSHandle js_array(thread, array); + JSHandle funcHandle(thread, func); + JSHandle newTargetHandle(thread, newTarget); + JSHandle jsArray(thread, array); - JSHandle super_func(thread, JSHandle::Cast(func_handle)->GetPrototype(thread)); - ASSERT(super_func->IsJSFunction()); + JSHandle superFunc(thread, JSHandle::Cast(funcHandle)->GetPrototype(thread)); + ASSERT(superFunc->IsJSFunction()); - JSHandle argv(thread, GetCallSpreadArgs(thread, js_array.GetTaggedValue())); + JSHandle argv(thread, GetCallSpreadArgs(thread, jsArray.GetTaggedValue())); - auto info = - NewRuntimeCallInfo(thread, super_func, JSTaggedValue::Undefined(), new_target_handle, argv->GetLength()); + auto info = NewRuntimeCallInfo(thread, superFunc, JSTaggedValue::Undefined(), newTargetHandle, argv->GetLength()); info->SetCallArg(argv->GetLength(), argv->GetData()); JSTaggedValue result = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2138,71 +2132,70 @@ JSTaggedValue SlowRuntimeStub::SuperCallSpread(JSThread *thread, JSTaggedValue f } JSTaggedValue SlowRuntimeStub::DefineMethod(JSThread *thread, JSMethod *method, - const JSHandle &home_object) + const JSHandle &homeObject) { INTERPRETER_TRACE(thread, DefineMethod); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - ASSERT(home_object->IsECMAObject()); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + ASSERT(homeObject->IsECMAObject()); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); - JSHandle js_func = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::NORMAL_FUNCTION); - js_func->SetHomeObject(thread, home_object); - js_func->SetupFunctionLength(thread); + JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::NORMAL_FUNCTION); + jsFunc->SetHomeObject(thread, homeObject); + jsFunc->SetupFunctionLength(thread); ASSERT_NO_ABRUPT_COMPLETION(thread); - return js_func.GetTaggedValue(); + return jsFunc.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::LdSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, - JSTaggedValue this_func) + JSTaggedValue thisFunc) { INTERPRETER_TRACE(thread, LdSuperByValue); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - ASSERT(this_func.IsJSFunction()); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + ASSERT(thisFunc.IsJSFunction()); // get Homeobject form function - JSHandle home_object(thread, JSFunction::Cast(this_func.GetTaggedObject())->GetHomeObject()); + JSHandle homeObject(thread, JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject()); if (obj.IsUndefined()) { return ThrowReferenceError(thread, obj, "this is uninitialized."); } - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, key); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, key); - JSHandle prop_key(JSTaggedValue::ToPropertyKey(thread, prop_handle)); - JSHandle super_base(thread, JSTaggedValue::GetSuperBase(thread, home_object)); - JSTaggedValue::RequireObjectCoercible(thread, super_base); + JSHandle propKey(JSTaggedValue::ToPropertyKey(thread, propHandle)); + JSHandle superBase(thread, JSTaggedValue::GetSuperBase(thread, homeObject)); + JSTaggedValue::RequireObjectCoercible(thread, superBase); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue res = - JSTaggedValue::GetProperty(thread, super_base, prop_key, obj_handle).GetValue().GetTaggedValue(); + JSTaggedValue res = JSTaggedValue::GetProperty(thread, superBase, propKey, objHandle).GetValue().GetTaggedValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res; } JSTaggedValue SlowRuntimeStub::StSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, - JSTaggedValue value, JSTaggedValue this_func) + JSTaggedValue value, JSTaggedValue thisFunc) { INTERPRETER_TRACE(thread, StSuperByValue); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - ASSERT(this_func.IsJSFunction()); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + ASSERT(thisFunc.IsJSFunction()); // get Homeobject form function - JSHandle home_object(thread, JSFunction::Cast(this_func.GetTaggedObject())->GetHomeObject()); + JSHandle homeObject(thread, JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject()); if (obj.IsUndefined()) { return ThrowReferenceError(thread, obj, "this is uninitialized."); } - JSHandle obj_handle(thread, obj); - JSHandle prop_handle(thread, key); - JSHandle value_handle(thread, value); + JSHandle objHandle(thread, obj); + JSHandle propHandle(thread, key); + JSHandle valueHandle(thread, value); - JSHandle prop_key(JSTaggedValue::ToPropertyKey(thread, prop_handle)); - JSHandle super_base(thread, JSTaggedValue::GetSuperBase(thread, home_object)); - JSTaggedValue::RequireObjectCoercible(thread, super_base); + JSHandle propKey(JSTaggedValue::ToPropertyKey(thread, propHandle)); + JSHandle superBase(thread, JSTaggedValue::GetSuperBase(thread, homeObject)); + JSTaggedValue::RequireObjectCoercible(thread, superBase); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // check may_throw is false? - JSTaggedValue::SetProperty(thread, super_base, prop_key, value_handle, obj_handle, true); + JSTaggedValue::SetProperty(thread, superBase, propKey, valueHandle, objHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::True(); } @@ -2210,41 +2203,41 @@ JSTaggedValue SlowRuntimeStub::StSuperByValue(JSThread *thread, JSTaggedValue ob JSTaggedValue SlowRuntimeStub::GetCallSpreadArgs(JSThread *thread, JSTaggedValue array) { INTERPRETER_TRACE(thread, GetCallSpreadArgs); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle js_array(thread, array); - uint32_t argv_may_max_length = JSHandle::Cast(js_array)->GetArrayLength(); - JSHandle argv = factory->NewTaggedArray(argv_may_max_length); - JSHandle itor = JSIterator::GetIterator(thread, js_array); + JSHandle jsArray(thread, array); + uint32_t argvMayMaxLength = JSHandle::Cast(jsArray)->GetArrayLength(); + JSHandle argv = factory->NewTaggedArray(argvMayMaxLength); + JSHandle itor = JSIterator::GetIterator(thread, jsArray); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSMutableHandle next(thread, JSTaggedValue::Undefined()); - JSMutableHandle next_arg(thread, JSTaggedValue::Undefined()); - size_t argv_index = 0; + JSMutableHandle nextArg(thread, JSTaggedValue::Undefined()); + size_t argvIndex = 0; while (true) { next.Update(JSIterator::IteratorStep(thread, itor).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (JSTaggedValue::SameValue(next.GetTaggedValue(), JSTaggedValue::False())) { break; } - next_arg.Update(JSIterator::IteratorValue(thread, next).GetTaggedValue()); + nextArg.Update(JSIterator::IteratorValue(thread, next).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - argv->Set(thread, argv_index++, next_arg); + argv->Set(thread, argvIndex++, nextArg); } - argv = factory->CopyArray(argv, argv_may_max_length, argv_index); + argv = factory->CopyArray(argv, argvMayMaxLength, argvIndex); return argv.GetTaggedValue(); } void SlowRuntimeStub::ThrowDeleteSuperProperty(JSThread *thread) { INTERPRETER_TRACE(thread, ThrowDeleteSuperProperty); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle info = factory->NewFromCanBeCompressString("Can not delete super property"); - JSHandle error_obj = factory->NewJSError(base::ErrorType::REFERENCE_ERROR, info); - THROW_NEW_ERROR_AND_RETURN(thread, error_obj.GetTaggedValue()); + JSHandle errorObj = factory->NewJSError(base::ErrorType::REFERENCE_ERROR, info); + THROW_NEW_ERROR_AND_RETURN(thread, errorObj.GetTaggedValue()); } JSTaggedValue SlowRuntimeStub::NotifyInlineCache(JSThread *thread, JSFunction *func, JSMethod *method) @@ -2258,17 +2251,17 @@ JSTaggedValue SlowRuntimeStub::NotifyInlineCache(JSThread *thread, JSFunction *f if (method->GetICMapping() == nullptr) { return JSTaggedValue::Undefined(); } - uint32_t ic_slot_size = method->GetSlotSize(); + uint32_t icSlotSize = method->GetSlotSize(); static_assert(std::is_pointer::value); - ASSERT(ic_slot_size <= std::numeric_limits::type>::max()); + ASSERT(icSlotSize <= std::numeric_limits::type>::max()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle func_handle(thread, func); - JSHandle profile_type_info = factory->NewProfileTypeInfo(ic_slot_size); - func_handle->SetProfileTypeInfo(thread, profile_type_info.GetTaggedValue()); + JSHandle funcHandle(thread, func); + JSHandle profileTypeInfo = factory->NewProfileTypeInfo(icSlotSize); + funcHandle->SetProfileTypeInfo(thread, profileTypeInfo.GetTaggedValue()); - return profile_type_info.GetTaggedValue(); + return profileTypeInfo.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::ResolveClass(JSThread *thread, JSTaggedValue ctor, TaggedArray *literal, @@ -2276,21 +2269,21 @@ JSTaggedValue SlowRuntimeStub::ResolveClass(JSThread *thread, JSTaggedValue ctor { ASSERT(ctor.IsClassConstructor()); JSHandle cls(thread, ctor); - JSHandle literal_buffer(thread, literal); - JSHandle lexical_env(thread, lexenv); - JSHandle constpool_handle(thread, constpool); + JSHandle literalBuffer(thread, literal); + JSHandle lexicalEnv(thread, lexenv); + JSHandle constpoolHandle(thread, constpool); SetClassInheritanceRelationship(thread, ctor, base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t literal_buffer_length = literal_buffer->GetLength(); + uint32_t literalBufferLength = literalBuffer->GetLength(); // only traverse the value of key-value pair - for (uint32_t index = 1; index < literal_buffer_length - 1; index += 2) { // 2: key-value pair - JSTaggedValue value = literal_buffer->Get(index); + for (uint32_t index = 1; index < literalBufferLength - 1; index += 2) { // 2: key-value pair + JSTaggedValue value = literalBuffer->Get(index); if (LIKELY(value.IsJSFunction())) { - JSFunction::Cast(value.GetTaggedObject())->SetLexicalEnv(thread, lexical_env.GetTaggedValue()); - JSFunction::Cast(value.GetTaggedObject())->SetConstantPool(thread, constpool_handle.GetTaggedValue()); + JSFunction::Cast(value.GetTaggedObject())->SetLexicalEnv(thread, lexicalEnv.GetTaggedValue()); + JSFunction::Cast(value.GetTaggedObject())->SetConstantPool(thread, constpoolHandle.GetTaggedValue()); } } @@ -2302,54 +2295,54 @@ JSTaggedValue SlowRuntimeStub::ResolveClass(JSThread *thread, JSTaggedValue ctor JSTaggedValue SlowRuntimeStub::CloneClassFromTemplate(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base, JSTaggedValue lexenv, ConstantPool *constpool) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); ASSERT(ctor.IsClassConstructor()); - JSHandle lexenv_handle(thread, lexenv); - JSHandle constpool_handle(thread, JSTaggedValue(constpool)); - JSHandle base_handle(thread, base); + JSHandle lexenvHandle(thread, lexenv); + JSHandle constpoolHandle(thread, JSTaggedValue(constpool)); + JSHandle baseHandle(thread, base); JSHandle cls(thread, ctor); - JSHandle cls_prototype(thread, cls->GetFunctionPrototype()); + JSHandle clsPrototype(thread, cls->GetFunctionPrototype()); - bool can_share_hclass = false; - if (cls->GetClass()->GetProto() == base_handle.GetTaggedValue()) { - can_share_hclass = true; + bool canShareHclass = false; + if (cls->GetClass()->GetProto() == baseHandle.GetTaggedValue()) { + canShareHclass = true; } - JSHandle clone_class = factory->CloneClassCtor(cls, lexenv_handle, can_share_hclass); + JSHandle cloneClass = factory->CloneClassCtor(cls, lexenvHandle, canShareHclass); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle clone_class_prototype = factory->CloneObjectLiteral( - JSHandle(cls_prototype), lexenv_handle, constpool_handle, can_share_hclass); + JSHandle cloneClassPrototype = + factory->CloneObjectLiteral(JSHandle(clsPrototype), lexenvHandle, constpoolHandle, canShareHclass); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // After clone both, reset "constructor" and "prototype" properties. - clone_class->SetFunctionPrototype(thread, clone_class_prototype.GetTaggedValue()); + cloneClass->SetFunctionPrototype(thread, cloneClassPrototype.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - PropertyDescriptor ctor_desc(thread, JSHandle(clone_class), true, false, true); - JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(clone_class_prototype), - global_const->GetHandledConstructorString(), ctor_desc); + PropertyDescriptor ctorDesc(thread, JSHandle(cloneClass), true, false, true); + JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(cloneClassPrototype), + globalConst->GetHandledConstructorString(), ctorDesc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - clone_class->SetHomeObject(thread, clone_class_prototype); + cloneClass->SetHomeObject(thread, cloneClassPrototype); - if (!can_share_hclass) { - SetClassInheritanceRelationship(thread, clone_class.GetTaggedValue(), base_handle.GetTaggedValue()); + if (!canShareHclass) { + SetClassInheritanceRelationship(thread, cloneClass.GetTaggedValue(), baseHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - return clone_class.GetTaggedValue(); + return cloneClass.GetTaggedValue(); } JSTaggedValue SlowRuntimeStub::SetClassInheritanceRelationship(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle cls(thread, ctor); ASSERT(cls->IsJSFunction()); @@ -2368,30 +2361,30 @@ JSTaggedValue SlowRuntimeStub::SetClassInheritanceRelationship(JSThread *thread, * Function.prototype Object.prototype / null B ----> B.prototype */ - JSHandle parent_prototype; + JSHandle parentPrototype; // hole means parent is not present if (parent->IsHole()) { JSHandle::Cast(cls)->SetFunctionKind(thread, FunctionKind::CLASS_CONSTRUCTOR); - parent_prototype = env->GetObjectFunctionPrototype(); + parentPrototype = env->GetObjectFunctionPrototype(); parent.Update(env->GetFunctionPrototype().GetTaggedValue()); } else if (parent->IsNull()) { JSHandle::Cast(cls)->SetFunctionKind(thread, FunctionKind::DERIVED_CONSTRUCTOR); - parent_prototype = JSHandle(thread, JSTaggedValue::Null()); + parentPrototype = JSHandle(thread, JSTaggedValue::Null()); parent.Update(env->GetFunctionPrototype().GetTaggedValue()); } else if (!parent->IsConstructor()) { return ThrowTypeError(thread, "parent class is not constructor"); } else { JSHandle::Cast(cls)->SetFunctionKind(thread, FunctionKind::DERIVED_CONSTRUCTOR); - parent_prototype = - JSTaggedValue::GetProperty(thread, parent, global_const->GetHandledPrototypeString()).GetValue(); - if (!parent_prototype->IsECMAObject() && !parent_prototype->IsNull()) { + parentPrototype = + JSTaggedValue::GetProperty(thread, parent, globalConst->GetHandledPrototypeString()).GetValue(); + if (!parentPrototype->IsECMAObject() && !parentPrototype->IsNull()) { return ThrowTypeError(thread, "parent class have no valid prototype"); } } cls->GetTaggedObject()->GetClass()->SetPrototype(thread, parent); - JSHandle cls_prototype(thread, JSHandle(cls)->GetFunctionPrototype()); - cls_prototype->GetClass()->SetPrototype(thread, parent_prototype); + JSHandle clsPrototype(thread, JSHandle(cls)->GetFunctionPrototype()); + clsPrototype->GetClass()->SetPrototype(thread, parentPrototype); return JSTaggedValue::Undefined(); } @@ -2404,27 +2397,27 @@ JSTaggedValue SlowRuntimeStub::SetClassConstructorLength(JSThread *thread, JSTag if (LIKELY(!cls->GetClass()->IsDictionaryMode())) { cls->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, length); } else { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - cls->UpdatePropertyInDictionary(thread, global_const->GetLengthString(), length); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + cls->UpdatePropertyInDictionary(thread, globalConst->GetLengthString(), length); } return JSTaggedValue::Undefined(); } -JSTaggedValue SlowRuntimeStub::LdEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue eval_bindings) +JSTaggedValue SlowRuntimeStub::LdEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue evalBindings) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle name_handle(thread, name); - JSHandle eval_bindings_handle(thread, eval_bindings); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle nameHandle(thread, name); + JSHandle evalBindingsHandle(thread, evalBindings); uint32_t index = 0; - JSMutableHandle lex_env( - thread, JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(eval_bindings_handle), index++)); + JSMutableHandle lexEnv( + thread, JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(evalBindingsHandle), index++)); - ArraySizeT size = eval_bindings_handle->GetArrayLength(); + ArraySizeT size = evalBindingsHandle->GetArrayLength(); while (index < size) { auto scope = JSHandle::Cast( - JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(eval_bindings_handle), index++)); + JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(evalBindingsHandle), index++)); ArraySizeT slot = 0; for (ArraySizeT j = 0; j < scope->GetLength(); slot++) { @@ -2434,67 +2427,67 @@ JSTaggedValue SlowRuntimeStub::LdEvalVar(JSThread *thread, JSTaggedValue name, J binding = scope->Get(j++); } - if (EcmaString::StringsAreEqual(*name_handle, static_cast(binding.GetHeapObject()))) { - return lex_env->GetProperties(slot); + if (EcmaString::StringsAreEqual(*nameHandle, static_cast(binding.GetHeapObject()))) { + return lexEnv->GetProperties(slot); } } - lex_env.Update(lex_env->GetParentEnv()); + lexEnv.Update(lexEnv->GetParentEnv()); } - auto global_obj = thread->GetGlobalObject(); + auto globalObj = thread->GetGlobalObject(); bool found = false; - JSTaggedValue result = FastRuntimeStub::GetGlobalOwnProperty(global_obj, name_handle.GetTaggedValue(), &found); + JSTaggedValue result = FastRuntimeStub::GetGlobalOwnProperty(globalObj, nameHandle.GetTaggedValue(), &found); if (found) { return result; } - return TryLdGlobalByName(thread, global_obj, name_handle.GetTaggedValue()); + return TryLdGlobalByName(thread, globalObj, nameHandle.GetTaggedValue()); } -JSTaggedValue SlowRuntimeStub::StEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue eval_bindings, +JSTaggedValue SlowRuntimeStub::StEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue evalBindings, JSTaggedValue value) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle name_handle(thread, name); - JSHandle eval_bindings_handle(thread, eval_bindings); - JSHandle value_handle(thread, value); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle nameHandle(thread, name); + JSHandle evalBindingsHandle(thread, evalBindings); + JSHandle valueHandle(thread, value); uint32_t index = 0; - JSMutableHandle lex_env( - thread, JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(eval_bindings_handle), index++)); + JSMutableHandle lexEnv( + thread, JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(evalBindingsHandle), index++)); - ArraySizeT size = eval_bindings_handle->GetArrayLength(); + ArraySizeT size = evalBindingsHandle->GetArrayLength(); while (index < size) { auto scope = JSHandle::Cast( - JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(eval_bindings_handle), index++)); + JSArray::FastGetPropertyByValue(thread, JSHandle::Cast(evalBindingsHandle), index++)); ArraySizeT slot = 0; for (ArraySizeT j = 0; j < scope->GetLength(); slot++) { JSTaggedValue binding = scope->Get(j++); - bool is_const = false; + bool isConst = false; if (binding.IsTrue()) { - is_const = true; + isConst = true; binding = scope->Get(j++); } - if (EcmaString::StringsAreEqual(*name_handle, static_cast(binding.GetHeapObject()))) { - if (is_const) { + if (EcmaString::StringsAreEqual(*nameHandle, static_cast(binding.GetHeapObject()))) { + if (isConst) { return ThrowTypeError(thread, "Assignment to constant variable"); } - lex_env->SetProperties(thread, slot, value_handle.GetTaggedValue()); - return value_handle.GetTaggedValue(); + lexEnv->SetProperties(thread, slot, valueHandle.GetTaggedValue()); + return valueHandle.GetTaggedValue(); } } - lex_env.Update(lex_env->GetParentEnv()); + lexEnv.Update(lexEnv->GetParentEnv()); } - JSObject::GlobalSetProperty(thread, JSHandle::Cast(name_handle), value_handle, true); + JSObject::GlobalSetProperty(thread, JSHandle::Cast(nameHandle), valueHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return value_handle.GetTaggedValue(); + return valueHandle.GetTaggedValue(); } } // namespace panda::ecmascript diff --git a/runtime/interpreter/slow_runtime_stub.h b/runtime/interpreter/slow_runtime_stub.h index 7b0754e7c0754a8367916ecbb9bd58c8cfcbe868..28a45556f23719a2df1df03fd60b68709418f1ea 100644 --- a/runtime/interpreter/slow_runtime_stub.h +++ b/runtime/interpreter/slow_runtime_stub.h @@ -37,7 +37,7 @@ public: static void ThrowDyn(JSThread *thread, JSTaggedValue value); static JSTaggedValue GetPropIterator(JSThread *thread, JSTaggedValue value); static void ThrowConstAssignment(JSThread *thread, JSTaggedValue value); - static JSTaggedValue Add2Dyn(JSThread *thread, EcmaVM *ecma_vm, JSTaggedValue left, JSTaggedValue right); + static JSTaggedValue Add2Dyn(JSThread *thread, EcmaVM *ecmaVm, JSTaggedValue left, JSTaggedValue right); static JSTaggedValue Sub2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right); static JSTaggedValue Mul2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right); static JSTaggedValue Div2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right); @@ -53,34 +53,34 @@ public: static JSTaggedValue ToJSTaggedValueWithUint32(JSThread *thread, JSTaggedValue value); static JSTaggedValue DelObjProp(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop); - static JSTaggedValue NewObjDynRange(JSThread *thread, uint16_t args_count, JSTaggedValue func, - JSTaggedValue new_target, JSTaggedType *stkargs); - static JSTaggedValue CreateObjectWithExcludedKeys(JSThread *thread, uint16_t num_keys, JSTaggedValue obj_val, + static JSTaggedValue NewObjDynRange(JSThread *thread, uint16_t argsCount, JSTaggedValue func, + JSTaggedValue newTarget, JSTaggedType *stkargs); + static JSTaggedValue CreateObjectWithExcludedKeys(JSThread *thread, uint16_t numKeys, JSTaggedValue objVal, JSTaggedType *stkargs); static JSTaggedValue ExpDyn(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent); static JSTaggedValue IsInDyn(JSThread *thread, JSTaggedValue prop, JSTaggedValue obj); static JSTaggedValue InstanceofDyn(JSThread *thread, JSTaggedValue obj, JSTaggedValue target); - static JSTaggedValue NewLexicalEnvDyn(JSThread *thread, uint16_t num_vars); + static JSTaggedValue NewLexicalEnvDyn(JSThread *thread, uint16_t numVars); static JSTaggedValue CreateIterResultObj(JSThread *thread, JSTaggedValue value, bool done); - static JSTaggedValue CreateGeneratorObj(JSThread *thread, JSTaggedValue gen_func); - static JSTaggedValue SetGeneratorState(JSThread *thread, JSTaggedValue gen_obj, uint8_t state); - static JSTaggedValue CreateAsyncGeneratorObj(JSThread *thread, JSTaggedValue gen_func); - static JSTaggedValue SuspendGenerator(JSThread *thread, JSTaggedValue gen_obj, JSTaggedValue value); - static JSTaggedValue SuspendAsyncGenerator(JSThread *thread, JSTaggedValue async_gen_obj, JSTaggedValue value); - static JSTaggedValue AsyncFunctionAwait(JSThread *thread, JSTaggedValue async_func_obj, JSTaggedValue value); - static JSTaggedValue AsyncFunctionResolveOrReject(JSThread *thread, JSTaggedValue async_func_obj, - JSTaggedValue value, bool is_resolve); - static JSTaggedValue AsyncGeneratorResolve(JSThread *thread, JSTaggedValue async_gen_obj, JSTaggedValue value); - static JSTaggedValue AsyncGeneratorReject(JSThread *thread, JSTaggedValue async_gen_obj, JSTaggedValue value); - static JSTaggedValue NewObjSpreadDyn(JSThread *thread, JSTaggedValue func, JSTaggedValue new_target, + static JSTaggedValue CreateGeneratorObj(JSThread *thread, JSTaggedValue genFunc); + static JSTaggedValue SetGeneratorState(JSThread *thread, JSTaggedValue genObj, uint8_t state); + static JSTaggedValue CreateAsyncGeneratorObj(JSThread *thread, JSTaggedValue genFunc); + static JSTaggedValue SuspendGenerator(JSThread *thread, JSTaggedValue genObj, JSTaggedValue value); + static JSTaggedValue SuspendAsyncGenerator(JSThread *thread, JSTaggedValue asyncGenObj, JSTaggedValue value); + static JSTaggedValue AsyncFunctionAwait(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value); + static JSTaggedValue AsyncFunctionResolveOrReject(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value, + bool isResolve); + static JSTaggedValue AsyncGeneratorResolve(JSThread *thread, JSTaggedValue asyncGenObj, JSTaggedValue value); + static JSTaggedValue AsyncGeneratorReject(JSThread *thread, JSTaggedValue asyncGenObj, JSTaggedValue value); + static JSTaggedValue NewObjSpreadDyn(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, JSTaggedValue array); - static void ThrowTdz(JSThread *thread, JSTaggedValue binding_name); + static void ThrowTdz(JSThread *thread, JSTaggedValue bindingName); static void ThrowIfNotObject(JSThread *thread); static void ThrowThrowNotExists(JSThread *thread); static void ThrowPatternNonCoercible(JSThread *thread); - static JSTaggedValue ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, JSTaggedValue this_value); + static JSTaggedValue ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, JSTaggedValue thisValue); static void ThrowDeleteSuperProperty(JSThread *thread); static JSTaggedValue StOwnByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value); @@ -91,55 +91,55 @@ public: const JSHandle &key, const JSHandle &value); static JSTaggedValue StOwnByValueWithNameSet(JSThread *thread, JSHandle obj, JSHandle key, JSHandle value); - static JSTaggedValue CreateEmptyArray(JSThread *thread, ObjectFactory *factory, JSHandle global_env); - static JSTaggedValue CreateEmptyObject(JSThread *thread, ObjectFactory *factory, JSHandle global_env); + static JSTaggedValue CreateEmptyArray(JSThread *thread, ObjectFactory *factory, JSHandle globalEnv); + static JSTaggedValue CreateEmptyObject(JSThread *thread, ObjectFactory *factory, JSHandle globalEnv); static JSTaggedValue CreateObjectWithBuffer(JSThread *thread, ObjectFactory *factory, JSObject *literal); static JSTaggedValue CreateObjectHavingMethod(JSThread *thread, ObjectFactory *factory, JSObject *literal, JSTaggedValue env, ConstantPool *constpool); static JSTaggedValue SetObjectWithProto(JSThread *thread, JSTaggedValue proto, JSTaggedValue obj); static JSTaggedValue CreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory, JSArray *literal); - static JSTaggedValue GetMethod(JSThread *thread, JSTaggedValue object, JSTaggedValue prop_key); + static JSTaggedValue GetMethod(JSThread *thread, JSTaggedValue object, JSTaggedValue propKey); static JSTaggedValue GetTemplateObject(JSThread *thread, JSTaggedValue literal); static JSTaggedValue GetNextPropName(JSThread *thread, JSTaggedValue iter); static JSTaggedValue CopyDataProperties(JSThread *thread, JSTaggedValue dst, JSTaggedValue src); - static JSTaggedValue GetUnmappedArgs(JSThread *thread, uint32_t actual_num_args, JSTaggedType *stkargs); - static JSTaggedValue CopyRestArgs(JSThread *thread, uint32_t rest_num_args, JSTaggedType *stkargs); + static JSTaggedValue GetUnmappedArgs(JSThread *thread, uint32_t actualNumArgs, JSTaggedType *stkargs); + static JSTaggedValue CopyRestArgs(JSThread *thread, uint32_t restNumArgs, JSTaggedType *stkargs); static JSTaggedValue GetIterator(JSThread *thread, JSTaggedValue obj, bool async = false, JSTaggedValue method = JSTaggedValue::Hole()); static JSTaggedValue CloseIterator(JSThread *thread, JSTaggedValue iter); - static JSTaggedValue ImportModule(JSThread *thread, JSTaggedValue module_name); - static void StModuleVar(JSThread *thread, JSTaggedValue export_name, JSTaggedValue export_obj); - static void CopyModule(JSThread *thread, JSTaggedValue src_module); - static JSTaggedValue LdModvarByName(JSThread *thread, JSTaggedValue module_obj, JSTaggedValue item_name); + static JSTaggedValue ImportModule(JSThread *thread, JSTaggedValue moduleName); + static void StModuleVar(JSThread *thread, JSTaggedValue exportName, JSTaggedValue exportObj); + static void CopyModule(JSThread *thread, JSTaggedValue srcModule); + static JSTaggedValue LdModvarByName(JSThread *thread, JSTaggedValue moduleObj, JSTaggedValue itemName); - static JSTaggedValue ClassFieldAdd(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop_name, + static JSTaggedValue ClassFieldAdd(JSThread *thread, JSTaggedValue obj, JSTaggedValue propName, JSTaggedValue value); static void DefineClassPrivateFields(JSThread *thread, ConstantPool *constpool, JSTaggedValue env, - JSTaggedValue ctor, JSTaggedValue private_buf); + JSTaggedValue ctor, JSTaggedValue privateBuf); static JSTaggedValue ClassPrivateMethodOrAccessorAdd(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj); static JSTaggedValue ClassPrivateFieldAdd(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name, JSTaggedValue value); + JSTaggedValue propName, JSTaggedValue value); static JSTaggedValue ClassPrivateFieldGet(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name); + JSTaggedValue propName); static JSTaggedValue ClassPrivateFieldSet(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name, JSTaggedValue value); + JSTaggedValue propName, JSTaggedValue value); static JSTaggedValue ClassPrivateFieldIn(JSThread *thread, JSTaggedValue ctor, JSTaggedValue obj, - JSTaggedValue prop_name); + JSTaggedValue propName); static JSTaggedValue CreateRegExpWithLiteral(JSThread *thread, JSTaggedValue pattern, uint8_t flags); static JSTaggedValue DefineGetterSetterByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue getter, JSTaggedValue setter, bool flag); - static JSTaggedValue LdObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, bool call_getter, + static JSTaggedValue LdObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, bool callGetter, JSTaggedValue receiver); static JSTaggedValue StObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value); - static JSTaggedValue LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool call_getter, + static JSTaggedValue LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter, JSTaggedValue receiver); static JSTaggedValue StObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value); - static JSTaggedValue LdObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool call_getter, + static JSTaggedValue LdObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter, JSTaggedValue receiver); static JSTaggedValue StObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value); static JSTaggedValue TryLdGlobalByName(JSThread *thread, JSTaggedValue global, JSTaggedValue prop); @@ -156,15 +156,14 @@ public: static JSTaggedValue DefineClass(JSThread *thread, JSFunction *func, TaggedArray *literal, JSTaggedValue proto, JSTaggedValue lexenv, ConstantPool *constpool); - static JSTaggedValue SuperCall(JSThread *thread, JSTaggedValue func, JSTaggedValue new_target, uint16_t args_count, + static JSTaggedValue SuperCall(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, uint16_t argsCount, JSTaggedType *stkargs); - static JSTaggedValue SuperCallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue new_target, + static JSTaggedValue SuperCallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, JSTaggedValue array); - static JSTaggedValue DefineMethod(JSThread *thread, JSMethod *method, const JSHandle &home_object); - static JSTaggedValue LdSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, - JSTaggedValue this_func); + static JSTaggedValue DefineMethod(JSThread *thread, JSMethod *method, const JSHandle &homeObject); + static JSTaggedValue LdSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue thisFunc); static JSTaggedValue StSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue value, - JSTaggedValue this_func); + JSTaggedValue thisFunc); static JSTaggedValue NotifyInlineCache(JSThread *thread, JSFunction *func, JSMethod *method); static JSTaggedValue ThrowReferenceError(JSThread *thread, JSTaggedValue prop, const char *desc); @@ -174,8 +173,8 @@ public: JSTaggedValue lexenv, ConstantPool *constpool); static JSTaggedValue SetClassConstructorLength(JSThread *thread, JSTaggedValue ctor, JSTaggedValue length); - static JSTaggedValue LdEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue eval_bindings); - static JSTaggedValue StEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue eval_bindings, + static JSTaggedValue LdEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue evalBindings); + static JSTaggedValue StEvalVar(JSThread *thread, JSTaggedValue name, JSTaggedValue evalBindings, JSTaggedValue value); /* -------------- Common API End, Don't change those interface!!! ----------------- */ diff --git a/runtime/intrinsics-inl.h b/runtime/intrinsics-inl.h index ebadd3ef4739a8a164d472bfe66c4004911cb773..045b9cc0e614becd1f58e753f04589814eebf61e 100644 --- a/runtime/intrinsics-inl.h +++ b/runtime/intrinsics-inl.h @@ -46,22 +46,22 @@ static inline JSTaggedValue GetRuntimeProfileTypeInfo(JSFunction *func) #endif template -static inline JSTaggedValue HandlerCall(JSThread *thread, EcmaRuntimeCallInfo *info, JSTaggedValue fn_object) +static inline JSTaggedValue HandlerCall(JSThread *thread, EcmaRuntimeCallInfo *info, JSTaggedValue fnObject) { - if (UNLIKELY(!fn_object.IsCallable())) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + if (UNLIKELY(!fnObject.IsCallable())) { + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle error = GetFactory(thread)->GetJSError(ErrorType::TYPE_ERROR, "is not callable"); thread->SetException(error.GetTaggedValue()); return JSTaggedValue(JSTaggedValue::VALUE_EXCEPTION); } - ECMAObject *js_object = ECMAObject::Cast(fn_object.GetHeapObject()); - Method *method = js_object->GetCallTarget(); + ECMAObject *jsObject = ECMAObject::Cast(fnObject.GetHeapObject()); + Method *method = jsObject->GetCallTarget(); // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (!THIS_CALL) { ASSERT(info->GetThis().GetTaggedValue() == JSTaggedValue::Undefined()); - if (fn_object.IsJSFunction() && !JSFunction::Cast(js_object)->IsStrict()) { + if (fnObject.IsJSFunction() && !JSFunction::Cast(jsObject)->IsStrict()) { // Set this=GlobalObject for sloppy function info->SetThis(thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject()); } @@ -73,17 +73,17 @@ static inline JSTaggedValue HandlerCall(JSThread *thread, EcmaRuntimeCallInfo *i LOG(DEBUG, INTERPRETER) << "Native function"; LOG(DEBUG, INTERPRETER) << "Entry: Runtime Call."; - JSTaggedValue ret_value = EcmaInterpreter::ExecuteNative(info); + JSTaggedValue retValue = EcmaInterpreter::ExecuteNative(info); if (UNLIKELY(thread->HasPendingException())) { return JSTaggedValue::Exception(); } LOG(DEBUG, INTERPRETER) << "Exit: Runtime Call."; - return ret_value; + return retValue; } - JSFunction *js_function = JSFunction::Cast(js_object); - if (UNLIKELY(js_function->IsClassConstructor())) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSFunction *jsFunction = JSFunction::Cast(jsObject); + if (UNLIKELY(jsFunction->IsClassConstructor())) { + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle error = thread->GetEcmaVM()->GetFactory()->GetJSError( ErrorType::TYPE_ERROR, "class constructor cannot called without 'new'"); thread->SetException(error.GetTaggedValue()); @@ -91,12 +91,12 @@ static inline JSTaggedValue HandlerCall(JSThread *thread, EcmaRuntimeCallInfo *i } LOG(DEBUG, INTERPRETER) << "Method name: " << method->GetName().data; - JSTaggedValue ret_value = EcmaInterpreter::ExecuteInvoke(info, fn_object); + JSTaggedValue retValue = EcmaInterpreter::ExecuteInvoke(info, fnObject); if (UNLIKELY(thread->HasPendingException())) { return JSTaggedValue::Exception(); } - return ret_value; + return retValue; } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -142,12 +142,12 @@ INLINE_ECMA_INTRINSICS uint64_t Ldstring([[maybe_unused]] JSThread *thread, [[ma } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Ldbigint([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint64_t number_big_int) +INLINE_ECMA_INTRINSICS uint64_t Ldbigint([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint64_t numberBigInt) { INTERPRETER_TRACE(thread, Ldbigint); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle big_int_handle(thread, JSTaggedValue(number_big_int)); - return JSTaggedValue::ToBigInt(thread, big_int_handle).GetRawData(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle bigIntHandle(thread, JSTaggedValue(numberBigInt)); + return JSTaggedValue::ToBigInt(thread, bigIntHandle).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -204,12 +204,12 @@ INLINE_ECMA_INTRINSICS uint64_t Add2Dyn(JSThread *thread, uint64_t lhs, uint64_t return JSTaggedValue(a0 + a1).GetRawData(); } if (left.IsNumber() && right.IsNumber()) { - double a0_double = left.IsInt() ? left.GetInt() : left.GetDouble(); - double a1_double = right.IsInt() ? right.GetInt() : right.GetDouble(); - return JSTaggedValue(a0_double + a1_double).GetRawData(); + double a0Double = left.IsInt() ? left.GetInt() : left.GetDouble(); + double a1Double = right.IsInt() ? right.GetInt() : right.GetDouble(); + return JSTaggedValue(a0Double + a1Double).GetRawData(); } - auto ecma_vm = thread->GetEcmaVM(); - return SlowRuntimeStub::Add2Dyn(thread, ecma_vm, left, right).GetRawData(); + auto ecmaVm = thread->GetEcmaVM(); + return SlowRuntimeStub::Add2Dyn(thread, ecmaVm, left, right).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -228,9 +228,9 @@ INLINE_ECMA_INTRINSICS uint64_t Sub2Dyn(JSThread *thread, uint64_t lhs, uint64_t return JSTaggedValue(a0 + a1).GetRawData(); } if (left.IsNumber() && right.IsNumber()) { - double a0_double = left.IsInt() ? left.GetInt() : left.GetDouble(); - double a1_double = right.IsInt() ? right.GetInt() : right.GetDouble(); - return JSTaggedValue(a0_double - a1_double).GetRawData(); + double a0Double = left.IsInt() ? left.GetInt() : left.GetDouble(); + double a1Double = right.IsInt() ? right.GetInt() : right.GetDouble(); + return JSTaggedValue(a0Double - a1Double).GetRawData(); } return SlowRuntimeStub::Sub2Dyn(thread, left, right).GetRawData(); } @@ -278,17 +278,17 @@ INLINE_ECMA_INTRINSICS uint64_t Mod2Dyn(JSThread *thread, uint64_t lhs, uint64_t } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t ExpDyn(JSThread *thread, uint64_t base_exp, uint64_t exp) +INLINE_ECMA_INTRINSICS uint64_t ExpDyn(JSThread *thread, uint64_t baseExp, uint64_t exp) { - auto base = JSTaggedValue(base_exp); + auto base = JSTaggedValue(baseExp); auto exponent = JSTaggedValue(exp); JSTaggedValue res; if (base.IsNumber() && exponent.IsNumber()) { - double double_base = base.IsInt() ? base.GetInt() : base.GetDouble(); - double double_exponent = exponent.IsInt() ? exponent.GetInt() : exponent.GetDouble(); - res = base::NumberHelper::Pow(double_base, double_exponent); + double doubleBase = base.IsInt() ? base.GetInt() : base.GetDouble(); + double doubleExponent = exponent.IsInt() ? exponent.GetInt() : exponent.GetDouble(); + res = base::NumberHelper::Pow(doubleBase, doubleExponent); } else { res = SlowRuntimeStub::ExpDyn(thread, base, exponent); } @@ -344,9 +344,9 @@ INLINE_ECMA_INTRINSICS uint64_t LessDyn(JSThread *thread, uint64_t lhs, uint64_t auto right = JSTaggedValue(rhs); if (left.IsNumber() && right.IsNumber()) { - double value_a = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); - double value_b = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); - bool ret = JSTaggedValue::StrictNumberCompare(value_a, value_b) == ComparisonResult::LESS; + double valueA = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); + double valueB = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); + bool ret = JSTaggedValue::StrictNumberCompare(valueA, valueB) == ComparisonResult::LESS; return ret ? JSTaggedValue::True().GetRawData() : JSTaggedValue::False().GetRawData(); } return SlowRuntimeStub::LessDyn(thread, left, right).GetRawData(); @@ -359,9 +359,9 @@ INLINE_ECMA_INTRINSICS uint64_t LessEqDyn(JSThread *thread, uint64_t lhs, uint64 auto right = JSTaggedValue(rhs); if (left.IsNumber() && right.IsNumber()) { - double value_a = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); - double value_b = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); - bool ret = JSTaggedValue::StrictNumberCompare(value_a, value_b) <= ComparisonResult::EQUAL; + double valueA = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); + double valueB = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); + bool ret = JSTaggedValue::StrictNumberCompare(valueA, valueB) <= ComparisonResult::EQUAL; return ret ? JSTaggedValue::True().GetRawData() : JSTaggedValue::False().GetRawData(); } return SlowRuntimeStub::LessEqDyn(thread, left, right).GetRawData(); @@ -374,9 +374,9 @@ INLINE_ECMA_INTRINSICS uint64_t GreaterDyn(JSThread *thread, uint64_t lhs, uint6 auto right = JSTaggedValue(rhs); if (left.IsNumber() && right.IsNumber()) { - double value_a = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); - double value_b = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); - bool ret = JSTaggedValue::StrictNumberCompare(value_a, value_b) == ComparisonResult::GREAT; + double valueA = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); + double valueB = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); + bool ret = JSTaggedValue::StrictNumberCompare(valueA, valueB) == ComparisonResult::GREAT; return ret ? JSTaggedValue::True().GetRawData() : JSTaggedValue::False().GetRawData(); } return SlowRuntimeStub::GreaterDyn(thread, left, right).GetRawData(); @@ -389,9 +389,9 @@ INLINE_ECMA_INTRINSICS uint64_t GreaterEqDyn(JSThread *thread, uint64_t lhs, uin auto right = JSTaggedValue(rhs); if (left.IsNumber() && right.IsNumber()) { - double value_a = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); - double value_b = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); - ComparisonResult comparison = JSTaggedValue::StrictNumberCompare(value_a, value_b); + double valueA = left.IsInt() ? static_cast(left.GetInt()) : left.GetDouble(); + double valueB = right.IsInt() ? static_cast(right.GetInt()) : right.GetDouble(); + ComparisonResult comparison = JSTaggedValue::StrictNumberCompare(valueA, valueB); bool ret = (comparison == ComparisonResult::GREAT) || (comparison == ComparisonResult::EQUAL); return ret ? JSTaggedValue::True().GetRawData() : JSTaggedValue::False().GetRawData(); } @@ -399,32 +399,31 @@ INLINE_ECMA_INTRINSICS uint64_t GreaterEqDyn(JSThread *thread, uint64_t lhs, uin } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t TryLdGlobalByValue([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint16_t slot_id, - [[maybe_unused]] uint64_t prop_value) +INLINE_ECMA_INTRINSICS uint64_t TryLdGlobalByValue([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint16_t slotId, + [[maybe_unused]] uint64_t propValue) { UNREACHABLE(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS void TryStGlobalByValue([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint16_t slot_id, - [[maybe_unused]] uint64_t prop_value, - [[maybe_unused]] uint64_t val_value) +INLINE_ECMA_INTRINSICS void TryStGlobalByValue([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint16_t slotId, + [[maybe_unused]] uint64_t propValue, [[maybe_unused]] uint64_t valValue) { UNREACHABLE(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t TryLdGlobalByName(JSThread *thread, uint64_t prop, [[maybe_unused]] uint16_t slot_id, +INLINE_ECMA_INTRINSICS uint64_t TryLdGlobalByName(JSThread *thread, uint64_t prop, [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { - JSTaggedType global_obj = GetGlobalObject(thread).GetRawData(); + JSTaggedType globalObj = GetGlobalObject(thread).GetRawData(); JSTaggedValue result = JSTaggedValue::Hole(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - result = ICRuntimeStub::LoadGlobalICByName(thread, js_func, JSTaggedValue(global_obj), JSTaggedValue(prop), - slot_id, true); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + result = ICRuntimeStub::LoadGlobalICByName(thread, jsFunc, JSTaggedValue(globalObj), JSTaggedValue(prop), + slotId, true); if (!result.IsHole()) { return result.GetRawData(); } @@ -433,12 +432,12 @@ INLINE_ECMA_INTRINSICS uint64_t TryLdGlobalByName(JSThread *thread, uint64_t pro bool found = false; ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - result = FastRuntimeStub::GetGlobalOwnProperty(JSTaggedValue(global_obj), JSTaggedValue(prop), &found); + result = FastRuntimeStub::GetGlobalOwnProperty(JSTaggedValue(globalObj), JSTaggedValue(prop), &found); if (found) { return result.GetRawData(); } ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - return SlowRuntimeStub::TryLdGlobalByName(thread, JSTaggedValue(global_obj), JSTaggedValue(prop)).GetRawData(); + return SlowRuntimeStub::TryLdGlobalByName(thread, JSTaggedValue(globalObj), JSTaggedValue(prop)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -549,12 +548,12 @@ INLINE_ECMA_INTRINSICS uint64_t DefinefuncDyn(JSThread *thread, uint64_t method, auto result = JSFunction::Cast(JSTaggedValue(method).GetHeapObject()); auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle lexenv_handle(thread, lexenv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle lexenvHandle(thread, lexenv); auto res = SlowRuntimeStub::DefinefuncDyn(thread, result->GetCallTarget()); result = JSFunction::Cast(res.GetHeapObject()); auto constpool = ConstantPool::Cast(cp); // May not be moved by GC - lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC + lexenv = lexenvHandle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(constpool)); } result->SetLexicalEnv(thread, lexenv); @@ -562,22 +561,22 @@ INLINE_ECMA_INTRINSICS uint64_t DefinefuncDyn(JSThread *thread, uint64_t method, } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t NewobjDynrange(JSThread *thread, uint16_t num_args, uint64_t func, uint64_t new_target, - void *stkargs_raw) +INLINE_ECMA_INTRINSICS uint64_t NewobjDynrange(JSThread *thread, uint16_t numArgs, uint64_t func, uint64_t newTarget, + void *stkargsRaw) { - return SlowRuntimeStub::NewObjDynRange(thread, num_args, JSTaggedValue(func), JSTaggedValue(new_target), - reinterpret_cast(stkargs_raw)) + return SlowRuntimeStub::NewObjDynRange(thread, numArgs, JSTaggedValue(func), JSTaggedValue(newTarget), + reinterpret_cast(stkargsRaw)) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t NewobjDynrangeHandled(JSThread *thread, uint16_t num_args, uint64_t func, - uint64_t new_target, void *stkargs_raw) +INLINE_ECMA_INTRINSICS uint64_t NewobjDynrangeHandled(JSThread *thread, uint16_t numArgs, uint64_t func, + uint64_t newTarget, void *stkargsRaw) { - JSSpanHandle args_handle(thread, Span(reinterpret_cast(stkargs_raw), num_args)); + JSSpanHandle argsHandle(thread, Span(reinterpret_cast(stkargsRaw), numArgs)); - return SlowRuntimeStub::NewObjDynRange(thread, num_args, JSTaggedValue(func), JSTaggedValue(new_target), - args_handle.DataTaggedType()) + return SlowRuntimeStub::NewObjDynRange(thread, numArgs, JSTaggedValue(func), JSTaggedValue(newTarget), + argsHandle.DataTaggedType()) .GetRawData(); } @@ -609,23 +608,21 @@ INLINE_ECMA_INTRINSICS uint64_t LdlexenvDyn([[maybe_unused]] JSThread *thread) } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t GetUnmappedArgs([[maybe_unused]] JSThread *thread, uint32_t num_args, void *args) +INLINE_ECMA_INTRINSICS uint64_t GetUnmappedArgs([[maybe_unused]] JSThread *thread, uint32_t numArgs, void *args) { ASSERT(thread->IsCurrentFrameCompiled()); - uint32_t actual_num_args = num_args - js_method_args::NUM_MANDATORY_ARGS; - return SlowRuntimeStub::GetUnmappedArgs(thread, actual_num_args, reinterpret_cast(args)) - .GetRawData(); + uint32_t actualNumArgs = numArgs - js_method_args::NUM_MANDATORY_ARGS; + return SlowRuntimeStub::GetUnmappedArgs(thread, actualNumArgs, reinterpret_cast(args)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t GetUnmappedArgsInterp(JSThread *thread) { ASSERT(!thread->IsCurrentFrameCompiled()); - uint32_t actual_num_args = thread->GetCurrentFrame()->GetNumActualArgs() - js_method_args::NUM_MANDATORY_ARGS; - uint32_t start_idx = thread->GetCurrentFrame()->GetMethod()->GetNumVregs() + js_method_args::NUM_MANDATORY_ARGS; - auto args = reinterpret_cast(&thread->GetCurrentFrame()->GetVReg(start_idx)); - return SlowRuntimeStub::GetUnmappedArgs(thread, actual_num_args, reinterpret_cast(args)) - .GetRawData(); + uint32_t actualNumArgs = thread->GetCurrentFrame()->GetNumActualArgs() - js_method_args::NUM_MANDATORY_ARGS; + uint32_t startIdx = thread->GetCurrentFrame()->GetMethod()->GetNumVregs() + js_method_args::NUM_MANDATORY_ARGS; + auto args = reinterpret_cast(&thread->GetCurrentFrame()->GetVReg(startIdx)); + return SlowRuntimeStub::GetUnmappedArgs(thread, actualNumArgs, reinterpret_cast(args)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -672,32 +669,31 @@ INLINE_ECMA_INTRINSICS uint64_t SuspendGenerator([[maybe_unused]] JSThread *thre } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t SuspendGeneratorInterp(JSThread *thread, uint64_t gen_obj, uint64_t value, uint64_t pc) +INLINE_ECMA_INTRINSICS uint64_t SuspendGeneratorInterp(JSThread *thread, uint64_t genObj, uint64_t value, uint64_t pc) { ASSERT(!thread->IsCurrentFrameCompiled()); thread->GetCurrentFrame()->SetBytecodeOffset(pc); - return SlowRuntimeStub::SuspendGenerator(thread, JSTaggedValue(gen_obj), JSTaggedValue(value)).GetRawData(); + return SlowRuntimeStub::SuspendGenerator(thread, JSTaggedValue(genObj), JSTaggedValue(value)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t SuspendAsyncGenerator([[maybe_unused]] JSThread *thread, - [[maybe_unused]] uint64_t gen_obj, - [[maybe_unused]] uint64_t value) + [[maybe_unused]] uint64_t genObj, [[maybe_unused]] uint64_t value) { UNREACHABLE(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t SuspendAsyncGeneratorInterp(JSThread *thread, uint64_t gen_obj, uint64_t value, +INLINE_ECMA_INTRINSICS uint64_t SuspendAsyncGeneratorInterp(JSThread *thread, uint64_t genObj, uint64_t value, uint64_t pc) { ASSERT(!thread->IsCurrentFrameCompiled()); thread->GetCurrentFrame()->SetBytecodeOffset(pc); - return SlowRuntimeStub::SuspendAsyncGenerator(thread, JSTaggedValue(gen_obj), JSTaggedValue(value)).GetRawData(); + return SlowRuntimeStub::SuspendAsyncGenerator(thread, JSTaggedValue(genObj), JSTaggedValue(value)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS void ThrowUndefined([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint64_t obj_value) +INLINE_ECMA_INTRINSICS void ThrowUndefined([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint64_t objValue) { UNREACHABLE(); } @@ -713,15 +709,15 @@ INLINE_ECMA_INTRINSICS uint64_t CopyrestargsInterp(JSThread *thread, uint16_t in { ASSERT(!thread->IsCurrentFrameCompiled()); auto *frame = thread->GetCurrentFrame(); - uint32_t num_vregs = frame->GetMethod()->GetNumVregs(); - int32_t actual_num_args = frame->GetNumActualArgs() - js_method_args::NUM_MANDATORY_ARGS; - int32_t tmp = actual_num_args - index; - uint32_t rest_num_args = (tmp > 0) ? tmp : 0; - uint32_t start_idx = num_vregs + js_method_args::NUM_MANDATORY_ARGS + index; + uint32_t numVregs = frame->GetMethod()->GetNumVregs(); + int32_t actualNumArgs = frame->GetNumActualArgs() - js_method_args::NUM_MANDATORY_ARGS; + int32_t tmp = actualNumArgs - index; + uint32_t restNumArgs = (tmp > 0) ? tmp : 0; + uint32_t startIdx = numVregs + js_method_args::NUM_MANDATORY_ARGS + index; - auto args = reinterpret_cast(&thread->GetCurrentFrame()->GetVReg(start_idx)); + auto args = reinterpret_cast(&thread->GetCurrentFrame()->GetVReg(startIdx)); - return SlowRuntimeStub::CopyRestArgs(thread, rest_num_args, args).GetRawData(); + return SlowRuntimeStub::CopyRestArgs(thread, restNumArgs, args).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -738,144 +734,143 @@ INLINE_ECMA_INTRINSICS void ReturnUndefined([[maybe_unused]] JSThread *thread) } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call0Dyn(JSThread *thread, uint64_t raw_fn_object) +INLINE_ECMA_INTRINSICS uint64_t Call0Dyn(JSThread *thread, uint64_t rawFnObject) { std::array args = { - JSTaggedValue(raw_fn_object), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call1Dyn(JSThread *thread, uint64_t raw_fn_object, uint64_t raw_a0) +INLINE_ECMA_INTRINSICS uint64_t Call1Dyn(JSThread *thread, uint64_t rawFnObject, uint64_t rawA0) { std::array args = { - JSTaggedValue(raw_fn_object), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), - JSTaggedValue(raw_a0), + JSTaggedValue(rawA0), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call2Dyn(JSThread *thread, uint64_t raw_fn_object, uint64_t raw_a0, uint64_t raw_a1) +INLINE_ECMA_INTRINSICS uint64_t Call2Dyn(JSThread *thread, uint64_t rawFnObject, uint64_t rawA0, uint64_t rawA1) { std::array args = { - JSTaggedValue(raw_fn_object), JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), - JSTaggedValue(raw_a0), JSTaggedValue(raw_a1), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), + JSTaggedValue(rawA0), JSTaggedValue(rawA1), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call3Dyn(JSThread *thread, uint64_t raw_fn_object, uint64_t raw_a0, uint64_t raw_a1, - uint64_t raw_a2) +INLINE_ECMA_INTRINSICS uint64_t Call3Dyn(JSThread *thread, uint64_t rawFnObject, uint64_t rawA0, uint64_t rawA1, + uint64_t rawA2) { std::array args = { - JSTaggedValue(raw_fn_object), JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), - JSTaggedValue(raw_a0), JSTaggedValue(raw_a1), JSTaggedValue(raw_a2), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), + JSTaggedValue(rawA0), JSTaggedValue(rawA1), JSTaggedValue(rawA2), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // Just declared here, not used // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t CalliRangeDyn([[maybe_unused]] JSThread *thread, [[maybe_unused]] uint16_t num, - [[maybe_unused]] uint64_t obj_value) + [[maybe_unused]] uint64_t objValue) { UNREACHABLE(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call0ThisDyn(JSThread *thread, uint64_t raw_fn_object, uint64_t raw_this) +INLINE_ECMA_INTRINSICS uint64_t Call0ThisDyn(JSThread *thread, uint64_t rawFnObject, uint64_t rawThis) { std::array args = { - JSTaggedValue(raw_fn_object), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), - JSTaggedValue(raw_this), + JSTaggedValue(rawThis), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call1ThisDyn(JSThread *thread, uint64_t raw_fn_object, uint64_t raw_this, - uint64_t raw_a0) +INLINE_ECMA_INTRINSICS uint64_t Call1ThisDyn(JSThread *thread, uint64_t rawFnObject, uint64_t rawThis, uint64_t rawA0) { std::array args = { - JSTaggedValue(raw_fn_object), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), - JSTaggedValue(raw_this), - JSTaggedValue(raw_a0), + JSTaggedValue(rawThis), + JSTaggedValue(rawA0), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call2ThisDyn(JSThread *thread, uint64_t raw_fn_object, uint64_t raw_this, - uint64_t raw_a0, uint64_t raw_a1) +INLINE_ECMA_INTRINSICS uint64_t Call2ThisDyn(JSThread *thread, uint64_t rawFnObject, uint64_t rawThis, uint64_t rawA0, + uint64_t rawA1) { std::array args = { - JSTaggedValue(raw_fn_object), JSTaggedValue::Undefined(), JSTaggedValue(raw_this), - JSTaggedValue(raw_a0), JSTaggedValue(raw_a1), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), JSTaggedValue(rawThis), + JSTaggedValue(rawA0), JSTaggedValue(rawA1), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t Call3ThisDyn(JSThread *thread, uint64_t raw_fn_object, uint64_t raw_this, - uint64_t raw_a0, uint64_t raw_a1, uint64_t raw_a2) +INLINE_ECMA_INTRINSICS uint64_t Call3ThisDyn(JSThread *thread, uint64_t rawFnObject, uint64_t rawThis, uint64_t rawA0, + uint64_t rawA1, uint64_t rawA2) { std::array args = { - JSTaggedValue(raw_fn_object), JSTaggedValue::Undefined(), JSTaggedValue(raw_this), - JSTaggedValue(raw_a0), JSTaggedValue(raw_a1), JSTaggedValue(raw_a2), + JSTaggedValue(rawFnObject), JSTaggedValue::Undefined(), JSTaggedValue(rawThis), + JSTaggedValue(rawA0), JSTaggedValue(rawA1), JSTaggedValue(rawA2), }; EcmaRuntimeCallInfo info(thread, args.size(), args.data()); - return HandlerCall(thread, &info, JSTaggedValue(raw_fn_object)).GetRawData(); + return HandlerCall(thread, &info, JSTaggedValue(rawFnObject)).GetRawData(); } // Just declared here, not used // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t CalliRangeDynInterp(JSThread *thread, uint16_t args_num, uint64_t args_ptr) +INLINE_ECMA_INTRINSICS uint64_t CalliRangeDynInterp(JSThread *thread, uint16_t argsNum, uint64_t argsPtr) { - auto args = reinterpret_cast(args_ptr); - auto fn_obj = args[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto *fn_args = &args[1]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto args = reinterpret_cast(argsPtr); + auto fnObj = args[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto *fnArgs = &args[1]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) // NOTE(vpukhov): copy in-place - auto info = NewRuntimeCallInfo(thread, fn_obj, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), args_num); - for (size_t i = 0; i < args_num; ++i) { - info->SetCallArg(i, fn_args[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto info = NewRuntimeCallInfo(thread, fnObj, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), argsNum); + for (size_t i = 0; i < argsNum; ++i) { + info->SetCallArg(i, fnArgs[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } - return HandlerCall(thread, info.Get(), fn_obj).GetRawData(); + return HandlerCall(thread, info.Get(), fnObj).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t CalliThisRangeDyn(JSThread *thread, uint16_t args_num, uint64_t args_ptr) +INLINE_ECMA_INTRINSICS uint64_t CalliThisRangeDyn(JSThread *thread, uint16_t argsNum, uint64_t argsPtr) { - auto args = reinterpret_cast(args_ptr); - auto fn_obj = args[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto this_obj = args[1]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto *fn_args = &args[2U]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - args_num--; + auto args = reinterpret_cast(argsPtr); + auto fnObj = args[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto thisObj = args[1]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto *fnArgs = &args[2U]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + argsNum--; // NOTE(vpukhov): copy in-place - auto info = NewRuntimeCallInfo(thread, fn_obj, this_obj, JSTaggedValue::Undefined(), args_num); - for (size_t i = 0; i < args_num; ++i) { - info->SetCallArg(i, fn_args[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto info = NewRuntimeCallInfo(thread, fnObj, thisObj, JSTaggedValue::Undefined(), argsNum); + for (size_t i = 0; i < argsNum; ++i) { + info->SetCallArg(i, fnArgs[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } - return HandlerCall(thread, info.Get(), fn_obj).GetRawData(); + return HandlerCall(thread, info.Get(), fnObj).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -903,7 +898,7 @@ INLINE_ECMA_INTRINSICS uint64_t Ldglobal(JSThread *thread) // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, - [[maybe_unused]] uint16_t slot_id, [[maybe_unused]] uint64_t func) + [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { // If ICRuntimeStub::LoadICByValue triggers GC it mustn't return Hole. // Using rec and pkey after ICRuntimeStub::LoadICByValue is valid. @@ -911,9 +906,9 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uin JSTaggedValue res = JSTaggedValue::Hole(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - res = ICRuntimeStub::LoadICByValue(thread, js_func, JSTaggedValue(rec), JSTaggedValue(pkey), slot_id); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + res = ICRuntimeStub::LoadICByValue(thread, jsFunc, JSTaggedValue(rec), JSTaggedValue(pkey), slotId); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } @@ -922,24 +917,24 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uin // fast path ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle receiver(thread, JSTaggedValue(rec)); - JSHandle prop_key(thread, JSTaggedValue(pkey)); + JSHandle propKey(thread, JSTaggedValue(pkey)); if (LIKELY(receiver->IsHeapObject())) { - res = FastRuntimeStub::GetPropertyByValue(thread, receiver, prop_key); + res = FastRuntimeStub::GetPropertyByValue(thread, receiver, propKey); if (!res.IsHole()) { return res.GetRawData(); } } // slow path - return SlowRuntimeStub::LdObjByValue(thread, receiver.GetTaggedValue(), prop_key.GetTaggedValue(), false, + return SlowRuntimeStub::LdObjByValue(thread, receiver.GetTaggedValue(), propKey.GetTaggedValue(), false, JSTaggedValue::Undefined()) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, uint64_t val, - [[maybe_unused]] uint16_t slot_id, [[maybe_unused]] uint64_t func) + [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { // If ICRuntimeStub::StoreICByValue triggers GC it mustn't return Hole. // Using rec and pkey after ICRuntimeStub::StoreICByValue is valid. @@ -947,10 +942,10 @@ INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uin JSTaggedValue res = JSTaggedValue::Hole(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetTaggedObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - res = ICRuntimeStub::StoreICByValue(thread, js_func, JSTaggedValue(rec), JSTaggedValue(pkey), - JSTaggedValue(val), slot_id); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetTaggedObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + res = ICRuntimeStub::StoreICByValue(thread, jsFunc, JSTaggedValue(rec), JSTaggedValue(pkey), JSTaggedValue(val), + slotId); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } @@ -958,36 +953,36 @@ INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uin #endif ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle receiver(thread, JSTaggedValue(rec)); - JSHandle prop_key(thread, JSTaggedValue(pkey)); + JSHandle propKey(thread, JSTaggedValue(pkey)); JSHandle value(thread, JSTaggedValue(val)); if (receiver->IsHeapObject()) { - res = FastRuntimeStub::SetPropertyByValue(thread, receiver, prop_key, value); + res = FastRuntimeStub::SetPropertyByValue(thread, receiver, propKey, value); if (!res.IsHole()) { return res.GetRawData(); } } - return SlowRuntimeStub::StObjByValue(thread, receiver.GetTaggedValue(), prop_key.GetTaggedValue(), + return SlowRuntimeStub::StObjByValue(thread, receiver.GetTaggedValue(), propKey.GetTaggedValue(), value.GetTaggedValue()) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t TryStGlobalByName(JSThread *thread, uint64_t prop_key, uint64_t value, - [[maybe_unused]] uint16_t slot_id, [[maybe_unused]] uint64_t func) +INLINE_ECMA_INTRINSICS uint64_t TryStGlobalByName(JSThread *thread, uint64_t propKey, uint64_t value, + [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { - JSTaggedType global_obj = GetGlobalObject(thread).GetRawData(); + JSTaggedType globalObj = GetGlobalObject(thread).GetRawData(); JSTaggedValue result = JSTaggedValue::Hole(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - result = ICRuntimeStub::StoreGlobalICByName(thread, js_func, JSTaggedValue(global_obj), JSTaggedValue(prop_key), - JSTaggedValue(value), slot_id, true); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + result = ICRuntimeStub::StoreGlobalICByName(thread, jsFunc, JSTaggedValue(globalObj), JSTaggedValue(propKey), + JSTaggedValue(value), slotId, true); if (!result.IsHole()) { return result.GetRawData(); } @@ -997,29 +992,29 @@ INLINE_ECMA_INTRINSICS uint64_t TryStGlobalByName(JSThread *thread, uint64_t pro ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); bool found = false; // 2. find from global object - FastRuntimeStub::GetGlobalOwnProperty(JSTaggedValue(global_obj), JSTaggedValue(prop_key), &found); + FastRuntimeStub::GetGlobalOwnProperty(JSTaggedValue(globalObj), JSTaggedValue(propKey), &found); if (!found) { - result = SlowRuntimeStub::ThrowReferenceError(thread, JSTaggedValue(prop_key), " is not defined"); + result = SlowRuntimeStub::ThrowReferenceError(thread, JSTaggedValue(propKey), " is not defined"); ASSERT(result.IsException()); return result.GetRawData(); } ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - return SlowRuntimeStub::StGlobalVar(thread, JSTaggedValue(prop_key), JSTaggedValue(value)).GetRawData(); + return SlowRuntimeStub::StGlobalVar(thread, JSTaggedValue(propKey), JSTaggedValue(value)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LdGlobalVar(JSThread *thread, uint64_t prop_key, [[maybe_unused]] uint16_t slot_id, +INLINE_ECMA_INTRINSICS uint64_t LdGlobalVar(JSThread *thread, uint64_t propKey, [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { - JSTaggedType global_obj = thread->GetGlobalObject().GetRawData(); + JSTaggedType globalObj = thread->GetGlobalObject().GetRawData(); JSTaggedValue result = JSTaggedValue::Hole(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - result = ICRuntimeStub::LoadGlobalICByName(thread, js_func, JSTaggedValue(global_obj), JSTaggedValue(prop_key), - slot_id); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + result = + ICRuntimeStub::LoadGlobalICByName(thread, jsFunc, JSTaggedValue(globalObj), JSTaggedValue(propKey), slotId); if (!result.IsHole()) { return result.GetRawData(); } @@ -1028,26 +1023,26 @@ INLINE_ECMA_INTRINSICS uint64_t LdGlobalVar(JSThread *thread, uint64_t prop_key, ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); bool found = false; - result = FastRuntimeStub::GetGlobalOwnProperty(JSTaggedValue(global_obj), JSTaggedValue(prop_key), &found); + result = FastRuntimeStub::GetGlobalOwnProperty(JSTaggedValue(globalObj), JSTaggedValue(propKey), &found); if (found) { return result.GetRawData(); } ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - return SlowRuntimeStub::LdGlobalVar(thread, JSTaggedValue(global_obj), JSTaggedValue(prop_key)).GetRawData(); + return SlowRuntimeStub::LdGlobalVar(thread, JSTaggedValue(globalObj), JSTaggedValue(propKey)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StGlobalVar(JSThread *thread, uint64_t prop, uint64_t value, - [[maybe_unused]] uint16_t slot_id, [[maybe_unused]] uint64_t func) + [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { - JSTaggedType global_obj = thread->GetGlobalObject().GetRawData(); + JSTaggedType globalObj = thread->GetGlobalObject().GetRawData(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - JSTaggedValue result = ICRuntimeStub::StoreGlobalICByName(thread, js_func, JSTaggedValue(global_obj), - JSTaggedValue(prop), JSTaggedValue(value), slot_id); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + JSTaggedValue result = ICRuntimeStub::StoreGlobalICByName(thread, jsFunc, JSTaggedValue(globalObj), + JSTaggedValue(prop), JSTaggedValue(value), slotId); if (!result.IsHole()) { return result.GetRawData(); } @@ -1059,8 +1054,8 @@ INLINE_ECMA_INTRINSICS uint64_t StGlobalVar(JSThread *thread, uint64_t prop, uin } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LdObjByName(JSThread *thread, uint64_t prop_key, uint64_t object, - [[maybe_unused]] uint16_t slot_id, [[maybe_unused]] uint64_t func) +INLINE_ECMA_INTRINSICS uint64_t LdObjByName(JSThread *thread, uint64_t propKey, uint64_t object, + [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { // CSA reports usage object and prop_key after GC triggered in ICRuntimeStub::LoadICByName. // If ICRuntimeStub::LoadICByName triggers GC it mustn't return Hole. @@ -1069,9 +1064,9 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByName(JSThread *thread, uint64_t prop_key, JSTaggedValue res = JSTaggedValue::Hole(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - res = ICRuntimeStub::LoadICByName(thread, js_func, JSTaggedValue(object), JSTaggedValue(prop_key), slot_id); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + res = ICRuntimeStub::LoadICByName(thread, jsFunc, JSTaggedValue(object), JSTaggedValue(propKey), slotId); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } @@ -1080,20 +1075,20 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByName(JSThread *thread, uint64_t prop_key, if (LIKELY(JSTaggedValue(object).IsHeapObject())) { ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - res = FastRuntimeStub::GetPropertyByName(thread, JSTaggedValue(object), JSTaggedValue(prop_key)); + res = FastRuntimeStub::GetPropertyByName(thread, JSTaggedValue(object), JSTaggedValue(propKey)); if (!res.IsHole()) { return res.GetRawData(); } } ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); - return SlowRuntimeStub::LdObjByName(thread, JSTaggedValue(object), JSTaggedValue(prop_key), false, + return SlowRuntimeStub::LdObjByName(thread, JSTaggedValue(object), JSTaggedValue(propKey), false, JSTaggedValue::Undefined()) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t StObjByName(JSThread *thread, uint64_t prop_key, uint64_t object, uint64_t val, - [[maybe_unused]] uint16_t slot_id, [[maybe_unused]] uint64_t func) +INLINE_ECMA_INTRINSICS uint64_t StObjByName(JSThread *thread, uint64_t propKey, uint64_t object, uint64_t val, + [[maybe_unused]] uint16_t slotId, [[maybe_unused]] uint64_t func) { // CSA reports usage object, prop_key and val after GC triggered in ICRuntimeStub::StoreICByName. // If ICRuntimeStub::StoreICByName triggers GC it mustn't return Hole. @@ -1102,10 +1097,10 @@ INLINE_ECMA_INTRINSICS uint64_t StObjByName(JSThread *thread, uint64_t prop_key, JSTaggedValue res = JSTaggedValue::Hole(); [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); #if ECMASCRIPT_ENABLE_IC - auto js_func = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); - if (ICRuntimeStub::HaveICForFunction(js_func)) { - res = ICRuntimeStub::StoreICByName(thread, js_func, JSTaggedValue(object), JSTaggedValue(prop_key), - JSTaggedValue(val), slot_id); + auto jsFunc = JSFunction::Cast(JSTaggedValue(func).GetHeapObject()); + if (ICRuntimeStub::HaveICForFunction(jsFunc)) { + res = ICRuntimeStub::StoreICByName(thread, jsFunc, JSTaggedValue(object), JSTaggedValue(propKey), + JSTaggedValue(val), slotId); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } @@ -1114,13 +1109,13 @@ INLINE_ECMA_INTRINSICS uint64_t StObjByName(JSThread *thread, uint64_t prop_key, ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); if (JSTaggedValue(object).IsHeapObject()) { - res = FastRuntimeStub::SetPropertyByName(thread, JSTaggedValue(object), JSTaggedValue(prop_key), + res = FastRuntimeStub::SetPropertyByName(thread, JSTaggedValue(object), JSTaggedValue(propKey), JSTaggedValue(val)); if (!res.IsHole()) { return res.GetRawData(); } } - return SlowRuntimeStub::StObjByName(thread, JSTaggedValue(object), JSTaggedValue(prop_key), JSTaggedValue(val)) + return SlowRuntimeStub::StObjByName(thread, JSTaggedValue(object), JSTaggedValue(propKey), JSTaggedValue(val)) .GetRawData(); } @@ -1181,25 +1176,25 @@ ARK_INLINE inline static JSTaggedValue GetLeftRightInt(JSThread *thread, uint64_ return JSTaggedValue::Hole(); } - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle right_handle(thread, jright); - JSHandle left_handle(thread, jleft); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle rightHandle(thread, jright); + JSHandle leftHandle(thread, jleft); - JSHandle left_value = JSTaggedValue::ToNumeric(thread, left_handle); + JSHandle leftValue = JSTaggedValue::ToNumeric(thread, leftHandle); - if (left_value->IsException()) { + if (leftValue->IsException()) { return JSTaggedValue::Exception(); } - JSHandle right_value = JSTaggedValue::ToNumeric(thread, right_handle); + JSHandle rightValue = JSTaggedValue::ToNumeric(thread, rightHandle); - if (right_value->IsException()) { + if (rightValue->IsException()) { return JSTaggedValue::Exception(); } - if (left_value->IsBigInt() || right_value->IsBigInt()) { - if (left_value->IsBigInt() && right_value->IsBigInt()) { - return BIGINT_OP(thread, JSHandle::Cast(left_value), JSHandle::Cast(right_value)) + if (leftValue->IsBigInt() || rightValue->IsBigInt()) { + if (leftValue->IsBigInt() && rightValue->IsBigInt()) { + return BIGINT_OP(thread, JSHandle::Cast(leftValue), JSHandle::Cast(rightValue)) .GetTaggedValue(); } @@ -1209,15 +1204,15 @@ ARK_INLINE inline static JSTaggedValue GetLeftRightInt(JSThread *thread, uint64_ return JSTaggedValue::Exception(); } - jleft = IS_U_LEFT ? SlowRuntimeStub::ToJSTaggedValueWithUint32(thread, left_value.GetTaggedValue()) - : SlowRuntimeStub::ToJSTaggedValueWithInt32(thread, left_value.GetTaggedValue()); + jleft = IS_U_LEFT ? SlowRuntimeStub::ToJSTaggedValueWithUint32(thread, leftValue.GetTaggedValue()) + : SlowRuntimeStub::ToJSTaggedValueWithInt32(thread, leftValue.GetTaggedValue()); if (jleft.IsException()) { return JSTaggedValue::Exception(); } - jright = IS_U_RIGHT ? SlowRuntimeStub::ToJSTaggedValueWithUint32(thread, right_value.GetTaggedValue()) - : SlowRuntimeStub::ToJSTaggedValueWithInt32(thread, right_value.GetTaggedValue()); + jright = IS_U_RIGHT ? SlowRuntimeStub::ToJSTaggedValueWithUint32(thread, rightValue.GetTaggedValue()) + : SlowRuntimeStub::ToJSTaggedValueWithInt32(thread, rightValue.GetTaggedValue()); if (jright.IsException()) { return JSTaggedValue::Exception(); @@ -1350,13 +1345,13 @@ INLINE_ECMA_INTRINSICS uint64_t Ashr2Dyn(JSThread *thread, uint64_t lhs, uint64_ // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t RethrowDyn(JSThread *thread, uint64_t obj) { - JSTaggedValue obj_value(obj); + JSTaggedValue objValue(obj); if (JSTaggedValue(obj).IsHole()) { - return obj_value.GetRawData(); + return objValue.GetRawData(); } - SlowRuntimeStub::ThrowDyn(thread, obj_value); + SlowRuntimeStub::ThrowDyn(thread, objValue); return JSTaggedValue(JSTaggedValue::VALUE_EXCEPTION).GetRawData(); } @@ -1374,63 +1369,63 @@ INLINE_ECMA_INTRINSICS uint64_t Delobjprop(JSThread *thread, uint64_t obj, uint6 // define not constructor function // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t DefineNCFuncDyn(JSThread *thread, uint64_t method, uint64_t env, uint64_t home_objv, +INLINE_ECMA_INTRINSICS uint64_t DefineNCFuncDyn(JSThread *thread, uint64_t method, uint64_t env, uint64_t homeObjv, uint64_t cp) { - auto home_obj = JSTaggedValue(home_objv); + auto homeObj = JSTaggedValue(homeObjv); auto result = JSFunction::Cast(JSTaggedValue(method).GetHeapObject()); auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle home_obj_handle(thread, home_obj); - JSHandle lexenv_handle(thread, lexenv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle homeObjHandle(thread, homeObj); + JSHandle lexenvHandle(thread, lexenv); auto res = SlowRuntimeStub::DefineNCFuncDyn(thread, result->GetCallTarget()); if (res.IsException()) { return res.GetRawData(); } result = JSFunction::Cast(res.GetHeapObject()); - home_obj = home_obj_handle.GetTaggedValue(); // May be moved by GC - lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC + homeObj = homeObjHandle.GetTaggedValue(); // May be moved by GC + lexenv = lexenvHandle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(cp)); // ConstantPool is non-movable } result->SetLexicalEnv(thread, lexenv); - result->SetHomeObject(thread, home_obj); + result->SetHomeObject(thread, homeObj); return JSTaggedValue(result).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t LdLexVarDyn([[maybe_unused]] JSThread *thread, uint16_t level, uint16_t slot, - uint64_t lex_env) + uint64_t lexEnv) { - LexicalEnv *env = LexicalEnv::Cast(lex_env); + LexicalEnv *env = LexicalEnv::Cast(lexEnv); for (int i = 0; i < level; i++) { - JSTaggedValue tagged_parent_env = env->GetParentEnv(); - ASSERT(!tagged_parent_env.IsUndefined()); - env = LexicalEnv::Cast(tagged_parent_env.GetHeapObject()); + JSTaggedValue taggedParentEnv = env->GetParentEnv(); + ASSERT(!taggedParentEnv.IsUndefined()); + env = LexicalEnv::Cast(taggedParentEnv.GetHeapObject()); } return env->GetProperties(slot).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LdLexDyn([[maybe_unused]] JSThread *thread, uint64_t binding_name, uint16_t level, - uint16_t slot, uint64_t lex_env) +INLINE_ECMA_INTRINSICS uint64_t LdLexDyn([[maybe_unused]] JSThread *thread, uint64_t bindingName, uint16_t level, + uint16_t slot, uint64_t lexEnv) { - JSTaggedValue binding(LdLexVarDyn(level, slot, lex_env)); + JSTaggedValue binding(LdLexVarDyn(level, slot, lexEnv)); if (!binding.IsHole()) { return binding.GetRawData(); } - SlowRuntimeStub::ThrowTdz(GetJSThread(), JSTaggedValue(binding_name)); + SlowRuntimeStub::ThrowTdz(GetJSThread(), JSTaggedValue(bindingName)); return JSTaggedValue(JSTaggedValue::VALUE_EXCEPTION).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t PopLexenvDyn([[maybe_unused]] JSThread *thread, uint64_t lex_env) +INLINE_ECMA_INTRINSICS uint64_t PopLexenvDyn([[maybe_unused]] JSThread *thread, uint64_t lexEnv) { - return LexicalEnv::Cast(lex_env)->GetParentEnv().GetRawData(); + return LexicalEnv::Cast(lexEnv)->GetParentEnv().GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1480,15 +1475,15 @@ INLINE_ECMA_INTRINSICS uint64_t ReturnDyn([[maybe_unused]] JSThread *thread, [[m } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t NewlexenvDyn(JSThread *thread, uint16_t num_slots, uint64_t lex_env) +INLINE_ECMA_INTRINSICS uint64_t NewlexenvDyn(JSThread *thread, uint16_t numSlots, uint64_t lexEnv) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); auto factory = thread->GetEcmaVM()->GetFactory(); - JSHandle env(thread, LexicalEnv::Cast(lex_env)); + JSHandle env(thread, LexicalEnv::Cast(lexEnv)); - JSTaggedValue res = FastRuntimeStub::NewLexicalEnvDyn(thread, factory, num_slots); + JSTaggedValue res = FastRuntimeStub::NewLexicalEnvDyn(thread, factory, numSlots); if (res.IsHole()) { - res = SlowRuntimeStub::NewLexicalEnvDyn(thread, num_slots); + res = SlowRuntimeStub::NewLexicalEnvDyn(thread, numSlots); if (res.IsException()) { return res.GetRawData(); } @@ -1498,67 +1493,67 @@ INLINE_ECMA_INTRINSICS uint64_t NewlexenvDyn(JSThread *thread, uint16_t num_slot } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t CopylexenvDyn(JSThread *thread, uint64_t lex_env) +INLINE_ECMA_INTRINSICS uint64_t CopylexenvDyn(JSThread *thread, uint64_t lexEnv) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); auto factory = thread->GetEcmaVM()->GetFactory(); - JSHandle old_env(thread, LexicalEnv::Cast(lex_env)); - JSHandle parent_env(thread, old_env->GetParentEnv()); - ArraySizeT num_of_slots = old_env->GetLength(); + JSHandle oldEnv(thread, LexicalEnv::Cast(lexEnv)); + JSHandle parentEnv(thread, oldEnv->GetParentEnv()); + ArraySizeT numOfSlots = oldEnv->GetLength(); - JSTaggedValue res = FastRuntimeStub::NewLexicalEnvDyn(thread, factory, num_of_slots); + JSTaggedValue res = FastRuntimeStub::NewLexicalEnvDyn(thread, factory, numOfSlots); if (res.IsHole()) { - res = SlowRuntimeStub::NewLexicalEnvDyn(thread, num_of_slots); + res = SlowRuntimeStub::NewLexicalEnvDyn(thread, numOfSlots); if (res.IsException()) { return res.GetRawData(); } } - LexicalEnv::Cast(res.GetHeapObject())->SetParentEnv(thread, parent_env.GetTaggedValue()); + LexicalEnv::Cast(res.GetHeapObject())->SetParentEnv(thread, parentEnv.GetTaggedValue()); - for (ArraySizeT i = 0; i < num_of_slots; i++) { - LexicalEnv::Cast(res.GetHeapObject())->Set(thread, i, old_env->Get(i)); + for (ArraySizeT i = 0; i < numOfSlots; i++) { + LexicalEnv::Cast(res.GetHeapObject())->Set(thread, i, oldEnv->Get(i)); } return res.GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS void ThrowTdz(JSThread *thread, uint64_t prop_key) +INLINE_ECMA_INTRINSICS void ThrowTdz(JSThread *thread, uint64_t propKey) { - SlowRuntimeStub::ThrowTdz(thread, JSTaggedValue(prop_key)); + SlowRuntimeStub::ThrowTdz(thread, JSTaggedValue(propKey)); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS void StLexVarDyn(JSThread *thread, uint16_t level, uint16_t slot, uint64_t value, - uint64_t lex_env) + uint64_t lexEnv) { - JSTaggedValue current_lexenv(LexicalEnv::Cast(lex_env)); - JSTaggedValue env(current_lexenv); + JSTaggedValue currentLexenv(LexicalEnv::Cast(lexEnv)); + JSTaggedValue env(currentLexenv); for (int i = 0; i < level; i++) { - JSTaggedValue tagged_parent_env = LexicalEnv::Cast(env.GetHeapObject())->GetParentEnv(); - ASSERT(!tagged_parent_env.IsUndefined()); - env = tagged_parent_env; + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetHeapObject())->GetParentEnv(); + ASSERT(!taggedParentEnv.IsUndefined()); + env = taggedParentEnv; } LexicalEnv::Cast(env.GetHeapObject())->SetProperties(thread, slot, JSTaggedValue(value)); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t StLexDyn(JSThread *thread, uint64_t prop_key, uint16_t level, uint16_t slot, - uint64_t value, uint64_t lex_env) +INLINE_ECMA_INTRINSICS uint64_t StLexDyn(JSThread *thread, uint64_t propKey, uint16_t level, uint16_t slot, + uint64_t value, uint64_t lexEnv) { - JSTaggedValue current_lexenv(LexicalEnv::Cast(lex_env)); - JSTaggedValue env(current_lexenv); + JSTaggedValue currentLexenv(LexicalEnv::Cast(lexEnv)); + JSTaggedValue env(currentLexenv); for (int i = 0; i < level; i++) { - JSTaggedValue tagged_parent_env = LexicalEnv::Cast(env.GetHeapObject())->GetParentEnv(); - ASSERT(!tagged_parent_env.IsUndefined()); - env = tagged_parent_env; + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetHeapObject())->GetParentEnv(); + ASSERT(!taggedParentEnv.IsUndefined()); + env = taggedParentEnv; } LexicalEnv *lexenv = LexicalEnv::Cast(env.GetHeapObject()); if (lexenv->GetProperties(slot).IsHole()) { - ThrowTdz(thread, prop_key); + ThrowTdz(thread, propKey); return JSTaggedValue(JSTaggedValue::VALUE_EXCEPTION).GetRawData(); } @@ -1584,14 +1579,14 @@ INLINE_ECMA_INTRINSICS uint64_t DefineGeneratorFunc(JSThread *thread, uint64_t m auto *result = JSFunction::Cast(JSTaggedValue(method).GetHeapObject()); auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle lexenv_handle(thread, lexenv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle lexenvHandle(thread, lexenv); auto res = SlowRuntimeStub::DefineGeneratorFunc(thread, result->GetCallTarget()); // Can trigger GC if (res.IsException()) { return res.GetRawData(); } result = JSFunction::Cast(res.GetHeapObject()); - lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC + lexenv = lexenvHandle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(cp)); // ConstantPool is non-movable } result->SetLexicalEnv(thread, lexenv); @@ -1619,21 +1614,21 @@ INLINE_ECMA_INTRINSICS uint64_t GetResumeMode(uint64_t genobj) } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t CreateGeneratorObj(JSThread *thread, uint64_t gen_func) +INLINE_ECMA_INTRINSICS uint64_t CreateGeneratorObj(JSThread *thread, uint64_t genFunc) { - return SlowRuntimeStub::CreateGeneratorObj(thread, JSTaggedValue(gen_func)).GetRawData(); + return SlowRuntimeStub::CreateGeneratorObj(thread, JSTaggedValue(genFunc)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t SetGeneratorState(JSThread *thread, uint64_t gen_func, uint8_t state) +INLINE_ECMA_INTRINSICS uint64_t SetGeneratorState(JSThread *thread, uint64_t genFunc, uint8_t state) { - return SlowRuntimeStub::SetGeneratorState(thread, JSTaggedValue(gen_func), state).GetRawData(); + return SlowRuntimeStub::SetGeneratorState(thread, JSTaggedValue(genFunc), state).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t CreateAsyncGeneratorObj(JSThread *thread, uint64_t gen_func) +INLINE_ECMA_INTRINSICS uint64_t CreateAsyncGeneratorObj(JSThread *thread, uint64_t genFunc) { - return SlowRuntimeStub::CreateAsyncGeneratorObj(thread, JSTaggedValue(gen_func)).GetRawData(); + return SlowRuntimeStub::CreateAsyncGeneratorObj(thread, JSTaggedValue(genFunc)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1642,14 +1637,14 @@ INLINE_ECMA_INTRINSICS uint64_t DefineAsyncFunc(JSThread *thread, uint64_t metho auto *result = JSFunction::Cast(JSTaggedValue(method).GetHeapObject()); auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle lexenv_handle(thread, lexenv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle lexenvHandle(thread, lexenv); auto res = SlowRuntimeStub::DefineAsyncFunc(thread, result->GetCallTarget()); // Can trigger GC if (res.IsException()) { return res.GetRawData(); } result = JSFunction::Cast(res.GetHeapObject()); - lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC + lexenv = lexenvHandle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(cp)); // ConstantPool is non-movable } result->SetLexicalEnv(thread, lexenv); @@ -1662,14 +1657,14 @@ INLINE_ECMA_INTRINSICS uint64_t DefineAsyncGeneratorFunc(JSThread *thread, uint6 auto *result = JSFunction::Cast(JSTaggedValue(method).GetHeapObject()); auto lexenv = JSTaggedValue(env); if (!result->GetLexicalEnv().IsUndefined()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle lexenv_handle(thread, lexenv); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle lexenvHandle(thread, lexenv); auto res = SlowRuntimeStub::DefineAsyncGeneratorFunc(thread, result->GetCallTarget()); // Can trigger GC if (res.IsException()) { return res.GetRawData(); } result = JSFunction::Cast(res.GetHeapObject()); - lexenv = lexenv_handle.GetTaggedValue(); // May be moved by GC + lexenv = lexenvHandle.GetTaggedValue(); // May be moved by GC result->SetConstantPool(thread, JSTaggedValue(cp)); // ConstantPool is non-movable } result->SetLexicalEnv(thread, lexenv); @@ -1683,39 +1678,35 @@ INLINE_ECMA_INTRINSICS uint64_t AsyncFunctionEnter(JSThread *thread) } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t AsyncFunctionAwait(JSThread *thread, uint64_t async_fn_obj, uint64_t value) +INLINE_ECMA_INTRINSICS uint64_t AsyncFunctionAwait(JSThread *thread, uint64_t asyncFnObj, uint64_t value) { - return SlowRuntimeStub::AsyncFunctionAwait(thread, JSTaggedValue(async_fn_obj), JSTaggedValue(value)).GetRawData(); + return SlowRuntimeStub::AsyncFunctionAwait(thread, JSTaggedValue(asyncFnObj), JSTaggedValue(value)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t AsyncFunctionResolve(JSThread *thread, uint64_t async_fn_obj, uint64_t value) +INLINE_ECMA_INTRINSICS uint64_t AsyncFunctionResolve(JSThread *thread, uint64_t asyncFnObj, uint64_t value) { - return SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, JSTaggedValue(async_fn_obj), JSTaggedValue(value), - true) + return SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, JSTaggedValue(asyncFnObj), JSTaggedValue(value), true) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t AsyncFunctionReject(JSThread *thread, uint64_t async_fn_obj, uint64_t value) +INLINE_ECMA_INTRINSICS uint64_t AsyncFunctionReject(JSThread *thread, uint64_t asyncFnObj, uint64_t value) { - return SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, JSTaggedValue(async_fn_obj), JSTaggedValue(value), - false) + return SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, JSTaggedValue(asyncFnObj), JSTaggedValue(value), false) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t AsyncGeneratorResolve(JSThread *thread, uint64_t async_fn_obj, uint64_t value) +INLINE_ECMA_INTRINSICS uint64_t AsyncGeneratorResolve(JSThread *thread, uint64_t asyncFnObj, uint64_t value) { - return SlowRuntimeStub::AsyncGeneratorResolve(thread, JSTaggedValue(async_fn_obj), JSTaggedValue(value)) - .GetRawData(); + return SlowRuntimeStub::AsyncGeneratorResolve(thread, JSTaggedValue(asyncFnObj), JSTaggedValue(value)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t AsyncGeneratorReject(JSThread *thread, uint64_t async_fn_obj, uint64_t value) +INLINE_ECMA_INTRINSICS uint64_t AsyncGeneratorReject(JSThread *thread, uint64_t asyncFnObj, uint64_t value) { - return SlowRuntimeStub::AsyncGeneratorReject(thread, JSTaggedValue(async_fn_obj), JSTaggedValue(value)) - .GetRawData(); + return SlowRuntimeStub::AsyncGeneratorReject(thread, JSTaggedValue(asyncFnObj), JSTaggedValue(value)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1725,9 +1716,9 @@ INLINE_ECMA_INTRINSICS void ThrowConstAssignment(JSThread *thread, uint64_t name } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t GetMethod(JSThread *thread, uint64_t prop_key, uint64_t object) +INLINE_ECMA_INTRINSICS uint64_t GetMethod(JSThread *thread, uint64_t propKey, uint64_t object) { - return SlowRuntimeStub::GetMethod(thread, JSTaggedValue(object), JSTaggedValue(prop_key)).GetRawData(); + return SlowRuntimeStub::GetMethod(thread, JSTaggedValue(object), JSTaggedValue(propKey)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1746,8 +1737,8 @@ INLINE_ECMA_INTRINSICS uint64_t GetNextPropName(JSThread *thread, uint64_t iter) INLINE_ECMA_INTRINSICS uint64_t CreateEmptyObject(JSThread *thread) { auto factory = thread->GetEcmaVM()->GetFactory(); - auto global_env = thread->GetEcmaVM()->GetGlobalEnv(); - return SlowRuntimeStub::CreateEmptyObject(thread, factory, global_env).GetRawData(); + auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + return SlowRuntimeStub::CreateEmptyObject(thread, factory, globalEnv).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1782,9 +1773,9 @@ INLINE_ECMA_INTRINSICS uint64_t DefineGetterSetterByValue(JSThread *thread, uint INLINE_ECMA_INTRINSICS uint64_t CreateEmptyArray(JSThread *thread) { auto factory = thread->GetEcmaVM()->GetFactory(); - auto global_env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); - return SlowRuntimeStub::CreateEmptyArray(thread, factory, global_env).GetRawData(); + return SlowRuntimeStub::CreateEmptyArray(thread, factory, globalEnv).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1839,7 +1830,7 @@ INLINE_ECMA_INTRINSICS uint64_t StOwnByName(JSThread *thread, uint64_t prop, uin // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StOwnByValue(JSThread *thread, uint64_t rec, uint64_t pkey, uint64_t val) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle receiver(thread, JSTaggedValue(rec)); JSHandle prop(thread, JSTaggedValue(pkey)); @@ -1894,11 +1885,11 @@ INLINE_ECMA_INTRINSICS void ThrowThrowNotExists(JSThread *thread) } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t CreateObjectWithExcludedKeys(JSThread *thread, uint16_t num_keys, uint64_t obj_value, - uint64_t excluded_keys) +INLINE_ECMA_INTRINSICS uint64_t CreateObjectWithExcludedKeys(JSThread *thread, uint16_t numKeys, uint64_t objValue, + uint64_t excludedKeys) { - return SlowRuntimeStub::CreateObjectWithExcludedKeys(thread, num_keys, JSTaggedValue(obj_value), - reinterpret_cast(excluded_keys)) + return SlowRuntimeStub::CreateObjectWithExcludedKeys(thread, numKeys, JSTaggedValue(objValue), + reinterpret_cast(excludedKeys)) .GetRawData(); } @@ -1911,10 +1902,10 @@ INLINE_ECMA_INTRINSICS void ThrowPatternNonCoercible(JSThread *thread) // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t CloseIterator(JSThread *thread, uint64_t iter, uint64_t completion) { - JSTaggedValue completion_value(completion); + JSTaggedValue completionValue(completion); - if (!completion_value.IsHole()) { - SlowRuntimeStub::ThrowDyn(thread, completion_value); + if (!completionValue.IsHole()) { + SlowRuntimeStub::ThrowDyn(thread, completionValue); } return SlowRuntimeStub::CloseIterator(thread, JSTaggedValue(iter)).GetRawData(); @@ -1939,9 +1930,9 @@ INLINE_ECMA_INTRINSICS void CopyModule(JSThread *thread, uint64_t module) } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LdModvarByName(JSThread *thread, uint64_t item_name, uint64_t module_obj) +INLINE_ECMA_INTRINSICS uint64_t LdModvarByName(JSThread *thread, uint64_t itemName, uint64_t moduleObj) { - return SlowRuntimeStub::LdModvarByName(thread, JSTaggedValue(module_obj), JSTaggedValue(item_name)).GetRawData(); + return SlowRuntimeStub::LdModvarByName(thread, JSTaggedValue(moduleObj), JSTaggedValue(itemName)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1952,12 +1943,12 @@ INLINE_ECMA_INTRINSICS uint64_t ClassFieldAdd(JSThread *thread, uint64_t ctor, u } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS void DefineClassPrivateFields(JSThread *thread, uint64_t private_buf, uint64_t env, - uint64_t ctor, uint64_t cp) +INLINE_ECMA_INTRINSICS void DefineClassPrivateFields(JSThread *thread, uint64_t privateBuf, uint64_t env, uint64_t ctor, + uint64_t cp) { auto *constpool = ConstantPool::Cast(cp); SlowRuntimeStub::DefineClassPrivateFields(thread, constpool, JSTaggedValue(env), JSTaggedValue(ctor), - JSTaggedValue(private_buf)); + JSTaggedValue(privateBuf)); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -2003,20 +1994,20 @@ INLINE_ECMA_INTRINSICS uint64_t ClassPrivateFieldIn(JSThread *thread, uint64_t p INLINE_ECMA_INTRINSICS uint64_t DefineClassWithBuffer(JSThread *thread, uint64_t ctor, uint16_t imm, uint64_t lexenv, uint64_t proto, uint64_t cp) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); auto *constpool = ConstantPool::Cast(cp); - JSHandle lex_env(thread, JSTaggedValue(lexenv)); - JSFunction *class_template = JSFunction::Cast(JSTaggedValue(ctor).GetTaggedObject()); - ASSERT(class_template != nullptr); + JSHandle lexEnv(thread, JSTaggedValue(lexenv)); + JSFunction *classTemplate = JSFunction::Cast(JSTaggedValue(ctor).GetTaggedObject()); + ASSERT(classTemplate != nullptr); - TaggedArray *literal_buffer = TaggedArray::Cast(constpool->GetObjectFromCache(imm).GetTaggedObject()); + TaggedArray *literalBuffer = TaggedArray::Cast(constpool->GetObjectFromCache(imm).GetTaggedObject()); // TaggedArray *literal_buffer = TaggedArray::Cast(JSTaggedValue(buffer).GetTaggedObject()); JSTaggedValue res; - if (LIKELY(!class_template->IsResolved())) { - res = SlowRuntimeStub::ResolveClass(thread, JSTaggedValue(class_template), literal_buffer, JSTaggedValue(proto), + if (LIKELY(!classTemplate->IsResolved())) { + res = SlowRuntimeStub::ResolveClass(thread, JSTaggedValue(classTemplate), literalBuffer, JSTaggedValue(proto), JSTaggedValue(lexenv), constpool); } else { - res = SlowRuntimeStub::CloneClassFromTemplate(thread, JSTaggedValue(class_template), JSTaggedValue(proto), + res = SlowRuntimeStub::CloneClassFromTemplate(thread, JSTaggedValue(classTemplate), JSTaggedValue(proto), JSTaggedValue(lexenv), constpool); } @@ -2026,70 +2017,69 @@ INLINE_ECMA_INTRINSICS uint64_t DefineClassWithBuffer(JSThread *thread, uint64_t ASSERT(res.IsClassConstructor()); JSFunction *cls = JSFunction::Cast(res.GetTaggedObject()); - cls->SetLexicalEnv(thread, lex_env.GetTaggedValue()); + cls->SetLexicalEnv(thread, lexEnv.GetTaggedValue()); SlowRuntimeStub::SetClassConstructorLength(thread, res, cls->GetMethod()->GetLength()); return res.GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS void SetClassComputedFields(JSThread *thread, uint64_t class_reg, uint64_t computed_fields) +INLINE_ECMA_INTRINSICS void SetClassComputedFields(JSThread *thread, uint64_t classReg, uint64_t computedFields) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle cls(thread, JSTaggedValue(class_reg)); - JSHandle computed_fields_handle(thread, JSTaggedValue(computed_fields)); - cls->SetComputedFields(thread, computed_fields_handle); + JSHandle cls(thread, JSTaggedValue(classReg)); + JSHandle computedFieldsHandle(thread, JSTaggedValue(computedFields)); + cls->SetComputedFields(thread, computedFieldsHandle); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LoadClassComputedInstanceFields(JSThread *thread, uint64_t class_reg) +INLINE_ECMA_INTRINSICS uint64_t LoadClassComputedInstanceFields(JSThread *thread, uint64_t classReg) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle cls(thread, JSTaggedValue(class_reg)); - JSTaggedValue computed_instance_fields = cls->GetComputedFields(); - ASSERT(computed_instance_fields.IsJSArray()); + JSHandle cls(thread, JSTaggedValue(classReg)); + JSTaggedValue computedInstanceFields = cls->GetComputedFields(); + ASSERT(computedInstanceFields.IsJSArray()); cls->SetComputedFields(thread, JSTaggedValue::Hole()); - return computed_instance_fields.GetRawData(); + return computedInstanceFields.GetRawData(); } // Just declared here, not used // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t SuperCall(JSThread *thread, uint16_t range, uint64_t args, uint64_t new_target, - uint64_t obj_value) +INLINE_ECMA_INTRINSICS uint64_t SuperCall(JSThread *thread, uint16_t range, uint64_t args, uint64_t newTarget, + uint64_t objValue) { - return SlowRuntimeStub::SuperCall(thread, JSTaggedValue(obj_value), JSTaggedValue(new_target), range, + return SlowRuntimeStub::SuperCall(thread, JSTaggedValue(objValue), JSTaggedValue(newTarget), range, reinterpret_cast(args)) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t SuperCallSpread(JSThread *thread, uint64_t array, uint64_t new_target, - uint64_t this_func) +INLINE_ECMA_INTRINSICS uint64_t SuperCallSpread(JSThread *thread, uint64_t array, uint64_t newTarget, uint64_t thisFunc) { - return SlowRuntimeStub::SuperCallSpread(thread, JSTaggedValue(this_func), JSTaggedValue(new_target), + return SlowRuntimeStub::SuperCallSpread(thread, JSTaggedValue(thisFunc), JSTaggedValue(newTarget), JSTaggedValue(array)) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t DefineMethod(JSThread *thread, uint64_t method, uint64_t tagged_cur_env, - uint64_t home_object, uint64_t cp) +INLINE_ECMA_INTRINSICS uint64_t DefineMethod(JSThread *thread, uint64_t method, uint64_t taggedCurEnv, + uint64_t homeObject, uint64_t cp) { auto result = JSFunction::Cast(JSTaggedValue(method).GetHeapObject()); - auto home = JSTaggedValue(home_object); - auto env = JSTaggedValue(tagged_cur_env); + auto home = JSTaggedValue(homeObject); + auto env = JSTaggedValue(taggedCurEnv); if (!result->GetLexicalEnv().IsUndefined()) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle home_handle(thread, home); - JSHandle env_handle(thread, env); - auto res = SlowRuntimeStub::DefineMethod(thread, result->GetCallTarget(), home_handle); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle homeHandle(thread, home); + JSHandle envHandle(thread, env); + auto res = SlowRuntimeStub::DefineMethod(thread, result->GetCallTarget(), homeHandle); if (res.IsException()) { return res.GetRawData(); } result = JSFunction::Cast(res.GetHeapObject()); - env = env_handle.GetTaggedValue(); // Maybe moved by GC + env = envHandle.GetTaggedValue(); // Maybe moved by GC result->SetConstantPool(thread, JSTaggedValue(cp)); // ConstantPool is non-movable } else { result->SetHomeObject(thread, home); @@ -2099,35 +2089,34 @@ INLINE_ECMA_INTRINSICS uint64_t DefineMethod(JSThread *thread, uint64_t method, } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t StSuperByName(JSThread *thread, uint64_t prop_key, uint64_t obj, uint64_t value, +INLINE_ECMA_INTRINSICS uint64_t StSuperByName(JSThread *thread, uint64_t propKey, uint64_t obj, uint64_t value, uint64_t func) { - return SlowRuntimeStub::StSuperByValue(thread, JSTaggedValue(obj), JSTaggedValue(prop_key), JSTaggedValue(value), + return SlowRuntimeStub::StSuperByValue(thread, JSTaggedValue(obj), JSTaggedValue(propKey), JSTaggedValue(value), JSTaggedValue(func)) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LdSuperByName(JSThread *thread, uint64_t prop_key, uint64_t obj, uint64_t func) +INLINE_ECMA_INTRINSICS uint64_t LdSuperByName(JSThread *thread, uint64_t propKey, uint64_t obj, uint64_t func) { - return SlowRuntimeStub::LdSuperByValue(thread, JSTaggedValue(obj), JSTaggedValue(prop_key), JSTaggedValue(func)) + return SlowRuntimeStub::LdSuperByValue(thread, JSTaggedValue(obj), JSTaggedValue(propKey), JSTaggedValue(func)) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t StSuperByValue(JSThread *thread, uint64_t receiver, uint64_t prop_key, uint64_t value, +INLINE_ECMA_INTRINSICS uint64_t StSuperByValue(JSThread *thread, uint64_t receiver, uint64_t propKey, uint64_t value, uint64_t func) { - return SlowRuntimeStub::StSuperByValue(thread, JSTaggedValue(receiver), JSTaggedValue(prop_key), + return SlowRuntimeStub::StSuperByValue(thread, JSTaggedValue(receiver), JSTaggedValue(propKey), JSTaggedValue(value), JSTaggedValue(func)) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LdSuperByValue(JSThread *thread, uint64_t receiver, uint64_t prop_key, uint64_t func) +INLINE_ECMA_INTRINSICS uint64_t LdSuperByValue(JSThread *thread, uint64_t receiver, uint64_t propKey, uint64_t func) { - return SlowRuntimeStub::LdSuperByValue(thread, JSTaggedValue(receiver), JSTaggedValue(prop_key), - JSTaggedValue(func)) + return SlowRuntimeStub::LdSuperByValue(thread, JSTaggedValue(receiver), JSTaggedValue(propKey), JSTaggedValue(func)) .GetRawData(); } @@ -2144,9 +2133,9 @@ INLINE_ECMA_INTRINSICS uint64_t CreateObjectHavingMethod(JSThread *thread, uint6 // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, - [[maybe_unused]] uint64_t this_value) + [[maybe_unused]] uint64_t thisValue) { - return SlowRuntimeStub::ThrowIfSuperNotCorrectCall(thread, index, JSTaggedValue(this_value)).GetRawData(); + return SlowRuntimeStub::ThrowIfSuperNotCorrectCall(thread, index, JSTaggedValue(thisValue)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -2168,21 +2157,21 @@ INLINE_ECMA_INTRINSICS uint64_t LdEvalBindings([[maybe_unused]] JSThread *thread } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t DirectEval(JSThread *thread, uint32_t status, uint64_t arg0, uint64_t eval_bindings) +INLINE_ECMA_INTRINSICS uint64_t DirectEval(JSThread *thread, uint32_t status, uint64_t arg0, uint64_t evalBindings) { - return EvalUtils::DirectEval(thread, status, JSTaggedValue(arg0), JSTaggedValue(eval_bindings)).GetRawData(); + return EvalUtils::DirectEval(thread, status, JSTaggedValue(arg0), JSTaggedValue(evalBindings)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t LdEvalVar(JSThread *thread, uint64_t name, uint64_t lexical_context) +INLINE_ECMA_INTRINSICS uint64_t LdEvalVar(JSThread *thread, uint64_t name, uint64_t lexicalContext) { - return SlowRuntimeStub::LdEvalVar(thread, JSTaggedValue(name), JSTaggedValue(lexical_context)).GetRawData(); + return SlowRuntimeStub::LdEvalVar(thread, JSTaggedValue(name), JSTaggedValue(lexicalContext)).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t StEvalVar(JSThread *thread, uint64_t name, uint64_t value, uint64_t lexical_context) +INLINE_ECMA_INTRINSICS uint64_t StEvalVar(JSThread *thread, uint64_t name, uint64_t value, uint64_t lexicalContext) { - return SlowRuntimeStub::StEvalVar(thread, JSTaggedValue(name), JSTaggedValue(lexical_context), JSTaggedValue(value)) + return SlowRuntimeStub::StEvalVar(thread, JSTaggedValue(name), JSTaggedValue(lexicalContext), JSTaggedValue(value)) .GetRawData(); } @@ -2233,8 +2222,8 @@ INLINE_ECMA_INTRINSICS uint8_t DynClassIsExtensible([[maybe_unused]] uint64_t ob // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t DynObjectGetClass(uint64_t obj) { - JSTaggedValue tagged_value(obj); - return JSTaggedValue(tagged_value.GetTaggedObject()->GetClass()).GetRawData(); + JSTaggedValue taggedValue(obj); + return JSTaggedValue(taggedValue.GetTaggedObject()->GetClass()).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -2260,14 +2249,14 @@ INLINE_ECMA_INTRINSICS uint32_t DynClassGetHash(uint64_t obj) // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t LdObjDynByName([[maybe_unused]] uint64_t obj, [[maybe_unused]] uint64_t key, - [[maybe_unused]] uint16_t ic_slot) + [[maybe_unused]] uint16_t icSlot) { return JSTaggedValue::Hole().GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StObjDynByName([[maybe_unused]] uint64_t obj, [[maybe_unused]] uint64_t key, - [[maybe_unused]] uint64_t value, [[maybe_unused]] uint16_t ic_slot) + [[maybe_unused]] uint64_t value, [[maybe_unused]] uint16_t icSlot) { return JSTaggedValue::Hole().GetRawData(); } diff --git a/runtime/jobs/micro_job_queue.cpp b/runtime/jobs/micro_job_queue.cpp index 537d606ac6a65c4be30dfdc4a02b62b5ec4d235e..16cf67a604f7ef3963849bdcb30b2afbc22285a3 100644 --- a/runtime/jobs/micro_job_queue.cpp +++ b/runtime/jobs/micro_job_queue.cpp @@ -27,7 +27,7 @@ #include "utils/expected.h" namespace panda::ecmascript::job { -void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle job_queue, QueueType queue_type, +void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle jobQueue, QueueType queueType, const JSHandle &job, const JSHandle &argv) { // 1. Assert: Type(queueName) is String and its value is the name of a Job Queue recognized by this implementation. @@ -36,41 +36,41 @@ void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle job_que // 4. Let callerContext be the running execution context. // 5. Let callerRealm be callerContext’s Realm. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle pending_job(factory->NewPendingJob(job, argv)); - if (queue_type == QueueType::QUEUE_PROMISE) { - JSHandle promise_queue(thread, job_queue->GetPromiseJobQueue()); - LOG_ECMA(DEBUG) << "promiseQueue start length: " << promise_queue->Size(); - TaggedQueue *new_promise_queue = TaggedQueue::Push(thread, promise_queue, JSHandle(pending_job)); - job_queue->SetPromiseJobQueue(thread, JSTaggedValue(new_promise_queue)); - LOG_ECMA(DEBUG) << "promiseQueue end length: " << new_promise_queue->Size(); - } else if (queue_type == QueueType::QUEUE_SCRIPT) { - JSHandle script_queue(thread, job_queue->GetScriptJobQueue()); - TaggedQueue *new_script_queue = TaggedQueue::Push(thread, script_queue, JSHandle(pending_job)); - job_queue->SetScriptJobQueue(thread, JSTaggedValue(new_script_queue)); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle pendingJob(factory->NewPendingJob(job, argv)); + if (queueType == QueueType::QUEUE_PROMISE) { + JSHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue()); + LOG_ECMA(DEBUG) << "promiseQueue start length: " << promiseQueue->Size(); + TaggedQueue *newPromiseQueue = TaggedQueue::Push(thread, promiseQueue, JSHandle(pendingJob)); + jobQueue->SetPromiseJobQueue(thread, JSTaggedValue(newPromiseQueue)); + LOG_ECMA(DEBUG) << "promiseQueue end length: " << newPromiseQueue->Size(); + } else if (queueType == QueueType::QUEUE_SCRIPT) { + JSHandle scriptQueue(thread, jobQueue->GetScriptJobQueue()); + TaggedQueue *newScriptQueue = TaggedQueue::Push(thread, scriptQueue, JSHandle(pendingJob)); + jobQueue->SetScriptJobQueue(thread, JSTaggedValue(newScriptQueue)); } } -void MicroJobQueue::ExecutePendingJob(JSThread *thread, JSHandle job_queue) +void MicroJobQueue::ExecutePendingJob(JSThread *thread, JSHandle jobQueue) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSMutableHandle promise_queue(thread, job_queue->GetPromiseJobQueue()); - JSMutableHandle pending_job(thread, JSTaggedValue::Undefined()); - while (!promise_queue->Empty()) { - LOG_ECMA(DEBUG) << "promiseQueue start length: " << promise_queue->Size(); - pending_job.Update(promise_queue->Pop(thread)); - LOG_ECMA(DEBUG) << "promiseQueue end length: " << promise_queue->Size(); - PendingJob::ExecutePendingJob(pending_job, thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSMutableHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue()); + JSMutableHandle pendingJob(thread, JSTaggedValue::Undefined()); + while (!promiseQueue->Empty()) { + LOG_ECMA(DEBUG) << "promiseQueue start length: " << promiseQueue->Size(); + pendingJob.Update(promiseQueue->Pop(thread)); + LOG_ECMA(DEBUG) << "promiseQueue end length: " << promiseQueue->Size(); + PendingJob::ExecutePendingJob(pendingJob, thread); if (UNLIKELY(thread->HasPendingException())) { return; } - promise_queue.Update(job_queue->GetPromiseJobQueue()); + promiseQueue.Update(jobQueue->GetPromiseJobQueue()); } - JSHandle script_queue(thread, job_queue->GetScriptJobQueue()); - while (!script_queue->Empty()) { - pending_job.Update(script_queue->Pop(thread)); - PendingJob::ExecutePendingJob(pending_job, thread); + JSHandle scriptQueue(thread, jobQueue->GetScriptJobQueue()); + while (!scriptQueue->Empty()) { + pendingJob.Update(scriptQueue->Pop(thread)); + PendingJob::ExecutePendingJob(pendingJob, thread); if (UNLIKELY(thread->HasPendingException())) { return; } diff --git a/runtime/jobs/micro_job_queue.h b/runtime/jobs/micro_job_queue.h index 9ee2c61ed798f2e89ebdcd9d792383789c1875b1..fa6454256e1cfe1161c31d47d832626da7353f8a 100644 --- a/runtime/jobs/micro_job_queue.h +++ b/runtime/jobs/micro_job_queue.h @@ -39,9 +39,9 @@ public: return static_cast(object); } - static void EnqueueJob(JSThread *thread, JSHandle job_queue, QueueType queue_type, + static void EnqueueJob(JSThread *thread, JSHandle jobQueue, QueueType queueType, const JSHandle &job, const JSHandle &argv); - static void ExecutePendingJob(JSThread *thread, JSHandle job_queue); + static void ExecutePendingJob(JSThread *thread, JSHandle jobQueue); ACCESSORS_BASE(Record) ACCESSORS(0, PromiseJobQueue) diff --git a/runtime/jobs/pending_job.h b/runtime/jobs/pending_job.h index a6b0c296a4b047d224008c27abab6c4536366671..125b434b778343022580ca9831e2db3b6c48b301 100644 --- a/runtime/jobs/pending_job.h +++ b/runtime/jobs/pending_job.h @@ -33,13 +33,13 @@ public: return static_cast(object); } - static JSTaggedValue ExecutePendingJob(const JSHandle &pending_job, JSThread *thread) + static JSTaggedValue ExecutePendingJob(const JSHandle &pendingJob, JSThread *thread) { - JSHandle job(thread, pending_job->GetJob()); + JSHandle job(thread, pendingJob->GetJob()); ASSERT(job->IsCallable()); - JSHandle this_value(thread, JSTaggedValue::Undefined()); - JSHandle argv(thread, pending_job->GetArguments()); - auto info = NewRuntimeCallInfo(thread, job, this_value, JSTaggedValue::Undefined(), argv->GetLength()); + JSHandle thisValue(thread, JSTaggedValue::Undefined()); + JSHandle argv(thread, pendingJob->GetArguments()); + auto info = NewRuntimeCallInfo(thread, job, thisValue, JSTaggedValue::Undefined(), argv->GetLength()); info->SetCallArg(argv->GetLength(), argv->GetData()); return JSFunction::Call(info.Get()); } diff --git a/runtime/js_arguments.cpp b/runtime/js_arguments.cpp index 4e9bb28a27e3bb7b87f87ee6a7fa375ee6480567..5f2cf4490bb014fd3e40fbc73d41f9e3b55e51a1 100644 --- a/runtime/js_arguments.cpp +++ b/runtime/js_arguments.cpp @@ -34,14 +34,14 @@ bool JSArguments::GetOwnProperty(JSThread *thread, const JSHandle & JSHandle map(thread, args->GetParameterMap()); // 5.Let isMapped be HasOwnProperty(map, P). - bool is_mapped = JSTaggedValue::HasOwnProperty(thread, map, key); + bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); // 6.Assert: isMapped is never an abrupt completion. ASSERT(!thread->HasPendingException()); // 7.If the value of isMapped is true, then // a.Set desc.[[Value]] to Get(map, P). - if (is_mapped) { + if (isMapped) { auto prop = JSObject::GetProperty(thread, map, key).GetValue(); desc.SetValue(prop); } @@ -64,7 +64,7 @@ bool JSArguments::DefineOwnProperty(JSThread *thread, const JSHandle map(thread, args->GetParameterMap()); // 3.Let isMapped be HasOwnProperty(map, P). - bool is_mapped = JSTaggedValue::HasOwnProperty(thread, map, key); + bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); // 4.Let allowed be OrdinaryDefineOwnProperty(args, P, Desc). bool allowed = JSObject::OrdinaryDefineOwnProperty(thread, JSHandle(args), key, desc); @@ -86,13 +86,13 @@ bool JSArguments::DefineOwnProperty(JSThread *thread, const JSHandle map(thread, args->GetParameterMap()); // 3.Let isMapped be HasOwnProperty(map, P). - bool is_mapped = JSTaggedValue::HasOwnProperty(thread, map, key); + bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); // 4.Assert: isMapped is not an abrupt completion. ASSERT(!thread->HasPendingException()); @@ -119,7 +119,7 @@ OperationResult JSArguments::GetProperty(JSThread *thread, const JSHandle::Cast(args), key, receiver); } @@ -136,22 +136,22 @@ bool JSArguments::SetProperty(JSThread *thread, const JSHandle &arg // 2.If SameValue(args, Receiver) is false, then // a.Let isMapped be false. - bool is_mapped = false; + bool isMapped = false; if (JSTaggedValue::SameValue(args.GetTaggedValue(), receiver.GetTaggedValue())) { // 3.Else, // a.Let map be the value of the [[ParameterMap]] internal slot of the arguments object. // b.Let isMapped be HasOwnProperty(map, P). // c.Assert: isMapped is not an abrupt completion. - is_mapped = JSTaggedValue::HasOwnProperty(thread, map, key); + isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); ASSERT(!thread->HasPendingException()); } // 4.If isMapped is true, then // a.Let setStatus be Set(map, P, V, false). // b.Assert: setStatus is true because formal parameters mapped by argument objects are always writable. - if (is_mapped) { - [[maybe_unused]] bool set_status = JSTaggedValue::SetProperty(thread, map, key, value); - ASSERT(set_status); + if (isMapped) { + [[maybe_unused]] bool setStatus = JSTaggedValue::SetProperty(thread, map, key, value); + ASSERT(setStatus); } // 5.Return the result of calling the default ordinary object [[Set]] internal method (9.1.9) @@ -166,7 +166,7 @@ bool JSArguments::DeleteProperty(JSThread *thread, const JSHandle & JSHandle map(thread, args->GetParameterMap()); // 2.Let isMapped be HasOwnProperty(map, P). - bool is_mapped = JSTaggedValue::HasOwnProperty(thread, map, key); + bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); // 3.Assert: isMapped is not an abrupt completion. ASSERT(!thread->HasPendingException()); @@ -180,7 +180,7 @@ bool JSArguments::DeleteProperty(JSThread *thread, const JSHandle & // 6.If result is true and the value of isMapped is true, then // a.Call map.[[Delete]](P). - if (result && is_mapped) { + if (result && isMapped) { JSTaggedValue::DeleteProperty(thread, map, key); } diff --git a/runtime/js_array.cpp b/runtime/js_array.cpp index 174ddcac0c78d0ad075e4332a0ee4178c83ec4fa..177f013d6011b2691b6275d5b82bcd96603c25b5 100644 --- a/runtime/js_array.cpp +++ b/runtime/js_array.cpp @@ -30,105 +30,104 @@ JSTaggedValue JSArray::LengthGetter([[maybe_unused]] JSThread *thread, const JSH } bool JSArray::LengthSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, - bool may_throw) + bool mayThrow) { - uint32_t new_len = 0; - if (!JSTaggedValue::ToArrayLength(thread, value, &new_len) && may_throw) { + uint32_t newLen = 0; + if (!JSTaggedValue::ToArrayLength(thread, value, &newLen) && mayThrow) { THROW_RANGE_ERROR_AND_RETURN(thread, "array length must less than 2^32 - 1", false); } if (!IsArrayLengthWritable(thread, self)) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot assign to read only property", false); } return false; } - uint32_t old_len = JSArray::Cast(*self)->GetArrayLength(); - JSArray::SetCapacity(thread, self, old_len, new_len); + uint32_t oldLen = JSArray::Cast(*self)->GetArrayLength(); + JSArray::SetCapacity(thread, self, oldLen, newLen); return true; } -JSHandle JSArray::ArrayCreate(JSThread *thread, JSTaggedNumber length, panda::SpaceType space_type) +JSHandle JSArray::ArrayCreate(JSThread *thread, JSTaggedNumber length, panda::SpaceType spaceType) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle array_function = env->GetArrayFunction(); - return JSArray::ArrayCreate(thread, length, array_function, space_type); + JSHandle arrayFunction = env->GetArrayFunction(); + return JSArray::ArrayCreate(thread, length, arrayFunction, spaceType); } // 9.4.2.2 ArrayCreate(length, proto) JSHandle JSArray::ArrayCreate(JSThread *thread, JSTaggedNumber length, - const JSHandle &new_target, panda::SpaceType space_type) + const JSHandle &newTarget, panda::SpaceType spaceType) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Assert: length is an integer Number ≥ 0. ASSERT_PRINT(length.IsInteger() && length.GetNumber() >= 0, "length must be positive integer"); // 2. If length is −0, let length be +0. - double array_length = JSTaggedValue::ToInteger(thread, JSHandle(thread, length)).GetDouble(); - if (array_length > MAX_ARRAY_INDEX) { + double arrayLength = JSTaggedValue::ToInteger(thread, JSHandle(thread, length)).GetDouble(); + if (arrayLength > MAX_ARRAY_INDEX) { JSHandle exception(thread, JSTaggedValue::Exception()); THROW_RANGE_ERROR_AND_RETURN(thread, "array length must less than 2^32 - 1", exception); } - uint32_t normal_array_length = length.ToUint32(); + uint32_t normalArrayLength = length.ToUint32(); // 8. Set the [[Prototype]] internal slot of A to proto. JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle array_func = env->GetArrayFunction(); - JSHandle obj = - factory->NewJSObjectByConstructor(JSHandle(array_func), new_target, space_type); + JSHandle arrayFunc = env->GetArrayFunction(); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(arrayFunc), newTarget, spaceType); // 9. Set the [[Extensible]] internal slot of A to true. obj->GetJSHClass()->SetExtensible(true); // 10. Perform OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor{[[Value]]: length, [[Writable]]: // true, [[Enumerable]]: false, [[Configurable]]: false}). - JSArray::Cast(*obj)->SetArrayLength(thread, normal_array_length); + JSArray::Cast(*obj)->SetArrayLength(thread, normalArrayLength); return JSHandle(obj); } // 9.4.2.3 ArraySpeciesCreate(original_array, length) -JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle &original_array, +JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle &originalArray, JSTaggedNumber length) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // Assert: length is an integer Number ≥ 0. ASSERT_PRINT(length.IsInteger() && length.GetNumber() >= 0, "length must be positive integer"); // If length is −0, let length be +0. - double array_length = JSTaggedValue::ToInteger(thread, JSHandle(thread, length)).GetDouble(); - if (array_length == -0) { - array_length = +0; + double arrayLength = JSTaggedValue::ToInteger(thread, JSHandle(thread, length)).GetDouble(); + if (arrayLength == -0) { + arrayLength = +0; } // Let C be undefined. // Let is_array be IsArray(original_array). - JSHandle original_value(original_array); - bool is_array = original_value->IsArray(thread); + JSHandle originalValue(originalArray); + bool isArray = originalValue->IsArray(thread); // ReturnIfAbrupt(is_array). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If is_array is true, then JSHandle constructor(thread, JSTaggedValue::Undefined()); - if (is_array) { + if (isArray) { // Let C be Get(original_array, "constructor"). - auto *hclass = original_array->GetJSHClass(); + auto *hclass = originalArray->GetJSHClass(); if (hclass->IsJSArray() && !hclass->HasConstructor()) { return JSArray::ArrayCreate(thread, length).GetTaggedValue(); } - JSHandle constructor_key = global_const->GetHandledConstructorString(); - constructor = JSTaggedValue::GetProperty(thread, original_value, constructor_key).GetValue(); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + constructor = JSTaggedValue::GetProperty(thread, originalValue, constructorKey).GetValue(); // ReturnIfAbrupt(C). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If IsConstructor(C) is true, then if (constructor->IsConstructor()) { // Let thisRealm be the running execution context’s Realm. // Let realmC be GetFunctionRealm(C). - JSHandle realm_c = JSObject::GetFunctionRealm(thread, constructor); + JSHandle realmC = JSObject::GetFunctionRealm(thread, constructor); // ReturnIfAbrupt(realmC). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If thisRealm and realmC are not the same Realm Record, then - if (*realm_c != *env) { - JSTaggedValue realm_array_constructor = realm_c->GetArrayFunction().GetTaggedValue(); + if (*realmC != *env) { + JSTaggedValue realmArrayConstructor = realmC->GetArrayFunction().GetTaggedValue(); // If SameValue(C, realmC.[[intrinsics]].[[%Array%]]) is true, let C be undefined. - if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), realm_array_constructor)) { + if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), realmArrayConstructor)) { return JSArray::ArrayCreate(thread, length).GetTaggedValue(); } } @@ -137,8 +136,8 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandleIsECMAObject()) { // Let C be Get(C, @@species). - JSHandle species_symbol = env->GetSpeciesSymbol(); - constructor = JSTaggedValue::GetProperty(thread, constructor, species_symbol).GetValue(); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + constructor = JSTaggedValue::GetProperty(thread, constructor, speciesSymbol).GetValue(); // ReturnIfAbrupt(C). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If C is null, let C be undefined. @@ -157,10 +156,10 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle new_target(thread, JSTaggedValue::Undefined()); + JSHandle newTarget(thread, JSTaggedValue::Undefined()); - auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), new_target, 1); - info->SetCallArgs(JSTaggedValue(array_length)); + auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), newTarget, 1); + info->SetCallArgs(JSTaggedValue(arrayLength)); JSTaggedValue result = JSFunction::Construct(info.Get()); // NOTEIf original_array was created using the standard built-in Array constructor for @@ -171,103 +170,103 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle &array, uint32_t old_len, uint32_t new_len) +void JSArray::SetCapacity(JSThread *thread, const JSHandle &array, uint32_t oldLen, uint32_t newLen) { TaggedArray *element = TaggedArray::Cast(array->GetElements().GetTaggedObject()); if (element->IsDictionaryMode()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - int32_t num_of_elements = array->GetNumberOfElements(); - uint32_t new_num_of_elements = new_len; - if (new_len < old_len && num_of_elements != 0) { - JSHandle dict_handle(thread, element); - JSHandle new_arr = factory->NewTaggedArray(num_of_elements); - GetAllElementKeys(thread, array, 0, new_arr); - for (uint32_t i = num_of_elements - 1; i >= new_len; i--) { - JSTaggedValue value = new_arr->Get(i); + int32_t numOfElements = array->GetNumberOfElements(); + uint32_t newNumOfElements = newLen; + if (newLen < oldLen && numOfElements != 0) { + JSHandle dictHandle(thread, element); + JSHandle newArr = factory->NewTaggedArray(numOfElements); + GetAllElementKeys(thread, array, 0, newArr); + for (uint32_t i = numOfElements - 1; i >= newLen; i--) { + JSTaggedValue value = newArr->Get(i); uint32_t output = 0; JSTaggedValue::StringToElementIndex(value, &output); JSTaggedValue key(static_cast(output)); - int entry = dict_handle->FindEntry(key); - uint32_t attr = dict_handle->GetAttributes(entry).GetValue(); - PropertyAttributes prop_attr(attr); - if (prop_attr.IsConfigurable()) { - JSHandle new_dict = NumberDictionary::Remove(thread, dict_handle, entry); - array->SetElements(thread, new_dict); + int entry = dictHandle->FindEntry(key); + uint32_t attr = dictHandle->GetAttributes(entry).GetValue(); + PropertyAttributes propAttr(attr); + if (propAttr.IsConfigurable()) { + JSHandle newDict = NumberDictionary::Remove(thread, dictHandle, entry); + array->SetElements(thread, newDict); if (i == 0) { - new_num_of_elements = i; + newNumOfElements = i; break; } } else { - new_num_of_elements = i + 1; + newNumOfElements = i + 1; break; } } } - JSArray::Cast(*array)->SetArrayLength(thread, new_num_of_elements); + JSArray::Cast(*array)->SetArrayLength(thread, newNumOfElements); return; } uint32_t capacity = element->GetLength(); - if (new_len <= capacity) { + if (newLen <= capacity) { // judge if need to cut down the array size, else fill the unused tail with holes - array->FillElementsWithHoles(thread, new_len, old_len < capacity ? old_len : capacity); + array->FillElementsWithHoles(thread, newLen, oldLen < capacity ? oldLen : capacity); } - if (JSObject::ShouldTransToDict(old_len, new_len)) { + if (JSObject::ShouldTransToDict(oldLen, newLen)) { JSObject::ElementsToDictionary(thread, array); - } else if (new_len > capacity) { - JSObject::GrowElementsCapacity(thread, array, new_len); + } else if (newLen > capacity) { + JSObject::GrowElementsCapacity(thread, array, newLen); } - JSArray::Cast(*array)->SetArrayLength(thread, new_len); + JSArray::Cast(*array)->SetArrayLength(thread, newLen); } bool JSArray::ArraySetLength(JSThread *thread, const JSHandle &array, const PropertyDescriptor &desc) { - JSHandle length_key_handle(thread->GlobalConstants()->GetHandledLengthString()); + JSHandle lengthKeyHandle(thread->GlobalConstants()->GetHandledLengthString()); // 1. If the [[Value]] field of Desc is absent, then if (!desc.HasValue()) { // 1a. Return OrdinaryDefineOwnProperty(A, "length", Desc). - return JSObject::OrdinaryDefineOwnProperty(thread, array, length_key_handle, desc); + return JSObject::OrdinaryDefineOwnProperty(thread, array, lengthKeyHandle, desc); } // 2. Let new_len_desc be a copy of Desc. // (Actual copying is not necessary.) - PropertyDescriptor new_len_desc = desc; + PropertyDescriptor newLenDesc = desc; // 3. - 7. Convert Desc.[[Value]] to new_len. - uint32_t new_len = 0; - if (!JSTaggedValue::ToArrayLength(thread, desc.GetValue(), &new_len)) { + uint32_t newLen = 0; + if (!JSTaggedValue::ToArrayLength(thread, desc.GetValue(), &newLen)) { THROW_RANGE_ERROR_AND_RETURN(thread, "array length must less than 2^32 - 1", false); } // 8. Set new_len_desc.[[Value]] to new_len. // (Done below, if needed.) // 9. Let old_len_desc be OrdinaryGetOwnProperty(A, "length"). - PropertyDescriptor old_len_desc(thread); - [[maybe_unused]] bool success = GetOwnProperty(thread, array, length_key_handle, old_len_desc); + PropertyDescriptor oldLenDesc(thread); + [[maybe_unused]] bool success = GetOwnProperty(thread, array, lengthKeyHandle, oldLenDesc); // 10. (Assert) ASSERT(success); // 11. Let old_len be old_len_desc.[[Value]]. - uint32_t old_len = 0; - JSTaggedValue::ToArrayLength(thread, old_len_desc.GetValue(), &old_len); + uint32_t oldLen = 0; + JSTaggedValue::ToArrayLength(thread, oldLenDesc.GetValue(), &oldLen); // 12. If new_len >= old_len, then - if (new_len >= old_len) { + if (newLen >= oldLen) { // 8. Set new_len_desc.[[Value]] to new_len. // 12a. Return OrdinaryDefineOwnProperty(A, "length", new_len_desc). - new_len_desc.SetValue(JSHandle(thread, JSTaggedValue(new_len))); - return JSObject::OrdinaryDefineOwnProperty(thread, array, length_key_handle, new_len_desc); + newLenDesc.SetValue(JSHandle(thread, JSTaggedValue(newLen))); + return JSObject::OrdinaryDefineOwnProperty(thread, array, lengthKeyHandle, newLenDesc); } // 13. If old_len_desc.[[Writable]] is false, return false. - if (!old_len_desc.IsWritable() || + if (!oldLenDesc.IsWritable() || // Also handle the {configurable: true} case since we later use // JSArray::SetLength instead of OrdinaryDefineOwnProperty to change // the length, and it doesn't have access to the descriptor anymore. - new_len_desc.IsConfigurable()) { + newLenDesc.IsConfigurable()) { return false; } // 14. If new_len_desc.[[Writable]] is absent or has the value true, // let new_writable be true. - bool new_writable = false; - if (!new_len_desc.HasWritable() || new_len_desc.IsWritable()) { - new_writable = true; + bool newWritable = false; + if (!newLenDesc.HasWritable() || newLenDesc.IsWritable()) { + newWritable = true; } // 15. Else, // 15a. Need to defer setting the [[Writable]] attribute to false in case @@ -277,18 +276,18 @@ bool JSArray::ArraySetLength(JSThread *thread, const JSHandle &array, // (Not needed.) // Most of steps 16 through 19 is implemented by JSArray::SetCapacity. - JSArray::SetCapacity(thread, array, old_len, new_len); + JSArray::SetCapacity(thread, array, oldLen, newLen); // Steps 19d-ii, 20. - if (!new_writable) { + if (!newWritable) { PropertyDescriptor readonly(thread); readonly.SetWritable(false); - success = JSObject::DefineOwnProperty(thread, array, length_key_handle, readonly); + success = JSObject::DefineOwnProperty(thread, array, lengthKeyHandle, readonly); ASSERT_PRINT(success, "DefineOwnProperty of length must be success here!"); } // Steps 19d-v, 21. Return false if there were non-deletable elements. - uint32_t array_length = JSArray::Cast(*array)->GetArrayLength(); - return array_length == new_len; + uint32_t arrayLength = JSArray::Cast(*array)->GetArrayLength(); + return arrayLength == newLen; } bool JSArray::PropertyKeyToArrayIndex(JSThread *thread, const JSHandle &key, uint32_t *output) @@ -312,8 +311,8 @@ bool JSArray::DefineOwnProperty(JSThread *thread, const JSHandle &arra // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). bool success = JSObject::OrdinaryDefineOwnProperty(thread, array, key, desc); if (success) { - JSTaggedValue constructor_key = thread->GlobalConstants()->GetConstructorString(); - if (key.GetTaggedValue() == constructor_key) { + JSTaggedValue constructorKey = thread->GlobalConstants()->GetConstructorString(); + if (key.GetTaggedValue() == constructorKey) { array->GetJSHClass()->SetHasConstructor(true); return true; } @@ -342,8 +341,8 @@ JSHandle JSArray::CreateArrayFromList(JSThread *thread, const JSHandle< // 4. For each element e of elements auto env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle array_func = env->GetArrayFunction(); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(array_func), array_func); + JSHandle arrayFunc = env->GetArrayFunction(); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(arrayFunc), arrayFunc); obj->GetJSHClass()->SetExtensible(true); JSArray::Cast(*obj)->SetArrayLength(thread, length); diff --git a/runtime/js_array.h b/runtime/js_array.h index 80f651fa0927e7e431bdb009d6d0e419e92ecd66..f8921f498b7518fcb3114fc533fdbcaa00ea247d 100644 --- a/runtime/js_array.h +++ b/runtime/js_array.h @@ -31,11 +31,11 @@ public: CAST_CHECK(JSArray, IsJSArray); PANDA_PUBLIC_API static JSHandle ArrayCreate( - JSThread *thread, JSTaggedNumber length, panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); + JSThread *thread, JSTaggedNumber length, panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); static JSHandle ArrayCreate(JSThread *thread, JSTaggedNumber length, - const JSHandle &new_target, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); - static JSTaggedValue ArraySpeciesCreate(JSThread *thread, const JSHandle &original_array, + const JSHandle &newTarget, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); + static JSTaggedValue ArraySpeciesCreate(JSThread *thread, const JSHandle &originalArray, JSTaggedNumber length); static bool ArraySetLength(JSThread *thread, const JSHandle &array, const PropertyDescriptor &desc); PANDA_PUBLIC_API static bool DefineOwnProperty(JSThread *thread, const JSHandle &array, @@ -82,7 +82,7 @@ public: static JSTaggedValue LengthGetter(JSThread *thread, const JSHandle &self); static bool LengthSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, - bool may_throw = false); + bool mayThrow = false); static JSHandle FastGetPropertyByValue(JSThread *thread, const JSHandle &obj, uint32_t index); @@ -97,7 +97,7 @@ public: const JSHandle &key, const JSHandle &value); private: - static void SetCapacity(JSThread *thread, const JSHandle &array, uint32_t old_len, uint32_t new_len); + static void SetCapacity(JSThread *thread, const JSHandle &array, uint32_t oldLen, uint32_t newLen); }; } // namespace panda::ecmascript diff --git a/runtime/js_array_iterator.cpp b/runtime/js_array_iterator.cpp index 2979db48bc067538429c2e21eb11413057e3becf..e69e75e9a2353c942b25f7aded89ffa9814cdfcd 100644 --- a/runtime/js_array_iterator.cpp +++ b/runtime/js_array_iterator.cpp @@ -26,7 +26,7 @@ JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let O be the this value. JSHandle input(builtins_common::GetThis(argv)); @@ -39,15 +39,15 @@ JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle iter(input); // 4.Let a be O.[[IteratedArrayLike]]. JSHandle array(thread, iter->GetIteratedArray()); - JSHandle undefined_handle(thread, JSTaggedValue::Undefined()); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); // 5.If a is undefined, return CreateIterResultObject(undefined, true). if (array->IsUndefined()) { - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } // 6.Let index be O.[[ArrayLikeNextIndex]]. uint32_t index = iter->GetNextIndex().GetInt(); // 7.Let itemKind be O.[[ArrayLikeIterationKind]]. - IterationKind item_kind = IterationKind(iter->GetIterationKind().GetInt()); + IterationKind itemKind = IterationKind(iter->GetIterationKind().GetInt()); uint32_t length; // 8. If a has a [[TypedArrayName]] internal slot, then @@ -56,12 +56,12 @@ JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) length = base::TypedArrayHelper::GetArrayLength(thread, JSHandle(array)); } else { // 9.Else - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle tagged_len = JSTaggedValue::GetProperty(thread, array, length_key).GetValue(); - if (UNLIKELY(!tagged_len->IsNumber())) { - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle taggedLen = JSTaggedValue::GetProperty(thread, array, lengthKey).GetValue(); + if (UNLIKELY(!taggedLen->IsNumber())) { + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } - length = tagged_len->GetArrayLength(); + length = taggedLen->GetArrayLength(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -69,30 +69,30 @@ JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) if (index >= length) { // Set O.[[IteratedArrayLike]] to undefined. // Return CreateIterResultObject(undefined, true). - iter->SetIteratedArray(thread, undefined_handle); - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + iter->SetIteratedArray(thread, undefinedHandle); + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } // 11.Set O.[[ArrayLikeNextIndex]] to index + 1. iter->SetNextIndex(thread, JSTaggedValue(index + 1)); // 12.If itemKind is key, return CreateIterResultObject(index, false). JSHandle key(thread, JSTaggedValue(index)); - if (item_kind == IterationKind::KEY) { + if (itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); } - JSHandle s_key(JSTaggedValue::ToString(thread, key)); - JSHandle value = JSTaggedValue::GetProperty(thread, array, s_key).GetValue(); + JSHandle sKey(JSTaggedValue::ToString(thread, key)); + JSHandle value = JSTaggedValue::GetProperty(thread, array, sKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 15.If itemKind is value, let result be elementValue. - if (item_kind == IterationKind::VALUE) { + if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } // 16. Else - ASSERT_PRINT(item_kind == IterationKind::KEY_AND_VALUE, "itemKind is invalid"); + ASSERT_PRINT(itemKind == IterationKind::KEY_AND_VALUE, "itemKind is invalid"); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle result_array(factory->NewTaggedArray(2)); // 2 means the length of array - result_array->Set(thread, 0, key); - result_array->Set(thread, 1, value); - JSHandle key_and_value(JSArray::CreateArrayFromList(thread, result_array)); - return JSIterator::CreateIterResultObject(thread, key_and_value, false).GetTaggedValue(); + JSHandle resultArray(factory->NewTaggedArray(2)); // 2 means the length of array + resultArray->Set(thread, 0, key); + resultArray->Set(thread, 1, value); + JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, resultArray)); + return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue(); } } // namespace panda::ecmascript diff --git a/runtime/js_arraybuffer.cpp b/runtime/js_arraybuffer.cpp index ea98b7ad7d57b8511e39c7b19783abbe385519cc..dab755daaa63ff14e388455c290adf8db2360471 100644 --- a/runtime/js_arraybuffer.cpp +++ b/runtime/js_arraybuffer.cpp @@ -23,41 +23,40 @@ #include "securec.h" namespace panda::ecmascript { -void JSArrayBuffer::CopyDataBlockBytes(JSTaggedValue to_block, JSTaggedValue from_block, int32_t from_index, - int32_t count) +void JSArrayBuffer::CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue fromBlock, int32_t fromIndex, int32_t count) { - void *from_buf = JSNativePointer::Cast(from_block.GetTaggedObject())->GetExternalPointer(); - void *to_buf = JSNativePointer::Cast(to_block.GetTaggedObject())->GetExternalPointer(); - auto *from = static_cast(from_buf); - auto *to = static_cast(to_buf); - if (memcpy_s(to, count, from + from_index, count) != EOK) { // NOLINT + void *fromBuf = JSNativePointer::Cast(fromBlock.GetTaggedObject())->GetExternalPointer(); + void *toBuf = JSNativePointer::Cast(toBlock.GetTaggedObject())->GetExternalPointer(); + auto *from = static_cast(fromBuf); + auto *to = static_cast(toBuf); + if (memcpy_s(to, count, from + fromIndex, count) != EOK) { // NOLINT LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } -void JSArrayBuffer::Attach(JSThread *thread, JSTaggedValue array_buffer_byte_length, JSTaggedValue array_buffer_data) +void JSArrayBuffer::Attach(JSThread *thread, JSTaggedValue arrayBufferByteLength, JSTaggedValue arrayBufferData) { - ASSERT(array_buffer_data.IsNativePointer()); - SetArrayBufferByteLength(thread, array_buffer_byte_length); - SetArrayBufferData(thread, array_buffer_data); + ASSERT(arrayBufferData.IsNativePointer()); + SetArrayBufferByteLength(thread, arrayBufferByteLength); + SetArrayBufferData(thread, arrayBufferData); EcmaVM *vm = thread->GetEcmaVM(); - vm->PushToArrayDataList(JSNativePointer::Cast(array_buffer_data.GetHeapObject())); + vm->PushToArrayDataList(JSNativePointer::Cast(arrayBufferData.GetHeapObject())); } void JSArrayBuffer::Detach(JSThread *thread) { - JSTaggedValue array_buffer_data = GetArrayBufferData(); + JSTaggedValue arrayBufferData = GetArrayBufferData(); // already detached. - if (array_buffer_data.IsNull()) { + if (arrayBufferData.IsNull()) { return; } EcmaVM *vm = thread->GetEcmaVM(); // remove vm's control over arrayBufferData. - JSNativePointer *js_native_pointer = JSNativePointer::Cast(array_buffer_data.GetHeapObject()); - vm->RemoveArrayDataList(js_native_pointer); - js_native_pointer->Destroy(); + JSNativePointer *jsNativePointer = JSNativePointer::Cast(arrayBufferData.GetHeapObject()); + vm->RemoveArrayDataList(jsNativePointer); + jsNativePointer->Destroy(); SetArrayBufferData(thread, JSTaggedValue::Null()); SetArrayBufferByteLength(thread, JSTaggedValue(0)); diff --git a/runtime/js_arraybuffer.h b/runtime/js_arraybuffer.h index 58f5420f31dcb1595116f34094a772d10ccbdf67..c9854c5b65f745491c9d316993ec53d003ff0d31 100644 --- a/runtime/js_arraybuffer.h +++ b/runtime/js_arraybuffer.h @@ -24,15 +24,15 @@ public: CAST_NO_CHECK(JSArrayBuffer); // 6.2.6.2 - static void CopyDataBlockBytes(JSTaggedValue to_block, JSTaggedValue from_block, int32_t from_index, int32_t count); + static void CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue fromBlock, int32_t fromIndex, int32_t count); - void Attach(JSThread *thread, JSTaggedValue array_buffer_byte_length, JSTaggedValue array_buffer_data); + void Attach(JSThread *thread, JSTaggedValue arrayBufferByteLength, JSTaggedValue arrayBufferData); void Detach(JSThread *thread); bool IsDetach() { - JSTaggedValue array_buffer_data = GetArrayBufferData(); - return array_buffer_data == JSTaggedValue::Null(); + JSTaggedValue arrayBufferData = GetArrayBufferData(); + return arrayBufferData == JSTaggedValue::Null(); } ACCESSORS_BASE(JSObject) diff --git a/runtime/js_arraylist.cpp b/runtime/js_arraylist.cpp index 8e5c993e1cacc28f09d343d0fac039609bcf28f7..001dd2449af18f6e520878a2959042579268c50d 100644 --- a/runtime/js_arraylist.cpp +++ b/runtime/js_arraylist.cpp @@ -19,31 +19,31 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript { -void JSArrayList::Add(JSThread *thread, const JSHandle &array_list, const JSHandle &value) +void JSArrayList::Add(JSThread *thread, const JSHandle &arrayList, const JSHandle &value) { // GrowCapacity - uint32_t length = array_list->GetLength().GetArrayLength(); - JSHandle elements = GrowCapacity(thread, array_list, length + 1); + uint32_t length = arrayList->GetLength().GetArrayLength(); + JSHandle elements = GrowCapacity(thread, arrayList, length + 1); ASSERT(!elements->IsDictionaryMode()); elements->Set(thread, length, value); - array_list->SetLength(thread, JSTaggedValue(++length)); + arrayList->SetLength(thread, JSTaggedValue(++length)); } JSHandle JSArrayList::GrowCapacity(const JSThread *thread, const JSHandle &obj, uint32_t capacity) { - JSHandle old_elements(thread, obj->GetElements()); - uint32_t old_length = old_elements->GetLength(); - if (capacity < old_length) { - return old_elements; + JSHandle oldElements(thread, obj->GetElements()); + uint32_t oldLength = oldElements->GetLength(); + if (capacity < oldLength) { + return oldElements; } - uint32_t new_capacity = ComputeCapacity(capacity); - JSHandle new_elements = - thread->GetEcmaVM()->GetFactory()->CopyArray(old_elements, old_length, new_capacity); + uint32_t newCapacity = ComputeCapacity(capacity); + JSHandle newElements = + thread->GetEcmaVM()->GetFactory()->CopyArray(oldElements, oldLength, newCapacity); - obj->SetElements(thread, new_elements); - return new_elements; + obj->SetElements(thread, newElements); + return newElements; } JSTaggedValue JSArrayList::Get(JSThread *thread, const uint32_t index) diff --git a/runtime/js_arraylist.h b/runtime/js_arraylist.h index e501bd0dd73eb14c9aeffb8ae02ad04a53095b83..ade3c418157e255125167e04d2db3736fafa2706 100644 --- a/runtime/js_arraylist.h +++ b/runtime/js_arraylist.h @@ -28,7 +28,7 @@ public: return static_cast(object); } - static void Add(JSThread *thread, const JSHandle &array_list, const JSHandle &value); + static void Add(JSThread *thread, const JSHandle &arrayList, const JSHandle &value); JSTaggedValue Get(JSThread *thread, uint32_t index); @@ -51,10 +51,10 @@ public: DECL_DUMP() private: - inline static uint32_t ComputeCapacity(uint32_t old_capacity) + inline static uint32_t ComputeCapacity(uint32_t oldCapacity) { - uint32_t new_capacity = old_capacity + (old_capacity >> 1U); - return new_capacity > DEFAULT_CAPACITY_LENGTH ? new_capacity : DEFAULT_CAPACITY_LENGTH; + uint32_t newCapacity = oldCapacity + (oldCapacity >> 1U); + return newCapacity > DEFAULT_CAPACITY_LENGTH ? newCapacity : DEFAULT_CAPACITY_LENGTH; } static JSHandle GrowCapacity(const JSThread *thread, const JSHandle &obj, uint32_t capacity); diff --git a/runtime/js_async_from_sync_iterator_object.cpp b/runtime/js_async_from_sync_iterator_object.cpp index 78a2346323976396cb41486c4c409cdbbc575db0..8df51c68a12e0d8e169ee1694e6d5c4a29120004 100644 --- a/runtime/js_async_from_sync_iterator_object.cpp +++ b/runtime/js_async_from_sync_iterator_object.cpp @@ -16,7 +16,7 @@ JSTaggedValue JSAsyncFromSyncIteratorValueUnwrapFunction::AsyncFromSyncIteratorV EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let F be the active function object. JSHandle func(builtins_common::GetConstructor(argv)); @@ -28,29 +28,29 @@ JSTaggedValue JSAsyncFromSyncIteratorValueUnwrapFunction::AsyncFromSyncIteratorV JSTaggedValue JSAsyncFromSyncIteratorObject::CreateAsyncFromSyncIterator(JSThread *thread, const JSHandle &iterator, - const JSHandle &next_method) + const JSHandle &nextMethod) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let asyncIterator be ! OrdinaryObjectCreate(%AsyncFromSyncIteratorPrototype%, « [[SyncIteratorRecord]] »). - JSHandle async_iterator = factory->NewJSAsyncFromSyncIteratorObject(); + JSHandle asyncIterator = factory->NewJSAsyncFromSyncIteratorObject(); // 2. Set asyncIterator.[[SyncIteratorRecord]] to syncIteratorRecord. - async_iterator->SetIterator(thread, iterator); - async_iterator->SetNextMethod(thread, next_method); + asyncIterator->SetIterator(thread, iterator); + asyncIterator->SetNextMethod(thread, nextMethod); // 3. Let nextMethod be ! Get(asyncIterator, "next"). // 4. Let iteratorRecord be the Record { [[Iterator]]: asyncIterator, [[NextMethod]]: nextMethod, [[Done]]: false }. // 5. Return iteratorRecord. - return async_iterator.GetTaggedValue(); + return asyncIterator.GetTaggedValue(); } JSTaggedValue JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation( - JSThread *thread, const JSHandle &result, const JSHandle &promise_capability) + JSThread *thread, const JSHandle &result, const JSHandle &promiseCapability) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -59,38 +59,38 @@ JSTaggedValue JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation( JSHandle done(thread, JSTaggedValue(JSIterator::IteratorComplete(thread, result))); // 2. IfAbruptRejectPromise(done, promiseCapability). - RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, done, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, done, promiseCapability); // 3. Let value be IteratorValue(result). JSHandle value = JSIterator::IteratorValue(thread, result); // 4. IfAbruptRejectPromise(value, promiseCapability). - RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, value, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, value, promiseCapability); // 5. Let valueWrapper be PromiseResolve(%Promise%, value). - JSHandle value_wrapper( + JSHandle valueWrapper( thread, JSPromise::PromiseResolve(thread, JSHandle::Cast(env->GetPromiseFunction()), value)); // 6. IfAbruptRejectPromise(valueWrapper, promiseCapability). - RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, value_wrapper, promise_capability); + RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, valueWrapper, promiseCapability); // 7. 7. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions. // 8. Let length be the number of non-optional parameters of the function definition in Async-from-Sync Iterator // Value Unwrap Functions. // 9. Let onFulfilled be ! CreateBuiltinFunction(steps, length, "", « [[Done]] »). - JSHandle on_fulfilled = + JSHandle onFulfilled = factory->NewJSAsyncFromSyncIteratorValueUnwrapFunction(reinterpret_cast( JSAsyncFromSyncIteratorValueUnwrapFunction::AsyncFromSyncIteratorValueUnwrapFunction)); // 10. Set onFulfilled.[[Done]] to done. - on_fulfilled->SetDone(thread, done.GetTaggedValue()); + onFulfilled->SetDone(thread, done.GetTaggedValue()); // 11. Perform ! PerformPromiseThen(valueWrapper, onFulfilled, undefined, promiseCapability). - [[maybe_unused]] JSTaggedValue then_result = builtins::promise::PerformPromiseThen( - thread, JSHandle::Cast(value_wrapper), JSHandle::Cast(on_fulfilled), - thread->GlobalConstants()->GetHandledUndefined(), JSHandle::Cast(promise_capability)); + [[maybe_unused]] JSTaggedValue thenResult = builtins::promise::PerformPromiseThen( + thread, JSHandle::Cast(valueWrapper), JSHandle::Cast(onFulfilled), + thread->GlobalConstants()->GetHandledUndefined(), JSHandle::Cast(promiseCapability)); // 12. Return promiseCapability.[[Promise]]. - return promise_capability->GetPromise(); + return promiseCapability->GetPromise(); } } // namespace panda::ecmascript diff --git a/runtime/js_async_from_sync_iterator_object.h b/runtime/js_async_from_sync_iterator_object.h index 348b1e5ae88e4db6a843e92f3fb5921662214251..1fa6b4c5f2b0b4bcc09840d0101993f32f1b100d 100644 --- a/runtime/js_async_from_sync_iterator_object.h +++ b/runtime/js_async_from_sync_iterator_object.h @@ -31,11 +31,11 @@ public: // 27.1.4.1 CreateAsyncFromSyncIterator ( syncIteratorRecord ) static JSTaggedValue CreateAsyncFromSyncIterator(JSThread *thread, const JSHandle &iterator, - const JSHandle &next_method); + const JSHandle &nextMethod); // 27.1.4.4 AsyncFromSyncIteratorContinuation ( result, promiseCapability ) static JSTaggedValue AsyncFromSyncIteratorContinuation(JSThread *thread, const JSHandle &result, - const JSHandle &promise_capability); + const JSHandle &promiseCapability); ACCESSORS_BASE(JSObject) ACCESSORS(0, Iterator) diff --git a/runtime/js_async_function.cpp b/runtime/js_async_function.cpp index f46d17e01d3e732c1e834aaf069692e7851f04f0..6193da6e2b05f6244ccfd3ba7384b22c6018c8c4 100644 --- a/runtime/js_async_function.cpp +++ b/runtime/js_async_function.cpp @@ -26,33 +26,33 @@ namespace panda::ecmascript { -JSTaggedValue JSAsyncFuncObject::AsyncFunctionAwait(JSThread *thread, const JSHandle &async_func_obj, +JSTaggedValue JSAsyncFuncObject::AsyncFunctionAwait(JSThread *thread, const JSHandle &asyncFuncObj, const JSHandle &value) { // 1.Let asyncContext be the running execution context. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle async_ctxt(thread, async_func_obj->GetGeneratorContext()); + JSHandle asyncCtxt(thread, asyncFuncObj->GetGeneratorContext()); // 2. Let promise be ? PromiseResolve(%Promise%, value). - JSTaggedValue promise_val = + JSTaggedValue promiseVal = JSPromise::PromiseResolve(thread, JSHandle::Cast(env->GetPromiseFunction()), value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle promise(thread, JSPromise::Cast(promise_val.GetHeapObject())); + JSHandle promise(thread, JSPromise::Cast(promiseVal.GetHeapObject())); // 4.Let onFulfilled be a new built-in function object as defined in AsyncFunction Awaited Fulfilled. - JSHandle ful_func = factory->NewJSAsyncAwaitStatusFunction( + JSHandle fulFunc = factory->NewJSAsyncAwaitStatusFunction( reinterpret_cast(builtins::promise_handler::AsyncAwaitFulfilled)); // 5.Let onRejected be a new built-in function object as defined in AsyncFunction Awaited Rejected. - JSHandle rej_func = + JSHandle rejFunc = factory->NewJSAsyncAwaitStatusFunction(reinterpret_cast(builtins::promise_handler::AsyncAwaitRejected)); // 6.Set onFulfilled.[[AsyncContext]] to asyncContext. // 7.Set onRejected.[[AsyncContext]] to asyncContext. - ful_func->SetAsyncContext(thread, async_ctxt); - rej_func->SetAsyncContext(thread, async_ctxt); + fulFunc->SetAsyncContext(thread, asyncCtxt); + rejFunc->SetAsyncContext(thread, asyncCtxt); // 8.Let throwawayCapability be ! NewPromiseCapability(%Promise%). // 9.Set throwawayCapability.[[Promise]].[[PromiseIsHandled]] to true. @@ -62,7 +62,7 @@ JSTaggedValue JSAsyncFuncObject::AsyncFunctionAwait(JSThread *thread, const JSHa // 10.Perform ! PerformPromiseThen(promiseCapability.[[Promise]], onFulfilled, onRejected, throwawayCapability). [[maybe_unused]] JSTaggedValue pres = builtins::promise::PerformPromiseThen( - thread, promise, JSHandle::Cast(ful_func), JSHandle::Cast(rej_func), + thread, promise, JSHandle::Cast(fulFunc), JSHandle::Cast(rejFunc), JSHandle::Cast(tcap)); // 11.Remove asyncContext from the execution context stack and restore the execution context that @@ -79,7 +79,7 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitFulfilled( JSThread *thread, const JSHandle &func, const JSHandle &value) { // 1.Let asyncContext be F.[[AsyncContext]]. - JSHandle async_ctxt(thread, func->GetAsyncContext()); + JSHandle asyncCtxt(thread, func->GetAsyncContext()); // 2.Let prevContext be the running execution context. // 3.Suspend prevContext. @@ -87,7 +87,7 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitFulfilled( // 5.Resume the suspended evaluation of asyncContext using NormalCompletion(value) as the result of the // operation that suspended it. Let result be the value returned by the resumed computation. JSHandle result = - GeneratorHelper::Continue(thread, async_ctxt, GeneratorResumeMode::NEXT, value.GetTaggedValue()); + GeneratorHelper::Continue(thread, asyncCtxt, GeneratorResumeMode::NEXT, value.GetTaggedValue()); // 6.Assert: When we reach this step, asyncContext has already been removed from the execution context stack // and prevContext is the currently running execution context. @@ -99,7 +99,7 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitRejected( JSThread *thread, const JSHandle &func, const JSHandle &reason) { // 1.Let asyncContext be F.[[AsyncContext]]. - JSHandle async_ctxt(thread, func->GetAsyncContext()); + JSHandle asyncCtxt(thread, func->GetAsyncContext()); // 2.Let prevContext be the running execution context. // 3.Suspend prevContext. @@ -108,7 +108,7 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitRejected( // [[Value]]: reason, [[Target]]: empty} as the result of the operation that suspended it. // Let result be the value returned by the resumed computation. JSHandle result = - GeneratorHelper::Continue(thread, async_ctxt, GeneratorResumeMode::THROW, reason.GetTaggedValue()); + GeneratorHelper::Continue(thread, asyncCtxt, GeneratorResumeMode::THROW, reason.GetTaggedValue()); // 6.Assert: When we reach this step, asyncContext has already been removed from the execution context stack // and prevContext is the currently running execution context. diff --git a/runtime/js_async_function.h b/runtime/js_async_function.h index d33e14294069ed2eb59a234cec05bf206fd5c9f5..52f80942b4f17892ed5b11e2bfd1df2e1a7daa3a 100644 --- a/runtime/js_async_function.h +++ b/runtime/js_async_function.h @@ -44,7 +44,7 @@ class JSAsyncFuncObject : public JSGeneratorObject { public: CAST_CHECK(JSAsyncFuncObject, IsAsyncFuncObject); - static JSTaggedValue AsyncFunctionAwait(JSThread *thread, const JSHandle &async_func_obj, + static JSTaggedValue AsyncFunctionAwait(JSThread *thread, const JSHandle &asyncFuncObj, const JSHandle &value); ACCESSORS_BASE(JSGeneratorObject) diff --git a/runtime/js_async_generator_object.cpp b/runtime/js_async_generator_object.cpp index 14cf2d74721c4d99cebccddfc868d884ebfc900a..864bc848aecb9da3df8d81539eda4e9d7c8e38ff 100644 --- a/runtime/js_async_generator_object.cpp +++ b/runtime/js_async_generator_object.cpp @@ -16,18 +16,18 @@ enum class AsyncGeneratorRequest : panda::ArraySizeT { COMPLETION, PROMISE_CAPAB JSTaggedValue JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextFulfilled(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let F be the active function object. - JSHandle this_func(builtins_common::GetConstructor(argv)); - JSHandle async_gen_object(thread, this_func->GetAsyncGenerator()); + JSHandle thisFunc(builtins_common::GetConstructor(argv)); + JSHandle asyncGenObject(thread, thisFunc->GetAsyncGenerator()); // 2. Set F.[[Generator]].[[AsyncGeneratorState]] to completed. - async_gen_object->SetState(thread, JSGeneratorState::COMPLETED); + asyncGenObject->SetState(thread, JSGeneratorState::COMPLETED); // 3. Return ! AsyncGeneratorResolve(F.[[Generator]], value, true). JSHandle value = builtins_common::GetCallArg(argv, 0); - return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, JSHandle::Cast(async_gen_object), value, + return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, JSHandle::Cast(asyncGenObject), value, true) .GetTaggedValue(); } @@ -35,18 +35,18 @@ JSTaggedValue JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextFulf JSTaggedValue JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextRejected(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let F be the active function object. - JSHandle this_func(builtins_common::GetConstructor(argv)); - JSHandle async_gen_object(thread, this_func->GetAsyncGenerator()); + JSHandle thisFunc(builtins_common::GetConstructor(argv)); + JSHandle asyncGenObject(thread, thisFunc->GetAsyncGenerator()); // 2. Set F.[[Generator]].[[AsyncGeneratorState]] to completed. - async_gen_object->SetState(thread, JSGeneratorState::COMPLETED); + asyncGenObject->SetState(thread, JSGeneratorState::COMPLETED); // 3. Return ! AsyncGeneratorReject(F.[[Generator]], reason). JSHandle reason = builtins_common::GetCallArg(argv, 0); - return JSAsyncGeneratorObject::AsyncGeneratorReject(thread, JSHandle::Cast(async_gen_object), reason) + return JSAsyncGeneratorObject::AsyncGeneratorReject(thread, JSHandle::Cast(asyncGenObject), reason) .GetTaggedValue(); } @@ -65,46 +65,46 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorResolve(JSThread * const JSHandle &generator, const JSHandle &value, bool done) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Assert: generator is an AsyncGenerator instance. ASSERT(generator->IsAsyncGeneratorObject()); - JSAsyncGeneratorObject *async_gen_object = JSAsyncGeneratorObject::Cast(generator->GetHeapObject()); + JSAsyncGeneratorObject *asyncGenObject = JSAsyncGeneratorObject::Cast(generator->GetHeapObject()); // 2. Let queue be generator.[[AsyncGeneratorQueue]]. - JSHandle queue(thread, TaggedQueue::Cast(async_gen_object->GetAsyncGeneratorQueue().GetHeapObject())); + JSHandle queue(thread, TaggedQueue::Cast(asyncGenObject->GetAsyncGeneratorQueue().GetHeapObject())); // 3. Assert: queue is not an empty List. ASSERT(!queue->Empty()); // 4. Let next be the first element of queue. // 5. Remove the first element from queue. - JSHandle next_async_generator_request(thread, queue->Pop(thread)); + JSHandle nextAsyncGeneratorRequest(thread, queue->Pop(thread)); // 6. Let promiseCapability be next.[[Capability]]. - JSTaggedValue promise_capability_value = - next_async_generator_request->Get(thread, helpers::ToUnderlying(AsyncGeneratorRequest::PROMISE_CAPABILITY)); - JSHandle promise_capability(thread, - PromiseCapability::Cast(promise_capability_value.GetHeapObject())); + JSTaggedValue promiseCapabilityValue = + nextAsyncGeneratorRequest->Get(thread, helpers::ToUnderlying(AsyncGeneratorRequest::PROMISE_CAPABILITY)); + JSHandle promiseCapability(thread, + PromiseCapability::Cast(promiseCapabilityValue.GetHeapObject())); // 7. Let iteratorResult be ! CreateIterResultObject(value, done). - JSHandle iterator_result = JSIterator::CreateIterResultObject(thread, value, done); + JSHandle iteratorResult = JSIterator::CreateIterResultObject(thread, value, done); // 8. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iteratorResult »). - JSHandle this_arg = global_const->GetHandledUndefined(); + JSHandle thisArg = globalConst->GetHandledUndefined(); - JSHandle resolve(thread, promise_capability->GetResolve()); - auto info = NewRuntimeCallInfo(thread, resolve, this_arg, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(iterator_result); + JSHandle resolve(thread, promiseCapability->GetResolve()); + auto info = NewRuntimeCallInfo(thread, resolve, thisArg, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(iteratorResult); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); // 9. Perform ! AsyncGeneratorResumeNext(generator). JSAsyncGeneratorObject::AsyncGeneratorResumeNext(thread, generator); // 10. Return undefined. - return global_const->GetHandledUndefined(); + return globalConst->GetHandledUndefined(); } // 27.6.3.5 AsyncGeneratorReject (generator, exception) @@ -112,16 +112,16 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorReject(JSThread *t const JSHandle &generator, const JSHandle &exception) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Assert: generator is an AsyncGenerator instance. ASSERT(generator->IsAsyncGeneratorObject()); - JSAsyncGeneratorObject *async_gen_object = JSAsyncGeneratorObject::Cast(generator->GetHeapObject()); + JSAsyncGeneratorObject *asyncGenObject = JSAsyncGeneratorObject::Cast(generator->GetHeapObject()); // 2. Let queue be generator.[[AsyncGeneratorQueue]]. - JSHandle queue(thread, TaggedQueue::Cast(async_gen_object->GetAsyncGeneratorQueue().GetHeapObject())); + JSHandle queue(thread, TaggedQueue::Cast(asyncGenObject->GetAsyncGeneratorQueue().GetHeapObject())); // 3. Assert: queue is not an empty List. ASSERT(!queue->Empty()); @@ -129,19 +129,19 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorReject(JSThread *t // 4. Let next be the first element of queue. // 5. Remove the first element from queue. JSTaggedValue next = queue->Pop(thread); - JSHandle next_async_generator_request(thread, TaggedArray::Cast(next.GetHeapObject())); + JSHandle nextAsyncGeneratorRequest(thread, TaggedArray::Cast(next.GetHeapObject())); // 6. Let promiseCapability be next.[[Capability]]. - JSTaggedValue promise_capability_value = - next_async_generator_request->Get(thread, helpers::ToUnderlying(AsyncGeneratorRequest::PROMISE_CAPABILITY)); - JSHandle promise_capability(thread, - PromiseCapability::Cast(promise_capability_value.GetHeapObject())); + JSTaggedValue promiseCapabilityValue = + nextAsyncGeneratorRequest->Get(thread, helpers::ToUnderlying(AsyncGeneratorRequest::PROMISE_CAPABILITY)); + JSHandle promiseCapability(thread, + PromiseCapability::Cast(promiseCapabilityValue.GetHeapObject())); // 7. Perform ! Call(promiseCapability.[[Reject]], undefined, « exception »). - JSHandle this_arg = global_const->GetHandledUndefined(); + JSHandle thisArg = globalConst->GetHandledUndefined(); - JSHandle reject(thread, promise_capability->GetReject()); - auto info = NewRuntimeCallInfo(thread, reject, this_arg, JSTaggedValue::Undefined(), 1); + JSHandle reject(thread, promiseCapability->GetReject()); + auto info = NewRuntimeCallInfo(thread, reject, thisArg, JSTaggedValue::Undefined(), 1); info->SetCallArgs(exception); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); @@ -149,58 +149,58 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorReject(JSThread *t JSAsyncGeneratorObject::AsyncGeneratorResumeNext(thread, generator); // 10. Return undefined. - return global_const->GetHandledUndefined(); + return globalConst->GetHandledUndefined(); } // 27.6.3.6 AsyncGeneratorResumeNext ( generator ) JSHandle JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThread *thread, const JSHandle &generator) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 1. Assert: generator is an AsyncGenerator instance. ASSERT(generator->IsAsyncGeneratorObject()); - JSHandle async_gen_object = JSHandle::Cast(generator); + JSHandle asyncGenObject = JSHandle::Cast(generator); // 2. Let state be generator.[[AsyncGeneratorState]]. - JSTaggedValue state = async_gen_object->GetGeneratorState(); + JSTaggedValue state = asyncGenObject->GetGeneratorState(); // 3. Assert: state is not executing. ASSERT(!JSGeneratorObject::IsState(state, JSGeneratorState::EXECUTING)); // 4. If state is awaiting-return, return undefined. if (JSGeneratorObject::IsState(state, JSGeneratorState::AWAITING_RETURN)) { - return global_const->GetHandledUndefined(); + return globalConst->GetHandledUndefined(); } // 5. Let queue be generator.[[AsyncGeneratorQueue]]. - JSHandle queue(thread, TaggedQueue::Cast(async_gen_object->GetAsyncGeneratorQueue().GetHeapObject())); + JSHandle queue(thread, TaggedQueue::Cast(asyncGenObject->GetAsyncGeneratorQueue().GetHeapObject())); // 6. If queue is an empty List, return undefined. if (queue->Empty()) { - return global_const->GetHandledUndefined(); + return globalConst->GetHandledUndefined(); } // 7. Let next be the value of the first element of queue. JSTaggedValue next = queue->Front(); // 8. Assert: next is an AsyncGeneratorRequest record. - JSHandle next_async_generator_request(thread, next); + JSHandle nextAsyncGeneratorRequest(thread, next); // 9. Let completion be next.[[Completion]]. JSHandle completion( - thread, next_async_generator_request->Get(thread, helpers::ToUnderlying(AsyncGeneratorRequest::COMPLETION))); + thread, nextAsyncGeneratorRequest->Get(thread, helpers::ToUnderlying(AsyncGeneratorRequest::COMPLETION))); // 10. If completion is an abrupt completion, then if (completion->IsAbrupt()) { // a. If state is suspendedStart, then if (JSGeneratorObject::IsState(state, JSGeneratorState::SUSPENDED_START)) { // i. Set generator.[[AsyncGeneratorState]] to completed. - async_gen_object->SetState(thread, JSGeneratorState::COMPLETED); + asyncGenObject->SetState(thread, JSGeneratorState::COMPLETED); // ii. Set state to completed. state = JSTaggedValue(static_cast(JSGeneratorState::COMPLETED)); } @@ -210,7 +210,7 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThrea // i. If completion.[[Type]] is return, then if (completion->IsReturn()) { // 1. Set generator.[[AsyncGeneratorState]] to awaiting-return. - async_gen_object->SetState(thread, JSGeneratorState::AWAITING_RETURN); + asyncGenObject->SetState(thread, JSGeneratorState::AWAITING_RETURN); // 2. Let promise be ? PromiseResolve(%Promise%, completion.[[Value]]). JSHandle promise( @@ -224,32 +224,32 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThrea // AsyncGeneratorResumeNext Return Processor Fulfilled Functions. // 5. Let onFulfilled be ! CreateBuiltinFunction(stepsFulfilled, lengthFulfilled, "", « [[Generator]] // »). - JSHandle on_fulfilled = + JSHandle onFulfilled = factory->NewJSAsyncGeneratorResolveNextFunction(reinterpret_cast( JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextFulfilled)); // 6. Set onFulfilled.[[Generator]] to generator. - on_fulfilled->SetAsyncGenerator(thread, async_gen_object.GetTaggedValue()); + onFulfilled->SetAsyncGenerator(thread, asyncGenObject.GetTaggedValue()); // 7. Let stepsRejected be the algorithm steps defined in AsyncGeneratorResumeNext Return Processor // Rejected Functions. // 8. Let lengthRejected be the number of non-optional parameters of the function definition in // AsyncGeneratorResumeNext Return Processor Rejected Functions. // 9. Let onRejected be ! CreateBuiltinFunction(stepsRejected, lengthRejected, "", « [[Generator]] »). - JSHandle on_rejected = + JSHandle onRejected = factory->NewJSAsyncGeneratorResolveNextFunction(reinterpret_cast( JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextRejected)); // 10. Set onRejected.[[Generator]] to generator. - on_rejected->SetAsyncGenerator(thread, async_gen_object.GetTaggedValue()); + onRejected->SetAsyncGenerator(thread, asyncGenObject.GetTaggedValue()); // 11. Perform ! PerformPromiseThen(promise, onFulfilled, onRejected). - [[maybe_unused]] JSTaggedValue then_result = builtins::promise::PerformPromiseThen( - thread, promise, JSHandle::Cast(on_fulfilled), - JSHandle::Cast(on_rejected), global_const->GetHandledUndefined()); + [[maybe_unused]] JSTaggedValue thenResult = builtins::promise::PerformPromiseThen( + thread, promise, JSHandle::Cast(onFulfilled), + JSHandle::Cast(onRejected), globalConst->GetHandledUndefined()); // 12. Return undefined. - return global_const->GetHandledUndefined(); + return globalConst->GetHandledUndefined(); } // ii. Else @@ -257,15 +257,15 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThrea ASSERT(completion->IsThrow()); // 2. Perform ! AsyncGeneratorReject(generator, completion.[[Value]]). - [[maybe_unused]] JSHandle reject_result = + [[maybe_unused]] JSHandle rejectResult = AsyncGeneratorReject(thread, generator, JSHandle(thread, completion->GetValue())); // 3. Return undefined. - return global_const->GetHandledUndefined(); + return globalConst->GetHandledUndefined(); } } else if (JSGeneratorObject::IsState(state, JSGeneratorState::COMPLETED)) { // 11. Else if state is completed, return ! AsyncGeneratorResolve(generator, undefined, true). - return AsyncGeneratorResolve(thread, generator, global_const->GetHandledUndefined(), true); + return AsyncGeneratorResolve(thread, generator, globalConst->GetHandledUndefined(), true); } // 12. Assert: state is either suspendedStart or suspendedYield. @@ -273,10 +273,10 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThrea JSGeneratorObject::IsState(state, JSGeneratorState::SUSPENDED_YIELD)); // 13. Let genContext be generator.[[AsyncGeneratorContext]]. - JSHandle gen_context(thread, async_gen_object->GetGeneratorContext()); + JSHandle genContext(thread, asyncGenObject->GetGeneratorContext()); // 16. Set generator.[[AsyncGeneratorState]] to executing - async_gen_object->SetState(thread, JSGeneratorState::EXECUTING); + asyncGenObject->SetState(thread, JSGeneratorState::EXECUTING); // 14. Let callerContext be the running execution context. // 15. Suspend callerContext. @@ -286,20 +286,20 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThrea if (completion->IsReturn()) { [[maybe_unused]] JSHandle result = - GeneratorHelper::Continue(thread, gen_context, GeneratorResumeMode::RETURN, completion->GetValue()); + GeneratorHelper::Continue(thread, genContext, GeneratorResumeMode::RETURN, completion->GetValue()); } else if (completion->IsThrow()) { [[maybe_unused]] JSHandle result = - GeneratorHelper::Continue(thread, gen_context, GeneratorResumeMode::THROW, completion->GetValue()); + GeneratorHelper::Continue(thread, genContext, GeneratorResumeMode::THROW, completion->GetValue()); } else { [[maybe_unused]] JSHandle result = - GeneratorHelper::Continue(thread, gen_context, GeneratorResumeMode::NEXT, completion->GetValue()); + GeneratorHelper::Continue(thread, genContext, GeneratorResumeMode::NEXT, completion->GetValue()); } // 19. Assert: result is never an abrupt completion. // 20. Assert: When we return here, genContext has already been removed from the execution context stack and // callerContext is the currently running execution context. // 21. Return undefined. - return global_const->GetHandledUndefined(); + return globalConst->GetHandledUndefined(); } // 27.6.3.7 AsyncGeneratorEnqueue(generator, value) @@ -307,13 +307,13 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorEnqueue(JSThread * const JSHandle &generator, const JSHandle &completion) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 1. Let promiseCapability be ! NewPromiseCapability(%Promise%). - JSHandle promise_capability = + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); // 2. Let check be AsyncGeneratorValidate(generator, generatorBrand). @@ -322,43 +322,43 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorEnqueue(JSThread * // 3. If check is an abrupt completion, then if (UNLIKELY(thread->HasPendingException())) { // a. Let badGeneratorError be a newly created TypeError object. - JSTaggedValue bad_generator_error = thread->GetException(); + JSTaggedValue badGeneratorError = thread->GetException(); thread->ClearException(); // b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »). - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle this_arg = global_const->GetHandledUndefined(); - JSHandle reject(thread, promise_capability->GetReject()); - auto info = NewRuntimeCallInfo(thread, reject, this_arg, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(bad_generator_error); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle thisArg = globalConst->GetHandledUndefined(); + JSHandle reject(thread, promiseCapability->GetReject()); + auto info = NewRuntimeCallInfo(thread, reject, thisArg, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(badGeneratorError); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); // c. Return promiseCapability.[[Promise]]. - return JSHandle(thread, promise_capability->GetPromise()); + return JSHandle(thread, promiseCapability->GetPromise()); } - JSHandle async_gen_object(thread, JSAsyncGeneratorObject::Cast(generator->GetHeapObject())); + JSHandle asyncGenObject(thread, JSAsyncGeneratorObject::Cast(generator->GetHeapObject())); // 4. Let queue be generator.[[AsyncGeneratorQueue]]. - JSHandle queue(thread, TaggedQueue::Cast(async_gen_object->GetAsyncGeneratorQueue().GetHeapObject())); + JSHandle queue(thread, TaggedQueue::Cast(asyncGenObject->GetAsyncGeneratorQueue().GetHeapObject())); // 5. Let request be AsyncGeneratorRequest { [[Completion]]: completion, [[Capability]]: promiseCapability }. JSHandle request = factory->NewTaggedArray(2); request->Set(thread, helpers::ToUnderlying(AsyncGeneratorRequest::COMPLETION), completion.GetTaggedValue()); request->Set(thread, helpers::ToUnderlying(AsyncGeneratorRequest::PROMISE_CAPABILITY), - promise_capability.GetTaggedValue()); - JSHandle request_value(thread, request.GetTaggedValue()); + promiseCapability.GetTaggedValue()); + JSHandle requestValue(thread, request.GetTaggedValue()); // 6. Append request to the end of queue. - JSTaggedValue new_queue(TaggedQueue::Push(thread, queue, request_value)); - async_gen_object->SetAsyncGeneratorQueue(thread, new_queue); + JSTaggedValue newQueue(TaggedQueue::Push(thread, queue, requestValue)); + asyncGenObject->SetAsyncGeneratorQueue(thread, newQueue); // 7. Let state be generator.[[AsyncGeneratorState]]. // 8. If state is not executing, then - if (!async_gen_object->IsExecuting()) { + if (!asyncGenObject->IsExecuting()) { AsyncGeneratorResumeNext(thread, generator); } // 9. Return promiseCapability.[[Promise]]. - return JSHandle(thread, promise_capability->GetPromise()); + return JSHandle(thread, promiseCapability->GetPromise()); } } // namespace panda::ecmascript diff --git a/runtime/js_bigint.cpp b/runtime/js_bigint.cpp index 0e976b1221a32651e50b9aa74eb1e88f451ae9ab..9d2aed02327001f5d47250ddac903a0ea4aef044 100644 --- a/runtime/js_bigint.cpp +++ b/runtime/js_bigint.cpp @@ -34,15 +34,15 @@ static int CharToInt(char c) return res; } -static std::string Division(std::string &num, uint32_t conversion_to_radix, uint32_t current_radix, uint32_t &remain) +static std::string Division(std::string &num, uint32_t conversionToRadix, uint32_t currentRadix, uint32_t &remain) { - ASSERT(conversion_to_radix != 0); + ASSERT(conversionToRadix != 0); uint32_t temp = 0; remain = 0; for (char &c : num) { - temp = (current_radix * remain + static_cast(CharToInt(c))); - c = DP[temp / conversion_to_radix]; - remain = temp % conversion_to_radix; + temp = (currentRadix * remain + static_cast(CharToInt(c))); + c = DP[temp / conversionToRadix]; + remain = temp % conversionToRadix; } int count = 0; while (num[count] == '0') { @@ -51,67 +51,67 @@ static std::string Division(std::string &num, uint32_t conversion_to_radix, uint return num.substr(count); } -std::string BigIntHelper::Conversion(const std::string &num, uint32_t conversion_to_radix, uint32_t current_radix) +std::string BigIntHelper::Conversion(const std::string &num, uint32_t conversionToRadix, uint32_t currentRadix) { - ASSERT(conversion_to_radix != 0); - std::string new_num = num; + ASSERT(conversionToRadix != 0); + std::string newNum = num; std::string res; uint32_t remain = 0; - while (!new_num.empty()) { - new_num = Division(new_num, conversion_to_radix, current_radix, remain); + while (!newNum.empty()) { + newNum = Division(newNum, conversionToRadix, currentRadix, remain); res.insert(res.begin(), DP[remain]); } return res; } -JSHandle BigIntHelper::SetBigInt(JSThread *thread, const std::string &num_str, uint32_t current_radix) +JSHandle BigIntHelper::SetBigInt(JSThread *thread, const std::string &numStr, uint32_t currentRadix) { int flag = 0; - if (num_str[0] == '-') { + if (numStr[0] == '-') { flag = 1; } - std::string binary_str; - if (current_radix != BigInt::BINARY) { - binary_str = Conversion(num_str.substr(flag), BigInt::BINARY, current_radix); + std::string binaryStr; + if (currentRadix != BigInt::BINARY) { + binaryStr = Conversion(numStr.substr(flag), BigInt::BINARY, currentRadix); } else { - binary_str = num_str.substr(flag); + binaryStr = numStr.substr(flag); } - JSHandle big_int; - size_t binary_str_len = binary_str.size(); - size_t len = binary_str_len / BigInt::DATEBITS; - size_t mod = binary_str_len % BigInt::DATEBITS; + JSHandle bigInt; + size_t binaryStrLen = binaryStr.size(); + size_t len = binaryStrLen / BigInt::DATEBITS; + size_t mod = binaryStrLen % BigInt::DATEBITS; int index = 0; if (mod == 0) { index = static_cast(len - 1); - big_int = BigInt::CreateBigInt(thread, len); + bigInt = BigInt::CreateBigInt(thread, len); } else { len++; index = static_cast(len - 1); - big_int = BigInt::CreateBigInt(thread, len); + bigInt = BigInt::CreateBigInt(thread, len); uint32_t val = 0; for (size_t i = 0; i < mod; ++i) { val <<= 1U; - val |= static_cast(binary_str[i] - '0'); + val |= static_cast(binaryStr[i] - '0'); } - BigInt::SetDigit(thread, big_int, index, val); + BigInt::SetDigit(thread, bigInt, index, val); index--; } if (flag == 1) { - big_int->SetSign(true); + bigInt->SetSign(true); } size_t i = mod; - while (i < binary_str_len) { + while (i < binaryStrLen) { uint32_t val = 0; - for (size_t j = 0; j < BigInt::DATEBITS && i < binary_str_len; ++j, ++i) { + for (size_t j = 0; j < BigInt::DATEBITS && i < binaryStrLen; ++j, ++i) { val <<= 1U; - val |= static_cast(binary_str[i] - '0'); + val |= static_cast(binaryStr[i] - '0'); } - BigInt::SetDigit(thread, big_int, index, val); + BigInt::SetDigit(thread, bigInt, index, val); index--; } - return BigIntHelper::RightTruncate(thread, big_int); + return BigIntHelper::RightTruncate(thread, bigInt); } JSHandle BigIntHelper::RightTruncate(JSThread *thread, JSHandle x) @@ -144,31 +144,31 @@ JSHandle BigIntHelper::RightTruncate(JSThread *thread, JSHandle return x; } -std::string BigIntHelper::GetBinary(const JSHandle &big_int) +std::string BigIntHelper::GetBinary(const JSHandle &bigInt) { int index = 0; - auto len = static_cast(big_int->GetLength()); - int str_len = BigInt::DATEBITS * len; - std::string res(str_len, '0'); - int str_index = str_len - 1; + auto len = static_cast(bigInt->GetLength()); + int strLen = BigInt::DATEBITS * len; + std::string res(strLen, '0'); + int strIndex = strLen - 1; while (index < len) { - int bity_len = BigInt::DATEBITS; - uint32_t val = big_int->GetDigit(index); - while (bity_len-- != 0) { - res[str_index--] = (val & 1U) + '0'; + int bityLen = BigInt::DATEBITS; + uint32_t val = bigInt->GetDigit(index); + while (bityLen-- != 0) { + res[strIndex--] = (val & 1U) + '0'; val = val >> 1UL; } index++; } size_t count = 0; - size_t res_len = res.size(); - for (size_t i = 0; i < res_len; ++i) { + size_t resLen = res.size(); + for (size_t i = 0; i < resLen; ++i) { if (res[i] != '0') { break; } count++; } - if (count == res_len) { + if (count == resLen) { return "0"; } return res.substr(count); @@ -176,40 +176,40 @@ std::string BigIntHelper::GetBinary(const JSHandle &big_int) uint32_t BigInt::GetDigit(uint32_t index) const { - TaggedArray *tagged_array = TaggedArray::Cast(GetData().GetTaggedObject()); - JSTaggedValue digit = tagged_array->Get(index); + TaggedArray *taggedArray = TaggedArray::Cast(GetData().GetTaggedObject()); + JSTaggedValue digit = taggedArray->Get(index); return static_cast(digit.GetInt()); } -void BigInt::SetDigit(JSThread *thread, JSHandle big_int, uint32_t index, uint32_t digit) +void BigInt::SetDigit(JSThread *thread, JSHandle bigInt, uint32_t index, uint32_t digit) { - JSHandle digits_handle(thread, big_int->GetData().GetTaggedObject()); - digits_handle->Set(thread, index, JSTaggedValue(static_cast(digit))); + JSHandle digitsHandle(thread, bigInt->GetData().GetTaggedObject()); + digitsHandle->Set(thread, index, JSTaggedValue(static_cast(digit))); } uint32_t BigInt::GetLength() const { - TaggedArray *tagged_array = TaggedArray::Cast(GetData().GetTaggedObject()); - return tagged_array->GetLength(); + TaggedArray *taggedArray = TaggedArray::Cast(GetData().GetTaggedObject()); + return taggedArray->GetLength(); } JSHandle BigInt::CreateBigInt(JSThread *thread, uint32_t size) { ASSERT(size < MAXSIZE); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle big_int = factory->NewBigInt(); - JSHandle tagged_array = factory->NewTaggedArray(size); - big_int->SetData(thread, tagged_array.GetTaggedValue()); - return big_int; + JSHandle bigInt = factory->NewBigInt(); + JSHandle taggedArray = factory->NewTaggedArray(size); + bigInt->SetData(thread, taggedArray.GetTaggedValue()); + return bigInt; } // 6.1.6.2.13 bool BigInt::Equal(JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y) { [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle x_handle(thread, x); - JSHandle y_handle(thread, y); - return Equal(x_handle, y_handle); + JSHandle xHandle(thread, x); + JSHandle yHandle(thread, y); + return Equal(xHandle, yHandle); } bool BigInt::Equal(const JSHandle &x, const JSHandle &y) @@ -237,74 +237,74 @@ bool BigInt::SameValueZero(JSThread *thread, const JSTaggedValue &x, const JSTag return Equal(thread, x, y); } -void BigInt::InitializationZero(JSThread *thread, JSHandle big_int) +void BigInt::InitializationZero(JSThread *thread, JSHandle bigInt) { - uint32_t len = big_int->GetLength(); + uint32_t len = bigInt->GetLength(); for (uint32_t i = 0; i < len; ++i) { - SetDigit(thread, big_int, i, 0); + SetDigit(thread, bigInt, i, 0); } } JSHandle BigInt::BitwiseOp(JSThread *thread, Operate op, JSHandle x, JSHandle y) { - uint32_t max_len = 0; - uint32_t min_len = 0; + uint32_t maxLen = 0; + uint32_t minLen = 0; uint32_t xlen = x->GetLength(); uint32_t ylen = y->GetLength(); if (xlen > ylen) { - max_len = xlen; - min_len = ylen; + maxLen = xlen; + minLen = ylen; } else { - max_len = ylen; - min_len = xlen; + maxLen = ylen; + minLen = xlen; } - JSHandle big_int = BigInt::CreateBigInt(thread, max_len); - InitializationZero(thread, big_int); - for (size_t i = 0; i < min_len; ++i) { + JSHandle bigInt = BigInt::CreateBigInt(thread, maxLen); + InitializationZero(thread, bigInt); + for (size_t i = 0; i < minLen; ++i) { if (op == Operate::OR) { - SetDigit(thread, big_int, i, x->GetDigit(i) | y->GetDigit(i)); + SetDigit(thread, bigInt, i, x->GetDigit(i) | y->GetDigit(i)); } else if (op == Operate::AND) { - SetDigit(thread, big_int, i, x->GetDigit(i) & y->GetDigit(i)); + SetDigit(thread, bigInt, i, x->GetDigit(i) & y->GetDigit(i)); } else { ASSERT(op == Operate::XOR); - SetDigit(thread, big_int, i, x->GetDigit(i) ^ y->GetDigit(i)); + SetDigit(thread, bigInt, i, x->GetDigit(i) ^ y->GetDigit(i)); } } if (op == Operate::OR || op == Operate::XOR) { if (xlen > ylen) { for (size_t i = ylen; i < xlen; ++i) { - SetDigit(thread, big_int, i, x->GetDigit(i)); + SetDigit(thread, bigInt, i, x->GetDigit(i)); } } else if (ylen > xlen) { for (size_t i = xlen; i < ylen; ++i) { - SetDigit(thread, big_int, i, y->GetDigit(i)); + SetDigit(thread, bigInt, i, y->GetDigit(i)); } } } - return BigIntHelper::RightTruncate(thread, big_int); + return BigIntHelper::RightTruncate(thread, bigInt); } JSHandle OneIsNegativeAND(JSThread *thread, JSHandle x, JSHandle y) { - JSHandle y_val = BigInt::BitwiseSubOne(thread, y, y->GetLength()); - uint32_t x_length = x->GetLength(); - uint32_t y_length = y_val->GetLength(); - uint32_t min_len = x_length; - if (x_length > y_length) { - min_len = y_length; + JSHandle yVal = BigInt::BitwiseSubOne(thread, y, y->GetLength()); + uint32_t xLength = x->GetLength(); + uint32_t yLength = yVal->GetLength(); + uint32_t minLen = xLength; + if (xLength > yLength) { + minLen = yLength; } - JSHandle new_big_int = BigInt::CreateBigInt(thread, x_length); + JSHandle newBigInt = BigInt::CreateBigInt(thread, xLength); uint32_t i = 0; - while (i < min_len) { - uint32_t res = x->GetDigit(i) & ~(y_val->GetDigit(i)); - BigInt::SetDigit(thread, new_big_int, i, res); + while (i < minLen) { + uint32_t res = x->GetDigit(i) & ~(yVal->GetDigit(i)); + BigInt::SetDigit(thread, newBigInt, i, res); ++i; } - while (i < x_length) { - BigInt::SetDigit(thread, new_big_int, i, x->GetDigit(i)); + while (i < xLength) { + BigInt::SetDigit(thread, newBigInt, i, x->GetDigit(i)); ++i; } - return BigIntHelper::RightTruncate(thread, new_big_int); + return BigIntHelper::RightTruncate(thread, newBigInt); } // 6.1.6.2.20 BigInt::bitwiseAND ( x, y ) @@ -312,9 +312,9 @@ JSHandle BigInt::BitwiseAND(JSThread *thread, JSHandle x, JSHand { if (x->GetSign() && y->GetSign()) { // (-x) & (-y) == -(((x-1) | (y-1)) + 1) - JSHandle x_val = BitwiseSubOne(thread, x, x->GetLength()); - JSHandle y_val = BitwiseSubOne(thread, y, y->GetLength()); - JSHandle temp = BitwiseOp(thread, Operate::OR, x_val, y_val); + JSHandle xVal = BitwiseSubOne(thread, x, x->GetLength()); + JSHandle yVal = BitwiseSubOne(thread, y, y->GetLength()); + JSHandle temp = BitwiseOp(thread, Operate::OR, xVal, yVal); JSHandle res = BitwiseAddOne(thread, temp); return res; } @@ -330,8 +330,8 @@ JSHandle BigInt::BitwiseAND(JSThread *thread, JSHandle x, JSHand JSHandle OneIsNegativeXOR(JSThread *thread, JSHandle x, JSHandle y) { - JSHandle y_val = BigInt::BitwiseSubOne(thread, y, y->GetLength()); - JSHandle temp = BigInt::BitwiseOp(thread, Operate::XOR, x, y_val); + JSHandle yVal = BigInt::BitwiseSubOne(thread, y, y->GetLength()); + JSHandle temp = BigInt::BitwiseOp(thread, Operate::XOR, x, yVal); JSHandle res = BigInt::BitwiseAddOne(thread, temp); return res; } @@ -341,9 +341,9 @@ JSHandle BigInt::BitwiseXOR(JSThread *thread, JSHandle x, JSHand { if (x->GetSign() && y->GetSign()) { // (-x) ^ (-y) == (x-1) ^ (y-1) - JSHandle x_val = BitwiseSubOne(thread, x, x->GetLength()); - JSHandle y_val = BitwiseSubOne(thread, y, y->GetLength()); - return BitwiseOp(thread, Operate::XOR, x_val, y_val); + JSHandle xVal = BitwiseSubOne(thread, x, x->GetLength()); + JSHandle yVal = BitwiseSubOne(thread, y, y->GetLength()); + return BitwiseOp(thread, Operate::XOR, xVal, yVal); } if (x->GetSign() != y->GetSign()) { // x ^ (-y) == -((x ^ (y-1)) + 1) @@ -355,84 +355,84 @@ JSHandle BigInt::BitwiseXOR(JSThread *thread, JSHandle x, JSHand return BitwiseOp(thread, Operate::XOR, x, y); } -JSHandle BigInt::BitwiseSubOne(JSThread *thread, JSHandle big_int, uint32_t max_len) +JSHandle BigInt::BitwiseSubOne(JSThread *thread, JSHandle bigInt, uint32_t maxLen) { - ASSERT(!big_int->IsZero()); - ASSERT(max_len >= big_int->GetLength()); + ASSERT(!bigInt->IsZero()); + ASSERT(maxLen >= bigInt->GetLength()); - JSHandle new_big_int = BigInt::CreateBigInt(thread, max_len); + JSHandle newBigInt = BigInt::CreateBigInt(thread, maxLen); - uint32_t big_int_len = big_int->GetLength(); + uint32_t bigIntLen = bigInt->GetLength(); uint32_t carry = 1; - for (uint32_t i = 0; i < big_int_len; i++) { - uint32_t big_int_carry = 0; - BigInt::SetDigit(thread, new_big_int, i, BigIntHelper::SubHelper(big_int->GetDigit(i), carry, big_int_carry)); - carry = big_int_carry; + for (uint32_t i = 0; i < bigIntLen; i++) { + uint32_t bigIntCarry = 0; + BigInt::SetDigit(thread, newBigInt, i, BigIntHelper::SubHelper(bigInt->GetDigit(i), carry, bigIntCarry)); + carry = bigIntCarry; } ASSERT(!carry); - for (uint32_t i = big_int_len; i < max_len; i++) { - BigInt::SetDigit(thread, new_big_int, i, carry); + for (uint32_t i = bigIntLen; i < maxLen; i++) { + BigInt::SetDigit(thread, newBigInt, i, carry); } - return BigIntHelper::RightTruncate(thread, new_big_int); + return BigIntHelper::RightTruncate(thread, newBigInt); } -JSHandle BigInt::BitwiseAddOne(JSThread *thread, JSHandle big_int) +JSHandle BigInt::BitwiseAddOne(JSThread *thread, JSHandle bigInt) { - uint32_t big_int_length = big_int->GetLength(); + uint32_t bigIntLength = bigInt->GetLength(); - bool need_expend = true; - for (uint32_t i = 0; i < big_int_length; i++) { - if (std::numeric_limits::max() != big_int->GetDigit(i)) { - need_expend = false; + bool needExpend = true; + for (uint32_t i = 0; i < bigIntLength; i++) { + if (std::numeric_limits::max() != bigInt->GetDigit(i)) { + needExpend = false; break; } } - uint32_t new_length = big_int_length; - if (need_expend) { - new_length += 1; + uint32_t newLength = bigIntLength; + if (needExpend) { + newLength += 1; } - JSHandle new_big_int = BigInt::CreateBigInt(thread, new_length); + JSHandle newBigInt = BigInt::CreateBigInt(thread, newLength); uint32_t carry = 1; - for (uint32_t i = 0; i < big_int_length; i++) { - uint32_t big_int_carry = 0; - BigInt::SetDigit(thread, new_big_int, i, BigIntHelper::AddHelper(big_int->GetDigit(i), carry, big_int_carry)); - carry = big_int_carry; + for (uint32_t i = 0; i < bigIntLength; i++) { + uint32_t bigIntCarry = 0; + BigInt::SetDigit(thread, newBigInt, i, BigIntHelper::AddHelper(bigInt->GetDigit(i), carry, bigIntCarry)); + carry = bigIntCarry; } - if (need_expend) { - BigInt::SetDigit(thread, new_big_int, big_int_length, carry); + if (needExpend) { + BigInt::SetDigit(thread, newBigInt, bigIntLength, carry); } else { ASSERT(!carry); } - new_big_int->SetSign(true); - return BigIntHelper::RightTruncate(thread, new_big_int); + newBigInt->SetSign(true); + return BigIntHelper::RightTruncate(thread, newBigInt); } JSHandle OneIsNegativeOR(JSThread *thread, JSHandle x, JSHandle y) { - uint32_t x_length = x->GetLength(); - uint32_t max_len = x_length; - if (max_len < y->GetLength()) { - max_len = y->GetLength(); + uint32_t xLength = x->GetLength(); + uint32_t maxLen = xLength; + if (maxLen < y->GetLength()) { + maxLen = y->GetLength(); } - JSHandle y_val = BigInt::BitwiseSubOne(thread, y, max_len); - uint32_t y_length = y_val->GetLength(); - uint32_t min_len = x_length; - if (min_len > y_length) { - min_len = y_length; + JSHandle yVal = BigInt::BitwiseSubOne(thread, y, maxLen); + uint32_t yLength = yVal->GetLength(); + uint32_t minLen = xLength; + if (minLen > yLength) { + minLen = yLength; } - JSHandle new_big_int = BigInt::CreateBigInt(thread, y_length); + JSHandle newBigInt = BigInt::CreateBigInt(thread, yLength); uint32_t i = 0; - while (i < min_len) { - uint32_t res = ~(x->GetDigit(i)) & y_val->GetDigit(i); - BigInt::SetDigit(thread, new_big_int, i, res); + while (i < minLen) { + uint32_t res = ~(x->GetDigit(i)) & yVal->GetDigit(i); + BigInt::SetDigit(thread, newBigInt, i, res); ++i; } - while (i < y_length) { - BigInt::SetDigit(thread, new_big_int, i, y_val->GetDigit(i)); + while (i < yLength) { + BigInt::SetDigit(thread, newBigInt, i, yVal->GetDigit(i)); ++i; } - JSHandle temp = BigIntHelper::RightTruncate(thread, new_big_int); + JSHandle temp = BigIntHelper::RightTruncate(thread, newBigInt); JSHandle res = BigInt::BitwiseAddOne(thread, temp); res->SetSign(true); return res; @@ -443,12 +443,12 @@ JSHandle BigInt::BitwiseOR(JSThread *thread, JSHandle x, JSHandl { if (x->GetSign() && y->GetSign()) { // (-x) | (-y) == -(((x-1) & (y-1)) + 1) - uint32_t max_len = x->GetLength(); - uint32_t y_len = y->GetLength(); - max_len < y_len ? max_len = y_len : 0; - JSHandle x_val = BitwiseSubOne(thread, x, max_len); - JSHandle y_val = BitwiseSubOne(thread, y, y_len); - JSHandle temp = BitwiseOp(thread, Operate::AND, x_val, y_val); + uint32_t maxLen = x->GetLength(); + uint32_t yLen = y->GetLength(); + maxLen < yLen ? maxLen = yLen : 0; + JSHandle xVal = BitwiseSubOne(thread, x, maxLen); + JSHandle yVal = BitwiseSubOne(thread, y, yLen); + JSHandle temp = BitwiseOp(thread, Operate::AND, xVal, yVal); JSHandle res = BitwiseAddOne(thread, temp); res->SetSign(true); return res; @@ -464,17 +464,17 @@ JSHandle BigInt::BitwiseOR(JSThread *thread, JSHandle x, JSHandl } // 6.1.6.2.23 BigInt::toString ( x ) -JSHandle BigInt::ToString(JSThread *thread, JSHandle big_int, uint32_t conversion_to_radix) +JSHandle BigInt::ToString(JSThread *thread, JSHandle bigInt, uint32_t conversionToRadix) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::string result = big_int->ToStdString(thread, conversion_to_radix); + std::string result = bigInt->ToStdString(thread, conversionToRadix); return factory->NewFromStdString(result); } -std::string BigInt::ToStdString(JSThread *thread, uint32_t conversion_to_radix) const +std::string BigInt::ToStdString(JSThread *thread, uint32_t conversionToRadix) const { - JSHandle this_handle(thread, JSTaggedValue(this)); - std::string result = BigIntHelper::Conversion(BigIntHelper::GetBinary(this_handle), conversion_to_radix, BINARY); + JSHandle thisHandle(thread, JSTaggedValue(this)); + std::string result = BigIntHelper::Conversion(BigIntHelper::GetBinary(thisHandle), conversionToRadix, BINARY); if (GetSign()) { result = "-" + result; } @@ -500,37 +500,37 @@ JSTaggedValue BigInt::NumberToBigInt(JSThread *thread, JSHandle n } // Take out bits 62-52 (11 bits in total) and subtract 1023 // NOLINTNEXTLINE(readability-magic-numbers) - uint64_t integer_digits = ((bits >> base::DOUBLE_SIGNIFICAND_SIZE) & 0x7FFU) - base::DOUBLE_EXPONENT_BIAS; - uint32_t may_need_len = integer_digits / BigInt::DATEBITS + 1; + uint64_t integerDigits = ((bits >> base::DOUBLE_SIGNIFICAND_SIZE) & 0x7FFU) - base::DOUBLE_EXPONENT_BIAS; + uint32_t mayNeedLen = integerDigits / BigInt::DATEBITS + 1; - JSHandle big_int = CreateBigInt(thread, may_need_len); - big_int->SetSign(num < 0); + JSHandle bigInt = CreateBigInt(thread, mayNeedLen); + bigInt->SetSign(num < 0); uint64_t mantissa = (bits & base::DOUBLE_SIGNIFICAND_MASK) | base::DOUBLE_HIDDEN_BIT; - int mantissa_size = base::DOUBLE_SIGNIFICAND_SIZE; + int mantissaSize = base::DOUBLE_SIGNIFICAND_SIZE; uint32_t leftover = 0; - bool is_first_into = true; - for (int index = static_cast(may_need_len - 1); index >= 0; --index) { - uint32_t double_num = 0; - if (is_first_into) { - is_first_into = false; - leftover = mantissa_size - static_cast(integer_digits % BigInt::DATEBITS); - double_num = static_cast(mantissa >> leftover); + bool isFirstInto = true; + for (int index = static_cast(mayNeedLen - 1); index >= 0; --index) { + uint32_t doubleNum = 0; + if (isFirstInto) { + isFirstInto = false; + leftover = mantissaSize - static_cast(integerDigits % BigInt::DATEBITS); + doubleNum = static_cast(mantissa >> leftover); mantissa = mantissa << (64U - leftover); // NOLINT(readability-magic-numbers) 64 : double bits size - BigInt::SetDigit(thread, big_int, index, double_num); + BigInt::SetDigit(thread, bigInt, index, doubleNum); } else { leftover -= BigInt::DATEBITS; - double_num = static_cast(mantissa >> BigInt::DATEBITS); + doubleNum = static_cast(mantissa >> BigInt::DATEBITS); mantissa = mantissa << BigInt::DATEBITS; - BigInt::SetDigit(thread, big_int, index, double_num); + BigInt::SetDigit(thread, bigInt, index, doubleNum); } } - return BigIntHelper::RightTruncate(thread, big_int).GetTaggedValue(); + return BigIntHelper::RightTruncate(thread, bigInt).GetTaggedValue(); } JSHandle BigInt::Int32ToBigInt(JSThread *thread, const int &number) { - JSHandle big_int = CreateBigInt(thread, 1); + JSHandle bigInt = CreateBigInt(thread, 1); uint32_t value = 0; bool sign = number < 0; if (sign) { @@ -538,14 +538,14 @@ JSHandle BigInt::Int32ToBigInt(JSThread *thread, const int &number) } else { value = number; } - BigInt::SetDigit(thread, big_int, 0, value); - big_int->SetSign(sign); - return big_int; + BigInt::SetDigit(thread, bigInt, 0, value); + bigInt->SetSign(sign); + return bigInt; } JSHandle BigInt::Int64ToBigInt(JSThread *thread, const int64_t &number) { - JSHandle big_int = CreateBigInt(thread, 2); // 2 : one int64_t bits need two uint32_t bits + JSHandle bigInt = CreateBigInt(thread, 2); // 2 : one int64_t bits need two uint32_t bits uint64_t value = 0; bool sign = number < 0; if (sign) { @@ -554,199 +554,199 @@ JSHandle BigInt::Int64ToBigInt(JSThread *thread, const int64_t &number) value = number; } auto *addr = reinterpret_cast(&value); - BigInt::SetDigit(thread, big_int, 0, *(addr)); + BigInt::SetDigit(thread, bigInt, 0, *(addr)); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - BigInt::SetDigit(thread, big_int, 1, *(addr + 1)); - big_int->SetSign(sign); - return BigIntHelper::RightTruncate(thread, big_int); + BigInt::SetDigit(thread, bigInt, 1, *(addr + 1)); + bigInt->SetSign(sign); + return BigIntHelper::RightTruncate(thread, bigInt); } JSHandle BigInt::Uint64ToBigInt(JSThread *thread, const uint64_t &number) { - JSHandle big_int = CreateBigInt(thread, 2); // 2 : one int64_t bits need two uint32_t bits + JSHandle bigInt = CreateBigInt(thread, 2); // 2 : one int64_t bits need two uint32_t bits const auto *addr = reinterpret_cast(&number); - BigInt::SetDigit(thread, big_int, 0, *(addr)); + BigInt::SetDigit(thread, bigInt, 0, *(addr)); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - BigInt::SetDigit(thread, big_int, 1, *(addr + 1)); - return BigIntHelper::RightTruncate(thread, big_int); + BigInt::SetDigit(thread, bigInt, 1, *(addr + 1)); + return BigIntHelper::RightTruncate(thread, bigInt); } -void BigInt::BigIntToInt64(JSThread *thread, JSHandle big_int, int64_t *c_value, bool *lossless) +void BigInt::BigIntToInt64(JSThread *thread, JSHandle bigInt, int64_t *cValue, bool *lossless) { - ASSERT(c_value != nullptr); + ASSERT(cValue != nullptr); ASSERT(lossless != nullptr); - JSHandle big_int64(thread, JSTaggedValue::ToBigInt64(thread, big_int)); + JSHandle bigInt64(thread, JSTaggedValue::ToBigInt64(thread, bigInt)); RETURN_IF_ABRUPT_COMPLETION(thread); - if (Equal(thread, big_int64.GetTaggedValue(), big_int.GetTaggedValue())) { + if (Equal(thread, bigInt64.GetTaggedValue(), bigInt.GetTaggedValue())) { *lossless = true; } - auto *addr = reinterpret_cast(c_value); - auto len = static_cast(big_int64->GetLength()); + auto *addr = reinterpret_cast(cValue); + auto len = static_cast(bigInt64->GetLength()); for (int index = len - 1; index >= 0; --index) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *(addr + index) = big_int64->GetDigit(index); + *(addr + index) = bigInt64->GetDigit(index); } - if (big_int64->GetSign()) { - *c_value = ~(static_cast(static_cast(*c_value - 1))); + if (bigInt64->GetSign()) { + *cValue = ~(static_cast(static_cast(*cValue - 1))); } } -void BigInt::BigIntToUint64(JSThread *thread, JSHandle big_int, uint64_t *c_value, bool *lossless) +void BigInt::BigIntToUint64(JSThread *thread, JSHandle bigInt, uint64_t *cValue, bool *lossless) { - ASSERT(c_value != nullptr); + ASSERT(cValue != nullptr); ASSERT(lossless != nullptr); - JSHandle big_uint64(thread, JSTaggedValue::ToBigUint64(thread, big_int)); + JSHandle bigUint64(thread, JSTaggedValue::ToBigUint64(thread, bigInt)); RETURN_IF_ABRUPT_COMPLETION(thread); - if (Equal(thread, big_uint64.GetTaggedValue(), big_int.GetTaggedValue())) { + if (Equal(thread, bigUint64.GetTaggedValue(), bigInt.GetTaggedValue())) { *lossless = true; } - auto *addr = reinterpret_cast(c_value); - auto len = static_cast(big_uint64->GetLength()); + auto *addr = reinterpret_cast(cValue); + auto len = static_cast(bigUint64->GetLength()); for (int index = len - 1; index >= 0; --index) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - UnalignedStore(addr + index, big_uint64->GetDigit(index)); + UnalignedStore(addr + index, bigUint64->GetDigit(index)); } } JSHandle BigInt::CreateBigWords(JSThread *thread, bool sign, uint32_t size, const uint64_t *words) { ASSERT(words != nullptr); - uint32_t need_len = size * 2; // 2 : uint64_t size to uint32_t size - JSHandle big_int = CreateBigInt(thread, need_len); + uint32_t needLen = size * 2; // 2 : uint64_t size to uint32_t size + JSHandle bigInt = CreateBigInt(thread, needLen); const auto *digits = reinterpret_cast(words); - for (uint32_t index = 0; index < need_len; ++index) { + for (uint32_t index = 0; index < needLen; ++index) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - SetDigit(thread, big_int, index, *(digits + index)); + SetDigit(thread, bigInt, index, *(digits + index)); } - big_int->SetSign(sign); - return BigIntHelper::RightTruncate(thread, big_int); + bigInt->SetSign(sign); + return BigIntHelper::RightTruncate(thread, bigInt); } JSHandle BigInt::Add(JSThread *thread, JSHandle x, JSHandle y) { - bool x_sign_flag = x->GetSign(); - bool y_sign_flag = y->GetSign(); + bool xSignFlag = x->GetSign(); + bool ySignFlag = y->GetSign(); // x + y == x + y // -x + -y == -(x + y) - if (x_sign_flag == y_sign_flag) { - return BigIntAdd(thread, x, y, x_sign_flag); + if (xSignFlag == ySignFlag) { + return BigIntAdd(thread, x, y, xSignFlag); } // x + -y == x - y == -(y - x) // -x + y == y - x == -(x - y) - uint32_t x_length = x->GetLength(); - uint32_t y_length = y->GetLength(); - uint32_t i = x_length - 1; - auto sub_size = static_cast(x_length - y_length); - if (sub_size > 0) { - return BigIntSub(thread, x, y, x_sign_flag); + uint32_t xLength = x->GetLength(); + uint32_t yLength = y->GetLength(); + uint32_t i = xLength - 1; + auto subSize = static_cast(xLength - yLength); + if (subSize > 0) { + return BigIntSub(thread, x, y, xSignFlag); } - if (sub_size == 0) { + if (subSize == 0) { while (i > 0 && x->GetDigit(i) == y->GetDigit(i)) { i--; } if ((x->GetDigit(i) > y->GetDigit(i))) { - return BigIntSub(thread, x, y, x_sign_flag); + return BigIntSub(thread, x, y, xSignFlag); } - return BigIntSub(thread, y, x, y_sign_flag); + return BigIntSub(thread, y, x, ySignFlag); } - return BigIntSub(thread, y, x, y_sign_flag); + return BigIntSub(thread, y, x, ySignFlag); } JSHandle BigInt::Subtract(JSThread *thread, JSHandle x, JSHandle y) { - bool x_sign_flag = x->GetSign(); - bool y_sign_flag = y->GetSign(); - if (x_sign_flag != y_sign_flag) { + bool xSignFlag = x->GetSign(); + bool ySignFlag = y->GetSign(); + if (xSignFlag != ySignFlag) { // x - (-y) == x + y // (-x) - y == -(x + y) - return BigIntAdd(thread, x, y, x_sign_flag); + return BigIntAdd(thread, x, y, xSignFlag); } // x - y == -(y - x) // (-x) - (-y) == y - x == -(x - y) - uint32_t x_length = x->GetLength(); - uint32_t y_length = y->GetLength(); - uint32_t i = x_length - 1; - auto sub_size = static_cast(x_length - y_length); - if (sub_size > 0) { - return BigIntSub(thread, x, y, x_sign_flag); + uint32_t xLength = x->GetLength(); + uint32_t yLength = y->GetLength(); + uint32_t i = xLength - 1; + auto subSize = static_cast(xLength - yLength); + if (subSize > 0) { + return BigIntSub(thread, x, y, xSignFlag); } - if (sub_size == 0) { + if (subSize == 0) { while (i > 0 && x->GetDigit(i) == y->GetDigit(i)) { i--; } if ((x->GetDigit(i) > y->GetDigit(i))) { - return BigIntSub(thread, x, y, x_sign_flag); + return BigIntSub(thread, x, y, xSignFlag); } - return BigIntSub(thread, y, x, !y_sign_flag); + return BigIntSub(thread, y, x, !ySignFlag); } - return BigIntSub(thread, y, x, !y_sign_flag); + return BigIntSub(thread, y, x, !ySignFlag); } -JSHandle BigInt::BigIntAdd(JSThread *thread, JSHandle x, JSHandle y, bool result_sign) +JSHandle BigInt::BigIntAdd(JSThread *thread, JSHandle x, JSHandle y, bool resultSign) { if (x->GetLength() < y->GetLength()) { - return BigIntAdd(thread, y, x, result_sign); + return BigIntAdd(thread, y, x, resultSign); } - JSHandle big_int = BigInt::CreateBigInt(thread, x->GetLength() + 1); - uint32_t big_int_carry = 0; + JSHandle bigInt = BigInt::CreateBigInt(thread, x->GetLength() + 1); + uint32_t bigIntCarry = 0; uint32_t i = 0; while (i < y->GetLength()) { - uint32_t new_big_int_carry = 0; - uint32_t add_plus = BigIntHelper::AddHelper(x->GetDigit(i), y->GetDigit(i), new_big_int_carry); - add_plus = BigIntHelper::AddHelper(add_plus, big_int_carry, new_big_int_carry); - SetDigit(thread, big_int, i, add_plus); - big_int_carry = new_big_int_carry; + uint32_t newBigIntCarry = 0; + uint32_t addPlus = BigIntHelper::AddHelper(x->GetDigit(i), y->GetDigit(i), newBigIntCarry); + addPlus = BigIntHelper::AddHelper(addPlus, bigIntCarry, newBigIntCarry); + SetDigit(thread, bigInt, i, addPlus); + bigIntCarry = newBigIntCarry; i++; } while (i < x->GetLength()) { - uint32_t new_big_int_carry = 0; - uint32_t add_plus = BigIntHelper::AddHelper(x->GetDigit(i), big_int_carry, new_big_int_carry); - SetDigit(thread, big_int, i, add_plus); - big_int_carry = new_big_int_carry; + uint32_t newBigIntCarry = 0; + uint32_t addPlus = BigIntHelper::AddHelper(x->GetDigit(i), bigIntCarry, newBigIntCarry); + SetDigit(thread, bigInt, i, addPlus); + bigIntCarry = newBigIntCarry; i++; } - SetDigit(thread, big_int, i, big_int_carry); - big_int->SetSign(result_sign); - return BigIntHelper::RightTruncate(thread, big_int); + SetDigit(thread, bigInt, i, bigIntCarry); + bigInt->SetSign(resultSign); + return BigIntHelper::RightTruncate(thread, bigInt); } -inline uint32_t BigIntHelper::AddHelper(uint32_t x, uint32_t y, uint32_t &big_int_carry) +inline uint32_t BigIntHelper::AddHelper(uint32_t x, uint32_t y, uint32_t &bigIntCarry) { - uint32_t add_plus = x + y; - if (add_plus < x) { - big_int_carry += 1; + uint32_t addPlus = x + y; + if (addPlus < x) { + bigIntCarry += 1; } - return add_plus; + return addPlus; } -JSHandle BigInt::BigIntSub(JSThread *thread, JSHandle x, JSHandle y, bool result_sign) +JSHandle BigInt::BigIntSub(JSThread *thread, JSHandle x, JSHandle y, bool resultSign) { - JSHandle big_int = BigInt::CreateBigInt(thread, x->GetLength()); - uint32_t big_int_carry = 0; + JSHandle bigInt = BigInt::CreateBigInt(thread, x->GetLength()); + uint32_t bigIntCarry = 0; uint32_t i = 0; while (i < y->GetLength()) { - uint32_t new_big_int_carry = 0; - uint32_t minu_sub = BigIntHelper::SubHelper(x->GetDigit(i), y->GetDigit(i), new_big_int_carry); - minu_sub = BigIntHelper::SubHelper(minu_sub, big_int_carry, new_big_int_carry); - SetDigit(thread, big_int, i, minu_sub); - big_int_carry = new_big_int_carry; + uint32_t newBigIntCarry = 0; + uint32_t minuSub = BigIntHelper::SubHelper(x->GetDigit(i), y->GetDigit(i), newBigIntCarry); + minuSub = BigIntHelper::SubHelper(minuSub, bigIntCarry, newBigIntCarry); + SetDigit(thread, bigInt, i, minuSub); + bigIntCarry = newBigIntCarry; i++; } while (i < x->GetLength()) { - uint32_t new_big_int_carry = 0; - uint32_t minu_sub = BigIntHelper::SubHelper(x->GetDigit(i), big_int_carry, new_big_int_carry); - SetDigit(thread, big_int, i, minu_sub); - big_int_carry = new_big_int_carry; + uint32_t newBigIntCarry = 0; + uint32_t minuSub = BigIntHelper::SubHelper(x->GetDigit(i), bigIntCarry, newBigIntCarry); + SetDigit(thread, bigInt, i, minuSub); + bigIntCarry = newBigIntCarry; i++; } - big_int->SetSign(result_sign); - return BigIntHelper::RightTruncate(thread, big_int); + bigInt->SetSign(resultSign); + return BigIntHelper::RightTruncate(thread, bigInt); } JSHandle BigInt::BigIntAddOne(JSThread *thread, JSHandle x) @@ -761,13 +761,13 @@ JSHandle BigInt::BigIntSubOne(JSThread *thread, JSHandle x) return Subtract(thread, x, temp); } -inline uint32_t BigIntHelper::SubHelper(uint32_t x, uint32_t y, uint32_t &big_int_carry) +inline uint32_t BigIntHelper::SubHelper(uint32_t x, uint32_t y, uint32_t &bigIntCarry) { - uint32_t minu_sub = x - y; - if (minu_sub > x) { - big_int_carry += 1; + uint32_t minuSub = x - y; + if (minuSub > x) { + bigIntCarry += 1; } - return minu_sub; + return minuSub; } ComparisonResult BigInt::Compare(JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y) @@ -784,43 +784,43 @@ ComparisonResult BigInt::Compare(JSThread *thread, const JSTaggedValue &x, const bool BigInt::LessThan(JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y) { [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle x_handle(thread, x); - JSHandle y_handle(thread, y); - return LessThan(x_handle, y_handle); + JSHandle xHandle(thread, x); + JSHandle yHandle(thread, y); + return LessThan(xHandle, yHandle); } bool BigInt::LessThan(const JSHandle &x, const JSHandle &y) { - bool x_sign_flag = x->GetSign(); - bool y_sign_flag = y->GetSign(); - auto min_size = static_cast(x->GetLength() - y->GetLength()); + bool xSignFlag = x->GetSign(); + bool ySignFlag = y->GetSign(); + auto minSize = static_cast(x->GetLength() - y->GetLength()); uint32_t i = x->GetLength() - 1; - if (x_sign_flag != y_sign_flag) { - return x_sign_flag; + if (xSignFlag != ySignFlag) { + return xSignFlag; } - if (min_size != 0 && x_sign_flag) { - return min_size > 0; + if (minSize != 0 && xSignFlag) { + return minSize > 0; } - if (min_size != 0 && !x_sign_flag) { - return min_size <= 0; + if (minSize != 0 && !xSignFlag) { + return minSize <= 0; } while (i > 0 && x->GetDigit(i) == y->GetDigit(i)) { i--; } if ((x->GetDigit(i) > y->GetDigit(i))) { - return x_sign_flag; + return xSignFlag; } if ((x->GetDigit(i) < y->GetDigit(i))) { - return !x_sign_flag; + return !xSignFlag; } return false; } JSHandle BigInt::SignedRightShift(JSThread *thread, JSHandle x, JSHandle y) { - bool x_is_null = (x->GetDigit(0) == 0U); - bool y_is_null = (y->GetDigit(0) == 0U); - if (x_is_null || y_is_null) { + bool xIsNull = (x->GetDigit(0) == 0U); + bool yIsNull = (y->GetDigit(0) == 0U); + if (xIsNull || yIsNull) { return x; } if (y->GetSign()) { @@ -831,21 +831,21 @@ JSHandle BigInt::SignedRightShift(JSThread *thread, JSHandle x, JSHandle BigInt::RightShiftHelper(JSThread *thread, JSHandle x, JSHandle y) { - std::string shift_binay = BigIntHelper::GetBinary(x); - std::string rev_temp = std::string(shift_binay.rbegin(), shift_binay.rend()); + std::string shiftBinay = BigIntHelper::GetBinary(x); + std::string revTemp = std::string(shiftBinay.rbegin(), shiftBinay.rend()); for (uint32_t i = 0; i < y->GetLength(); i++) { - rev_temp = rev_temp.erase(0, y->GetDigit(i)); + revTemp = revTemp.erase(0, y->GetDigit(i)); } - std::string final_binay = std::string(rev_temp.rbegin(), rev_temp.rend()); - if (final_binay.empty()) { - final_binay = "0"; + std::string finalBinay = std::string(revTemp.rbegin(), revTemp.rend()); + if (finalBinay.empty()) { + finalBinay = "0"; } - JSHandle big_int = BigIntHelper::SetBigInt(thread, final_binay, BINARY); + JSHandle bigInt = BigIntHelper::SetBigInt(thread, finalBinay, BINARY); if (x->GetSign()) { - SetDigit(thread, big_int, 0, big_int->GetDigit(0) + 1); + SetDigit(thread, bigInt, 0, bigInt->GetDigit(0) + 1); } - big_int->SetSign(x->GetSign()); - return BigIntHelper::RightTruncate(thread, big_int); + bigInt->SetSign(x->GetSign()); + return BigIntHelper::RightTruncate(thread, bigInt); } JSHandle BigInt::LeftShift(JSThread *thread, JSHandle x, JSHandle y) @@ -858,13 +858,13 @@ JSHandle BigInt::LeftShift(JSThread *thread, JSHandle x, JSHandl JSHandle BigInt::LeftShiftHelper(JSThread *thread, JSHandle x, JSHandle y) { - std::string shift_binary = BigIntHelper::GetBinary(x); + std::string shiftBinary = BigIntHelper::GetBinary(x); for (size_t i = 0; i < y->GetLength(); i++) { - shift_binary = shift_binary.append(y->GetDigit(i), '0'); + shiftBinary = shiftBinary.append(y->GetDigit(i), '0'); } - JSHandle big_int = BigIntHelper::SetBigInt(thread, shift_binary, BINARY); - big_int->SetSign(x->GetSign()); - return BigIntHelper::RightTruncate(thread, big_int); + JSHandle bigInt = BigIntHelper::SetBigInt(thread, shiftBinary, BINARY); + bigInt->SetSign(x->GetSign()); + return BigIntHelper::RightTruncate(thread, bigInt); } JSHandle BigInt::UnsignedRightShift(JSThread *thread, [[maybe_unused]] JSHandle x, @@ -913,8 +913,8 @@ JSHandle BigInt::BitwiseNOT(JSThread *thread, JSHandle x) JSHandle BigInt::Exponentiate(JSThread *thread, JSHandle base, JSHandle exponent) { if (exponent->GetSign()) { - JSHandle big_int(thread, JSTaggedValue::Exception()); - THROW_RANGE_ERROR_AND_RETURN(thread, "Exponent must be positive", big_int); + JSHandle bigInt(thread, JSTaggedValue::Exception()); + THROW_RANGE_ERROR_AND_RETURN(thread, "Exponent must be positive", bigInt); } ASSERT(exponent->GetLength() == 1); if (exponent->IsZero()) { @@ -924,8 +924,8 @@ JSHandle BigInt::Exponentiate(JSThread *thread, JSHandle base, J if (base->IsZero()) { return BigIntHelper::SetBigInt(thread, "0"); } - uint32_t e_value = exponent->GetDigit(0); - if (e_value == 1) { + uint32_t eValue = exponent->GetDigit(0); + if (eValue == 1) { return base; } uint32_t j = exponent->GetDigit(0) - 1; @@ -1025,22 +1025,22 @@ Comparestr BigInt::ComString(std::string &a, std::string &b) return Comparestr::EQUAL; } -std::string BigIntHelper::DevStr(std::string &str_value) +std::string BigIntHelper::DevStr(std::string &strValue) { size_t i = 0; - for (i = 0; i < str_value.length(); i++) { + for (i = 0; i < strValue.length(); i++) { // NOLINTNEXTLINE(readability-magic-numbers) - if (str_value.at(i) >= 48 && str_value.at(i) <= 57) { // 48 and 57 is '0' and '9' + if (strValue.at(i) >= 48 && strValue.at(i) <= 57) { // 48 and 57 is '0' and '9' // NOLINTNEXTLINE(readability-magic-numbers) - str_value.at(i) -= 48; // 48:'0' + strValue.at(i) -= 48; // 48:'0' } // NOLINTNEXTLINE(readability-magic-numbers) - if (str_value.at(i) >= 97 && str_value.at(i) <= 122) { // 97 and 122 is 'a' and 'z' + if (strValue.at(i) >= 97 && strValue.at(i) <= 122) { // 97 and 122 is 'a' and 'z' // NOLINTNEXTLINE(readability-magic-numbers) - str_value.at(i) -= 87; // 87 control result is greater than 10 + strValue.at(i) -= 87; // 87 control result is greater than 10 } } - return str_value; + return strValue; } std::string BigIntHelper::Minus(std::string &a, std::string &b) @@ -1165,8 +1165,8 @@ JSHandle BigIntHelper::DivideImpl(JSThread *thread, JSHandle x, JSHandle BigInt::Divide(JSThread *thread, JSHandle x, JSHandle y) { if (y->IsZero()) { - JSHandle big_int(thread, JSTaggedValue::Exception()); - THROW_RANGE_ERROR_AND_RETURN(thread, "Division by zero", big_int); + JSHandle bigInt(thread, JSTaggedValue::Exception()); + THROW_RANGE_ERROR_AND_RETURN(thread, "Division by zero", bigInt); } return BigIntHelper::DivideImpl(thread, x, y); } @@ -1174,8 +1174,8 @@ JSHandle BigInt::Divide(JSThread *thread, JSHandle x, JSHandle BigInt::Remainder(JSThread *thread, JSHandle n, JSHandle d) { if (d->IsZero()) { - JSHandle big_int(thread, JSTaggedValue::Exception()); - THROW_RANGE_ERROR_AND_RETURN(thread, "Division by zero", big_int); + JSHandle bigInt(thread, JSTaggedValue::Exception()); + THROW_RANGE_ERROR_AND_RETURN(thread, "Division by zero", bigInt); } if (n->IsZero()) { return n; @@ -1185,74 +1185,74 @@ JSHandle BigInt::Remainder(JSThread *thread, JSHandle n, JSHandl return Subtract(thread, n, p); } -JSHandle BigInt::FloorMod(JSThread *thread, JSHandle left_val, JSHandle right_val) +JSHandle BigInt::FloorMod(JSThread *thread, JSHandle leftVal, JSHandle rightVal) { - if (left_val->GetSign()) { - JSHandle quotient_val = Divide(thread, left_val, right_val); - if (quotient_val->IsZero()) { - return Add(thread, left_val, right_val); + if (leftVal->GetSign()) { + JSHandle quotientVal = Divide(thread, leftVal, rightVal); + if (quotientVal->IsZero()) { + return Add(thread, leftVal, rightVal); } - JSHandle num = Multiply(thread, quotient_val, right_val); - if (Equal(num, left_val)) { + JSHandle num = Multiply(thread, quotientVal, rightVal); + if (Equal(num, leftVal)) { return Int32ToBigInt(thread, 0); } - return Subtract(thread, left_val, Subtract(thread, num, right_val)); + return Subtract(thread, leftVal, Subtract(thread, num, rightVal)); } - return Remainder(thread, left_val, right_val); + return Remainder(thread, leftVal, rightVal); } -JSTaggedValue BigInt::AsUintN(JSThread *thread, JSTaggedNumber &bits, JSHandle big_int) +JSTaggedValue BigInt::AsUintN(JSThread *thread, JSTaggedNumber &bits, JSHandle bigInt) { uint32_t bit = bits.ToUint32(); if (bit == 0) { return Int32ToBigInt(thread, 0).GetTaggedValue(); } - if (big_int->IsZero()) { - return big_int.GetTaggedValue(); + if (bigInt->IsZero()) { + return bigInt.GetTaggedValue(); } JSHandle exponent = Int32ToBigInt(thread, bit); JSHandle base = Int32ToBigInt(thread, 2); // 2 : base value - JSHandle t_value = Exponentiate(thread, base, exponent); - return FloorMod(thread, big_int, t_value).GetTaggedValue(); + JSHandle tValue = Exponentiate(thread, base, exponent); + return FloorMod(thread, bigInt, tValue).GetTaggedValue(); } -JSTaggedValue BigInt::AsintN(JSThread *thread, JSTaggedNumber &bits, JSHandle big_int) +JSTaggedValue BigInt::AsintN(JSThread *thread, JSTaggedNumber &bits, JSHandle bigInt) { uint32_t bit = bits.ToUint32(); if (bit == 0) { return Int32ToBigInt(thread, 0).GetTaggedValue(); } - if (big_int->IsZero()) { - return big_int.GetTaggedValue(); + if (bigInt->IsZero()) { + return bigInt.GetTaggedValue(); } JSHandle exp = Int32ToBigInt(thread, bit); JSHandle exponent = Int32ToBigInt(thread, static_cast(bit - 1)); JSHandle base = Int32ToBigInt(thread, 2); // 2 : base value - JSHandle t_value = Exponentiate(thread, base, exp); - JSHandle mod_value = FloorMod(thread, big_int, t_value); - JSHandle res_value = Exponentiate(thread, base, exponent); + JSHandle tValue = Exponentiate(thread, base, exp); + JSHandle modValue = FloorMod(thread, bigInt, tValue); + JSHandle resValue = Exponentiate(thread, base, exponent); // If mod ≥ 2bits - 1, return ℤ(mod - 2bits); otherwise, return (mod). - if (LessThan(res_value, mod_value) || Equal(res_value, mod_value)) { - return Subtract(thread, mod_value, t_value).GetTaggedValue(); + if (LessThan(resValue, modValue) || Equal(resValue, modValue)) { + return Subtract(thread, modValue, tValue).GetTaggedValue(); } - return mod_value.GetTaggedValue(); + return modValue.GetTaggedValue(); } static JSTaggedNumber CalculateNumber(const uint64_t &sign, const uint64_t &mantissa, uint64_t &exponent) { exponent = (exponent + base::DOUBLE_EXPONENT_BIAS) << base::DOUBLE_SIGNIFICAND_SIZE; - uint64_t double_bit = sign | exponent | mantissa; + uint64_t doubleBit = sign | exponent | mantissa; double res = 0; - if (memcpy_s(&res, sizeof(res), &double_bit, sizeof(double_bit)) != EOK) { + if (memcpy_s(&res, sizeof(res), &doubleBit, sizeof(doubleBit)) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } return JSTaggedNumber(res); } -static JSTaggedNumber Rounding(const uint64_t &sign, uint64_t &mantissa, uint64_t &exponent, bool need_round) +static JSTaggedNumber Rounding(const uint64_t &sign, uint64_t &mantissa, uint64_t &exponent, bool needRound) { - if (need_round || (mantissa & 1U) == 1U) { + if (needRound || (mantissa & 1U) == 1U) { ++mantissa; if ((mantissa >> base::DOUBLE_SIGNIFICAND_SIZE) != 0) { mantissa = 0; @@ -1265,67 +1265,67 @@ static JSTaggedNumber Rounding(const uint64_t &sign, uint64_t &mantissa, uint64_ return CalculateNumber(sign, mantissa, exponent); } -JSTaggedNumber BigInt::BigIntToNumber(JSHandle big_int) +JSTaggedNumber BigInt::BigIntToNumber(JSHandle bigInt) { - if (big_int->IsZero()) { + if (bigInt->IsZero()) { return JSTaggedNumber(0); } - uint32_t big_int_len = big_int->GetLength(); - uint32_t big_int_head = big_int->GetDigit(big_int_len - 1); + uint32_t bigIntLen = bigInt->GetLength(); + uint32_t bigIntHead = bigInt->GetDigit(bigIntLen - 1); uint32_t bits = BigInt::DATEBITS; - uint32_t pre_zero = 0; + uint32_t preZero = 0; while (bits-- != 0U) { - if (((big_int_head >> bits) | 0U) != 0) { + if (((bigIntHead >> bits) | 0U) != 0) { break; } - pre_zero++; + preZero++; } - uint32_t big_int_bit_len = big_int_len * BigInt::DATEBITS - pre_zero; + uint32_t bigIntBitLen = bigIntLen * BigInt::DATEBITS - preZero; // if Significant bits greater than 1024 then double is infinity - bool big_int_sign = big_int->GetSign(); - if (big_int_bit_len > (base::DOUBLE_EXPONENT_BIAS + 1)) { - return JSTaggedNumber(big_int_sign ? -base::POSITIVE_INFINITY : base::POSITIVE_INFINITY); + bool bigIntSign = bigInt->GetSign(); + if (bigIntBitLen > (base::DOUBLE_EXPONENT_BIAS + 1)) { + return JSTaggedNumber(bigIntSign ? -base::POSITIVE_INFINITY : base::POSITIVE_INFINITY); } // NOLINTNEXTLINE(readability-magic-numbers) - uint64_t sign = big_int_sign ? 1ULL << 63ULL : 0; // 63 : Set the sign bit of sign to 1 - uint32_t need_move_bit = pre_zero + BigInt::DATEBITS + 1; + uint64_t sign = bigIntSign ? 1ULL << 63ULL : 0; // 63 : Set the sign bit of sign to 1 + uint32_t needMoveBit = preZero + BigInt::DATEBITS + 1; // Align to the most significant bit, then right shift 12 bits so that the head of the mantissa is in place // NOLINTNEXTLINE(readability-magic-numbers) - auto mantissa = (static_cast(big_int_head) << need_move_bit) >> 12ULL; // 12 mantissa just has 52 bits - auto remain_mantissa_bits = static_cast(need_move_bit - 12); // NOLINT(readability-magic-numbers) - auto exponent = static_cast(big_int_bit_len - 1); - auto index = static_cast(big_int_len - 1); + auto mantissa = (static_cast(bigIntHead) << needMoveBit) >> 12ULL; // 12 mantissa just has 52 bits + auto remainMantissaBits = static_cast(needMoveBit - 12); // NOLINT(readability-magic-numbers) + auto exponent = static_cast(bigIntBitLen - 1); + auto index = static_cast(bigIntLen - 1); uint32_t digit = 0; if (index > 0) { - digit = big_int->GetDigit(--index); + digit = bigInt->GetDigit(--index); } else { return CalculateNumber(sign, mantissa, exponent); } // pad unset mantissa - if (static_cast(remain_mantissa_bits) >= BigInt::DATEBITS) { - mantissa |= (static_cast(digit) << (remain_mantissa_bits - BigInt::DATEBITS)); - remain_mantissa_bits -= BigInt::DATEBITS; + if (static_cast(remainMantissaBits) >= BigInt::DATEBITS) { + mantissa |= (static_cast(digit) << (remainMantissaBits - BigInt::DATEBITS)); + remainMantissaBits -= BigInt::DATEBITS; index--; } - if (remain_mantissa_bits > 0 && index >= 0) { - digit = big_int->GetDigit(index); - mantissa |= (static_cast(digit) >> (BigInt::DATEBITS - remain_mantissa_bits)); - remain_mantissa_bits -= BigInt::DATEBITS; + if (remainMantissaBits > 0 && index >= 0) { + digit = bigInt->GetDigit(index); + mantissa |= (static_cast(digit) >> (BigInt::DATEBITS - remainMantissaBits)); + remainMantissaBits -= BigInt::DATEBITS; } // After the mantissa is filled, if the bits of BigInt have not been used up, consider the rounding problem // The remaining bits of the current digit - int remain_digit_bits = 1; - if (remain_mantissa_bits < 0) { - remain_digit_bits = -remain_mantissa_bits; + int remainDigitBits = 1; + if (remainMantissaBits < 0) { + remainDigitBits = -remainMantissaBits; } - if (remain_mantissa_bits == 0) { + if (remainMantissaBits == 0) { if (index == 0) { return CalculateNumber(sign, mantissa, exponent); } - digit = big_int->GetDigit(index--); - remain_digit_bits = BigInt::DATEBITS; + digit = bigInt->GetDigit(index--); + remainDigitBits = BigInt::DATEBITS; } - uint32_t temp = 1ULL << (remain_digit_bits - 1); // NOLINT(hicpp-signed-bitwise) + uint32_t temp = 1ULL << (remainDigitBits - 1); // NOLINT(hicpp-signed-bitwise) if ((digit & temp) == 0U) { return CalculateNumber(sign, mantissa, exponent); } @@ -1333,47 +1333,47 @@ JSTaggedNumber BigInt::BigIntToNumber(JSHandle big_int) return Rounding(sign, mantissa, exponent, true); } while (index > 0) { - if (big_int->GetDigit(index--) != 0) { + if (bigInt->GetDigit(index--) != 0) { return Rounding(sign, mantissa, exponent, true); } } return Rounding(sign, mantissa, exponent, false); } -static int CompareToBitsLen(JSHandle big_int, uint32_t num_bit_len, uint32_t &pre_zero) +static int CompareToBitsLen(JSHandle bigInt, uint32_t numBitLen, uint32_t &preZero) { - uint32_t big_int_len = big_int->GetLength(); - uint32_t big_int_head = big_int->GetDigit(big_int_len - 1); + uint32_t bigIntLen = bigInt->GetLength(); + uint32_t bigIntHead = bigInt->GetDigit(bigIntLen - 1); uint32_t bits = BigInt::DATEBITS; while (bits != 0U) { bits--; - if (((big_int_head >> bits) | 0U) != 0) { + if (((bigIntHead >> bits) | 0U) != 0) { break; } - pre_zero++; + preZero++; } - uint32_t big_int_bit_len = big_int_len * BigInt::DATEBITS - pre_zero; - bool big_int_sign = big_int->GetSign(); - if (big_int_bit_len > num_bit_len) { - return big_int_sign ? 0 : 1; + uint32_t bigIntBitLen = bigIntLen * BigInt::DATEBITS - preZero; + bool bigIntSign = bigInt->GetSign(); + if (bigIntBitLen > numBitLen) { + return bigIntSign ? 0 : 1; } - if (big_int_bit_len < num_bit_len) { - return big_int_sign ? 1 : 0; + if (bigIntBitLen < numBitLen) { + return bigIntSign ? 1 : 0; } return -1; } -ComparisonResult BigInt::CompareWithNumber(JSHandle big_int, JSHandle number) +ComparisonResult BigInt::CompareWithNumber(JSHandle bigInt, JSHandle number) { double num = number->GetNumber(); - bool number_sign = num < 0; + bool numberSign = num < 0; if (std::isnan(num)) { return ComparisonResult::UNDEFINED; } if (!std::isfinite(num)) { - return (!number_sign ? ComparisonResult::LESS : ComparisonResult::GREAT); + return (!numberSign ? ComparisonResult::LESS : ComparisonResult::GREAT); } // Bit operations must be of integer type uint64_t bits = 0; @@ -1384,63 +1384,63 @@ ComparisonResult BigInt::CompareWithNumber(JSHandle big_int, JSHandle> base::DOUBLE_SIGNIFICAND_SIZE) & 0x7FFU; // NOLINT(readability-magic-numbers) // Take out bits 62-52 (11 bits in total) and subtract 1023 - auto integer_digits = static_cast(exponential - base::DOUBLE_EXPONENT_BIAS); + auto integerDigits = static_cast(exponential - base::DOUBLE_EXPONENT_BIAS); uint64_t mantissa = (bits & base::DOUBLE_SIGNIFICAND_MASK) | base::DOUBLE_HIDDEN_BIT; - bool big_int_sign = big_int->GetSign(); + bool bigIntSign = bigInt->GetSign(); // Handling the opposite sign - if (!number_sign && big_int_sign) { + if (!numberSign && bigIntSign) { return ComparisonResult::LESS; } - if (number_sign && !big_int_sign) { + if (numberSign && !bigIntSign) { return ComparisonResult::GREAT; } - if (big_int->IsZero() && num == 0.0) { + if (bigInt->IsZero() && num == 0.0) { return ComparisonResult::EQUAL; } - if (big_int->IsZero() && num > 0) { + if (bigInt->IsZero() && num > 0) { return ComparisonResult::LESS; } - if (integer_digits < 0) { - return big_int_sign ? ComparisonResult::LESS : ComparisonResult::GREAT; + if (integerDigits < 0) { + return bigIntSign ? ComparisonResult::LESS : ComparisonResult::GREAT; } // Compare the significant bits of BigInt with the significant integer bits of double - uint32_t pre_zero = 0; - int res = CompareToBitsLen(big_int, integer_digits + 1, pre_zero); + uint32_t preZero = 0; + int res = CompareToBitsLen(bigInt, integerDigits + 1, preZero); if (res == 0) { return ComparisonResult::LESS; } if (res == 1) { return ComparisonResult::GREAT; } - int mantissa_size = base::DOUBLE_SIGNIFICAND_SIZE; // mantissaSize - uint32_t big_int_len = big_int->GetLength(); + int mantissaSize = base::DOUBLE_SIGNIFICAND_SIZE; // mantissaSize + uint32_t bigIntLen = bigInt->GetLength(); uint32_t leftover = 0; - bool is_first_into = true; - for (int index = static_cast(big_int_len - 1); index >= 0; --index) { - uint32_t double_num = 0; - uint32_t big_int_num = big_int->GetDigit(index); - if (is_first_into) { - is_first_into = false; - leftover = mantissa_size - BigInt::DATEBITS + pre_zero + 1; - double_num = static_cast(mantissa >> leftover); + bool isFirstInto = true; + for (int index = static_cast(bigIntLen - 1); index >= 0; --index) { + uint32_t doubleNum = 0; + uint32_t bigIntNum = bigInt->GetDigit(index); + if (isFirstInto) { + isFirstInto = false; + leftover = mantissaSize - BigInt::DATEBITS + preZero + 1; + doubleNum = static_cast(mantissa >> leftover); mantissa = mantissa << (64U - leftover); // NOLINT(readability-magic-numbers) 64 : double bits - if (big_int_num > double_num) { - return big_int_sign ? ComparisonResult::LESS : ComparisonResult::GREAT; + if (bigIntNum > doubleNum) { + return bigIntSign ? ComparisonResult::LESS : ComparisonResult::GREAT; } - if (big_int_num < double_num) { - return big_int_sign ? ComparisonResult::GREAT : ComparisonResult::LESS; + if (bigIntNum < doubleNum) { + return bigIntSign ? ComparisonResult::GREAT : ComparisonResult::LESS; } } else { leftover -= BigInt::DATEBITS; - double_num = static_cast(mantissa >> BigInt::DATEBITS); + doubleNum = static_cast(mantissa >> BigInt::DATEBITS); mantissa = mantissa << BigInt::DATEBITS; - if (big_int_num > double_num) { - return big_int_sign ? ComparisonResult::LESS : ComparisonResult::GREAT; + if (bigIntNum > doubleNum) { + return bigIntSign ? ComparisonResult::LESS : ComparisonResult::GREAT; } - if (big_int_num < double_num) { - return big_int_sign ? ComparisonResult::GREAT : ComparisonResult::LESS; + if (bigIntNum < doubleNum) { + return bigIntSign ? ComparisonResult::GREAT : ComparisonResult::LESS; } leftover -= BigInt::DATEBITS; } @@ -1448,7 +1448,7 @@ ComparisonResult BigInt::CompareWithNumber(JSHandle big_int, JSHandle 0); - return big_int_sign ? ComparisonResult::GREAT : ComparisonResult::LESS; + return bigIntSign ? ComparisonResult::GREAT : ComparisonResult::LESS; } return ComparisonResult::EQUAL; } diff --git a/runtime/js_bigint.h b/runtime/js_bigint.h index ed84a604fffb2ac56066a204149b01b584cf0da2..d18cad6148863174a45dad7e591c3f9dc065827f 100644 --- a/runtime/js_bigint.h +++ b/runtime/js_bigint.h @@ -43,16 +43,16 @@ public: static bool SameValue(JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y); static bool SameValueZero(JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y); - static void InitializationZero(JSThread *thread, JSHandle big_int); + static void InitializationZero(JSThread *thread, JSHandle bigInt); static JSHandle BitwiseOp(JSThread *thread, Operate op, JSHandle x, JSHandle y); static JSHandle BitwiseAND(JSThread *thread, JSHandle x, JSHandle y); static JSHandle BitwiseXOR(JSThread *thread, JSHandle x, JSHandle y); static JSHandle BitwiseOR(JSThread *thread, JSHandle x, JSHandle y); - static JSHandle BitwiseSubOne(JSThread *thread, JSHandle big_int, uint32_t max_len); - static JSHandle BitwiseAddOne(JSThread *thread, JSHandle big_int); - static JSHandle ToString(JSThread *thread, JSHandle big_int, - uint32_t conversion_to_radix = BigInt::DECIMAL); - std::string ToStdString(JSThread *thread, uint32_t conversion_to_radix) const; + static JSHandle BitwiseSubOne(JSThread *thread, JSHandle bigInt, uint32_t maxLen); + static JSHandle BitwiseAddOne(JSThread *thread, JSHandle bigInt); + static JSHandle ToString(JSThread *thread, JSHandle bigInt, + uint32_t conversionToRadix = BigInt::DECIMAL); + std::string ToStdString(JSThread *thread, uint32_t conversionToRadix) const; static JSHandle UnaryMinus(JSThread *thread, JSHandle x); static JSHandle BitwiseNOT(JSThread *thread, JSHandle x); @@ -73,28 +73,28 @@ public: static JSHandle UnsignedRightShift(JSThread *thread, JSHandle x, JSHandle y); static JSHandle LeftShift(JSThread *thread, JSHandle x, JSHandle y); static JSHandle LeftShiftHelper(JSThread *thread, JSHandle x, JSHandle y); - static JSHandle BigIntAdd(JSThread *thread, JSHandle x, JSHandle y, bool result_sign); - static JSHandle BigIntSub(JSThread *thread, JSHandle x, JSHandle y, bool result_sign); + static JSHandle BigIntAdd(JSThread *thread, JSHandle x, JSHandle y, bool resultSign); + static JSHandle BigIntSub(JSThread *thread, JSHandle x, JSHandle y, bool resultSign); static JSTaggedValue NumberToBigInt(JSThread *thread, JSHandle number); static JSHandle Int32ToBigInt(JSThread *thread, const int &number); static JSHandle Int64ToBigInt(JSThread *thread, const int64_t &number); static JSHandle Uint64ToBigInt(JSThread *thread, const uint64_t &number); - static void BigIntToInt64(JSThread *thread, JSHandle big_int, int64_t *c_value, bool *lossless); - static void BigIntToUint64(JSThread *thread, JSHandle big_int, uint64_t *c_value, bool *lossless); + static void BigIntToInt64(JSThread *thread, JSHandle bigInt, int64_t *cValue, bool *lossless); + static void BigIntToUint64(JSThread *thread, JSHandle bigInt, uint64_t *cValue, bool *lossless); static JSHandle CreateBigWords(JSThread *thread, bool sign, uint32_t size, const uint64_t *words); - static JSHandle FloorMod(JSThread *thread, JSHandle left_val, JSHandle right_val); - static JSTaggedValue AsUintN(JSThread *thread, JSTaggedNumber &bits, JSHandle big_int); - static JSTaggedValue AsintN(JSThread *thread, JSTaggedNumber &bits, JSHandle big_int); - static JSTaggedNumber BigIntToNumber(JSHandle big_int); - static ComparisonResult CompareWithNumber(JSHandle big_int, JSHandle number); + static JSHandle FloorMod(JSThread *thread, JSHandle leftVal, JSHandle rightVal); + static JSTaggedValue AsUintN(JSThread *thread, JSTaggedNumber &bits, JSHandle bigInt); + static JSTaggedValue AsintN(JSThread *thread, JSTaggedNumber &bits, JSHandle bigInt); + static JSTaggedNumber BigIntToNumber(JSHandle bigInt); + static ComparisonResult CompareWithNumber(JSHandle bigInt, JSHandle number); inline bool IsZero() { return GetLength() == 1 && GetDigit(0) == 0; } uint32_t GetDigit(uint32_t index) const; - static void SetDigit(JSThread *thread, JSHandle big_int, uint32_t index, uint32_t digit); + static void SetDigit(JSThread *thread, JSHandle bigInt, uint32_t index, uint32_t digit); uint32_t GetLength() const; @@ -125,21 +125,21 @@ private: class BigIntHelper { public: - static std::string Conversion(const std::string &num, uint32_t conversion_to_radix, uint32_t current_radix); - static JSHandle SetBigInt(JSThread *thread, const std::string &num_str, - uint32_t current_radix = BigInt::DECIMAL); - static std::string GetBinary(const JSHandle &big_int); + static std::string Conversion(const std::string &num, uint32_t conversionToRadix, uint32_t currentRadix); + static JSHandle SetBigInt(JSThread *thread, const std::string &numStr, + uint32_t currentRadix = BigInt::DECIMAL); + static std::string GetBinary(const JSHandle &bigInt); static JSHandle RightTruncate(JSThread *thread, JSHandle x); static JSHandle DivideImpl(JSThread *thread, JSHandle x, JSHandle y); static std::string MultiplyImpl(std::string &a, std::string &b); static std::string DeZero(std::string &a); static std::string Minus(std::string &a, std::string &b); - static std::string DevStr(std::string &str_value); + static std::string DevStr(std::string &strValue); static std::string Divide(std::string &a, std::string &b); - static uint32_t AddHelper(uint32_t x, uint32_t y, uint32_t &big_int_carry); - static uint32_t SubHelper(uint32_t x, uint32_t y, uint32_t &big_int_carry); + static uint32_t AddHelper(uint32_t x, uint32_t y, uint32_t &bigIntCarry); + static uint32_t SubHelper(uint32_t x, uint32_t y, uint32_t &bigIntCarry); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JS_BIGINT_H diff --git a/runtime/js_collator.cpp b/runtime/js_collator.cpp index c2d645ec4ab0ccc8fa9fc739b0c699fe4521693b..5b3cbe5aff5aef0dafa29d652d4b005d807eccbb 100644 --- a/runtime/js_collator.cpp +++ b/runtime/js_collator.cpp @@ -37,28 +37,28 @@ JSHandle JSCollator::GetAvailableLocales(JSThread *thread) { const char *key = nullptr; const char *path = JSCollator::uIcuDataColl.c_str(); - JSHandle available_locales = JSLocale::GetAvailableLocales(thread, key, path); - return available_locales; + JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, key, path); + return availableLocales; } /* static */ -void JSCollator::SetIcuCollator(JSThread *thread, const JSHandle &collator, icu::Collator *icu_collator, +void JSCollator::SetIcuCollator(JSThread *thread, const JSHandle &collator, icu::Collator *icuCollator, const DeleteEntryPoint &callback) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); - ASSERT(icu_collator != nullptr); + ASSERT(icuCollator != nullptr); JSTaggedValue data = collator->GetIcuField(); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); - native->ResetExternalPointer(icu_collator); + native->ResetExternalPointer(icuCollator); return; } - JSHandle pointer = factory->NewJSNativePointer(icu_collator); + JSHandle pointer = factory->NewJSNativePointer(icuCollator); pointer->SetDeleter(callback); collator->SetIcuField(thread, pointer.GetTaggedValue()); - ecma_vm->PushToArrayDataList(*pointer); + ecmaVm->PushToArrayDataList(*pointer); } // NOLINTNEXTLINE(readability-function-size), CODECHECK-NOLINTNEXTLINE(C_RULE_ID_FUNCTION_SIZE) @@ -66,36 +66,36 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa const JSHandle &locales, const JSHandle &options) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); // 2. If options is undefined, then // a. Let options be ObjectCreate(null). // 3. Else, // a. Let options be ? ToObject(options). - JSHandle options_object; + JSHandle optionsObject; if (options->IsUndefined()) { - JSHandle null_value = global_const->GetHandledNull(); - options_object = factory->OrdinaryNewJSObjectCreate(null_value); + JSHandle nullValue = globalConst->GetHandledNull(); + optionsObject = factory->OrdinaryNewJSObjectCreate(nullValue); } else { - options_object = JSTaggedValue::ToObject(thread, options); + optionsObject = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); } // 4. Let usage be ? GetOption(options, "usage", "string", « "sort", "search" », "sort"). - auto usage = JSLocale::GetOptionOfString(thread, options_object, global_const->GetHandledUsageString(), + auto usage = JSLocale::GetOptionOfString(thread, optionsObject, globalConst->GetHandledUsageString(), {UsageOption::SORT, UsageOption::SEARCH}, {"sort", "search"}, UsageOption::SORT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); - JSHandle usage_value(thread, JSTaggedValue(static_cast(usage))); - collator->SetUsage(thread, usage_value); + JSHandle usageValue(thread, JSTaggedValue(static_cast(usage))); + collator->SetUsage(thread, usageValue); // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). auto matcher = JSLocale::GetOptionOfString( - thread, options_object, global_const->GetHandledLocaleMatcherString(), + thread, optionsObject, globalConst->GetHandledLocaleMatcherString(), {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); @@ -104,61 +104,61 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // 7. If collation is not undefined, then // a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. JSHandle collation = - JSLocale::GetOption(thread, options_object, global_const->GetHandledCollationString(), OptionType::STRING, - global_const->GetHandledUndefined(), global_const->GetHandledUndefined()); + JSLocale::GetOption(thread, optionsObject, globalConst->GetHandledCollationString(), OptionType::STRING, + globalConst->GetHandledUndefined(), globalConst->GetHandledUndefined()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); collator->SetCollation(thread, collation); - std::string collation_str; + std::string collationStr; if (!collation->IsUndefined()) { - JSHandle collation_ecma_str = JSHandle::Cast(collation); - collation_str = JSLocale::ConvertToStdString(collation_ecma_str); - if (!JSLocale::IsWellAlphaNumList(collation_str)) { + JSHandle collationEcmaStr = JSHandle::Cast(collation); + collationStr = JSLocale::ConvertToStdString(collationEcmaStr); + if (!JSLocale::IsWellAlphaNumList(collationStr)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid collation", collator); } } // 8. Let numeric be ? GetOption(options, "numeric", "boolean", undefined, undefined). bool numeric = false; - bool found_numeric = - JSLocale::GetOptionOfBool(thread, options_object, global_const->GetHandledNumericString(), false, &numeric); + bool foundNumeric = + JSLocale::GetOptionOfBool(thread, optionsObject, globalConst->GetHandledNumericString(), false, &numeric); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); - JSHandle numeric_value(thread, JSTaggedValue(numeric)); - collator->SetNumeric(thread, numeric_value); + JSHandle numericValue(thread, JSTaggedValue(numeric)); + collator->SetNumeric(thread, numericValue); // 14. Let caseFirst be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined). - auto case_first = JSLocale::GetOptionOfString( - thread, options_object, global_const->GetHandledCaseFirstString(), + auto caseFirst = JSLocale::GetOptionOfString( + thread, optionsObject, globalConst->GetHandledCaseFirstString(), {CaseFirstOption::UPPER, CaseFirstOption::LOWER, CaseFirstOption::FALSE_OPTION}, {"upper", "lower", "false"}, CaseFirstOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); - JSHandle case_first_value(thread, JSTaggedValue(static_cast(case_first))); - collator->SetCaseFirst(thread, case_first_value); + JSHandle caseFirstValue(thread, JSTaggedValue(static_cast(caseFirst))); + collator->SetCaseFirst(thread, caseFirstValue); // 16. Let relevantExtensionKeys be %Collator%.[[RelevantExtensionKeys]]. - std::set relevant_extension_keys = {"co", "kn", "kf"}; + std::set relevantExtensionKeys = {"co", "kn", "kf"}; // 17. Let r be ResolveLocale(%Collator%.[[AvailableLocales]], requestedLocales, opt, // %Collator%.[[RelevantExtensionKeys]], localeData). - JSHandle available_locales; - if (requested_locales->GetLength() == 0) { - available_locales = factory->EmptyArray(); + JSHandle availableLocales; + if (requestedLocales->GetLength() == 0) { + availableLocales = factory->EmptyArray(); } else { - available_locales = GetAvailableLocales(thread); + availableLocales = GetAvailableLocales(thread); } ResolvedLocale r = - JSLocale::ResolveLocale(thread, available_locales, requested_locales, matcher, relevant_extension_keys); - icu::Locale icu_locale = r.locale_data; - JSHandle locale_str = JSLocale::ToLanguageTag(thread, icu_locale); - collator->SetLocale(thread, locale_str.GetTaggedValue()); - ASSERT_PRINT(!icu_locale.isBogus(), "icuLocale is bogus"); + JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys); + icu::Locale icuLocale = r.localeData; + JSHandle localeStr = JSLocale::ToLanguageTag(thread, icuLocale); + collator->SetLocale(thread, localeStr.GetTaggedValue()); + ASSERT_PRINT(!icuLocale.isBogus(), "icuLocale is bogus"); // If collation is undefined iterate RelevantExtensionKeys to find "co" // if found, set ICU collator UnicodeKeyword to iterator->second UErrorCode status = U_ZERO_ERROR; if (!collation->IsUndefined()) { - auto extension_iter = r.extensions.find("co"); - if (extension_iter != r.extensions.end() && extension_iter->second != collation_str) { - icu_locale.setUnicodeKeywordValue("co", nullptr, status); + auto extensionIter = r.extensions.find("co"); + if (extensionIter != r.extensions.end() && extensionIter->second != collationStr) { + icuLocale.setUnicodeKeywordValue("co", nullptr, status); ASSERT_PRINT(U_SUCCESS(status), "icuLocale set co failed"); } } @@ -166,46 +166,46 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // If usage is serach set co-serach to icu locale key word value // Eles set collation string to icu locale key word value if (usage == UsageOption::SEARCH) { - icu_locale.setUnicodeKeywordValue("co", "search", status); + icuLocale.setUnicodeKeywordValue("co", "search", status); ASSERT(U_SUCCESS(status)); } else { - if (!collation_str.empty() && JSLocale::IsWellCollation(icu_locale, collation_str)) { - icu_locale.setUnicodeKeywordValue("co", collation_str, status); + if (!collationStr.empty() && JSLocale::IsWellCollation(icuLocale, collationStr)) { + icuLocale.setUnicodeKeywordValue("co", collationStr, status); ASSERT(U_SUCCESS(status)); } } - std::unique_ptr icu_collator(icu::Collator::createInstance(icu_locale, status)); - if (U_FAILURE(status) || icu_collator == nullptr) { // NOLINT(readability-implicit-bool-conversion) + std::unique_ptr icuCollator(icu::Collator::createInstance(icuLocale, status)); + if (U_FAILURE(status) || icuCollator == nullptr) { // NOLINT(readability-implicit-bool-conversion) status = U_ZERO_ERROR; - icu::Locale locale_name(icu_locale.getBaseName()); - icu_collator.reset(icu::Collator::createInstance(locale_name, status)); - if (U_FAILURE(status) || icu_collator == nullptr) { // NOLINT(readability-implicit-bool-conversion) + icu::Locale localeName(icuLocale.getBaseName()); + icuCollator.reset(icu::Collator::createInstance(localeName, status)); + if (U_FAILURE(status) || icuCollator == nullptr) { // NOLINT(readability-implicit-bool-conversion) THROW_RANGE_ERROR_AND_RETURN(thread, "invalid collation", collator); } } ASSERT(U_SUCCESS(status)); - icu::Locale collator_locale(icu_collator->getLocale(ULOC_VALID_LOCALE, status)); + icu::Locale collatorLocale(icuCollator->getLocale(ULOC_VALID_LOCALE, status)); - icu_collator->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status); + icuCollator->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status); ASSERT(U_SUCCESS(status)); // If numeric is found set ICU collator UCOL_NUMERIC_COLLATION to numeric // Else iterate RelevantExtensionKeys to find "kn" // if found, set ICU collator UCOL_NUMERIC_COLLATION to iterator->second status = U_ZERO_ERROR; - if (found_numeric) { - ASSERT(icu_collator.get() != nullptr); - icu_collator->setAttribute(UCOL_NUMERIC_COLLATION, numeric ? UCOL_ON : UCOL_OFF, status); + if (foundNumeric) { + ASSERT(icuCollator.get() != nullptr); + icuCollator->setAttribute(UCOL_NUMERIC_COLLATION, numeric ? UCOL_ON : UCOL_OFF, status); ASSERT(U_SUCCESS(status)); } else { - auto extension_iter = r.extensions.find("kn"); - if (extension_iter != r.extensions.end()) { - ASSERT(icu_collator.get() != nullptr); - bool found = (extension_iter->second == "true"); - JSHandle is_numeric(thread, JSTaggedValue(found)); - collator->SetNumeric(thread, is_numeric); - icu_collator->setAttribute(UCOL_NUMERIC_COLLATION, found ? UCOL_ON : UCOL_OFF, status); + auto extensionIter = r.extensions.find("kn"); + if (extensionIter != r.extensions.end()) { + ASSERT(icuCollator.get() != nullptr); + bool found = (extensionIter->second == "true"); + JSHandle isNumeric(thread, JSTaggedValue(found)); + collator->SetNumeric(thread, isNumeric); + icuCollator->setAttribute(UCOL_NUMERIC_COLLATION, found ? UCOL_ON : UCOL_OFF, status); ASSERT(U_SUCCESS(status)); } } @@ -214,21 +214,21 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // Else iterate RelevantExtensionKeys to find "kf" // if found, set ICU collator UColAttributeValue to iterator->second status = U_ZERO_ERROR; - if (case_first != CaseFirstOption::UNDEFINED) { - ASSERT(icu_collator.get() != nullptr); - icu_collator->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(case_first), status); + if (caseFirst != CaseFirstOption::UNDEFINED) { + ASSERT(icuCollator.get() != nullptr); + icuCollator->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(caseFirst), status); ASSERT(U_SUCCESS(status)); } else { - auto extension_iter = r.extensions.find("kf"); - if (extension_iter != r.extensions.end()) { - ASSERT(icu_collator.get() != nullptr); - auto map_iter = CASE_FIRST_MAP.find(extension_iter->second); - if (map_iter != CASE_FIRST_MAP.end()) { - icu_collator->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(map_iter->second), status); - JSHandle value(thread, JSTaggedValue(static_cast(map_iter->second))); + auto extensionIter = r.extensions.find("kf"); + if (extensionIter != r.extensions.end()) { + ASSERT(icuCollator.get() != nullptr); + auto mapIter = CASE_FIRST_MAP.find(extensionIter->second); + if (mapIter != CASE_FIRST_MAP.end()) { + icuCollator->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(mapIter->second), status); + JSHandle value(thread, JSTaggedValue(static_cast(mapIter->second))); collator->SetCaseFirst(thread, value); } else { - icu_collator->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(CaseFirstOption::UNDEFINED), status); + icuCollator->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(CaseFirstOption::UNDEFINED), status); } ASSERT(U_SUCCESS(status)); } @@ -237,7 +237,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // 24. Let sensitivity be ? GetOption(options, "sensitivity", "string", « "base", "accent", "case", "variant" », // undefined). auto sensitivity = JSLocale::GetOptionOfString( - thread, options_object, global_const->GetHandledSensitivityString(), + thread, optionsObject, globalConst->GetHandledSensitivityString(), {SensitivityOption::BASE, SensitivityOption::ACCENT, SensitivityOption::CASE, SensitivityOption::VARIANT}, {"base", "accent", "case", "variant"}, SensitivityOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); @@ -249,23 +249,23 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa sensitivity = SensitivityOption::VARIANT; } } - JSHandle sensitivity_value(thread, JSTaggedValue(static_cast(sensitivity))); - collator->SetSensitivity(thread, sensitivity_value); + JSHandle sensitivityValue(thread, JSTaggedValue(static_cast(sensitivity))); + collator->SetSensitivity(thread, sensitivityValue); // Trans SensitivityOption to Icu strength option switch (sensitivity) { case SensitivityOption::BASE: - icu_collator->setStrength(icu::Collator::PRIMARY); + icuCollator->setStrength(icu::Collator::PRIMARY); break; case SensitivityOption::ACCENT: - icu_collator->setStrength(icu::Collator::SECONDARY); + icuCollator->setStrength(icu::Collator::SECONDARY); break; case SensitivityOption::CASE: - icu_collator->setStrength(icu::Collator::PRIMARY); - icu_collator->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status); + icuCollator->setStrength(icu::Collator::PRIMARY); + icuCollator->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status); break; case SensitivityOption::VARIANT: - icu_collator->setStrength(icu::Collator::TERTIARY); + icuCollator->setStrength(icu::Collator::TERTIARY); break; case SensitivityOption::UNDEFINED: break; @@ -275,26 +275,26 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // 27. Let ignorePunctuation be ? GetOption(options, "ignorePunctuation", "boolean", undefined, false). // 28. Set collator.[[IgnorePunctuation]] to ignorePunctuation. - bool ignore_punctuation = false; - JSLocale::GetOptionOfBool(thread, options_object, global_const->GetHandledIgnorePunctuationString(), false, - &ignore_punctuation); - JSHandle ignore_punctuation_value(thread, JSTaggedValue(ignore_punctuation)); - collator->SetIgnorePunctuation(thread, ignore_punctuation_value); - if (ignore_punctuation) { + bool ignorePunctuation = false; + JSLocale::GetOptionOfBool(thread, optionsObject, globalConst->GetHandledIgnorePunctuationString(), false, + &ignorePunctuation); + JSHandle ignorePunctuationValue(thread, JSTaggedValue(ignorePunctuation)); + collator->SetIgnorePunctuation(thread, ignorePunctuationValue); + if (ignorePunctuation) { status = U_ZERO_ERROR; - icu_collator->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status); + icuCollator->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status); ASSERT(U_SUCCESS(status)); } - SetIcuCollator(thread, collator, icu_collator.release(), JSCollator::FreeIcuCollator); + SetIcuCollator(thread, collator, icuCollator.release(), JSCollator::FreeIcuCollator); collator->SetBoundCompare(thread, JSTaggedValue::Undefined()); // 29. Return collator. return collator; } -UColAttributeValue JSCollator::OptionToUColAttribute(CaseFirstOption case_first_option) +UColAttributeValue JSCollator::OptionToUColAttribute(CaseFirstOption caseFirstOption) { - auto iter = U_COL_ATTRIBUTE_VALUE_MAP.find(case_first_option); + auto iter = U_COL_ATTRIBUTE_VALUE_MAP.find(caseFirstOption); if (iter != U_COL_ATTRIBUTE_VALUE_MAP.end()) { return iter->second; } @@ -304,13 +304,13 @@ UColAttributeValue JSCollator::OptionToUColAttribute(CaseFirstOption case_first_ JSHandle OptionsToEcmaString(JSThread *thread, UsageOption usage) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); switch (usage) { case UsageOption::SORT: - result.Update(global_const->GetSortString()); + result.Update(globalConst->GetSortString()); break; case UsageOption::SEARCH: - result.Update(global_const->GetSearchString()); + result.Update(globalConst->GetSearchString()); break; default: UNREACHABLE(); @@ -321,19 +321,19 @@ JSHandle OptionsToEcmaString(JSThread *thread, UsageOption usage) JSHandle OptionsToEcmaString(JSThread *thread, SensitivityOption sensitivity) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); switch (sensitivity) { case SensitivityOption::BASE: - result.Update(global_const->GetBaseString()); + result.Update(globalConst->GetBaseString()); break; case SensitivityOption::ACCENT: - result.Update(global_const->GetAccentString()); + result.Update(globalConst->GetAccentString()); break; case SensitivityOption::CASE: - result.Update(global_const->GetCaseString()); + result.Update(globalConst->GetCaseString()); break; case SensitivityOption::VARIANT: - result.Update(global_const->GetVariantString()); + result.Update(globalConst->GetVariantString()); break; case SensitivityOption::UNDEFINED: break; @@ -343,22 +343,22 @@ JSHandle OptionsToEcmaString(JSThread *thread, SensitivityOption return result; } -JSHandle OptionsToEcmaString(JSThread *thread, CaseFirstOption case_first) +JSHandle OptionsToEcmaString(JSThread *thread, CaseFirstOption caseFirst) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); - switch (case_first) { + auto globalConst = thread->GlobalConstants(); + switch (caseFirst) { case CaseFirstOption::UPPER: - result.Update(global_const->GetUpperString()); + result.Update(globalConst->GetUpperString()); break; case CaseFirstOption::LOWER: - result.Update(global_const->GetLowerString()); + result.Update(globalConst->GetLowerString()); break; case CaseFirstOption::FALSE_OPTION: - result.Update(global_const->GetFalseString()); + result.Update(globalConst->GetFalseString()); break; case CaseFirstOption::UNDEFINED: - result.Update(global_const->GetUpperString()); + result.Update(globalConst->GetUpperString()); break; default: UNREACHABLE(); @@ -369,71 +369,71 @@ JSHandle OptionsToEcmaString(JSThread *thread, CaseFirstOption ca // 11.3.4 Intl.Collator.prototype.resolvedOptions () JSHandle JSCollator::ResolvedOptions(JSThread *thread, const JSHandle &collator) { - auto ecma_vm = thread->GetEcmaVM(); - auto global_const = thread->GlobalConstants(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread->GetEcmaVM(); + auto globalConst = thread->GlobalConstants(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle ctor = env->GetObjectFunction(); - JSHandle fun_ctor = JSHandle::Cast(env->GetObjectFunction()); - JSHandle options(factory->NewJSObjectByConstructor(fun_ctor, ctor)); + JSHandle funCtor = JSHandle::Cast(env->GetObjectFunction()); + JSHandle options(factory->NewJSObjectByConstructor(funCtor, ctor)); // [[Locale]] - JSHandle property = global_const->GetHandledLocaleString(); + JSHandle property = globalConst->GetHandledLocaleString(); JSHandle locale(thread, collator->GetLocale()); JSObject::CreateDataPropertyOrThrow(thread, options, property, locale); // [[Usage]] - UsageOption usage_option = static_cast(collator->GetUsage().GetNumber()); - JSHandle usage_value = OptionsToEcmaString(thread, usage_option); - JSObject::CreateDataProperty(thread, options, global_const->GetHandledUsageString(), usage_value); + UsageOption usageOption = static_cast(collator->GetUsage().GetNumber()); + JSHandle usageValue = OptionsToEcmaString(thread, usageOption); + JSObject::CreateDataProperty(thread, options, globalConst->GetHandledUsageString(), usageValue); // [[Sensitivity]] - auto sentivity_option = static_cast(collator->GetSensitivity().GetNumber()); - JSHandle sensitivity_value = OptionsToEcmaString(thread, sentivity_option); - JSObject::CreateDataProperty(thread, options, global_const->GetHandledSensitivityString(), sensitivity_value); + auto sentivityOption = static_cast(collator->GetSensitivity().GetNumber()); + JSHandle sensitivityValue = OptionsToEcmaString(thread, sentivityOption); + JSObject::CreateDataProperty(thread, options, globalConst->GetHandledSensitivityString(), sensitivityValue); // [[IgnorePunctuation]] - JSHandle ignore_punctuation_value(thread, collator->GetIgnorePunctuation()); - JSObject::CreateDataProperty(thread, options, global_const->GetHandledIgnorePunctuationString(), - ignore_punctuation_value); + JSHandle ignorePunctuationValue(thread, collator->GetIgnorePunctuation()); + JSObject::CreateDataProperty(thread, options, globalConst->GetHandledIgnorePunctuationString(), + ignorePunctuationValue); // [[Collation]] - JSMutableHandle collation_value(thread, collator->GetCollation()); - if (collation_value->IsUndefined()) { - collation_value.Update(global_const->GetDefaultString()); + JSMutableHandle collationValue(thread, collator->GetCollation()); + if (collationValue->IsUndefined()) { + collationValue.Update(globalConst->GetDefaultString()); } - JSObject::CreateDataProperty(thread, options, global_const->GetHandledCollationString(), collation_value); + JSObject::CreateDataProperty(thread, options, globalConst->GetHandledCollationString(), collationValue); // [[Numeric]] - JSHandle numeric_value(thread, collator->GetNumeric()); - JSObject::CreateDataProperty(thread, options, global_const->GetHandledNumericString(), numeric_value); + JSHandle numericValue(thread, collator->GetNumeric()); + JSObject::CreateDataProperty(thread, options, globalConst->GetHandledNumericString(), numericValue); // [[CaseFirst]] - CaseFirstOption case_first_option = static_cast(collator->GetCaseFirst().GetNumber()); + CaseFirstOption caseFirstOption = static_cast(collator->GetCaseFirst().GetNumber()); // In Ecma402 spec, caseFirst is an optional property so we set it to Upper when input is undefined // the requirement maybe change in the future - JSHandle case_first_value = OptionsToEcmaString(thread, case_first_option); - JSObject::CreateDataProperty(thread, options, global_const->GetHandledCaseFirstString(), case_first_value); + JSHandle caseFirstValue = OptionsToEcmaString(thread, caseFirstOption); + JSObject::CreateDataProperty(thread, options, globalConst->GetHandledCaseFirstString(), caseFirstValue); return options; } icu::UnicodeString EcmaStringToUString(const JSHandle &string) { - std::string std_string(ConvertToPandaString(*string, StringConvertedUsage::LOGICOPERATION)); - icu::StringPiece sp(std_string); - icu::UnicodeString u_string = icu::UnicodeString::fromUTF8(sp); - return u_string; + std::string stdString(ConvertToPandaString(*string, StringConvertedUsage::LOGICOPERATION)); + icu::StringPiece sp(stdString); + icu::UnicodeString uString = icu::UnicodeString::fromUTF8(sp); + return uString; } -JSTaggedValue JSCollator::CompareStrings(const icu::Collator *icu_collator, const JSHandle &string1, +JSTaggedValue JSCollator::CompareStrings(const icu::Collator *icuCollator, const JSHandle &string1, const JSHandle &string2) { - icu::UnicodeString u_string1 = EcmaStringToUString(string1); - icu::UnicodeString u_string2 = EcmaStringToUString(string2); + icu::UnicodeString uString1 = EcmaStringToUString(string1); + icu::UnicodeString uString2 = EcmaStringToUString(string2); UCollationResult result; UErrorCode status = U_ZERO_ERROR; - result = icu_collator->compare(u_string1, u_string2, status); + result = icuCollator->compare(uString1, uString2, status); ASSERT(U_SUCCESS(status)); return JSTaggedValue(result); diff --git a/runtime/js_collator.h b/runtime/js_collator.h index 9e5ffe7632149c9b75dc088e7d52363861273cef..4294f1bd8df5e072db9f01d862aee04c8b9ca82e 100644 --- a/runtime/js_collator.h +++ b/runtime/js_collator.h @@ -63,11 +63,11 @@ public: if (pointer == nullptr) { return; } - auto icu_collator = reinterpret_cast(pointer); - delete icu_collator; + auto icuCollator = reinterpret_cast(pointer); + delete icuCollator; } - static void SetIcuCollator(JSThread *thread, const JSHandle &collator, icu::Collator *icu_collator, + static void SetIcuCollator(JSThread *thread, const JSHandle &collator, icu::Collator *icuCollator, const DeleteEntryPoint &callback); // 11.1.1 InitializeCollator ( collator, locales, options ) @@ -80,20 +80,20 @@ public: static JSHandle GetAvailableLocales(JSThread *thread); - static JSTaggedValue CompareStrings(const icu::Collator *icu_collator, const JSHandle &string1, + static JSTaggedValue CompareStrings(const icu::Collator *icuCollator, const JSHandle &string1, const JSHandle &string2); private: static CaseFirstOption StringToCaseForstOption(const std::string &str); - static UColAttributeValue OptionToUColAttribute(CaseFirstOption case_first_option); + static UColAttributeValue OptionToUColAttribute(CaseFirstOption caseFirstOption); - static std::set BuildLocaleSet(const std::vector &available_locales, const char *path, + static std::set BuildLocaleSet(const std::vector &availableLocales, const char *path, const char *key); - static void SetNumericOption(icu::Collator *icu_collator, bool numeric); + static void SetNumericOption(icu::Collator *icuCollator, bool numeric); - static void SetCaseFirstOption(icu::Collator *icu_collator, CaseFirstOption case_first_option); + static void SetCaseFirstOption(icu::Collator *icuCollator, CaseFirstOption caseFirstOption); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JS_COLLATOR_H \ No newline at end of file diff --git a/runtime/js_date.cpp b/runtime/js_date.cpp index aefcc477a4ce50b2ee4e7c8249d8ea008a254add..178dfb7960433ee994bb8027f16df87957d4bec4 100644 --- a/runtime/js_date.cpp +++ b/runtime/js_date.cpp @@ -21,10 +21,10 @@ namespace panda::ecmascript { using NumberHelper = base::NumberHelper; -void DateUtils::TransferTimeToDate(int64_t time_ms, std::array *date) +void DateUtils::TransferTimeToDate(int64_t timeMs, std::array *date) { - (*date)[HOUR] = Mod(time_ms, MS_PER_DAY); // ms from hour, minutes, second, ms - (*date)[DAYS] = (time_ms - (*date)[HOUR]) / MS_PER_DAY; // days from year, month, day + (*date)[HOUR] = Mod(timeMs, MS_PER_DAY); // ms from hour, minutes, second, ms + (*date)[DAYS] = (timeMs - (*date)[HOUR]) / MS_PER_DAY; // days from year, month, day (*date)[MS] = (*date)[HOUR] % MS_PER_SECOND; // ms (*date)[HOUR] = ((*date)[HOUR] - (*date)[MS]) / MS_PER_SECOND; // s from hour, minutes, second (*date)[SEC] = (*date)[HOUR] % SEC_PER_MINUTE; // second @@ -68,24 +68,24 @@ int64_t DateUtils::FloorDiv(int64_t a, int64_t b) // static int64_t DateUtils::GetYearFromDays(int64_t *days) { - int64_t real_day; - int64_t day_temp = 0; + int64_t realDay; + int64_t dayTemp = 0; int64_t d = *days; int64_t year = FloorDiv(d * APPROXIMATION_NUMBER[0], APPROXIMATION_NUMBER[1]) + YEAR_NUMBER[0]; - real_day = d - GetDaysFromYear(year); - while (real_day != 0) { - if (real_day < 0) { + realDay = d - GetDaysFromYear(year); + while (realDay != 0) { + if (realDay < 0) { year--; } else { - day_temp = GetDaysInYear(year); - if (real_day < day_temp) { + dayTemp = GetDaysInYear(year); + if (realDay < dayTemp) { break; } year++; } - real_day = d - GetDaysFromYear(year); + realDay = d - GetDaysFromYear(year); } - *days = real_day; + *days = realDay; return year; } @@ -103,11 +103,11 @@ int64_t DateUtils::Mod(int64_t a, int b) double JSDate::MakeTime(double hour, double min, double sec, double ms) { if (std::isfinite(hour) && std::isfinite(min) && std::isfinite(sec) && std::isfinite(ms)) { - double hour_integer = NumberHelper::TruncateDouble(hour); - double min_integer = NumberHelper::TruncateDouble(min); - double sec_integer = NumberHelper::TruncateDouble(sec); - double ms_integer = NumberHelper::TruncateDouble(ms); - return hour_integer * MS_PER_HOUR + min_integer * MS_PER_MINUTE + sec_integer * MS_PER_SECOND + ms_integer; + double hourInteger = NumberHelper::TruncateDouble(hour); + double minInteger = NumberHelper::TruncateDouble(min); + double secInteger = NumberHelper::TruncateDouble(sec); + double msInteger = NumberHelper::TruncateDouble(ms); + return hourInteger * MS_PER_HOUR + minInteger * MS_PER_MINUTE + secInteger * MS_PER_SECOND + msInteger; } return base::NAN_VALUE; } @@ -117,10 +117,10 @@ double JSDate::MakeTime(double hour, double min, double sec, double ms) double JSDate::MakeDay(double year, double month, double date) { if (std::isfinite(year) && std::isfinite(month) && std::isfinite(date)) { - double year_integer = NumberHelper::TruncateDouble(year); - double month_integer = NumberHelper::TruncateDouble(month); - int64_t y = static_cast(year_integer) + static_cast(month_integer / MOUTH_PER_YEAR); - int64_t m = static_cast(month_integer) % MOUTH_PER_YEAR; + double yearInteger = NumberHelper::TruncateDouble(year); + double monthInteger = NumberHelper::TruncateDouble(month); + int64_t y = static_cast(yearInteger) + static_cast(monthInteger / MOUTH_PER_YEAR); + int64_t m = static_cast(monthInteger) % MOUTH_PER_YEAR; if (m < 0) { m += MOUTH_PER_YEAR; y -= 1; @@ -155,15 +155,15 @@ double JSDate::TimeClip(double time) } // 20.4.1.8 -double JSDate::LocalTime(double time_ms) const +double JSDate::LocalTime(double timeMs) const { - return time_ms + GetLocalOffsetFromOS(time_ms, true); + return timeMs + GetLocalOffsetFromOS(timeMs, true); } // 20.4.1.9 -double JSDate::UTCTime(double time_ms) const +double JSDate::UTCTime(double timeMs) const { - return time_ms - GetLocalOffsetFromOS(time_ms, false); + return timeMs - GetLocalOffsetFromOS(timeMs, false); } // static @@ -180,46 +180,46 @@ int JSDate::GetSignedNumFromString(const PandaString &str, int len, int *index) // static bool JSDate::GetNumFromString(const PandaString &str, int len, int *index, int *num) { - int index_str = *index; - char one_byte = 0; - while (index_str < len) { - one_byte = str.at(index_str); - if (one_byte >= '0' && one_byte <= '9') { + int indexStr = *index; + char oneByte = 0; + while (indexStr < len) { + oneByte = str.at(indexStr); + if (oneByte >= '0' && oneByte <= '9') { break; } - index_str++; + indexStr++; } - if (index_str >= len) { + if (indexStr >= len) { return false; } int value = 0; - while (index_str < len) { - one_byte = str.at(index_str); - int val = one_byte - '0'; + while (indexStr < len) { + oneByte = str.at(indexStr); + int val = oneByte - '0'; if (val >= 0 && val <= NUM_NINE) { value = value * TEN + val; - index_str++; + indexStr++; } else { break; } } *num = value; - *index = index_str; + *index = indexStr; return true; } // 20.4.1.7 -int64_t JSDate::GetLocalOffsetInMin(const JSThread *thread, int64_t time_ms, bool is_local) +int64_t JSDate::GetLocalOffsetInMin(const JSThread *thread, int64_t timeMs, bool isLocal) { - if (!is_local) { + if (!isLocal) { return 0; } - double local_offset = this->GetLocalOffset().GetDouble(); - if (local_offset == MAX_DOUBLE) { - local_offset = static_cast(GetLocalOffsetFromOS(time_ms, is_local)); - SetLocalOffset(thread, JSTaggedValue(local_offset)); + double localOffset = this->GetLocalOffset().GetDouble(); + if (localOffset == MAX_DOUBLE) { + localOffset = static_cast(GetLocalOffsetFromOS(timeMs, isLocal)); + SetLocalOffset(thread, JSTaggedValue(localOffset)); } - return local_offset; + return localOffset; } // static @@ -234,20 +234,20 @@ JSTaggedValue JSDate::LocalParseStringToMs(const PandaString &str) int ms = 0; int index = 0; int len = str.length(); - bool is_local = false; - PandaString::size_type index_gmt; - PandaString::size_type index_plus = PandaString::npos; - std::array month_name = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - int local_time = 0; - int local_hours = 0; - int local_minutes = 0; - int64_t local_ms = 0; - PandaString::size_type local_space; - local_space = str.find(' ', index); - PandaString str_month = str.substr(local_space + 1, LENGTH_MONTH_NAME); + bool isLocal = false; + PandaString::size_type indexGmt; + PandaString::size_type indexPlus = PandaString::npos; + std::array monthName = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + int localTime = 0; + int localHours = 0; + int localMinutes = 0; + int64_t localMs = 0; + PandaString::size_type localSpace; + localSpace = str.find(' ', index); + PandaString strMonth = str.substr(localSpace + 1, LENGTH_MONTH_NAME); for (int i = 0; i < MOUTH_PER_YEAR; i++) { - if (str_month == month_name[i]) { + if (strMonth == monthName[i]) { month = i; break; } @@ -255,39 +255,39 @@ JSTaggedValue JSDate::LocalParseStringToMs(const PandaString &str) index += (LENGTH_MONTH_NAME + 1); GetNumFromString(str, len, &index, &date); GetNumFromString(str, len, &index, &year); - index_gmt = str.find("GMT", index); - if (index_gmt == PandaString::npos) { + indexGmt = str.find("GMT", index); + if (indexGmt == PandaString::npos) { GetNumFromString(str, len, &index, &hours); GetNumFromString(str, len, &index, &minutes); GetNumFromString(str, len, &index, &seconds); - is_local = true; - local_ms -= (GetLocalOffsetFromOS(local_ms, true) * MS_PER_MINUTE); + isLocal = true; + localMs -= (GetLocalOffsetFromOS(localMs, true) * MS_PER_MINUTE); } else { - index_plus = str.find(PLUS, index_gmt); - int index_local = static_cast(index_gmt); - GetNumFromString(str, index_gmt, &index, &hours); - GetNumFromString(str, index_gmt, &index, &minutes); - GetNumFromString(str, index_gmt, &index, &seconds); - GetNumFromString(str, len, &index_local, &local_time); - local_hours = local_time / HUNDRED; - local_minutes = local_time % HUNDRED; - local_ms = static_cast(MakeTime(local_hours, local_minutes, 0, 0)); - if (index_plus != PandaString::npos) { - local_ms = -local_ms; + indexPlus = str.find(PLUS, indexGmt); + int indexLocal = static_cast(indexGmt); + GetNumFromString(str, indexGmt, &index, &hours); + GetNumFromString(str, indexGmt, &index, &minutes); + GetNumFromString(str, indexGmt, &index, &seconds); + GetNumFromString(str, len, &indexLocal, &localTime); + localHours = localTime / HUNDRED; + localMinutes = localTime % HUNDRED; + localMs = static_cast(MakeTime(localHours, localMinutes, 0, 0)); + if (indexPlus != PandaString::npos) { + localMs = -localMs; } } double day = MakeDay(year, month, date); double time = MakeTime(hours, minutes, seconds, ms); - double time_value = TimeClip(MakeDate(day, time)); - if (std::isnan(time_value)) { - return JSTaggedValue(time_value); + double timeValue = TimeClip(MakeDate(day, time)); + if (std::isnan(timeValue)) { + return JSTaggedValue(timeValue); } - if (is_local && time_value < CHINA_1901_MS && (-local_ms / MS_PER_MINUTE) == CHINA_AFTER_1901_MIN) { - time_value += static_cast(local_ms - CHINA_BEFORE_1901_MS); + if (isLocal && timeValue < CHINA_1901_MS && (-localMs / MS_PER_MINUTE) == CHINA_AFTER_1901_MIN) { + timeValue += static_cast(localMs - CHINA_BEFORE_1901_MS); } else { - time_value += local_ms; + timeValue += localMs; } - return JSTaggedValue(time_value); + return JSTaggedValue(timeValue); } // static @@ -302,58 +302,58 @@ JSTaggedValue JSDate::UtcParseStringToMs(const PandaString &str) int ms = 0; int index = 0; int len = str.length(); - PandaString::size_type index_gmt; - PandaString::size_type index_plus = PandaString::npos; - int local_time = 0; - int local_hours = 0; - int local_minutes = 0; - int64_t local_ms = 0; - bool is_local = false; - std::array month_name = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + PandaString::size_type indexGmt; + PandaString::size_type indexPlus = PandaString::npos; + int localTime = 0; + int localHours = 0; + int localMinutes = 0; + int64_t localMs = 0; + bool isLocal = false; + std::array monthName = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; GetNumFromString(str, len, &index, &date); - PandaString str_month = str.substr(index + 1, LENGTH_MONTH_NAME); + PandaString strMonth = str.substr(index + 1, LENGTH_MONTH_NAME); for (int i = 0; i < MOUTH_PER_YEAR; i++) { - if (str_month == month_name[i]) { + if (strMonth == monthName[i]) { month = i; break; } } index += (LENGTH_MONTH_NAME + 1); GetNumFromString(str, len, &index, &year); - index_gmt = str.find("GMT", index); - if (index_gmt == PandaString::npos) { + indexGmt = str.find("GMT", index); + if (indexGmt == PandaString::npos) { GetNumFromString(str, len, &index, &hours); GetNumFromString(str, len, &index, &minutes); GetNumFromString(str, len, &index, &seconds); - is_local = true; - local_ms -= (GetLocalOffsetFromOS(local_ms, true) * MS_PER_MINUTE); + isLocal = true; + localMs -= (GetLocalOffsetFromOS(localMs, true) * MS_PER_MINUTE); } else { - index_plus = str.find(PLUS, index_gmt); - int index_local = static_cast(index_gmt); - GetNumFromString(str, index_gmt, &index, &hours); - GetNumFromString(str, index_gmt, &index, &minutes); - GetNumFromString(str, index_gmt, &index, &seconds); - GetNumFromString(str, len, &index_local, &local_time); - local_hours = local_time / HUNDRED; - local_minutes = local_time % HUNDRED; - local_ms = static_cast(MakeTime(local_hours, local_minutes, 0, 0)); - if (index_plus != PandaString::npos) { - local_ms = -local_ms; + indexPlus = str.find(PLUS, indexGmt); + int indexLocal = static_cast(indexGmt); + GetNumFromString(str, indexGmt, &index, &hours); + GetNumFromString(str, indexGmt, &index, &minutes); + GetNumFromString(str, indexGmt, &index, &seconds); + GetNumFromString(str, len, &indexLocal, &localTime); + localHours = localTime / HUNDRED; + localMinutes = localTime % HUNDRED; + localMs = static_cast(MakeTime(localHours, localMinutes, 0, 0)); + if (indexPlus != PandaString::npos) { + localMs = -localMs; } } double day = MakeDay(year, month, date); double time = MakeTime(hours, minutes, seconds, ms); - double time_value = TimeClip(MakeDate(day, time)); - if (std::isnan(time_value)) { - return JSTaggedValue(time_value); + double timeValue = TimeClip(MakeDate(day, time)); + if (std::isnan(timeValue)) { + return JSTaggedValue(timeValue); } - if (is_local && time_value < CHINA_1901_MS && (-local_ms / MS_PER_MINUTE) == CHINA_AFTER_1901_MIN) { - time_value += static_cast(local_ms - CHINA_BEFORE_1901_MS); + if (isLocal && timeValue < CHINA_1901_MS && (-localMs / MS_PER_MINUTE) == CHINA_AFTER_1901_MIN) { + timeValue += static_cast(localMs - CHINA_BEFORE_1901_MS); } else { - time_value += local_ms; + timeValue += localMs; } - return JSTaggedValue(time_value); + return JSTaggedValue(timeValue); } // static JSTaggedValue JSDate::IsoParseStringToMs(const PandaString &str) @@ -369,32 +369,32 @@ JSTaggedValue JSDate::IsoParseStringToMs(const PandaString &str) int index = 0; int len = str.length(); year = GetSignedNumFromString(str, len, &index); - PandaString::size_type index_t = str.find(FLAG_TIME, index); - PandaString::size_type index_z = str.find(FLAG_UTC, index); - PandaString::size_type index_end_flag = 0; - int64_t local_ms = 0; - if (index_z != PandaString::npos) { - index_end_flag = index_z; + PandaString::size_type indexT = str.find(FLAG_TIME, index); + PandaString::size_type indexZ = str.find(FLAG_UTC, index); + PandaString::size_type indexEndFlag = 0; + int64_t localMs = 0; + if (indexZ != PandaString::npos) { + indexEndFlag = indexZ; } else if (len >= MIN_LENGTH && str.at(len - INDEX_PLUS_NEG) == NEG) { - index_end_flag = len - INDEX_PLUS_NEG; + indexEndFlag = len - INDEX_PLUS_NEG; flag = NEG; } else if (len >= MIN_LENGTH && str.at(len - INDEX_PLUS_NEG) == PLUS) { - index_end_flag = len - INDEX_PLUS_NEG; + indexEndFlag = len - INDEX_PLUS_NEG; flag = PLUS; } - if (index_t != PandaString::npos) { - if ((index_t - index) == LENGTH_PER_TIME) { + if (indexT != PandaString::npos) { + if ((indexT - index) == LENGTH_PER_TIME) { GetNumFromString(str, len, &index, &month); - } else if ((index_t - index) == (LENGTH_PER_TIME + LENGTH_PER_TIME)) { + } else if ((indexT - index) == (LENGTH_PER_TIME + LENGTH_PER_TIME)) { GetNumFromString(str, len, &index, &month); GetNumFromString(str, len, &index, &date); } GetNumFromString(str, len, &index, &hours); GetNumFromString(str, len, &index, &minutes); - if (index_end_flag > 0) { - if (index_end_flag - index == LENGTH_PER_TIME) { + if (indexEndFlag > 0) { + if (indexEndFlag - index == LENGTH_PER_TIME) { GetNumFromString(str, len, &index, &seconds); - } else if (index_end_flag - index == (LENGTH_PER_TIME + LENGTH_PER_TIME + 1)) { + } else if (indexEndFlag - index == (LENGTH_PER_TIME + LENGTH_PER_TIME + 1)) { GetNumFromString(str, len, &index, &seconds); GetNumFromString(str, len, &index, &ms); } @@ -410,35 +410,35 @@ JSTaggedValue JSDate::IsoParseStringToMs(const PandaString &str) GetNumFromString(str, len, &index, &month); GetNumFromString(str, len, &index, &date); } - if (index_end_flag > 0) { - int local_hours = 0; - int local_minutes = 0; - if (index_z == PandaString::npos) { - GetNumFromString(str, len, &index, &local_hours); - GetNumFromString(str, len, &index, &local_minutes); + if (indexEndFlag > 0) { + int localHours = 0; + int localMinutes = 0; + if (indexZ == PandaString::npos) { + GetNumFromString(str, len, &index, &localHours); + GetNumFromString(str, len, &index, &localMinutes); if (flag == PLUS) { - local_ms = static_cast(-MakeTime(local_hours, local_minutes, 0, 0)); + localMs = static_cast(-MakeTime(localHours, localMinutes, 0, 0)); } else { - local_ms = static_cast(MakeTime(local_hours, local_minutes, 0, 0)); + localMs = static_cast(MakeTime(localHours, localMinutes, 0, 0)); } } } - if (index_end_flag == 0 && index_t != PandaString::npos) { - local_ms -= (GetLocalOffsetFromOS(local_ms, true) * MS_PER_MINUTE); + if (indexEndFlag == 0 && indexT != PandaString::npos) { + localMs -= (GetLocalOffsetFromOS(localMs, true) * MS_PER_MINUTE); } double day = MakeDay(year, month - 1, date); double time = MakeTime(hours, minutes, seconds, ms); - double time_value = TimeClip(MakeDate(day, time)); - if (std::isnan(time_value)) { - return JSTaggedValue(time_value); + double timeValue = TimeClip(MakeDate(day, time)); + if (std::isnan(timeValue)) { + return JSTaggedValue(timeValue); } - if (flag == 0 && time_value < CHINA_1901_MS && (-local_ms / MS_PER_MINUTE) == CHINA_AFTER_1901_MIN) { - time_value += static_cast(local_ms - CHINA_BEFORE_1901_MS); + if (flag == 0 && timeValue < CHINA_1901_MS && (-localMs / MS_PER_MINUTE) == CHINA_AFTER_1901_MIN) { + timeValue += static_cast(localMs - CHINA_BEFORE_1901_MS); } else { - time_value += local_ms; + timeValue += localMs; } - return JSTaggedValue(time_value); + return JSTaggedValue(timeValue); } // 20.4.3.2 static @@ -446,42 +446,42 @@ JSTaggedValue JSDate::Parse(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - const PandaString iso_pri_str = "(^|(\\+|-)(\\d{2}))"; - const PandaString iso_date_str = + const PandaString isoPriStr = "(^|(\\+|-)(\\d{2}))"; + const PandaString isoDateStr = "(((\\d{4})-(0?[1-9]|1[0-2])-(0?[1-9]|1[0-9]|2[0-9]|3[0-1]))" "|((\\d{4})-(0?[1-9]|1[0-2]))|(\\d{4}))"; - const PandaString iso_time_str = + const PandaString isoTimeStr = "((T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])" "\\.(\\d{3}))|(T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]))|" "(T([01][0-9]|2[0-3]):([0-5][0-9]))|(T([01][0-9]|2[0-3])))" "($|Z|((\\+|-)(([01][0-9]|2[0-3]):([0-5][0-9]))))"; - const PandaString iso_reg_str = iso_pri_str + iso_date_str + "($|Z|(" + iso_time_str + "))"; - const PandaString utc_date_str = + const PandaString isoRegStr = isoPriStr + isoDateStr + "($|Z|(" + isoTimeStr + "))"; + const PandaString utcDateStr = "^\\D*(0?[1-9]|1[0-9]|2[0-9]|3[0-1]) " "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\\d{4})"; - const PandaString time_str = + const PandaString timeStr = "(( ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]))|( ([01][0-9]|2[0-3]):([0-5][0-9])))" "($| *| GMT *| GMT((\\+|-)(\\d{4})) *)"; - const PandaString utc_reg_str = utc_date_str + "($| *| GMT *| GMT((\\+|-)(\\d{4})) *|(" + time_str + "))"; - const PandaString local_date_str = + const PandaString utcRegStr = utcDateStr + "($| *| GMT *| GMT((\\+|-)(\\d{4})) *|(" + timeStr + "))"; + const PandaString localDateStr = "^[a-zA-Z]* (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) " "(0?[1-9]|1[0-9]|2[0-9]|3[0-1]) (\\d{4})"; - const PandaString local_reg_str = local_date_str + "($| *| GMT *| GMT((\\+|-)(\\d{4})) *|(" + time_str + "))"; + const PandaString localRegStr = localDateStr + "($| *| GMT *| GMT((\\+|-)(\\d{4})) *|(" + timeStr + "))"; - std::regex iso_reg(iso_reg_str); - std::regex utc_reg(utc_reg_str); - std::regex local_reg(local_reg_str); + std::regex isoReg(isoRegStr); + std::regex utcReg(utcRegStr); + std::regex localReg(localRegStr); JSHandle msg = builtins_common::GetCallArg(argv, 0); JSHandle str = JSHandle::Cast(JSTaggedValue::ToString(thread, msg)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); PandaString date = ConvertToPandaString(EcmaString::Cast(str->GetTaggedObject())); - if (std::regex_match(date, iso_reg)) { + if (std::regex_match(date, isoReg)) { return IsoParseStringToMs(date); } - if (std::regex_match(date, utc_reg)) { + if (std::regex_match(date, utcReg)) { return UtcParseStringToMs(date); } - if (std::regex_match(date, local_reg)) { + if (std::regex_match(date, localReg)) { return LocalParseStringToMs(date); } return JSTaggedValue(base::NAN_VALUE); @@ -509,12 +509,12 @@ JSTaggedValue JSDate::UTC(EcmaRuntimeCallInfo *argv) double seconds = 0; double ms = 0; JSThread *thread = argv->GetThread(); - JSHandle year_arg = builtins_common::GetCallArg(argv, 0); - JSTaggedNumber year_value = JSTaggedValue::ToNumber(thread, year_arg); + JSHandle yearArg = builtins_common::GetCallArg(argv, 0); + JSTaggedNumber yearValue = JSTaggedValue::ToNumber(thread, yearArg); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - if (year_value.IsNumber()) { - year = year_value.GetNumber(); - if (std::isfinite(year) && !year_value.IsInt()) { + if (yearValue.IsNumber()) { + year = yearValue.GetNumber(); + if (std::isfinite(year) && !yearValue.IsInt()) { year = NumberHelper::TruncateDouble(year); } if (year >= 0 && year <= (HUNDRED - 1)) { @@ -524,44 +524,44 @@ JSTaggedValue JSDate::UTC(EcmaRuntimeCallInfo *argv) year = base::NAN_VALUE; } uint32_t index = 1; - uint32_t num_args = argv->GetArgsNumber(); + uint32_t numArgs = argv->GetArgsNumber(); JSTaggedValue res; - if (num_args > index) { + if (numArgs > index) { JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); month = res.GetNumber(); index++; } - if (num_args > index) { + if (numArgs > index) { JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); date = res.GetNumber(); index++; } - if (num_args > index) { + if (numArgs > index) { JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); hours = res.GetNumber(); index++; } - if (num_args > index) { + if (numArgs > index) { JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); minutes = res.GetNumber(); index++; } - if (num_args > index) { + if (numArgs > index) { JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); seconds = res.GetNumber(); index++; } - if (num_args > index) { + if (numArgs > index) { JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -572,14 +572,14 @@ JSTaggedValue JSDate::UTC(EcmaRuntimeCallInfo *argv) return JSTaggedValue(TimeClip(MakeDate(day, time))); } -int64_t JSDate::GetLocalOffsetFromOS(int64_t time_ms, bool is_local) +int64_t JSDate::GetLocalOffsetFromOS(int64_t timeMs, bool isLocal) { // Preserve the old behavior for non-ICU implementation by ignoring both timeMs and is_utc. - if (!is_local) { + if (!isLocal) { return 0; } - time_ms /= JSDate::THOUSAND; - time_t tv = std::time(reinterpret_cast(&time_ms)); + timeMs /= JSDate::THOUSAND; + time_t tv = std::time(reinterpret_cast(&timeMs)); struct tm tm {}; // localtime_r is only suitable for linux. struct tm *t = localtime_r(&tv, &tm); @@ -615,68 +615,68 @@ PandaString JSDate::StrToTargetLength(const PandaString &str, int length) return sub; } -bool JSDate::GetThisDateValues(std::array *date, bool is_local) const +bool JSDate::GetThisDateValues(std::array *date, bool isLocal) const { - double time_ms = this->GetTimeValue().GetDouble(); - if (std::isnan(time_ms)) { + double timeMs = this->GetTimeValue().GetDouble(); + if (std::isnan(timeMs)) { return false; } - GetDateValues(time_ms, date, is_local); + GetDateValues(timeMs, date, isLocal); return true; } // 20.4.4.35 JSTaggedValue JSDate::ToDateString(JSThread *thread) const { - std::array month_name = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - std::array weekday_name = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + std::array monthName = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + std::array weekdayName = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; std::array fields = {0}; if (!GetThisDateValues(&fields, true)) { return JSTaggedValue(base::NAN_VALUE); } PandaString year = StrToTargetLength(ToPandaString(fields[YEAR]), STR_LENGTH_YEAR); PandaString day = StrToTargetLength(ToPandaString(fields[DAYS]), STR_LENGTH_OTHERS); - PandaString str = weekday_name[fields[WEEKDAY]] + SPACE + month_name[fields[MONTH]] + SPACE + day + SPACE + year; + PandaString str = weekdayName[fields[WEEKDAY]] + SPACE + monthName[fields[MONTH]] + SPACE + day + SPACE + year; JSHandle result = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); return result.GetTaggedValue(); } // static -PandaString JSDate::ToDateString(double time_ms) +PandaString JSDate::ToDateString(double timeMs) { - if (std::isnan(time_ms)) { + if (std::isnan(timeMs)) { return "Invalid Date"; } - std::array month_name = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - std::array weekday_name = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + std::array monthName = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + std::array weekdayName = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; std::array fields = {0}; - GetDateValues(time_ms, &fields, true); - PandaString local_time; - int local_min = 0; - local_min = GetLocalOffsetFromOS(local_min, true); - if (time_ms < CHINA_BEFORE_1900_MS && local_min == CHINA_AFTER_1901_MIN) { - local_min = CHINA_BEFORE_1901_MIN; - } - if (local_min >= 0) { - local_time += PLUS; - } else if (local_min < 0) { - local_time += NEG; - local_min = -local_min; - } - local_time = local_time + StrToTargetLength(ToPandaString(local_min / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - local_time = local_time + StrToTargetLength(ToPandaString(local_min % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + GetDateValues(timeMs, &fields, true); + PandaString localTime; + int localMin = 0; + localMin = GetLocalOffsetFromOS(localMin, true); + if (timeMs < CHINA_BEFORE_1900_MS && localMin == CHINA_AFTER_1901_MIN) { + localMin = CHINA_BEFORE_1901_MIN; + } + if (localMin >= 0) { + localTime += PLUS; + } else if (localMin < 0) { + localTime += NEG; + localMin = -localMin; + } + localTime = localTime + StrToTargetLength(ToPandaString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + localTime = localTime + StrToTargetLength(ToPandaString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); PandaString year = ToPandaString(fields[YEAR]); year = StrToTargetLength(year, STR_LENGTH_YEAR); - PandaString weekday = weekday_name[fields[WEEKDAY]]; - PandaString month = month_name[fields[MONTH]]; + PandaString weekday = weekdayName[fields[WEEKDAY]]; + PandaString month = monthName[fields[MONTH]]; PandaString day = StrToTargetLength(ToPandaString(fields[DAYS]), STR_LENGTH_OTHERS); PandaString hour = StrToTargetLength(ToPandaString(fields[HOUR]), STR_LENGTH_OTHERS); PandaString minute = StrToTargetLength(ToPandaString(fields[MIN]), STR_LENGTH_OTHERS); PandaString second = StrToTargetLength(ToPandaString(fields[SEC]), STR_LENGTH_OTHERS); PandaString str = weekday + SPACE + month + SPACE + day + SPACE + year + SPACE + hour + COLON + minute + COLON + - second + SPACE + "GMT" + local_time; + second + SPACE + "GMT" + localTime; return str; } // 20.4.4.36 @@ -756,9 +756,9 @@ JSTaggedValue JSDate::ToLocaleString(JSThread *thread) const if (!GetThisDateValues(&fields, true)) { return JSTaggedValue(base::NAN_VALUE); } - PandaString str_date = GetLocaleDateStr(fields); - PandaString str_time = GetLocaleTimeStr(fields); - return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str_date + SPACE + str_time).GetTaggedValue(); + PandaString strDate = GetLocaleDateStr(fields); + PandaString strTime = GetLocaleTimeStr(fields); + return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(strDate + SPACE + strTime).GetTaggedValue(); } // 20.4.4.40 @@ -775,84 +775,84 @@ JSTaggedValue JSDate::ToLocaleTimeString(JSThread *thread) const // 20.4.4.41 JSTaggedValue JSDate::ToString(JSThread *thread) const { - std::array weekday_name = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; - std::array month_name = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - int local_min = 0; + std::array weekdayName = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + std::array monthName = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + int localMin = 0; std::array fields = {0}; if (!GetThisDateValues(&fields, true)) { return JSTaggedValue(base::NAN_VALUE); } - PandaString local_time; - local_min = GetLocalOffsetFromOS(local_min, true); + PandaString localTime; + localMin = GetLocalOffsetFromOS(localMin, true); if (static_cast(this->GetTimeValue().GetDouble()) < CHINA_BEFORE_1900_MS && - local_min == CHINA_AFTER_1901_MIN) { - local_min = CHINA_BEFORE_1901_MIN; + localMin == CHINA_AFTER_1901_MIN) { + localMin = CHINA_BEFORE_1901_MIN; } - if (local_min >= 0) { - local_time += PLUS; - } else if (local_min < 0) { - local_time += NEG; - local_min = -local_min; + if (localMin >= 0) { + localTime += PLUS; + } else if (localMin < 0) { + localTime += NEG; + localMin = -localMin; } - local_time = local_time + StrToTargetLength(ToPandaString(local_min / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - local_time = local_time + StrToTargetLength(ToPandaString(local_min % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + localTime = localTime + StrToTargetLength(ToPandaString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + localTime = localTime + StrToTargetLength(ToPandaString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); PandaString year = ToPandaString(fields[YEAR]); year = StrToTargetLength(year, STR_LENGTH_YEAR); - PandaString weekday = weekday_name[fields[WEEKDAY]]; - PandaString month = month_name[fields[MONTH]]; + PandaString weekday = weekdayName[fields[WEEKDAY]]; + PandaString month = monthName[fields[MONTH]]; PandaString day = StrToTargetLength(ToPandaString(fields[DAYS]), STR_LENGTH_OTHERS); PandaString hour = StrToTargetLength(ToPandaString(fields[HOUR]), STR_LENGTH_OTHERS); PandaString minute = StrToTargetLength(ToPandaString(fields[MIN]), STR_LENGTH_OTHERS); PandaString second = StrToTargetLength(ToPandaString(fields[SEC]), STR_LENGTH_OTHERS); PandaString str = weekday + SPACE + month + SPACE + day + SPACE + year + SPACE + hour + COLON + minute + COLON + - second + SPACE + "GMT" + local_time; + second + SPACE + "GMT" + localTime; return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str).GetTaggedValue(); } // 20.4.4.42 JSTaggedValue JSDate::ToTimeString(JSThread *thread) const { - int local_min = 0; + int localMin = 0; std::array fields = {0}; if (!GetThisDateValues(&fields, true)) { return JSTaggedValue(base::NAN_VALUE); } - PandaString local_time; - local_min = GetLocalOffsetFromOS(local_min, true); + PandaString localTime; + localMin = GetLocalOffsetFromOS(localMin, true); if (static_cast(this->GetTimeValue().GetDouble()) < CHINA_BEFORE_1900_MS && - local_min == CHINA_AFTER_1901_MIN) { - local_min = CHINA_BEFORE_1901_MIN; + localMin == CHINA_AFTER_1901_MIN) { + localMin = CHINA_BEFORE_1901_MIN; } - if (local_min >= 0) { - local_time += PLUS; + if (localMin >= 0) { + localTime += PLUS; } else { - local_time += NEG; - local_min = -local_min; + localTime += NEG; + localMin = -localMin; } - local_time = local_time + StrToTargetLength(ToPandaString(local_min / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - local_time = local_time + StrToTargetLength(ToPandaString(local_min % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + localTime = localTime + StrToTargetLength(ToPandaString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + localTime = localTime + StrToTargetLength(ToPandaString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); PandaString hour = StrToTargetLength(ToPandaString(fields[HOUR]), STR_LENGTH_OTHERS); PandaString minute = StrToTargetLength(ToPandaString(fields[MIN]), STR_LENGTH_OTHERS); PandaString second = StrToTargetLength(ToPandaString(fields[SEC]), STR_LENGTH_OTHERS); - PandaString str = hour + COLON + minute + COLON + second + SPACE + "GMT" + local_time; + PandaString str = hour + COLON + minute + COLON + second + SPACE + "GMT" + localTime; return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str).GetTaggedValue(); } // 20.4.4.43 JSTaggedValue JSDate::ToUTCString(JSThread *thread) const { - std::array weekday_name = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; - std::array month_name = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + std::array weekdayName = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + std::array monthName = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; std::array fields = {0}; if (!GetThisDateValues(&fields, false)) { return JSTaggedValue(base::NAN_VALUE); } PandaString year = ToPandaString(fields[YEAR]); year = StrToTargetLength(year, STR_LENGTH_YEAR); - PandaString weekday = weekday_name[fields[WEEKDAY]]; - PandaString month = month_name[fields[MONTH]]; + PandaString weekday = weekdayName[fields[WEEKDAY]]; + PandaString month = monthName[fields[MONTH]]; PandaString day = StrToTargetLength(ToPandaString(fields[DAYS]), STR_LENGTH_OTHERS); PandaString hour = StrToTargetLength(ToPandaString(fields[HOUR]), STR_LENGTH_OTHERS); PandaString minute = StrToTargetLength(ToPandaString(fields[MIN]), STR_LENGTH_OTHERS); @@ -870,24 +870,24 @@ JSTaggedValue JSDate::ValueOf() const } // static -void JSDate::GetDateValues(double time_ms, std::array *date, bool is_local) +void JSDate::GetDateValues(double timeMs, std::array *date, bool isLocal) { int64_t tz = 0; - int64_t time_ms_int; + int64_t timeMsInt; int month = 0; - time_ms_int = static_cast(time_ms); - if (is_local) { // timezone offset - tz = GetLocalOffsetFromOS(time_ms_int, is_local); - if (time_ms_int < CHINA_BEFORE_1900_MS && tz == CHINA_AFTER_1901_MIN) { - time_ms_int += CHINA_BEFORE_1901_ADDMS; - time_ms_int += tz * MS_PER_SECOND * SEC_PER_MINUTE; + timeMsInt = static_cast(timeMs); + if (isLocal) { // timezone offset + tz = GetLocalOffsetFromOS(timeMsInt, isLocal); + if (timeMsInt < CHINA_BEFORE_1900_MS && tz == CHINA_AFTER_1901_MIN) { + timeMsInt += CHINA_BEFORE_1901_ADDMS; + timeMsInt += tz * MS_PER_SECOND * SEC_PER_MINUTE; tz = CHINA_BEFORE_1901_MIN; } else { - time_ms_int += tz * MS_PER_SECOND * SEC_PER_MINUTE; + timeMsInt += tz * MS_PER_SECOND * SEC_PER_MINUTE; } } - DateUtils::TransferTimeToDate(time_ms_int, date); + DateUtils::TransferTimeToDate(timeMsInt, date); int index = DateUtils::IsLeap((*date)[YEAR]) ? 1 : 0; int left = 0; @@ -911,22 +911,22 @@ void JSDate::GetDateValues(double time_ms, std::array *dat (*date)[TIMEZONE] = -tz; } -double JSDate::GetDateValue(double time_ms, uint8_t code, bool is_local) const +double JSDate::GetDateValue(double timeMs, uint8_t code, bool isLocal) const { - if (std::isnan(time_ms)) { + if (std::isnan(timeMs)) { return base::NAN_VALUE; } std::array date = {0}; - GetDateValues(time_ms, &date, is_local); + GetDateValues(timeMs, &date, isLocal); return static_cast(date[code]); } -JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, bool is_local) const +JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, bool isLocal) const { // get date values. std::array date = {0}; - double time_ms = this->GetTimeValue().GetDouble(); - if (std::isnan(time_ms)) { + double timeMs = this->GetTimeValue().GetDouble(); + if (std::isnan(timeMs)) { return JSTaggedValue(base::NAN_VALUE); } @@ -936,17 +936,17 @@ JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, boo return JSTaggedValue(base::NAN_VALUE); } - uint32_t first_value = code & CODE_FLAG; - uint32_t end_value = (code >> CODE_4_BIT) & CODE_FLAG; - uint32_t count = end_value - first_value; + uint32_t firstValue = code & CODE_FLAG; + uint32_t endValue = (code >> CODE_4_BIT) & CODE_FLAG; + uint32_t count = endValue - firstValue; if (argc < count) { count = argc; } - GetDateValues(time_ms, &date, is_local); + GetDateValues(timeMs, &date, isLocal); - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); for (uint32_t i = 0; i < count; i++) { JSHandle value = builtins_common::GetCallArg(argv, i); JSThread *thread = argv->GetThread(); @@ -956,14 +956,14 @@ JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, boo if (std::isnan(temp)) { return JSTaggedValue(base::NAN_VALUE); } - date[first_value + i] = NumberHelper::TruncateDouble(temp); + date[firstValue + i] = NumberHelper::TruncateDouble(temp); } // set date values. - return JSTaggedValue(SetDateValues(&date, is_local)); + return JSTaggedValue(SetDateValues(&date, isLocal)); } // static -double JSDate::SetDateValues(const std::array *date, bool is_local) +double JSDate::SetDateValues(const std::array *date, bool isLocal) { int64_t month = DateUtils::Mod((*date)[MONTH], MONTH_PER_YEAR); int64_t year = (*date)[YEAR] + ((*date)[MONTH] - month) / MONTH_PER_YEAR; @@ -975,8 +975,8 @@ double JSDate::SetDateValues(const std::array *date, bool int64_t millisecond = (((*date)[HOUR] * MIN_PER_HOUR + (*date)[MIN]) * SEC_PER_MINUTE + (*date)[SEC]) * MS_PER_SECOND + (*date)[MS]; int64_t result = days * MS_PER_DAY + millisecond; - if (is_local) { - int64_t offset = GetLocalOffsetFromOS(result, is_local) * SEC_PER_MINUTE * MS_PER_SECOND; + if (isLocal) { + int64_t offset = GetLocalOffsetFromOS(result, isLocal) * SEC_PER_MINUTE * MS_PER_SECOND; if (result < CHINA_1901_MS && (offset / MS_PER_MINUTE) == CHINA_AFTER_1901_MIN) { offset += CHINA_BEFORE_1901_ADDMS; } diff --git a/runtime/js_date.h b/runtime/js_date.h index 4a17c0b88108fb10717afb830c66a66b57badc7e..b105ae0c8e0581a4fed4cde860044beef1db241e 100644 --- a/runtime/js_date.h +++ b/runtime/js_date.h @@ -52,7 +52,7 @@ static constexpr std::array YEAR_NUMBER = {1970, 1969, 1901, 1601}; class DateUtils { public: - static void TransferTimeToDate(int64_t time_ms, std::array *date); + static void TransferTimeToDate(int64_t timeMs, std::array *date); static int64_t Mod(int64_t a, int b); static bool IsLeap(int64_t year); static int64_t GetDaysInYear(int64_t year); @@ -81,13 +81,13 @@ public: static bool GetNumFromString(const PandaString &str, int len, int *index, int *num); // 20.4.1.7 - int64_t GetLocalOffsetInMin(const JSThread *thread, int64_t time_ms, bool is_local); + int64_t GetLocalOffsetInMin(const JSThread *thread, int64_t timeMs, bool isLocal); // 20.4.1.8 - double LocalTime(double time_ms) const; + double LocalTime(double timeMs) const; // 20.4.1.9 - double UTCTime(double time_ms) const; + double UTCTime(double timeMs) const; // 20.4.3.1 static JSTaggedValue Now(); @@ -106,7 +106,7 @@ public: // 20.4.4.35 JSTaggedValue ToDateString(JSThread *thread) const; - static PandaString ToDateString(double time_ms); + static PandaString ToDateString(double timeMs); // 20.4.4.36 JSTaggedValue ToISOString(JSThread *thread) const; @@ -132,22 +132,22 @@ public: // 20.4.4.44 JSTaggedValue ValueOf() const; - JSTaggedValue SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, bool is_local) const; - double GetDateValue(double time_ms, uint8_t code, bool is_local) const; + JSTaggedValue SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, bool isLocal) const; + double GetDateValue(double timeMs, uint8_t code, bool isLocal) const; static constexpr double MAX_DOUBLE = std::numeric_limits::max(); static constexpr double MAX_INT = std::numeric_limits::max(); static constexpr uint16_t NINETEEN_HUNDRED_YEAR = 1900; static constexpr uint16_t HUNDRED = 100; static constexpr uint16_t THOUSAND = 1000; - static double SetDateValues(const std::array *date, bool is_local); - static void GetDateValues(double time_ms, std::array *date, bool is_local); - static int64_t GetLocalOffsetFromOS(int64_t time_ms, bool is_local); + static double SetDateValues(const std::array *date, bool isLocal); + static void GetDateValues(double timeMs, std::array *date, bool isLocal); + static int64_t GetLocalOffsetFromOS(int64_t timeMs, bool isLocal); static PandaString StrToTargetLength(const PandaString &str, int length); DECL_DUMP() private: - bool GetThisDateValues(std::array *date, bool is_local) const; + bool GetThisDateValues(std::array *date, bool isLocal) const; PandaString GetLocaleTimeStr(const std::array &fields) const; PandaString GetLocaleDateStr(const std::array &fields) const; static int64_t MathMod(int64_t a, int b); diff --git a/runtime/js_date_time_format.cpp b/runtime/js_date_time_format.cpp index 775de22052484355759b73e9426c729dbe4a9c66..b8019758a3849aa14cb8bec6741bf07cf04d5bd4 100644 --- a/runtime/js_date_time_format.cpp +++ b/runtime/js_date_time_format.cpp @@ -26,19 +26,15 @@ namespace panda::ecmascript { struct CommonDateFormatPart { - int32_t f_field = 0; // NOLINT(misc-non-private-member-variables-in-classes) - int32_t f_begin_index = 0; // NOLINT(misc-non-private-member-variables-in-classes) - int32_t f_end_index = 0; // NOLINT(misc-non-private-member-variables-in-classes) - int32_t index = 0; // NOLINT(misc-non-private-member-variables-in-classes) - bool is_pre_exist = false; // NOLINT(misc-non-private-member-variables-in-classes) + int32_t fField = 0; // NOLINT(misc-non-private-member-variables-in-classes) + int32_t fBeginIndex = 0; // NOLINT(misc-non-private-member-variables-in-classes) + int32_t fEndIndex = 0; // NOLINT(misc-non-private-member-variables-in-classes) + int32_t index = 0; // NOLINT(misc-non-private-member-variables-in-classes) + bool isPreExist = false; // NOLINT(misc-non-private-member-variables-in-classes) CommonDateFormatPart() = default; - CommonDateFormatPart(int32_t f_field, int32_t f_begin_index, int32_t f_end_index, int32_t index, bool is_pre_exist) - : f_field(f_field), - f_begin_index(f_begin_index), - f_end_index(f_end_index), - index(index), - is_pre_exist(is_pre_exist) + CommonDateFormatPart(int32_t fField, int32_t fBeginIndex, int32_t fEndIndex, int32_t index, bool isPreExist) + : fField(fField), fBeginIndex(fBeginIndex), fEndIndex(fEndIndex), index(index), isPreExist(isPreExist) { } @@ -108,22 +104,22 @@ icu::Locale *JSDateTimeFormat::GetIcuLocale() const } /* static */ -void JSDateTimeFormat::SetIcuLocale(JSThread *thread, JSHandle obj, const icu::Locale &icu_locale, +void JSDateTimeFormat::SetIcuLocale(JSThread *thread, JSHandle obj, const icu::Locale &icuLocale, const DeleteEntryPoint &callback) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - icu::Locale *icu_pointer = Runtime::GetCurrent()->GetInternalAllocator()->New(icu_locale); - ASSERT(icu_pointer != nullptr); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + icu::Locale *icuPointer = Runtime::GetCurrent()->GetInternalAllocator()->New(icuLocale); + ASSERT(icuPointer != nullptr); JSTaggedValue data = obj->GetLocaleIcu(); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); - native->ResetExternalPointer(icu_pointer); + native->ResetExternalPointer(icuPointer); return; } - JSHandle pointer = factory->NewJSNativePointer(icu_pointer, callback, ecma_vm); + JSHandle pointer = factory->NewJSNativePointer(icuPointer, callback, ecmaVm); obj->SetLocaleIcu(thread, pointer.GetTaggedValue()); - ecma_vm->PushToArrayDataList(*pointer); + ecmaVm->PushToArrayDataList(*pointer); } void JSDateTimeFormat::FreeIcuLocale(void *pointer, [[maybe_unused]] void *data) @@ -131,8 +127,8 @@ void JSDateTimeFormat::FreeIcuLocale(void *pointer, [[maybe_unused]] void *data) if (pointer == nullptr) { return; } - auto icu_locale = reinterpret_cast(pointer); - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icu_locale); + auto icuLocale = reinterpret_cast(pointer); + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuLocale); } icu::SimpleDateFormat *JSDateTimeFormat::GetIcuSimpleDateFormat() const @@ -144,23 +140,23 @@ icu::SimpleDateFormat *JSDateTimeFormat::GetIcuSimpleDateFormat() const /* static */ void JSDateTimeFormat::SetIcuSimpleDateFormat(JSThread *thread, JSHandle obj, - const icu::SimpleDateFormat &icu_simple_date_time_format, + const icu::SimpleDateFormat &icuSimpleDateTimeFormat, const DeleteEntryPoint &callback) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - icu::SimpleDateFormat *icu_pointer = allocator->New(icu_simple_date_time_format); - ASSERT(icu_pointer != nullptr); + icu::SimpleDateFormat *icuPointer = allocator->New(icuSimpleDateTimeFormat); + ASSERT(icuPointer != nullptr); JSTaggedValue data = obj->GetSimpleDateTimeFormatIcu(); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); - native->ResetExternalPointer(icu_pointer); + native->ResetExternalPointer(icuPointer); return; } - JSHandle pointer = factory->NewJSNativePointer(icu_pointer, callback, ecma_vm); + JSHandle pointer = factory->NewJSNativePointer(icuPointer, callback, ecmaVm); obj->SetSimpleDateTimeFormatIcu(thread, pointer.GetTaggedValue()); - ecma_vm->PushToArrayDataList(*pointer); + ecmaVm->PushToArrayDataList(*pointer); } void JSDateTimeFormat::FreeSimpleDateFormat(void *pointer, [[maybe_unused]] void *data) @@ -168,23 +164,23 @@ void JSDateTimeFormat::FreeSimpleDateFormat(void *pointer, [[maybe_unused]] void if (pointer == nullptr) { return; } - auto icu_simple_date_format = reinterpret_cast(pointer); - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icu_simple_date_format); + auto icuSimpleDateFormat = reinterpret_cast(pointer); + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuSimpleDateFormat); } JSHandle JSDateTimeFormat::ToValueString(JSThread *thread, const Value value) { - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); JSMutableHandle result(thread, JSTaggedValue::Undefined()); switch (value) { case Value::SHARED: - result.Update(global_const->GetHandledSharedString().GetTaggedValue()); + result.Update(globalConst->GetHandledSharedString().GetTaggedValue()); break; case Value::START_RANGE: - result.Update(global_const->GetHandledStartRangeString().GetTaggedValue()); + result.Update(globalConst->GetHandledStartRangeString().GetTaggedValue()); break; case Value::END_RANGE: - result.Update(global_const->GetHandledEndRangeString().GetTaggedValue()); + result.Update(globalConst->GetHandledEndRangeString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -194,76 +190,76 @@ JSHandle JSDateTimeFormat::ToValueString(JSThread *thread, const Val // 13.1.1 InitializeDateTimeFormat (dateTimeFormat, locales, options) // NOLINTNEXTLINE(readability-function-size) -JSHandle JSDateTimeFormat::InitializeDateTimeFormat( - JSThread *thread, const JSHandle &date_time_format, const JSHandle &locales, - const JSHandle &options) +JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread *thread, + const JSHandle &dateTimeFormat, + const JSHandle &locales, + const JSHandle &options) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); // 2. Let options be ? ToDateTimeOptions(options, "any", "date"). - JSHandle date_time_options = - ToDateTimeOptions(thread, options, RequiredOption::ANY, DefaultsOption::DATE); + JSHandle dateTimeOptions = ToDateTimeOptions(thread, options, RequiredOption::ANY, DefaultsOption::DATE); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); // 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). auto matcher = JSLocale::GetOptionOfString( - thread, date_time_options, global_const->GetHandledLocaleMatcherString(), + thread, dateTimeOptions, globalConst->GetHandledLocaleMatcherString(), {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); // 6. Let calendar be ? GetOption(options, "calendar", "string", undefined, undefined). JSHandle calendar = - JSLocale::GetOption(thread, date_time_options, global_const->GetHandledCalendarString(), OptionType::STRING, - global_const->GetHandledUndefined(), global_const->GetHandledUndefined()); + JSLocale::GetOption(thread, dateTimeOptions, globalConst->GetHandledCalendarString(), OptionType::STRING, + globalConst->GetHandledUndefined(), globalConst->GetHandledUndefined()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - date_time_format->SetCalendar(thread, calendar); + dateTimeFormat->SetCalendar(thread, calendar); // 7. If calendar is not undefined, then // a. If calendar does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. - std::string calendar_str; + std::string calendarStr; if (!calendar->IsUndefined()) { - JSHandle calendar_ecma_str = JSHandle::Cast(calendar); - calendar_str = JSLocale::ConvertToStdString(calendar_ecma_str); - if (!JSLocale::IsNormativeCalendar(calendar_str)) { - THROW_RANGE_ERROR_AND_RETURN(thread, "invalid calendar", date_time_format); + JSHandle calendarEcmaStr = JSHandle::Cast(calendar); + calendarStr = JSLocale::ConvertToStdString(calendarEcmaStr); + if (!JSLocale::IsNormativeCalendar(calendarStr)) { + THROW_RANGE_ERROR_AND_RETURN(thread, "invalid calendar", dateTimeFormat); } } // 9. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). - JSHandle numbering_system = JSLocale::GetOption( - thread, date_time_options, global_const->GetHandledNumberingSystemString(), OptionType::STRING, - global_const->GetHandledUndefined(), global_const->GetHandledUndefined()); + JSHandle numberingSystem = + JSLocale::GetOption(thread, dateTimeOptions, globalConst->GetHandledNumberingSystemString(), OptionType::STRING, + globalConst->GetHandledUndefined(), globalConst->GetHandledUndefined()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - date_time_format->SetNumberingSystem(thread, numbering_system); + dateTimeFormat->SetNumberingSystem(thread, numberingSystem); // 10. If numberingSystem is not undefined, then // a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError // exception. - std::string ns_str; - if (!numbering_system->IsUndefined()) { - JSHandle ns_ecma_str = JSHandle::Cast(numbering_system); - ns_str = JSLocale::ConvertToStdString(ns_ecma_str); - if (!JSLocale::IsWellNumberingSystem(ns_str)) { - THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", date_time_format); + std::string nsStr; + if (!numberingSystem->IsUndefined()) { + JSHandle nsEcmaStr = JSHandle::Cast(numberingSystem); + nsStr = JSLocale::ConvertToStdString(nsEcmaStr); + if (!JSLocale::IsWellNumberingSystem(nsStr)) { + THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", dateTimeFormat); } } // 12. Let hour12 be ? GetOption(options, "hour12", "boolean", undefined, undefined). JSHandle hour12 = - JSLocale::GetOption(thread, date_time_options, global_const->GetHandledHour12String(), OptionType::BOOLEAN, - global_const->GetHandledUndefined(), global_const->GetHandledUndefined()); + JSLocale::GetOption(thread, dateTimeOptions, globalConst->GetHandledHour12String(), OptionType::BOOLEAN, + globalConst->GetHandledUndefined(), globalConst->GetHandledUndefined()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); // 13. Let hourCycle be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined). - auto hour_cycle = JSLocale::GetOptionOfString( - thread, date_time_options, global_const->GetHandledHourCycleString(), + auto hourCycle = JSLocale::GetOptionOfString( + thread, dateTimeOptions, globalConst->GetHandledHourCycleString(), {HourCycleOption::H11, HourCycleOption::H12, HourCycleOption::H23, HourCycleOption::H24}, {"h11", "h12", "h23", "h24"}, HourCycleOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); @@ -271,80 +267,80 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat( // 14. If hour12 is not undefined, then // a. Let hourCycle be null. if (!hour12->IsUndefined()) { - hour_cycle = HourCycleOption::UNDEFINED; + hourCycle = HourCycleOption::UNDEFINED; } // 16. Let localeData be %DateTimeFormat%.[[LocaleData]]. - JSHandle available_locales = - (requested_locales->GetLength() == 0) ? factory->EmptyArray() : GainAvailableLocales(thread); + JSHandle availableLocales = + (requestedLocales->GetLength() == 0) ? factory->EmptyArray() : GainAvailableLocales(thread); // 17. Let r be ResolveLocale(%DateTimeFormat%.[[AvailableLocales]], requestedLocales, opt, %DateTimeFormat% // .[[RelevantExtensionKeys]], localeData). - ResolvedLocale resolved_locale = - JSLocale::ResolveLocale(thread, available_locales, requested_locales, matcher, RELEVANT_EXTENSION_KEYS); + ResolvedLocale resolvedLocale = + JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, RELEVANT_EXTENSION_KEYS); // 18. Set icuLocale to r.[[locale]]. - icu::Locale icu_locale = resolved_locale.locale_data; - ASSERT_PRINT(!icu_locale.isBogus(), "icuLocale is bogus"); + icu::Locale icuLocale = resolvedLocale.localeData; + ASSERT_PRINT(!icuLocale.isBogus(), "icuLocale is bogus"); UErrorCode status = U_ZERO_ERROR; // Set resolvedIcuLocaleCopy to a copy of icuLocale. // Set icuLocale.[[ca]] to calendar. // Set icuLocale.[[nu]] to numberingSystem. - icu::Locale resolved_icu_locale_copy(icu_locale); - if (!calendar->IsUndefined() && JSLocale::IsWellCalendar(icu_locale, calendar_str)) { - icu_locale.setUnicodeKeywordValue("ca", calendar_str, status); + icu::Locale resolvedIcuLocaleCopy(icuLocale); + if (!calendar->IsUndefined() && JSLocale::IsWellCalendar(icuLocale, calendarStr)) { + icuLocale.setUnicodeKeywordValue("ca", calendarStr, status); } - if (!numbering_system->IsUndefined() && JSLocale::IsWellNumberingSystem(ns_str)) { - icu_locale.setUnicodeKeywordValue("nu", ns_str, status); + if (!numberingSystem->IsUndefined() && JSLocale::IsWellNumberingSystem(nsStr)) { + icuLocale.setUnicodeKeywordValue("nu", nsStr, status); } // 24. Let timeZone be ? Get(options, "timeZone"). - OperationResult operation_result = - JSObject::GetProperty(thread, date_time_options, global_const->GetHandledTimeZoneString()); + OperationResult operationResult = + JSObject::GetProperty(thread, dateTimeOptions, globalConst->GetHandledTimeZoneString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - date_time_format->SetTimeZone(thread, operation_result.GetValue()); + dateTimeFormat->SetTimeZone(thread, operationResult.GetValue()); // 25. If timeZone is not undefined, then // a. Let timeZone be ? ToString(timeZone). // b. If the result of IsValidTimeZoneName(timeZone) is false, then // i. Throw a RangeError exception. - std::unique_ptr icu_time_zone; - if (!operation_result.GetValue()->IsUndefined()) { - JSHandle timezone = JSTaggedValue::ToString(thread, operation_result.GetValue()); + std::unique_ptr icuTimeZone; + if (!operationResult.GetValue()->IsUndefined()) { + JSHandle timezone = JSTaggedValue::ToString(thread, operationResult.GetValue()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - icu_time_zone = ConstructTimeZone(JSLocale::ConvertToStdString(timezone)); - if (icu_time_zone == nullptr) { - THROW_RANGE_ERROR_AND_RETURN(thread, "invalid timeZone", date_time_format); + icuTimeZone = ConstructTimeZone(JSLocale::ConvertToStdString(timezone)); + if (icuTimeZone == nullptr) { + THROW_RANGE_ERROR_AND_RETURN(thread, "invalid timeZone", dateTimeFormat); } } else { // 26. Else, // a. Let timeZone be DefaultTimeZone(). - icu_time_zone = std::unique_ptr(icu::TimeZone::createDefault()); + icuTimeZone = std::unique_ptr(icu::TimeZone::createDefault()); } // 36.a. Let hcDefault be dataLocaleData.[[hourCycle]]. std::unique_ptr generator( - icu::DateTimePatternGenerator::createInstance(icu_locale, status)); + icu::DateTimePatternGenerator::createInstance(icuLocale, status)); ASSERT_PRINT(U_SUCCESS(status), "constructGenerator failed"); - HourCycleOption hc_default = OptionToHourCycle(generator->getDefaultHourCycle(status)); + HourCycleOption hcDefault = OptionToHourCycle(generator->getDefaultHourCycle(status)); // b. Let hc be dateTimeFormat.[[HourCycle]]. - HourCycleOption hc = hour_cycle; - if (hc == HourCycleOption::UNDEFINED && resolved_locale.extensions.find("hc") != resolved_locale.extensions.end()) { - hc = OptionToHourCycle(resolved_locale.extensions.find("hc")->second); + HourCycleOption hc = hourCycle; + if (hc == HourCycleOption::UNDEFINED && resolvedLocale.extensions.find("hc") != resolvedLocale.extensions.end()) { + hc = OptionToHourCycle(resolvedLocale.extensions.find("hc")->second); } // c. If hc is null, then // i. Set hc to hcDefault. if (hc == HourCycleOption::UNDEFINED) { - hc = hc_default; + hc = hcDefault; } // d. If hour12 is not undefined, then if (!hour12->IsUndefined()) { // i. If hour12 is true, then if (JSTaggedValue::SameValue(hour12.GetTaggedValue(), JSTaggedValue::True())) { // 1. If hcDefault is "h11" or "h23", then - if (hc_default == HourCycleOption::H11 || hc_default == HourCycleOption::H23) { + if (hcDefault == HourCycleOption::H11 || hcDefault == HourCycleOption::H23) { // a. Set hc to "h11". hc = HourCycleOption::H11; } else { @@ -355,7 +351,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat( } else { // ii. Else, // 2. If hcDefault is "h11" or "h23", then - if (hc_default == HourCycleOption::H11 || hc_default == HourCycleOption::H23) { + if (hcDefault == HourCycleOption::H11 || hcDefault == HourCycleOption::H23) { // a. Set hc to "h23". hc = HourCycleOption::H23; } else { @@ -367,7 +363,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat( } // Set isHourDefined be false when dateTimeFormat.[[Hour]] is not undefined. - bool is_hour_defined = false; + bool isHourDefined = false; // 29. For each row of Table 6, except the header row, in table order, do // a. Let prop be the name given in the Property column of the row. @@ -379,143 +375,143 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat( for (const IcuPatternDesc &item : data) { // prop be [[TimeZoneName]] if (item.property == "timeZoneName") { - int second_digits_string = JSLocale::GetNumberOption( - thread, date_time_options, global_const->GetHandledFractionalSecondDigitsString(), 1, 3, 0); - skeleton.append(second_digits_string, 'S'); + int secondDigitsString = JSLocale::GetNumberOption( + thread, dateTimeOptions, globalConst->GetHandledFractionalSecondDigitsString(), 1, 3, 0); + skeleton.append(secondDigitsString, 'S'); } JSHandle property(thread, factory->NewFromStdString(item.property).GetTaggedValue()); std::string value; - bool is_find = JSLocale::GetOptionOfString(thread, date_time_options, property, item.allowed_values, &value); + bool isFind = JSLocale::GetOptionOfString(thread, dateTimeOptions, property, item.allowedValues, &value); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - if (is_find) { + if (isFind) { skeleton += item.map.find(value)->second; // [[Hour]] is defined. - is_hour_defined = (item.property == "hour") ? true : is_hour_defined; + isHourDefined = (item.property == "hour") ? true : isHourDefined; } } // 13.1.3 BasicFormatMatcher (options, formats) - [[maybe_unused]] auto format_matcher = JSLocale::GetOptionOfString( - thread, date_time_options, global_const->GetHandledFormatMatcherString(), + [[maybe_unused]] auto formatMatcher = JSLocale::GetOptionOfString( + thread, dateTimeOptions, globalConst->GetHandledFormatMatcherString(), {FormatMatcherOption::BASIC, FormatMatcherOption::BEST_FIT}, {"basic", "best fit"}, FormatMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); // Let dateStyle be ? GetOption(options, "string", «"full", "long", "medium", "short"», undefined). // Set dateTimeFormat.[[dateStyle]] - auto date_style = JSLocale::GetOptionOfString( - thread, date_time_options, global_const->GetHandledDateStyleString(), + auto dateStyle = JSLocale::GetOptionOfString( + thread, dateTimeOptions, globalConst->GetHandledDateStyleString(), {DateTimeStyleOption::FULL, DateTimeStyleOption::LONG, DateTimeStyleOption::MEDIUM, DateTimeStyleOption::SHORT}, {"full", "long", "medium", "short"}, DateTimeStyleOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - date_time_format->SetDateStyle(thread, JSTaggedValue(static_cast(date_style))); + dateTimeFormat->SetDateStyle(thread, JSTaggedValue(static_cast(dateStyle))); // Let timeStyle be ? GetOption(options, "string", «"full", "long", "medium", "short"», undefined). // Set dateTimeFormat.[[timeStyle]] - auto time_style = JSLocale::GetOptionOfString( - thread, date_time_options, global_const->GetHandledTimeStyleString(), + auto timeStyle = JSLocale::GetOptionOfString( + thread, dateTimeOptions, globalConst->GetHandledTimeStyleString(), {DateTimeStyleOption::FULL, DateTimeStyleOption::LONG, DateTimeStyleOption::MEDIUM, DateTimeStyleOption::SHORT}, {"full", "long", "medium", "short"}, DateTimeStyleOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - date_time_format->SetTimeStyle(thread, JSTaggedValue(static_cast(time_style))); + dateTimeFormat->SetTimeStyle(thread, JSTaggedValue(static_cast(timeStyle))); - HourCycleOption dtf_hour_cycle = HourCycleOption::UNDEFINED; + HourCycleOption dtfHourCycle = HourCycleOption::UNDEFINED; // If dateTimeFormat.[[Hour]] is defined, then - if (is_hour_defined) { + if (isHourDefined) { // e. Set dateTimeFormat.[[HourCycle]] to hc. - dtf_hour_cycle = hc; + dtfHourCycle = hc; } else { // 37. Else, // a. Set dateTimeFormat.[[HourCycle]] to undefined. - dtf_hour_cycle = HourCycleOption::UNDEFINED; + dtfHourCycle = HourCycleOption::UNDEFINED; } // Set dateTimeFormat.[[hourCycle]]. - date_time_format->SetHourCycle(thread, JSTaggedValue(static_cast(dtf_hour_cycle))); + dateTimeFormat->SetHourCycle(thread, JSTaggedValue(static_cast(dtfHourCycle))); // Set dateTimeFormat.[[icuLocale]]. - JSDateTimeFormat::SetIcuLocale(thread, date_time_format, icu_locale, JSDateTimeFormat::FreeIcuLocale); + JSDateTimeFormat::SetIcuLocale(thread, dateTimeFormat, icuLocale, JSDateTimeFormat::FreeIcuLocale); // Creates a Calendar using the given timezone and given locale. // Set dateTimeFormat.[[icuSimpleDateFormat]]. - icu::UnicodeString dtf_skeleton(skeleton.c_str()); + icu::UnicodeString dtfSkeleton(skeleton.c_str()); status = U_ZERO_ERROR; icu::UnicodeString pattern = ChangeHourCyclePattern( - generator->getBestPattern(dtf_skeleton, UDATPG_MATCH_HOUR_FIELD_LENGTH, status), dtf_hour_cycle); + generator->getBestPattern(dtfSkeleton, UDATPG_MATCH_HOUR_FIELD_LENGTH, status), dtfHourCycle); ASSERT_PRINT((U_SUCCESS(status) != 0), "get best pattern failed"); - auto simple_date_format_icu(std::make_unique(pattern, icu_locale, status)); + auto simpleDateFormatIcu(std::make_unique(pattern, icuLocale, status)); if (U_FAILURE(status) != 0) { - simple_date_format_icu = std::unique_ptr(); + simpleDateFormatIcu = std::unique_ptr(); } - ASSERT_PRINT(simple_date_format_icu != nullptr, "invalid icuSimpleDateFormat"); - std::unique_ptr calendar_ptr = BuildCalendar(icu_locale, *icu_time_zone); - ASSERT_PRINT(calendar_ptr != nullptr, "invalid calendar"); - simple_date_format_icu->adoptCalendar(calendar_ptr.release()); - SetIcuSimpleDateFormat(thread, date_time_format, *simple_date_format_icu, JSDateTimeFormat::FreeSimpleDateFormat); + ASSERT_PRINT(simpleDateFormatIcu != nullptr, "invalid icuSimpleDateFormat"); + std::unique_ptr calendarPtr = BuildCalendar(icuLocale, *icuTimeZone); + ASSERT_PRINT(calendarPtr != nullptr, "invalid calendar"); + simpleDateFormatIcu->adoptCalendar(calendarPtr.release()); + SetIcuSimpleDateFormat(thread, dateTimeFormat, *simpleDateFormatIcu, JSDateTimeFormat::FreeSimpleDateFormat); // Set dateTimeFormat.[[iso8601]]. - bool iso8601 = strstr(icu_locale.getName(), "calendar=iso8601") != nullptr; - date_time_format->SetIso8601(thread, JSTaggedValue(iso8601)); + bool iso8601 = strstr(icuLocale.getName(), "calendar=iso8601") != nullptr; + dateTimeFormat->SetIso8601(thread, JSTaggedValue(iso8601)); // Set dateTimeFormat.[[locale]]. - if (!hour12->IsUndefined() || hour_cycle != HourCycleOption::UNDEFINED) { - if ((resolved_locale.extensions.find("hc") != resolved_locale.extensions.end()) && - (dtf_hour_cycle != OptionToHourCycle((resolved_locale.extensions.find("hc")->second)))) { - resolved_icu_locale_copy.setUnicodeKeywordValue("hc", nullptr, status); + if (!hour12->IsUndefined() || hourCycle != HourCycleOption::UNDEFINED) { + if ((resolvedLocale.extensions.find("hc") != resolvedLocale.extensions.end()) && + (dtfHourCycle != OptionToHourCycle((resolvedLocale.extensions.find("hc")->second)))) { + resolvedIcuLocaleCopy.setUnicodeKeywordValue("hc", nullptr, status); ASSERT_PRINT(U_SUCCESS(status), "resolvedIcuLocaleCopy set hc failed"); } } - JSHandle locale_str = JSLocale::ToLanguageTag(thread, resolved_icu_locale_copy); - date_time_format->SetLocale(thread, locale_str.GetTaggedValue()); + JSHandle localeStr = JSLocale::ToLanguageTag(thread, resolvedIcuLocaleCopy); + dateTimeFormat->SetLocale(thread, localeStr.GetTaggedValue()); // Set dateTimeFormat.[[boundFormat]]. - date_time_format->SetBoundFormat(thread, JSTaggedValue::Undefined()); + dateTimeFormat->SetBoundFormat(thread, JSTaggedValue::Undefined()); // 39. Return dateTimeFormat. - return date_time_format; + return dateTimeFormat; } // 13.1.2 ToDateTimeOptions (options, required, defaults) JSHandle JSDateTimeFormat::ToDateTimeOptions(JSThread *thread, const JSHandle &options, const RequiredOption &required, const DefaultsOption &defaults) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If options is undefined, let options be null; otherwise let options be ? ToObject(options). - JSHandle options_result(thread, JSTaggedValue::Null()); + JSHandle optionsResult(thread, JSTaggedValue::Null()); if (!options->IsUndefined()) { - options_result = JSTaggedValue::ToObject(thread, options); + optionsResult = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); } // 2. Let options be ObjectCreate(options). - options_result = JSObject::ObjectCreate(thread, options_result); + optionsResult = JSObject::ObjectCreate(thread, optionsResult); // 3. Let needDefaults be true. - bool need_defaults = true; + bool needDefaults = true; // 4. If required is "date" or "any", then // a. For each of the property names "weekday", "year", "month", "day", do // i. Let prop be the property name. // ii. Let value be ? Get(options, prop). // iii. If value is not undefined, let needDefaults be false. - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); if (required == RequiredOption::DATE || required == RequiredOption::ANY) { JSHandle array = factory->NewTaggedArray(CAPACITY_4); - array->Set(thread, 0, global_const->GetHandledWeekdayString()); - array->Set(thread, 1, global_const->GetHandledYearString()); - array->Set(thread, 2, global_const->GetHandledMonthString()); // 2 means the third slot - array->Set(thread, 3, global_const->GetHandledDayString()); // 3 means the fourth slot + array->Set(thread, 0, globalConst->GetHandledWeekdayString()); + array->Set(thread, 1, globalConst->GetHandledYearString()); + array->Set(thread, 2, globalConst->GetHandledMonthString()); // 2 means the third slot + array->Set(thread, 3, globalConst->GetHandledDayString()); // 3 means the fourth slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); uint32_t len = array->GetLength(); for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); - OperationResult operation_result = JSObject::GetProperty(thread, options_result, key); + OperationResult operationResult = JSObject::GetProperty(thread, optionsResult, key); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - if (!operation_result.GetValue()->IsUndefined()) { - need_defaults = false; + if (!operationResult.GetValue()->IsUndefined()) { + needDefaults = false; } } } @@ -527,59 +523,59 @@ JSHandle JSDateTimeFormat::ToDateTimeOptions(JSThread *thread, const J // iii. If value is not undefined, let needDefaults be false. if (required == RequiredOption::TIME || required == RequiredOption::ANY) { JSHandle array = factory->NewTaggedArray(CAPACITY_5); - array->Set(thread, 0, global_const->GetHandledDayPeriodString()); - array->Set(thread, 1, global_const->GetHandledHourString()); - array->Set(thread, 2, global_const->GetHandledMinuteString()); // 2 means the second slot - array->Set(thread, 3, global_const->GetHandledSecondString()); // 3 means the third slot - array->Set(thread, 4, global_const->GetHandledFractionalSecondDigitsString()); // 4 means the fourth slot + array->Set(thread, 0, globalConst->GetHandledDayPeriodString()); + array->Set(thread, 1, globalConst->GetHandledHourString()); + array->Set(thread, 2, globalConst->GetHandledMinuteString()); // 2 means the second slot + array->Set(thread, 3, globalConst->GetHandledSecondString()); // 3 means the third slot + array->Set(thread, 4, globalConst->GetHandledFractionalSecondDigitsString()); // 4 means the fourth slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); uint32_t len = array->GetLength(); for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); - OperationResult operation_result = JSObject::GetProperty(thread, options_result, key); + OperationResult operationResult = JSObject::GetProperty(thread, optionsResult, key); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - if (!operation_result.GetValue()->IsUndefined()) { - need_defaults = false; + if (!operationResult.GetValue()->IsUndefined()) { + needDefaults = false; } } } // Let dateStyle/timeStyle be ? Get(options, "dateStyle"/"timeStyle"). - OperationResult date_style_result = - JSObject::GetProperty(thread, options_result, global_const->GetHandledDateStyleString()); + OperationResult dateStyleResult = + JSObject::GetProperty(thread, optionsResult, globalConst->GetHandledDateStyleString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - JSHandle date_style = date_style_result.GetValue(); - OperationResult time_style_result = - JSObject::GetProperty(thread, options_result, global_const->GetHandledTimeStyleString()); + JSHandle dateStyle = dateStyleResult.GetValue(); + OperationResult timeStyleResult = + JSObject::GetProperty(thread, optionsResult, globalConst->GetHandledTimeStyleString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - JSHandle time_style = time_style_result.GetValue(); + JSHandle timeStyle = timeStyleResult.GetValue(); // If dateStyle is not undefined or timeStyle is not undefined, let needDefaults be false. - if (!date_style->IsUndefined() || !time_style->IsUndefined()) { - need_defaults = false; + if (!dateStyle->IsUndefined() || !timeStyle->IsUndefined()) { + needDefaults = false; } // If required is "date"/"time" and timeStyle is not undefined, throw a TypeError exception. - if (required == RequiredOption::DATE && !time_style->IsUndefined()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "timeStyle is not undefined", options_result); + if (required == RequiredOption::DATE && !timeStyle->IsUndefined()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "timeStyle is not undefined", optionsResult); } - if (required == RequiredOption::TIME && !date_style->IsUndefined()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "dateStyle is not undefined", options_result); + if (required == RequiredOption::TIME && !dateStyle->IsUndefined()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "dateStyle is not undefined", optionsResult); } // 6. If needDefaults is true and defaults is either "date" or "all", then // a. For each of the property names "year", "month", "day", do // i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric"). - if (need_defaults && (defaults == DefaultsOption::DATE || defaults == DefaultsOption::ALL)) { + if (needDefaults && (defaults == DefaultsOption::DATE || defaults == DefaultsOption::ALL)) { JSHandle array = factory->NewTaggedArray(CAPACITY_3); - array->Set(thread, 0, global_const->GetHandledYearString()); - array->Set(thread, 1, global_const->GetHandledMonthString()); - array->Set(thread, 2, global_const->GetHandledDayString()); // 2 means the third slot + array->Set(thread, 0, globalConst->GetHandledYearString()); + array->Set(thread, 1, globalConst->GetHandledMonthString()); + array->Set(thread, 2, globalConst->GetHandledDayString()); // 2 means the third slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); uint32_t len = array->GetLength(); for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); - JSObject::CreateDataPropertyOrThrow(thread, options_result, key, global_const->GetHandledNumericString()); + JSObject::CreateDataPropertyOrThrow(thread, optionsResult, key, globalConst->GetHandledNumericString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); } } @@ -587,32 +583,32 @@ JSHandle JSDateTimeFormat::ToDateTimeOptions(JSThread *thread, const J // 7. If needDefaults is true and defaults is either "time" or "all", then // a. For each of the property names "hour", "minute", "second", do // i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric"). - if (need_defaults && (defaults == DefaultsOption::TIME || defaults == DefaultsOption::ALL)) { + if (needDefaults && (defaults == DefaultsOption::TIME || defaults == DefaultsOption::ALL)) { JSHandle array = factory->NewTaggedArray(CAPACITY_3); - array->Set(thread, 0, global_const->GetHandledHourString()); - array->Set(thread, 1, global_const->GetHandledMinuteString()); - array->Set(thread, 2, global_const->GetHandledSecondString()); // 2 means the third slot + array->Set(thread, 0, globalConst->GetHandledHourString()); + array->Set(thread, 1, globalConst->GetHandledMinuteString()); + array->Set(thread, 2, globalConst->GetHandledSecondString()); // 2 means the third slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); uint32_t len = array->GetLength(); for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); - JSObject::CreateDataPropertyOrThrow(thread, options_result, key, global_const->GetHandledNumericString()); + JSObject::CreateDataPropertyOrThrow(thread, optionsResult, key, globalConst->GetHandledNumericString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); } } // 8. Return options. - return options_result; + return optionsResult; } // 13.1.7 FormatDateTime(dateTimeFormat, x) JSHandle JSDateTimeFormat::FormatDateTime(JSThread *thread, - const JSHandle &date_time_format, double x) + const JSHandle &dateTimeFormat, double x) { - icu::SimpleDateFormat *simple_date_format = date_time_format->GetIcuSimpleDateFormat(); + icu::SimpleDateFormat *simpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(); // 1. Let parts be ? PartitionDateTimePattern(dateTimeFormat, x). - double x_value = JSDate::TimeClip(x); - if (std::isnan(x_value)) { + double xValue = JSDate::TimeClip(x); + if (std::isnan(xValue)) { THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid time value", thread->GetEcmaVM()->GetFactory()->GetEmptyString()); } @@ -620,7 +616,7 @@ JSHandle JSDateTimeFormat::FormatDateTime(JSThread *thread, icu::UnicodeString result; // 3. Set result to the string-concatenation of result and part.[[Value]]. - simple_date_format->format(x_value, result); + simpleDateFormat->format(xValue, result); // 4. Return result. return JSLocale::IcuToString(thread, result); @@ -628,61 +624,61 @@ JSHandle JSDateTimeFormat::FormatDateTime(JSThread *thread, // 13.1.8 FormatDateTimeToParts (dateTimeFormat, x) JSHandle JSDateTimeFormat::FormatDateTimeToParts(JSThread *thread, - const JSHandle &date_time_format, double x) + const JSHandle &dateTimeFormat, double x) { - icu::SimpleDateFormat *simple_date_format = date_time_format->GetIcuSimpleDateFormat(); - ASSERT(simple_date_format != nullptr); + icu::SimpleDateFormat *simpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(); + ASSERT(simpleDateFormat != nullptr); UErrorCode status = U_ZERO_ERROR; - icu::FieldPositionIterator field_position_iter; - icu::UnicodeString formatted_parts; - simple_date_format->format(x, formatted_parts, &field_position_iter, status); + icu::FieldPositionIterator fieldPositionIter; + icu::UnicodeString formattedParts; + simpleDateFormat->format(x, formattedParts, &fieldPositionIter, status); if (U_FAILURE(status) != 0) { THROW_TYPE_ERROR_AND_RETURN(thread, "format failed", thread->GetEcmaVM()->GetFactory()->NewJSArray()); } // 2. Let result be ArrayCreate(0). JSHandle result(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); - if (formatted_parts.isBogus() != 0) { + if (formattedParts.isBogus() != 0) { return result; } // 3. Let n be 0. int32_t index = 0; - int32_t pre_edge_pos = 0; + int32_t preEdgePos = 0; std::vector parts; - icu::FieldPosition field_position; - while (field_position_iter.next(field_position) != 0) { - int32_t f_field = field_position.getField(); - int32_t f_begin_index = field_position.getBeginIndex(); - int32_t f_end_index = field_position.getEndIndex(); - if (pre_edge_pos < f_begin_index) { - parts.emplace_back(CommonDateFormatPart(f_field, pre_edge_pos, f_begin_index, index, true)); + icu::FieldPosition fieldPosition; + while (fieldPositionIter.next(fieldPosition) != 0) { + int32_t fField = fieldPosition.getField(); + int32_t fBeginIndex = fieldPosition.getBeginIndex(); + int32_t fEndIndex = fieldPosition.getEndIndex(); + if (preEdgePos < fBeginIndex) { + parts.emplace_back(CommonDateFormatPart(fField, preEdgePos, fBeginIndex, index, true)); ++index; } - parts.emplace_back(CommonDateFormatPart(f_field, f_begin_index, f_end_index, index, false)); - pre_edge_pos = f_end_index; + parts.emplace_back(CommonDateFormatPart(fField, fBeginIndex, fEndIndex, index, false)); + preEdgePos = fEndIndex; ++index; } - int32_t length = formatted_parts.length(); - if (pre_edge_pos < length) { - parts.emplace_back(CommonDateFormatPart(-1, pre_edge_pos, length, index, true)); + int32_t length = formattedParts.length(); + if (preEdgePos < length) { + parts.emplace_back(CommonDateFormatPart(-1, preEdgePos, length, index, true)); } JSMutableHandle substring(thread, JSTaggedValue::Undefined()); // 4. For each part in parts, do for (auto part : parts) { substring.Update( - JSLocale::IcuToString(thread, formatted_parts, part.f_begin_index, part.f_end_index).GetTaggedValue()); + JSLocale::IcuToString(thread, formattedParts, part.fBeginIndex, part.fEndIndex).GetTaggedValue()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); // Let O be ObjectCreate(%ObjectPrototype%). // Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). // Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]). // Perform ! CreateDataProperty(result, ! ToString(n), O). - if (part.is_pre_exist) { + if (part.isPreExist) { JSLocale::PutElement(thread, part.index, result, ConvertFieldIdToDateType(thread, -1), JSHandle::Cast(substring)); } else { - JSLocale::PutElement(thread, part.index, result, ConvertFieldIdToDateType(thread, part.f_field), + JSLocale::PutElement(thread, part.index, result, ConvertFieldIdToDateType(thread, part.fField), JSHandle::Cast(substring)); } } @@ -693,50 +689,50 @@ JSHandle JSDateTimeFormat::FormatDateTimeToParts(JSThread *thread, // 13.1.10 UnwrapDateTimeFormat(dtf) JSHandle JSDateTimeFormat::UnwrapDateTimeFormat(JSThread *thread, - const JSHandle &date_time_format) + const JSHandle &dateTimeFormat) { // 1. Assert: Type(dtf) is Object. - ASSERT_PRINT(date_time_format->IsJSObject(), "dateTimeFormat is not object"); + ASSERT_PRINT(dateTimeFormat->IsJSObject(), "dateTimeFormat is not object"); // 2. If dateTimeFormat does not have an [[InitializedDateTimeFormat]] internal slot // and ? InstanceofOperator(dateTimeFormat, %DateTimeFormat%) is true, then // a. Let dateTimeFormat be ? Get(dateTimeFormat, %Intl%.[[FallbackSymbol]]). JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - bool is_instance_of = JSFunction::InstanceOf(thread, date_time_format, env->GetDateTimeFormatFunction()); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, date_time_format); - if (!date_time_format->IsJSDateTimeFormat() && is_instance_of) { + bool isInstanceOf = JSFunction::InstanceOf(thread, dateTimeFormat, env->GetDateTimeFormatFunction()); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, dateTimeFormat); + if (!dateTimeFormat->IsJSDateTimeFormat() && isInstanceOf) { JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - OperationResult operation_result = JSTaggedValue::GetProperty(thread, date_time_format, key); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, date_time_format); - return operation_result.GetValue(); + OperationResult operationResult = JSTaggedValue::GetProperty(thread, dateTimeFormat, key); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, dateTimeFormat); + return operationResult.GetValue(); } // 3. Perform ? RequireInternalSlot(dateTimeFormat, [[InitializedDateTimeFormat]]). - if (!date_time_format->IsJSDateTimeFormat()) { + if (!dateTimeFormat->IsJSDateTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "is not JSDateTimeFormat", JSHandle(thread, JSTaggedValue::Exception())); } // 4. Return dateTimeFormat. - return date_time_format; + return dateTimeFormat; } JSHandle ToHourCycleEcmaString(JSThread *thread, int32_t hc) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); switch (hc) { case static_cast(HourCycleOption::H11): - result.Update(global_const->GetHandledH11String().GetTaggedValue()); + result.Update(globalConst->GetHandledH11String().GetTaggedValue()); break; case static_cast(HourCycleOption::H12): - result.Update(global_const->GetHandledH12String().GetTaggedValue()); + result.Update(globalConst->GetHandledH12String().GetTaggedValue()); break; case static_cast(HourCycleOption::H23): - result.Update(global_const->GetHandledH23String().GetTaggedValue()); + result.Update(globalConst->GetHandledH23String().GetTaggedValue()); break; case static_cast(HourCycleOption::H24): - result.Update(global_const->GetHandledH24String().GetTaggedValue()); + result.Update(globalConst->GetHandledH24String().GetTaggedValue()); break; default: UNREACHABLE(); @@ -747,19 +743,19 @@ JSHandle ToHourCycleEcmaString(JSThread *thread, int32_t hc) JSHandle ToDateTimeStyleEcmaString(JSThread *thread, int32_t style) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); switch (style) { case static_cast(DateTimeStyleOption::FULL): - result.Update(global_const->GetHandledFullString().GetTaggedValue()); + result.Update(globalConst->GetHandledFullString().GetTaggedValue()); break; case static_cast(DateTimeStyleOption::LONG): - result.Update(global_const->GetHandledLongString().GetTaggedValue()); + result.Update(globalConst->GetHandledLongString().GetTaggedValue()); break; case static_cast(DateTimeStyleOption::MEDIUM): - result.Update(global_const->GetHandledMediumString().GetTaggedValue()); + result.Update(globalConst->GetHandledMediumString().GetTaggedValue()); break; case static_cast(DateTimeStyleOption::SHORT): - result.Update(global_const->GetHandledShortString().GetTaggedValue()); + result.Update(globalConst->GetHandledShortString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -768,7 +764,7 @@ JSHandle ToDateTimeStyleEcmaString(JSThread *thread, int32_t styl } // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () -void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle &date_time_format, +void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle &dateTimeFormat, const JSHandle &options) { // Table 8: Resolved Options of DateTimeFormat Instances // Internal Slot Property @@ -787,113 +783,113 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandleGlobalConstants(); + auto globalConst = thread->GlobalConstants(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 5. For each row of Table 8, except the header row, in table order, do // Let p be the Property value of the current row. // [[Locale]] - JSHandle locale(thread, date_time_format->GetLocale()); - JSHandle property = global_const->GetHandledLocaleString(); + JSHandle locale(thread, dateTimeFormat->GetLocale()); + JSHandle property = globalConst->GetHandledLocaleString(); JSObject::CreateDataPropertyOrThrow(thread, options, property, locale); // [[Calendar]] - JSMutableHandle calendar_value(thread, date_time_format->GetCalendar()); - icu::SimpleDateFormat *icu_simple_date_format = date_time_format->GetIcuSimpleDateFormat(); - const icu::Calendar *calendar = icu_simple_date_format->getCalendar(); - std::string icu_calendar = calendar->getType(); - if (icu_calendar == "gregorian") { - if (date_time_format->GetIso8601() == JSTaggedValue::True()) { - calendar_value.Update(global_const->GetHandledIso8601String().GetTaggedValue()); + JSMutableHandle calendarValue(thread, dateTimeFormat->GetCalendar()); + icu::SimpleDateFormat *icuSimpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(); + const icu::Calendar *calendar = icuSimpleDateFormat->getCalendar(); + std::string icuCalendar = calendar->getType(); + if (icuCalendar == "gregorian") { + if (dateTimeFormat->GetIso8601() == JSTaggedValue::True()) { + calendarValue.Update(globalConst->GetHandledIso8601String().GetTaggedValue()); } else { - calendar_value.Update(global_const->GetHandledGregoryString().GetTaggedValue()); + calendarValue.Update(globalConst->GetHandledGregoryString().GetTaggedValue()); } - } else if (icu_calendar == "ethiopic-amete-alem") { - calendar_value.Update(global_const->GetHandledEthioaaString().GetTaggedValue()); + } else if (icuCalendar == "ethiopic-amete-alem") { + calendarValue.Update(globalConst->GetHandledEthioaaString().GetTaggedValue()); } - property = global_const->GetHandledCalendarString(); - JSObject::CreateDataPropertyOrThrow(thread, options, property, calendar_value); + property = globalConst->GetHandledCalendarString(); + JSObject::CreateDataPropertyOrThrow(thread, options, property, calendarValue); // [[NumberingSystem]] - JSHandle numbering_system(thread, date_time_format->GetNumberingSystem()); - if (numbering_system->IsUndefined()) { - numbering_system = global_const->GetHandledLatnString(); + JSHandle numberingSystem(thread, dateTimeFormat->GetNumberingSystem()); + if (numberingSystem->IsUndefined()) { + numberingSystem = globalConst->GetHandledLatnString(); } - property = global_const->GetHandledNumberingSystemString(); - JSObject::CreateDataPropertyOrThrow(thread, options, property, numbering_system); + property = globalConst->GetHandledNumberingSystemString(); + JSObject::CreateDataPropertyOrThrow(thread, options, property, numberingSystem); // [[TimeZone]] - JSMutableHandle timezone_value(thread, date_time_format->GetTimeZone()); - const icu::TimeZone &icu_tz = calendar->getTimeZone(); + JSMutableHandle timezoneValue(thread, dateTimeFormat->GetTimeZone()); + const icu::TimeZone &icuTz = calendar->getTimeZone(); icu::UnicodeString timezone; - icu_tz.getID(timezone); + icuTz.getID(timezone); UErrorCode status = U_ZERO_ERROR; - icu::UnicodeString canonical_timezone; - icu::TimeZone::getCanonicalID(timezone, canonical_timezone, status); + icu::UnicodeString canonicalTimezone; + icu::TimeZone::getCanonicalID(timezone, canonicalTimezone, status); if (U_SUCCESS(status) != 0) { - if ((canonical_timezone == UNICODE_STRING_SIMPLE("Etc/UTC")) != 0 || - (canonical_timezone == UNICODE_STRING_SIMPLE("Etc/GMT")) != 0) { - timezone_value.Update(global_const->GetUTCString()); + if ((canonicalTimezone == UNICODE_STRING_SIMPLE("Etc/UTC")) != 0 || + (canonicalTimezone == UNICODE_STRING_SIMPLE("Etc/GMT")) != 0) { + timezoneValue.Update(globalConst->GetUTCString()); } else { - timezone_value.Update(JSLocale::IcuToString(thread, canonical_timezone).GetTaggedValue()); + timezoneValue.Update(JSLocale::IcuToString(thread, canonicalTimezone).GetTaggedValue()); } } - property = global_const->GetHandledTimeZoneString(); - JSObject::CreateDataPropertyOrThrow(thread, options, property, timezone_value); + property = globalConst->GetHandledTimeZoneString(); + JSObject::CreateDataPropertyOrThrow(thread, options, property, timezoneValue); // [[HourCycle]] // For web compatibility reasons, if the property "hourCycle" is set, the "hour12" property should be set to true // when "hourCycle" is "h11" or "h12", or to false when "hourCycle" is "h23" or "h24". // i. Let hc be dtf.[[HourCycle]]. - JSHandle hc_value; - HourCycleOption hc = static_cast(date_time_format->GetHourCycle().GetInt()); + JSHandle hcValue; + HourCycleOption hc = static_cast(dateTimeFormat->GetHourCycle().GetInt()); if (hc != HourCycleOption::UNDEFINED) { - property = global_const->GetHandledHourCycleString(); - hc_value = ToHourCycleEcmaString(thread, date_time_format->GetHourCycle().GetInt()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, hc_value); + property = globalConst->GetHandledHourCycleString(); + hcValue = ToHourCycleEcmaString(thread, dateTimeFormat->GetHourCycle().GetInt()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); if (hc == HourCycleOption::H11 || hc == HourCycleOption::H12) { - JSHandle true_value(thread, JSTaggedValue::True()); - hc_value = true_value; + JSHandle trueValue(thread, JSTaggedValue::True()); + hcValue = trueValue; } else if (hc == HourCycleOption::H23 || hc == HourCycleOption::H24) { - JSHandle false_value(thread, JSTaggedValue::False()); - hc_value = false_value; + JSHandle falseValue(thread, JSTaggedValue::False()); + hcValue = falseValue; } - property = global_const->GetHandledHour12String(); - JSObject::CreateDataPropertyOrThrow(thread, options, property, hc_value); + property = globalConst->GetHandledHour12String(); + JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); } // [[DateStyle]], [[TimeStyle]]. - icu::UnicodeString pattern_unicode; - icu_simple_date_format->toPattern(pattern_unicode); + icu::UnicodeString patternUnicode; + icuSimpleDateFormat->toPattern(patternUnicode); std::string pattern; - pattern_unicode.toUTF8String(pattern); - if (date_time_format->GetDateStyle() == JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED)) && - date_time_format->GetTimeStyle() == JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { + patternUnicode.toUTF8String(pattern); + if (dateTimeFormat->GetDateStyle() == JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED)) && + dateTimeFormat->GetTimeStyle() == JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { for (const auto &item : BuildIcuPatternDescs()) { // fractionalSecondsDigits need to be added before timeZoneName. if (item.property == "timeZoneName") { - int tmp_result = count(pattern.begin(), pattern.end(), 'S'); - int fsd = (tmp_result >= STRING_LENGTH_3) ? STRING_LENGTH_3 : tmp_result; + int tmpResult = count(pattern.begin(), pattern.end(), 'S'); + int fsd = (tmpResult >= STRING_LENGTH_3) ? STRING_LENGTH_3 : tmpResult; if (fsd > 0) { - JSHandle fsd_value(thread, JSTaggedValue(fsd)); - property = global_const->GetHandledFractionalSecondDigitsString(); - JSObject::CreateDataPropertyOrThrow(thread, options, property, fsd_value); + JSHandle fsdValue(thread, JSTaggedValue(fsd)); + property = globalConst->GetHandledFractionalSecondDigitsString(); + JSObject::CreateDataPropertyOrThrow(thread, options, property, fsdValue); } } property = JSHandle::Cast(factory->NewFromStdString(item.property)); for (const auto &pair : item.pairs) { if (pattern.find(pair.first) != std::string::npos) { - hc_value = JSHandle::Cast(factory->NewFromStdString(pair.second)); - JSObject::CreateDataPropertyOrThrow(thread, options, property, hc_value); + hcValue = JSHandle::Cast(factory->NewFromStdString(pair.second)); + JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); break; } } } } - if (date_time_format->GetDateStyle() != JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { - property = global_const->GetHandledDateStyleString(); - hc_value = ToDateTimeStyleEcmaString(thread, date_time_format->GetDateStyle().GetInt()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, hc_value); + if (dateTimeFormat->GetDateStyle() != JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { + property = globalConst->GetHandledDateStyleString(); + hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetDateStyle().GetInt()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); } - if (date_time_format->GetTimeStyle() != JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { - property = global_const->GetHandledTimeStyleString(); - hc_value = ToDateTimeStyleEcmaString(thread, date_time_format->GetTimeStyle().GetInt()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, hc_value); + if (dateTimeFormat->GetTimeStyle() != JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { + property = globalConst->GetHandledTimeStyleString(); + hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetTimeStyle().GetInt()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); } } @@ -901,14 +897,14 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle &dtf, double x, double y) { - std::unique_ptr date_interval_format(ConstructDateIntervalFormat(dtf)); - if (date_interval_format == nullptr) { - icu::FormattedDateInterval empty_value; - THROW_TYPE_ERROR_AND_RETURN(thread, "create dateIntervalFormat failed", empty_value); + std::unique_ptr dateIntervalFormat(ConstructDateIntervalFormat(dtf)); + if (dateIntervalFormat == nullptr) { + icu::FormattedDateInterval emptyValue; + THROW_TYPE_ERROR_AND_RETURN(thread, "create dateIntervalFormat failed", emptyValue); } UErrorCode status = U_ZERO_ERROR; - icu::DateInterval date_interval(x, y); - icu::FormattedDateInterval formatted = date_interval_format->formatToValue(date_interval, status); + icu::DateInterval dateInterval(x, y); + icu::FormattedDateInterval formatted = dateIntervalFormat->formatToValue(dateInterval, status); return formatted; } @@ -934,9 +930,9 @@ JSHandle JSDateTimeFormat::NormDateTimeRange(JSThread *thread, const RETURN_HANDLE_IF_ABRUPT_COMPLETION(EcmaString, thread); // Formatted to string. - bool output_range = false; + bool outputRange = false; UErrorCode status = U_ZERO_ERROR; - icu::UnicodeString format_result = formatted.toString(status); + icu::UnicodeString formatResult = formatted.toString(status); if (U_FAILURE(status) != 0) { THROW_TYPE_ERROR_AND_RETURN(thread, "format to string failed", thread->GetEcmaVM()->GetFactory()->GetEmptyString()); @@ -944,12 +940,12 @@ JSHandle JSDateTimeFormat::NormDateTimeRange(JSThread *thread, const icu::ConstrainedFieldPosition cfpos; while (formatted.nextPosition(cfpos, status) != 0) { if (cfpos.getCategory() == UFIELD_CATEGORY_DATE_INTERVAL_SPAN) { - output_range = true; + outputRange = true; break; } } - result = JSLocale::IcuToString(thread, format_result); - if (!output_range) { + result = JSLocale::IcuToString(thread, formatResult); + if (!outputRange) { return FormatDateTime(thread, dtf, x); } return result; @@ -980,27 +976,27 @@ JSHandle JSDateTimeFormat::NormDateTimeRangeToParts(JSThread *thread, c JSHandle JSDateTimeFormat::GainAvailableLocales(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle date_time_format_locales = env->GetDateTimeFormatLocales(); + JSHandle dateTimeFormatLocales = env->GetDateTimeFormatLocales(); const char *key = "calendar"; const char *path = nullptr; - if (date_time_format_locales->IsUndefined()) { - JSHandle available_locales = JSLocale::GetAvailableLocales(thread, key, path); - env->SetDateTimeFormatLocales(thread, available_locales); - return available_locales; + if (dateTimeFormatLocales->IsUndefined()) { + JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, key, path); + env->SetDateTimeFormatLocales(thread, availableLocales); + return availableLocales; } - return JSHandle::Cast(date_time_format_locales); + return JSHandle::Cast(dateTimeFormatLocales); } JSHandle JSDateTimeFormat::ConstructFDateIntervalToJSArray(JSThread *thread, const icu::FormattedDateInterval &formatted) { UErrorCode status = U_ZERO_ERROR; - icu::UnicodeString formatted_value = formatted.toTempString(status); + icu::UnicodeString formattedValue = formatted.toTempString(status); // Let result be ArrayCreate(0). JSHandle array(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); // Let index be 0. int index = 0; - int32_t pre_end_pos = 0; + int32_t preEndPos = 0; std::array begin {}; std::array end {}; begin[0] = begin[1] = end[0] = end[1] = 0; @@ -1026,47 +1022,47 @@ JSHandle JSDateTimeFormat::ConstructFDateIntervalToJSArray(JSThread *th JSMutableHandle substring(thread, JSTaggedValue::Undefined()); icu::ConstrainedFieldPosition cfpos; while (formatted.nextPosition(cfpos, status) != 0) { - int32_t f_category = cfpos.getCategory(); - int32_t f_field = cfpos.getField(); - int32_t f_start = cfpos.getStart(); - int32_t f_limit = cfpos.getLimit(); + int32_t fCategory = cfpos.getCategory(); + int32_t fField = cfpos.getField(); + int32_t fStart = cfpos.getStart(); + int32_t fLimit = cfpos.getLimit(); // 2 means the number of elements in category - if (f_category == UFIELD_CATEGORY_DATE_INTERVAL_SPAN && (f_field == 0 || f_field == 1)) { - begin[f_field] = f_start; - end[f_field] = f_limit; + if (fCategory == UFIELD_CATEGORY_DATE_INTERVAL_SPAN && (fField == 0 || fField == 1)) { + begin[fField] = fStart; + end[fField] = fLimit; } - if (f_category == UFIELD_CATEGORY_DATE) { - if (pre_end_pos < f_start) { - parts.emplace_back(CommonDateFormatPart(f_field, pre_end_pos, f_start, index, true)); + if (fCategory == UFIELD_CATEGORY_DATE) { + if (preEndPos < fStart) { + parts.emplace_back(CommonDateFormatPart(fField, preEndPos, fStart, index, true)); index++; } - parts.emplace_back(CommonDateFormatPart(f_field, f_start, f_limit, index, false)); - pre_end_pos = f_limit; + parts.emplace_back(CommonDateFormatPart(fField, fStart, fLimit, index, false)); + preEndPos = fLimit; ++index; } } if (U_FAILURE(status) != 0) { THROW_TYPE_ERROR_AND_RETURN(thread, "format date interval error", array); } - int32_t length = formatted_value.length(); - if (length > pre_end_pos) { - parts.emplace_back(CommonDateFormatPart(-1, pre_end_pos, length, index, true)); + int32_t length = formattedValue.length(); + if (length > preEndPos) { + parts.emplace_back(CommonDateFormatPart(-1, preEndPos, length, index, true)); } for (auto part : parts) { substring.Update( - JSLocale::IcuToString(thread, formatted_value, part.f_begin_index, part.f_end_index).GetTaggedValue()); + JSLocale::IcuToString(thread, formattedValue, part.fBeginIndex, part.fEndIndex).GetTaggedValue()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); JSHandle element; - if (part.is_pre_exist) { + if (part.isPreExist) { element = JSLocale::PutElement(thread, part.index, array, ConvertFieldIdToDateType(thread, -1), JSHandle::Cast(substring)); } else { - element = JSLocale::PutElement(thread, part.index, array, ConvertFieldIdToDateType(thread, part.f_field), + element = JSLocale::PutElement(thread, part.index, array, ConvertFieldIdToDateType(thread, part.fField), JSHandle::Cast(substring)); } JSHandle value = JSHandle::Cast( - ToValueString(thread, TrackValue(part.f_begin_index, part.f_end_index, begin, end))); + ToValueString(thread, TrackValue(part.fBeginIndex, part.fEndIndex, begin, end))); JSObject::SetProperty(thread, element, thread->GlobalConstants()->GetHandledSourceString(), value, true); } return array; @@ -1099,41 +1095,41 @@ std::vector BuildIcuPatternDescs() return items; } -std::vector InitializePattern(const IcuPatternDesc &hour_data) +std::vector InitializePattern(const IcuPatternDesc &hourData) { std::vector result; std::vector items = BuildIcuPatternDescs(); auto item = items.begin(); while (static_cast(item != items.end()) != 0) { if (item->property != "hour") { - result.emplace_back(IcuPatternDesc(item->property, item->pairs, item->allowed_values)); + result.emplace_back(IcuPatternDesc(item->property, item->pairs, item->allowedValues)); } else { - result.emplace_back(hour_data); + result.emplace_back(hourData); } item++; } return result; } -std::vector JSDateTimeFormat::GetIcuPatternDesc(const HourCycleOption &hour_cycle) +std::vector JSDateTimeFormat::GetIcuPatternDesc(const HourCycleOption &hourCycle) { - if (hour_cycle == HourCycleOption::H11) { + if (hourCycle == HourCycleOption::H11) { Pattern h11("KK", "K"); return h11.Get(); } - if (hour_cycle == HourCycleOption::H12) { + if (hourCycle == HourCycleOption::H12) { Pattern h12("hh", "h"); return h12.Get(); } - if (hour_cycle == HourCycleOption::H23) { + if (hourCycle == HourCycleOption::H23) { Pattern h23("HH", "H"); return h23.Get(); } - if (hour_cycle == HourCycleOption::H24) { + if (hourCycle == HourCycleOption::H24) { Pattern h24("kk", "k"); return h24.Get(); } - if (hour_cycle == HourCycleOption::UNDEFINED) { + if (hourCycle == HourCycleOption::UNDEFINED) { Pattern pattern("jj", "j"); return pattern.Get(); } @@ -1147,22 +1143,22 @@ icu::UnicodeString JSDateTimeFormat::ChangeHourCyclePattern(const icu::UnicodeSt } icu::UnicodeString result; char16_t key = u'\0'; - auto map_iter = + auto mapIter = std::find_if(HOUR_CYCLE_MAP.begin(), HOUR_CYCLE_MAP.end(), [hc](const std::map::value_type item) { return item.second == hc; }); - if (map_iter != HOUR_CYCLE_MAP.end()) { - key = map_iter->first; + if (mapIter != HOUR_CYCLE_MAP.end()) { + key = mapIter->first; } - bool need_change = true; + bool needChange = true; char16_t last = u'\0'; for (int32_t i = 0; i < pattern.length(); i++) { char16_t ch = pattern.charAt(i); if (ch == '\'') { - need_change = !need_change; + needChange = !needChange; result.append(ch); } else if (HOUR_CYCLE_MAP.find(ch) != HOUR_CYCLE_MAP.end()) { - result = (need_change && last == u'd') ? result.append(' ') : result; - result.append(need_change ? key : ch); + result = (needChange && last == u'd') ? result.append(' ') : result; + result.append(needChange ? key : ch); } else { result.append(ch); } @@ -1171,7 +1167,7 @@ icu::UnicodeString JSDateTimeFormat::ChangeHourCyclePattern(const icu::UnicodeSt return result; } -std::unique_ptr JSDateTimeFormat::CreateICUSimpleDateFormat(const icu::Locale &icu_locale, +std::unique_ptr JSDateTimeFormat::CreateICUSimpleDateFormat(const icu::Locale &icuLocale, const icu::UnicodeString &skeleton, icu::DateTimePatternGenerator *gn, HourCycleOption hc) @@ -1183,19 +1179,18 @@ std::unique_ptr JSDateTimeFormat::CreateICUSimpleDateForm ASSERT_PRINT((U_SUCCESS(status) != 0), "get best pattern failed"); status = U_ZERO_ERROR; - auto date_format(std::make_unique(pattern, icu_locale, status)); + auto dateFormat(std::make_unique(pattern, icuLocale, status)); if (U_FAILURE(status) != 0) { return std::unique_ptr(); } - ASSERT_PRINT(date_format != nullptr, "dateFormat failed"); - return date_format; + ASSERT_PRINT(dateFormat != nullptr, "dateFormat failed"); + return dateFormat; } -std::unique_ptr JSDateTimeFormat::BuildCalendar(const icu::Locale &locale, - const icu::TimeZone &time_zone) +std::unique_ptr JSDateTimeFormat::BuildCalendar(const icu::Locale &locale, const icu::TimeZone &timeZone) { UErrorCode status = U_ZERO_ERROR; - std::unique_ptr calendar(icu::Calendar::createInstance(time_zone, locale, status)); + std::unique_ptr calendar(icu::Calendar::createInstance(timeZone, locale, status)); ASSERT_PRINT(U_SUCCESS(status), "buildCalendar failed"); ASSERT_PRINT(calendar.get() != nullptr, "calender is nullptr"); @@ -1209,10 +1204,10 @@ std::unique_ptr JSDateTimeFormat::BuildCalendar(const icu::Locale * Derived::getStaticClassID()) ... */ if (calendar->getDynamicClassID() == icu::GregorianCalendar::getStaticClassID()) { - auto gregorian_calendar = static_cast(calendar.get()); + auto gregorianCalendar = static_cast(calendar.get()); // ECMAScript start time, value = -(2**53) - const double begin_time = -9007199254740992; - gregorian_calendar->setGregorianChange(begin_time, status); + const double beginTime = -9007199254740992; + gregorianCalendar->setGregorianChange(beginTime, status); ASSERT(U_SUCCESS(status)); } return calendar; @@ -1234,7 +1229,7 @@ std::unique_ptr JSDateTimeFormat::ConstructTimeZone(const std::st std::map JSDateTimeFormat::GetSpecialTimeZoneMap() { - std::vector specical_time_zones = { + std::vector specicalTimeZones = { "America/Argentina/ComodRivadavia" "America/Knox_IN" "Antarctica/McMurdo" @@ -1267,7 +1262,7 @@ std::map JSDateTimeFormat::GetSpecialTimeZoneMap() "W-SU" "WET"}; std::map map; - for (const auto &item : specical_time_zones) { + for (const auto &item : specicalTimeZones) { std::string upper(item); transform(upper.begin(), upper.end(), upper.begin(), toupper); map.insert({upper, item}); @@ -1307,8 +1302,8 @@ std::string JSDateTimeFormat::ToTitleCaseFunction(const std::string &input) bool JSDateTimeFormat::IsValidTimeZoneInput(const std::string &input) { std::regex r("[a-zA-Z_-/]*"); - bool is_valid = regex_match(input, r); - return is_valid; + bool isValid = regex_match(input, r); + return isValid; } std::string JSDateTimeFormat::ToTitleCaseTimezonePosition(const std::string &input) @@ -1316,30 +1311,30 @@ std::string JSDateTimeFormat::ToTitleCaseTimezonePosition(const std::string &inp if (!IsValidTimeZoneInput(input)) { return std::string(); } - std::vector title_entry; - std::vector char_entry; - int32_t left_position = 0; - int32_t title_length = 0; + std::vector titleEntry; + std::vector charEntry; + int32_t leftPosition = 0; + int32_t titleLength = 0; for (size_t i = 0; i < input.length(); i++) { if (input[i] == '_' || input[i] == '-' || input[i] == '/') { std::string s(1, input[i]); - char_entry.emplace_back(s); - title_length = i - left_position; - title_entry.emplace_back(input.substr(left_position, title_length)); - left_position = i + 1; + charEntry.emplace_back(s); + titleLength = i - leftPosition; + titleEntry.emplace_back(input.substr(leftPosition, titleLength)); + leftPosition = i + 1; } else { continue; } } std::string result; - for (size_t i = 0; i < title_entry.size() - 1; i++) { - std::string title_value = ToTitleCaseFunction(title_entry[i]); - if (title_value == "Of" || title_value == "Es" || title_value == "Au") { - title_value[0] = tolower(title_value[0]); + for (size_t i = 0; i < titleEntry.size() - 1; i++) { + std::string titleValue = ToTitleCaseFunction(titleEntry[i]); + if (titleValue == "Of" || titleValue == "Es" || titleValue == "Au") { + titleValue[0] = tolower(titleValue[0]); } - result += title_value + char_entry[i]; + result += titleValue + charEntry[i]; } - result = result + ToTitleCaseFunction(title_entry[title_entry.size() - 1]); + result = result + ToTitleCaseFunction(titleEntry[titleEntry.size() - 1]); return result; } @@ -1358,12 +1353,12 @@ std::string JSDateTimeFormat::ConstructGMTTimeZoneID(const std::string &input) std::string JSDateTimeFormat::ToHourCycleString(int32_t hc) { - auto map_iter = std::find_if(TO_HOUR_CYCLE_MAP.begin(), TO_HOUR_CYCLE_MAP.end(), - [hc](const std::map::value_type &item) { - return static_cast(item.second) == hc; - }); - if (map_iter != TO_HOUR_CYCLE_MAP.end()) { - return map_iter->first; + auto mapIter = std::find_if(TO_HOUR_CYCLE_MAP.begin(), TO_HOUR_CYCLE_MAP.end(), + [hc](const std::map::value_type &item) { + return static_cast(item.second) == hc; + }); + if (mapIter != TO_HOUR_CYCLE_MAP.end()) { + return mapIter->first; } return ""; } @@ -1379,65 +1374,65 @@ HourCycleOption JSDateTimeFormat::OptionToHourCycle(const std::string &hc) HourCycleOption JSDateTimeFormat::OptionToHourCycle(UDateFormatHourCycle hc) { - HourCycleOption hc_option = HourCycleOption::UNDEFINED; + HourCycleOption hcOption = HourCycleOption::UNDEFINED; switch (hc) { case UDAT_HOUR_CYCLE_11: - hc_option = HourCycleOption::H11; + hcOption = HourCycleOption::H11; break; case UDAT_HOUR_CYCLE_12: - hc_option = HourCycleOption::H12; + hcOption = HourCycleOption::H12; break; case UDAT_HOUR_CYCLE_23: - hc_option = HourCycleOption::H23; + hcOption = HourCycleOption::H23; break; case UDAT_HOUR_CYCLE_24: - hc_option = HourCycleOption::H24; + hcOption = HourCycleOption::H24; break; default: UNREACHABLE(); } - return hc_option; + return hcOption; } -JSHandle JSDateTimeFormat::ConvertFieldIdToDateType(JSThread *thread, int32_t field_id) +JSHandle JSDateTimeFormat::ConvertFieldIdToDateType(JSThread *thread, int32_t fieldId) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); - if (field_id == -1) { - result.Update(global_const->GetHandledLiteralString().GetTaggedValue()); - } else if (field_id == UDAT_YEAR_FIELD || field_id == UDAT_EXTENDED_YEAR_FIELD) { - result.Update(global_const->GetHandledYearString().GetTaggedValue()); - } else if (field_id == UDAT_YEAR_NAME_FIELD) { - result.Update(global_const->GetHandledYearNameString().GetTaggedValue()); - } else if (field_id == UDAT_MONTH_FIELD || field_id == UDAT_STANDALONE_MONTH_FIELD) { - result.Update(global_const->GetHandledMonthString().GetTaggedValue()); - } else if (field_id == UDAT_DATE_FIELD) { - result.Update(global_const->GetHandledDayString().GetTaggedValue()); - } else if (field_id == UDAT_HOUR_OF_DAY1_FIELD || field_id == UDAT_HOUR_OF_DAY0_FIELD || - field_id == UDAT_HOUR1_FIELD || field_id == UDAT_HOUR0_FIELD) { - result.Update(global_const->GetHandledHourString().GetTaggedValue()); - } else if (field_id == UDAT_MINUTE_FIELD) { - result.Update(global_const->GetHandledMinuteString().GetTaggedValue()); - } else if (field_id == UDAT_SECOND_FIELD) { - result.Update(global_const->GetHandledSecondString().GetTaggedValue()); - } else if (field_id == UDAT_DAY_OF_WEEK_FIELD || field_id == UDAT_DOW_LOCAL_FIELD || - field_id == UDAT_STANDALONE_DAY_FIELD) { - result.Update(global_const->GetHandledWeekdayString().GetTaggedValue()); - } else if (field_id == UDAT_AM_PM_FIELD || field_id == UDAT_AM_PM_MIDNIGHT_NOON_FIELD || - field_id == UDAT_FLEXIBLE_DAY_PERIOD_FIELD) { - result.Update(global_const->GetHandledDayPeriodString().GetTaggedValue()); - } else if (field_id == UDAT_TIMEZONE_FIELD || field_id == UDAT_TIMEZONE_RFC_FIELD || - field_id == UDAT_TIMEZONE_GENERIC_FIELD || field_id == UDAT_TIMEZONE_SPECIAL_FIELD || - field_id == UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD || field_id == UDAT_TIMEZONE_ISO_FIELD || - field_id == UDAT_TIMEZONE_ISO_LOCAL_FIELD) { - result.Update(global_const->GetHandledTimeZoneNameString().GetTaggedValue()); - } else if (field_id == UDAT_ERA_FIELD) { - result.Update(global_const->GetHandledEraString().GetTaggedValue()); - } else if (field_id == UDAT_FRACTIONAL_SECOND_FIELD) { - result.Update(global_const->GetHandledFractionalSecondString().GetTaggedValue()); - } else if (field_id == UDAT_RELATED_YEAR_FIELD) { - result.Update(global_const->GetHandledRelatedYearString().GetTaggedValue()); - } else if (field_id == UDAT_QUARTER_FIELD || field_id == UDAT_STANDALONE_QUARTER_FIELD) { + auto globalConst = thread->GlobalConstants(); + if (fieldId == -1) { + result.Update(globalConst->GetHandledLiteralString().GetTaggedValue()); + } else if (fieldId == UDAT_YEAR_FIELD || fieldId == UDAT_EXTENDED_YEAR_FIELD) { + result.Update(globalConst->GetHandledYearString().GetTaggedValue()); + } else if (fieldId == UDAT_YEAR_NAME_FIELD) { + result.Update(globalConst->GetHandledYearNameString().GetTaggedValue()); + } else if (fieldId == UDAT_MONTH_FIELD || fieldId == UDAT_STANDALONE_MONTH_FIELD) { + result.Update(globalConst->GetHandledMonthString().GetTaggedValue()); + } else if (fieldId == UDAT_DATE_FIELD) { + result.Update(globalConst->GetHandledDayString().GetTaggedValue()); + } else if (fieldId == UDAT_HOUR_OF_DAY1_FIELD || fieldId == UDAT_HOUR_OF_DAY0_FIELD || + fieldId == UDAT_HOUR1_FIELD || fieldId == UDAT_HOUR0_FIELD) { + result.Update(globalConst->GetHandledHourString().GetTaggedValue()); + } else if (fieldId == UDAT_MINUTE_FIELD) { + result.Update(globalConst->GetHandledMinuteString().GetTaggedValue()); + } else if (fieldId == UDAT_SECOND_FIELD) { + result.Update(globalConst->GetHandledSecondString().GetTaggedValue()); + } else if (fieldId == UDAT_DAY_OF_WEEK_FIELD || fieldId == UDAT_DOW_LOCAL_FIELD || + fieldId == UDAT_STANDALONE_DAY_FIELD) { + result.Update(globalConst->GetHandledWeekdayString().GetTaggedValue()); + } else if (fieldId == UDAT_AM_PM_FIELD || fieldId == UDAT_AM_PM_MIDNIGHT_NOON_FIELD || + fieldId == UDAT_FLEXIBLE_DAY_PERIOD_FIELD) { + result.Update(globalConst->GetHandledDayPeriodString().GetTaggedValue()); + } else if (fieldId == UDAT_TIMEZONE_FIELD || fieldId == UDAT_TIMEZONE_RFC_FIELD || + fieldId == UDAT_TIMEZONE_GENERIC_FIELD || fieldId == UDAT_TIMEZONE_SPECIAL_FIELD || + fieldId == UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD || fieldId == UDAT_TIMEZONE_ISO_FIELD || + fieldId == UDAT_TIMEZONE_ISO_LOCAL_FIELD) { + result.Update(globalConst->GetHandledTimeZoneNameString().GetTaggedValue()); + } else if (fieldId == UDAT_ERA_FIELD) { + result.Update(globalConst->GetHandledEraString().GetTaggedValue()); + } else if (fieldId == UDAT_FRACTIONAL_SECOND_FIELD) { + result.Update(globalConst->GetHandledFractionalSecondString().GetTaggedValue()); + } else if (fieldId == UDAT_RELATED_YEAR_FIELD) { + result.Update(globalConst->GetHandledRelatedYearString().GetTaggedValue()); + } else if (fieldId == UDAT_QUARTER_FIELD || fieldId == UDAT_STANDALONE_QUARTER_FIELD) { UNREACHABLE(); } return result; @@ -1446,26 +1441,26 @@ JSHandle JSDateTimeFormat::ConvertFieldIdToDateType(JSThread *thr std::unique_ptr JSDateTimeFormat::ConstructDateIntervalFormat( const JSHandle &dtf) { - icu::SimpleDateFormat *icu_simple_date_format = dtf->GetIcuSimpleDateFormat(); + icu::SimpleDateFormat *icuSimpleDateFormat = dtf->GetIcuSimpleDateFormat(); icu::Locale locale = *(dtf->GetIcuLocale()); - std::string hc_string = ToHourCycleString(dtf->GetHourCycle().GetInt()); + std::string hcString = ToHourCycleString(dtf->GetHourCycle().GetInt()); UErrorCode status = U_ZERO_ERROR; // Sets the Unicode value for a Unicode keyword. - if (!hc_string.empty()) { - locale.setUnicodeKeywordValue("hc", hc_string, status); + if (!hcString.empty()) { + locale.setUnicodeKeywordValue("hc", hcString, status); } icu::UnicodeString pattern; // Return a pattern string describing this date format. - pattern = icu_simple_date_format->toPattern(pattern); + pattern = icuSimpleDateFormat->toPattern(pattern); // Utility to return a unique skeleton from a given pattern. icu::UnicodeString skeleton = icu::DateTimePatternGenerator::staticGetSkeleton(pattern, status); // Construct a DateIntervalFormat from skeleton and a given locale. - std::unique_ptr date_interval_format( + std::unique_ptr dateIntervalFormat( icu::DateIntervalFormat::createInstance(skeleton, locale, status)); if (U_FAILURE(status) != 0) { return nullptr; } - date_interval_format->setTimeZone(icu_simple_date_format->getTimeZone()); - return date_interval_format; + dateIntervalFormat->setTimeZone(icuSimpleDateFormat->getTimeZone()); + return dateIntervalFormat; } } // namespace panda::ecmascript diff --git a/runtime/js_date_time_format.h b/runtime/js_date_time_format.h index f165fff022517070b05886f9497ed9ec3a0a4754..1d9b6bd7c51477a946a0d7abe77d33a5ee6ef87d 100644 --- a/runtime/js_date_time_format.h +++ b/runtime/js_date_time_format.h @@ -39,18 +39,16 @@ constexpr int STRING_LENGTH_10 = 10; class IcuPatternDesc; std::vector BuildIcuPatternDescs(); -std::vector InitializePattern(const IcuPatternDesc &hour_data); +std::vector InitializePattern(const IcuPatternDesc &hourData); using IcuPatternDescVect = std::vector; using IcuPatternEntry = std::pair; class IcuPatternDesc { public: - IcuPatternDesc(std::string property_param, std::vector pairs_param, - std::vector allowed_values_param) - : property(std::move(property_param)), - pairs(std::move(pairs_param)), - allowed_values(std::move(allowed_values_param)) + IcuPatternDesc(std::string propertyParam, std::vector pairsParam, + std::vector allowedValuesParam) + : property(std::move(propertyParam)), pairs(std::move(pairsParam)), allowedValues(std::move(allowedValuesParam)) { for (const auto &pair : pairs) { map.insert(std::make_pair(pair.second, pair.first)); @@ -62,7 +60,7 @@ public: std::string property; // NOLINT(misc-non-private-member-variables-in-classes) std::vector pairs; // NOLINT(misc-non-private-member-variables-in-classes) std::map map; // NOLINT(misc-non-private-member-variables-in-classes) - std::vector allowed_values; // NOLINT(misc-non-private-member-variables-in-classes) + std::vector allowedValues; // NOLINT(misc-non-private-member-variables-in-classes) DEFAULT_COPY_SEMANTIC(IcuPatternDesc); // NOLINT(performance-noexcept-move-constructor, hicpp-noexcept-move) @@ -109,19 +107,19 @@ public: DECL_DUMP() icu::Locale *GetIcuLocale() const; - static void SetIcuLocale(JSThread *thread, JSHandle obj, const icu::Locale &icu_locale, + static void SetIcuLocale(JSThread *thread, JSHandle obj, const icu::Locale &icuLocale, const DeleteEntryPoint &callback); static void FreeIcuLocale(void *pointer, void *data); icu::SimpleDateFormat *GetIcuSimpleDateFormat() const; static void SetIcuSimpleDateFormat(JSThread *thread, JSHandle obj, - const icu::SimpleDateFormat &icu_simple_date_time_format, + const icu::SimpleDateFormat &icuSimpleDateTimeFormat, const DeleteEntryPoint &callback); static void FreeSimpleDateFormat(void *pointer, void *data); // 13.1.1 InitializeDateTimeFormat (dateTimeFormat, locales, options) static JSHandle InitializeDateTimeFormat(JSThread *thread, - const JSHandle &date_time_format, + const JSHandle &dateTimeFormat, const JSHandle &locales, const JSHandle &options); @@ -130,20 +128,20 @@ public: const RequiredOption &required, const DefaultsOption &defaults); // 13.1.7 FormatDateTime(dateTimeFormat, x) - static JSHandle FormatDateTime(JSThread *thread, const JSHandle &date_time_format, + static JSHandle FormatDateTime(JSThread *thread, const JSHandle &dateTimeFormat, double x); // 13.1.8 FormatDateTimeToParts (dateTimeFormat, x) - static JSHandle FormatDateTimeToParts(JSThread *thread, const JSHandle &date_time_format, + static JSHandle FormatDateTimeToParts(JSThread *thread, const JSHandle &dateTimeFormat, double x); // 13.1.10 UnwrapDateTimeFormat(dtf) static JSHandle UnwrapDateTimeFormat(JSThread *thread, - const JSHandle &date_time_format); + const JSHandle &dateTimeFormat); static JSHandle GainAvailableLocales(JSThread *thread); - static void ResolvedOptions(JSThread *thread, const JSHandle &date_time_format, + static void ResolvedOptions(JSThread *thread, const JSHandle &dateTimeFormat, const JSHandle &options); static JSHandle NormDateTimeRange(JSThread *thread, const JSHandle &dtf, double x, @@ -172,21 +170,21 @@ private: static std::string ConstructGMTTimeZoneID(const std::string &input); - static std::unique_ptr BuildCalendar(const icu::Locale &locale, const icu::TimeZone &time_zone); + static std::unique_ptr BuildCalendar(const icu::Locale &locale, const icu::TimeZone &timeZone); static std::map GetSpecialTimeZoneMap(); static JSHandle ConstructFDateIntervalToJSArray(JSThread *thread, const icu::FormattedDateInterval &formatted); - static std::vector GetIcuPatternDesc(const HourCycleOption &hour_cycle); + static std::vector GetIcuPatternDesc(const HourCycleOption &hourCycle); - static std::unique_ptr CreateICUSimpleDateFormat(const icu::Locale &icu_locale, + static std::unique_ptr CreateICUSimpleDateFormat(const icu::Locale &icuLocale, const icu::UnicodeString &skeleton, icu::DateTimePatternGenerator *gn, HourCycleOption hc); - static JSHandle ConvertFieldIdToDateType(JSThread *thread, int32_t field_id); + static JSHandle ConvertFieldIdToDateType(JSThread *thread, int32_t fieldId); static icu::UnicodeString ChangeHourCyclePattern(const icu::UnicodeString &pattern, HourCycleOption hc); diff --git a/runtime/js_eval.cpp b/runtime/js_eval.cpp index 73e3c5c4dc127c13837b0eac1bdb688b03f593da..f216b1ebfb342a195b10f7cc2256e5a31c290470 100644 --- a/runtime/js_eval.cpp +++ b/runtime/js_eval.cpp @@ -24,18 +24,18 @@ namespace panda::ecmascript { JSTaggedValue EvalUtils::GetEvaluatedScript(JSThread *thread, const JSHandle &str, - const es2panda::CompilerOptions &options, uint32_t parser_status) + const es2panda::CompilerOptions &options, uint32_t parserStatus) { auto buffer = str->GetCString(); es2panda::Compiler compiler(es2panda::ScriptExtension::JS); es2panda::SourceFile input("eval.js", std::string_view(buffer.get()), false); - std::unique_ptr program(compiler.Compile(input, options, parser_status)); - ObjectFactory *object_factory = thread->GetEcmaVM()->GetFactory(); + std::unique_ptr program(compiler.Compile(input, options, parserStatus)); + ObjectFactory *objectFactory = thread->GetEcmaVM()->GetFactory(); if (!program) { const auto &err = compiler.GetError(); - JSHandle error = object_factory->GetJSError(ErrorType::SYNTAX_ERROR, err.Message().c_str()); + JSHandle error = objectFactory->GetJSError(ErrorType::SYNTAX_ERROR, err.Message().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Exception()); } @@ -47,16 +47,16 @@ JSTaggedValue EvalUtils::GetEvaluatedScript(JSThread *thread, const JSHandleGetEcmaVM(); + auto *pandaFile = pf.get(); + auto *ecmaVm = thread->GetEcmaVM(); - ecma_vm->AddPandaFile(panda_file, false); + ecmaVm->AddPandaFile(pandaFile, false); Runtime::GetCurrent()->GetClassLinker()->AddPandaFile(std::move(pf)); - auto resolve_func = ecma_vm->GetInvocableFunction(*panda_file, "func_main_0"); - ASSERT(resolve_func.HasValue()); + auto resolveFunc = ecmaVm->GetInvocableFunction(*pandaFile, "func_main_0"); + ASSERT(resolveFunc.HasValue()); - JSHandle func(thread, resolve_func.Value()); + JSHandle func(thread, resolveFunc.Value()); // For DirectEval, functions in envirement and in arguments are different. // Compiled code use function form the parameter for creating envirement. // So we temporary disable compilation for eval calls. @@ -65,35 +65,35 @@ JSTaggedValue EvalUtils::GetEvaluatedScript(JSThread *thread, const JSHandleAtomicSetCompilationStatus(Method::NOT_COMPILED, Method::FAILED); ASSERT(method->GetCompilationStatus() == Method::FAILED); - return resolve_func.Value(); + return resolveFunc.Value(); } -JSTaggedValue EvalUtils::DirectEval(JSThread *thread, uint32_t parser_status, JSTaggedValue arg0, +JSTaggedValue EvalUtils::DirectEval(JSThread *thread, uint32_t parserStatus, JSTaggedValue arg0, JSTaggedValue evalbindings) { [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle arg0_handle(thread, arg0); - JSHandle eval_bindings_handle(thread, evalbindings); - JSHandle arg_str = JSTaggedValue::ToString(thread, arg0_handle); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, arg_str.GetTaggedValue()); + JSHandle arg0Handle(thread, arg0); + JSHandle evalBindingsHandle(thread, evalbindings); + JSHandle argStr = JSTaggedValue::ToString(thread, arg0Handle); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, argStr.GetTaggedValue()); es2panda::CompilerOptions options; - options.is_eval = true; - options.is_direct_eval = true; + options.isEval = true; + options.isDirectEval = true; - JSHandle func(thread, GetEvaluatedScript(thread, arg_str, options, parser_status)); + JSHandle func(thread, GetEvaluatedScript(thread, argStr, options, parserStatus)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); uint32_t index = 0; - JSHandle param_func = JSArray::FastGetPropertyByValue(thread, eval_bindings_handle, index++); - JSHandle new_target = JSArray::FastGetPropertyByValue(thread, eval_bindings_handle, index++); - JSHandle this_value = JSArray::FastGetPropertyByValue(thread, eval_bindings_handle, index++); - JSHandle lexical_context = JSArray::FastGetPropertyByValue(thread, eval_bindings_handle, index++); + JSHandle paramFunc = JSArray::FastGetPropertyByValue(thread, evalBindingsHandle, index++); + JSHandle newTarget = JSArray::FastGetPropertyByValue(thread, evalBindingsHandle, index++); + JSHandle thisValue = JSArray::FastGetPropertyByValue(thread, evalBindingsHandle, index++); + JSHandle lexicalContext = JSArray::FastGetPropertyByValue(thread, evalBindingsHandle, index++); ASSERT(1 == index - js_method_args::NUM_MANDATORY_ARGS); - auto info = NewRuntimeCallInfo(thread, param_func, this_value, new_target, 1); - info->SetCallArgs(lexical_context); + auto info = NewRuntimeCallInfo(thread, paramFunc, thisValue, newTarget, 1); + info->SetCallArgs(lexicalContext); auto res = EcmaInterpreter::ExecuteInEnv(info.Get(), func.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -104,118 +104,118 @@ JSTaggedValue EvalUtils::Eval(JSThread *thread, const JSHandle &a { [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle arg_str = JSTaggedValue::ToString(thread, arg0); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, arg_str.GetTaggedValue()); + JSHandle argStr = JSTaggedValue::ToString(thread, arg0); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, argStr.GetTaggedValue()); es2panda::CompilerOptions options; - options.is_eval = true; - JSHandle func(thread, GetEvaluatedScript(thread, arg_str, options)); + options.isEval = true; + JSHandle func(thread, GetEvaluatedScript(thread, argStr, options)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); - JSHandle this_value(thread, thread->GetGlobalObject()); - auto info = NewRuntimeCallInfo(thread, func, this_value, JSTaggedValue::Undefined(), 0); + JSHandle thisValue(thread, thread->GetGlobalObject()); + auto info = NewRuntimeCallInfo(thread, func, thisValue, JSTaggedValue::Undefined(), 0); return EcmaInterpreter::Execute(info.Get()); } JSTaggedValue EvalUtils::CreateDynamicFunction(EcmaRuntimeCallInfo *argv, DynamicFunctionKind kind) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle function_body(thread, JSTaggedValue::Undefined()); - JSHandle function_param_str = factory->GetEmptyString(); + JSHandle functionBody(thread, JSTaggedValue::Undefined()); + JSHandle functionParamStr = factory->GetEmptyString(); uint32_t nargs = argv->GetArgsNumber(); if (nargs == 1) { - function_body = builtins_common::GetCallArg(argv, 0); + functionBody = builtins_common::GetCallArg(argv, 0); } else if (nargs > 1) { - JSHandle first_param_handle = builtins_common::GetCallArg(argv, 0); - function_param_str = JSTaggedValue::ToString(thread, first_param_handle); + JSHandle firstParamHandle = builtins_common::GetCallArg(argv, 0); + functionParamStr = JSTaggedValue::ToString(thread, firstParamHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint32_t iter = 1; while (iter < nargs - 1) { - JSHandle comma_str = factory->NewFromCanBeCompressString(","); - function_param_str = factory->ConcatFromString(function_param_str, comma_str); - JSHandle param_handle = builtins_common::GetCallArg(argv, iter); - JSHandle param_string = JSTaggedValue::ToString(thread, param_handle); + JSHandle commaStr = factory->NewFromCanBeCompressString(","); + functionParamStr = factory->ConcatFromString(functionParamStr, commaStr); + JSHandle paramHandle = builtins_common::GetCallArg(argv, iter); + JSHandle paramString = JSTaggedValue::ToString(thread, paramHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - function_param_str = factory->ConcatFromString(function_param_str, param_string); + functionParamStr = factory->ConcatFromString(functionParamStr, paramString); iter++; } - function_body = builtins_common::GetCallArg(argv, iter); + functionBody = builtins_common::GetCallArg(argv, iter); } - JSHandle result_str = factory->NewFromCanBeCompressString("("); - JSHandle function_body_str = factory->GetEmptyString(); + JSHandle resultStr = factory->NewFromCanBeCompressString("("); + JSHandle functionBodyStr = factory->GetEmptyString(); - if (!function_body->IsUndefined()) { - function_body_str = JSTaggedValue::ToString(thread, function_body); + if (!functionBody->IsUndefined()) { + functionBodyStr = JSTaggedValue::ToString(thread, functionBody); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } if (kind == DynamicFunctionKind::ASYNC || kind == DynamicFunctionKind::ASYNC_GENERATOR) { // '(async function' - JSHandle async_str = factory->NewFromCanBeCompressString("async "); - result_str = factory->ConcatFromString(result_str, async_str); + JSHandle asyncStr = factory->NewFromCanBeCompressString("async "); + resultStr = factory->ConcatFromString(resultStr, asyncStr); } // '(function' - JSHandle function_str = factory->NewFromCanBeCompressString("function "); - result_str = factory->ConcatFromString(result_str, function_str); + JSHandle functionStr = factory->NewFromCanBeCompressString("function "); + resultStr = factory->ConcatFromString(resultStr, functionStr); if (kind == DynamicFunctionKind::GENERATOR || kind == DynamicFunctionKind::ASYNC_GENERATOR) { // '(function*' - JSHandle asterisk_str = factory->NewFromCanBeCompressString("* "); - result_str = factory->ConcatFromString(result_str, asterisk_str); + JSHandle asteriskStr = factory->NewFromCanBeCompressString("* "); + resultStr = factory->ConcatFromString(resultStr, asteriskStr); } // '(function anonymous(' - JSHandle anonymous_str = factory->NewFromCanBeCompressString("anonymous("); - result_str = factory->ConcatFromString(result_str, anonymous_str); + JSHandle anonymousStr = factory->NewFromCanBeCompressString("anonymous("); + resultStr = factory->ConcatFromString(resultStr, anonymousStr); // '(function anonymous(params' - result_str = factory->ConcatFromString(result_str, function_param_str); + resultStr = factory->ConcatFromString(resultStr, functionParamStr); // '(function anonymous(params){' - JSHandle right_paren_left_brace = factory->NewFromCanBeCompressString("){"); - result_str = factory->ConcatFromString(result_str, right_paren_left_brace); + JSHandle rightParenLeftBrace = factory->NewFromCanBeCompressString("){"); + resultStr = factory->ConcatFromString(resultStr, rightParenLeftBrace); // '(function anonymous(params) {body' - result_str = factory->ConcatFromString(result_str, function_body_str); + resultStr = factory->ConcatFromString(resultStr, functionBodyStr); // '(function anonymous(params) {body})' - JSHandle right_brace_right_paren = factory->NewFromCanBeCompressString("})"); - result_str = factory->ConcatFromString(result_str, right_brace_right_paren); + JSHandle rightBraceRightParen = factory->NewFromCanBeCompressString("})"); + resultStr = factory->ConcatFromString(resultStr, rightBraceRightParen); es2panda::CompilerOptions options; - options.is_eval = true; - options.is_function_eval = true; - JSHandle func(thread, GetEvaluatedScript(thread, result_str, options)); + options.isEval = true; + options.isFunctionEval = true; + JSHandle func(thread, GetEvaluatedScript(thread, resultStr, options)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); - JSHandle this_value(thread, thread->GetGlobalObject()); + JSHandle thisValue(thread, thread->GetGlobalObject()); - auto info = NewRuntimeCallInfo(thread, func, this_value, JSTaggedValue::Undefined(), 0); + auto info = NewRuntimeCallInfo(thread, func, thisValue, JSTaggedValue::Undefined(), 0); JSHandle res(thread, EcmaInterpreter::Execute(info.Get())); ASSERT(res->IsCallable()); - JSHandle new_target_handle = argv->GetNewTarget(); + JSHandle newTargetHandle = argv->GetNewTarget(); - if (new_target_handle->IsUndefined()) { + if (newTargetHandle->IsUndefined()) { return res.GetTaggedValue(); } - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle new_target_proto = - JSTaggedValue::GetProperty(thread, new_target_handle, global_const->GetHandledPrototypeString()).GetValue(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle newTargetProto = + JSTaggedValue::GetProperty(thread, newTargetHandle, globalConst->GetHandledPrototypeString()).GetValue(); - if (new_target_proto->IsECMAObject()) { - JSObject::SetPrototype(thread, JSHandle::Cast(res), new_target_proto); + if (newTargetProto->IsECMAObject()) { + JSObject::SetPrototype(thread, JSHandle::Cast(res), newTargetProto); } return res.GetTaggedValue(); diff --git a/runtime/js_eval.h b/runtime/js_eval.h index 98f8b6720865566cebe3caef85f1816497a98415..d32de6e0da2a31185c7b19bbfa70c3c14cdbd564 100644 --- a/runtime/js_eval.h +++ b/runtime/js_eval.h @@ -28,14 +28,14 @@ class EvalUtils { public: enum class DynamicFunctionKind { NORMAL, GENERATOR, ASYNC, ASYNC_GENERATOR }; - static JSTaggedValue DirectEval(JSThread *thread, uint32_t parser_status, JSTaggedValue arg0, + static JSTaggedValue DirectEval(JSThread *thread, uint32_t parserStatus, JSTaggedValue arg0, JSTaggedValue evalbindings); static JSTaggedValue Eval(JSThread *thread, const JSHandle &arg0); static JSTaggedValue CreateDynamicFunction(EcmaRuntimeCallInfo *argv, DynamicFunctionKind kind); private: static JSTaggedValue GetEvaluatedScript(JSThread *thread, const JSHandle &str, - const es2panda::CompilerOptions &options, uint32_t parser_status = 0); + const es2panda::CompilerOptions &options, uint32_t parserStatus = 0); }; } // namespace panda::ecmascript diff --git a/runtime/js_finalization_registry.cpp b/runtime/js_finalization_registry.cpp index 04b3abf393550eabeb75a0400307a684ec4e5a8e..c238476ae2d72a5ffbd86af8ad10bd457a397713 100644 --- a/runtime/js_finalization_registry.cpp +++ b/runtime/js_finalization_registry.cpp @@ -57,18 +57,18 @@ void JSFinalizationRegistry::SetToken(const JSThread *thread, uint32_t idx, JSTa } void JSFinalizationRegistry::Register(const JSThread *thread, const JSHandle ®istry, - const JSHandle &object, - const JSHandle &callback_arg, const JSHandle &token) + const JSHandle &object, const JSHandle &callbackArg, + const JSHandle &token) { uint32_t length = registry->GetLength(); - uint32_t free_cell_idx = length; + uint32_t freeCellIdx = length; // Find a free triplet. The free triplet is a triplet where the object value is JSTaggedValue::Hole(). bool found = false; for (uint32_t i = 0; i < length && !found; ++i) { JSHandle obj(thread, registry->GetObject(i)); if (obj.GetTaggedValue().IsHole()) { found = true; - free_cell_idx = i; + freeCellIdx = i; } } if (!found) { @@ -78,14 +78,14 @@ void JSFinalizationRegistry::Register(const JSThread *thread, const JSHandleSetCells(thread, cells); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle obj_weak_ref = factory->NewWeakRef(JSHandle::Cast(object)); - registry->SetObject(thread, free_cell_idx, obj_weak_ref.GetTaggedValue()); - registry->SetCallbackArg(thread, free_cell_idx, callback_arg.GetTaggedValue()); + JSHandle objWeakRef = factory->NewWeakRef(JSHandle::Cast(object)); + registry->SetObject(thread, freeCellIdx, objWeakRef.GetTaggedValue()); + registry->SetCallbackArg(thread, freeCellIdx, callbackArg.GetTaggedValue()); if (token->IsHole()) { - registry->SetToken(thread, free_cell_idx, JSTaggedValue::Hole()); + registry->SetToken(thread, freeCellIdx, JSTaggedValue::Hole()); } else { - JSHandle token_weak_ref = factory->NewWeakRef(JSHandle::Cast(token)); - registry->SetToken(thread, free_cell_idx, token_weak_ref.GetTaggedValue()); + JSHandle tokenWeakRef = factory->NewWeakRef(JSHandle::Cast(token)); + registry->SetToken(thread, freeCellIdx, tokenWeakRef.GetTaggedValue()); } } @@ -112,15 +112,15 @@ bool JSFinalizationRegistry::Unregister(JSThread *thread, const JSHandle registry) { JSHandle callback(thread, registry->GetCleanupCallback()); - JSHandle new_target(thread, JSTaggedValue::Undefined()); + JSHandle newTarget(thread, JSTaggedValue::Undefined()); JSHandle global(thread, thread->GetGlobalObject()); // Find all GC-ed objects and call FinalizationRegistry.callback for them. uint32_t length = registry->GetLength(); for (uint32_t i = 0; i < length; ++i) { if (!registry->GetObject(i).IsHole()) { - JSHandle obj_weak_ref(thread, JSWeakRef::Cast(registry->GetObject(i).GetRawHeapObject())); - if (obj_weak_ref->GetReferent().IsUndefined()) { + JSHandle objWeakRef(thread, JSWeakRef::Cast(registry->GetObject(i).GetRawHeapObject())); + if (objWeakRef->GetReferent().IsUndefined()) { JSHandle arg(thread, registry->GetCallbackArg(i)); // Clear the triplet. registry->SetObject(thread, i, JSTaggedValue::Hole()); diff --git a/runtime/js_finalization_registry.h b/runtime/js_finalization_registry.h index f6567d5945b9bb9789293ebb7964c3f2512513b7..ef65c6e1580cc41327817f5678b872b47ecef97f 100644 --- a/runtime/js_finalization_registry.h +++ b/runtime/js_finalization_registry.h @@ -26,7 +26,7 @@ public: CAST_CHECK(JSFinalizationRegistry, IsJSFinalizationRegistry); static void Register(const JSThread *thread, const JSHandle ®istry, - const JSHandle &obj, const JSHandle &callback_arg, + const JSHandle &obj, const JSHandle &callbackArg, const JSHandle &token); static bool Unregister(JSThread *thread, const JSHandle ®istry, const JSHandle &token); diff --git a/runtime/js_for_in_iterator.cpp b/runtime/js_for_in_iterator.cpp index 109527f744fdd7184f279a463bd94ce9c2424a30..446eb56c5d4a5b95e729352f6741089761d25c0d 100644 --- a/runtime/js_for_in_iterator.cpp +++ b/runtime/js_for_in_iterator.cpp @@ -36,8 +36,8 @@ bool JSForInIterator::CheckObjProto(const JSThread *thread, const JSHandleGetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - if (js_type != JSType::JS_OBJECT) { + JSType jsType = hclass->GetObjectType(); + if (jsType != JSType::JS_OBJECT) { return false; } JSTaggedValue proto = hclass->GetPrototype(); @@ -54,86 +54,86 @@ void JSForInIterator::FastGetAllEnumKeys(const JSThread *thread, const JSHandle< JSMutableHandle value(thread, JSTaggedValue::Undefined()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj(object); - uint32_t num_of_elements = obj->GetNumberOfElements(); - uint32_t num_of_keys = obj->GetNumberOfKeys(); - JSHandle remaining = factory->NewTaggedQueue(num_of_elements + num_of_keys + 1); - if (num_of_elements > 0) { - uint32_t element_index = 0; + uint32_t numOfElements = obj->GetNumberOfElements(); + uint32_t numOfKeys = obj->GetNumberOfKeys(); + JSHandle remaining = factory->NewTaggedQueue(numOfElements + numOfKeys + 1); + if (numOfElements > 0) { + uint32_t elementIndex = 0; if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) { - element_index = JSPrimitiveRef::Cast(*obj)->GetStringLength(); - for (uint32_t i = 0; i < element_index; i++) { + elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength(); + for (uint32_t i = 0; i < elementIndex; i++) { value.Update(factory->NewFromCanBeCompressString(ToPandaString(i)).GetTaggedValue()); TaggedQueue::PushFixedQueue(thread, remaining, value); } } else { JSHandle elements(thread, obj->GetElements()); if (!elements->IsDictionaryMode()) { - uint32_t elements_len = elements->GetLength(); - for (uint32_t i = 0; i < elements_len; ++i) { + uint32_t elementsLen = elements->GetLength(); + for (uint32_t i = 0; i < elementsLen; ++i) { if (!elements->Get(i).IsHole()) { value.Update(factory->NewFromCanBeCompressString(ToPandaString(i)).GetTaggedValue()); TaggedQueue::PushFixedQueue(thread, remaining, value); } } } else { - JSHandle number_dic(elements); - int size = number_dic->Size(); - PandaVector sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = number_dic->GetKey(hash_index); + JSHandle numberDic(elements); + int size = numberDic->Size(); + PandaVector sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = numberDic->GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = number_dic->GetAttributes(hash_index); + PropertyAttributes attr = numberDic->GetAttributes(hashIndex); if (attr.IsEnumerable()) { - sort_arr.push_back(JSTaggedValue(static_cast(key.GetInt()))); + sortArr.push_back(JSTaggedValue(static_cast(key.GetInt()))); } } } - std::sort(sort_arr.begin(), sort_arr.end(), NumberDictionary::CompKey); - for (const auto &entry : sort_arr) { + std::sort(sortArr.begin(), sortArr.end(), NumberDictionary::CompKey); + for (const auto &entry : sortArr) { value.Update(factory->NewFromCanBeCompressString(ToPandaString(entry.GetInt())).GetTaggedValue()); TaggedQueue::PushFixedQueue(thread, remaining, value); } } } } - if (num_of_keys > 0) { + if (numOfKeys > 0) { if (obj->IsJSGlobalObject()) { GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties().GetTaggedObject()); int size = dict->Size(); - PandaVector> sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = dict->GetKey(hash_index); + PandaVector> sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = dict->GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = dict->GetAttributes(hash_index); + PropertyAttributes attr = dict->GetAttributes(hashIndex); if (attr.IsEnumerable()) { std::pair pair(key, attr.GetOffset()); - sort_arr.emplace_back(pair); + sortArr.emplace_back(pair); } } } - std::sort(sort_arr.begin(), sort_arr.end(), GlobalDictionary::CompKey); - for (const auto &entry : sort_arr) { - JSTaggedValue name_key = entry.first; - if (name_key.IsString()) { - value.Update(name_key); + std::sort(sortArr.begin(), sortArr.end(), GlobalDictionary::CompKey); + for (const auto &entry : sortArr) { + JSTaggedValue nameKey = entry.first; + if (nameKey.IsString()) { + value.Update(nameKey); TaggedQueue::PushFixedQueue(thread, remaining, value); } } } else { - JSHandle properties_arr(thread, obj->GetProperties()); - if (!properties_arr->IsDictionaryMode()) { - JSHClass *js_hclass = obj->GetJSHClass(); - JSTaggedValue enum_cache = js_hclass->GetEnumCache(); - if (!enum_cache.IsNull()) { - JSHandle cache(thread, enum_cache); + JSHandle propertiesArr(thread, obj->GetProperties()); + if (!propertiesArr->IsDictionaryMode()) { + JSHClass *jsHclass = obj->GetJSHClass(); + JSTaggedValue enumCache = jsHclass->GetEnumCache(); + if (!enumCache.IsNull()) { + JSHandle cache(thread, enumCache); uint32_t length = cache->GetLength(); - if (length != num_of_keys) { - JSHandle layout_info_handle(thread, js_hclass->GetLayout()); - for (uint32_t i = 0; i < num_of_keys; i++) { - JSTaggedValue key = layout_info_handle->GetKey(i); + if (length != numOfKeys) { + JSHandle layoutInfoHandle(thread, jsHclass->GetLayout()); + for (uint32_t i = 0; i < numOfKeys; i++) { + JSTaggedValue key = layoutInfoHandle->GetKey(i); if (key.IsString()) { value.Update(key); - if (layout_info_handle->GetAttr(i).IsEnumerable()) { + if (layoutInfoHandle->GetAttr(i).IsEnumerable()) { TaggedQueue::PushFixedQueue(thread, remaining, value); } } @@ -148,33 +148,33 @@ void JSForInIterator::FastGetAllEnumKeys(const JSThread *thread, const JSHandle< } } } else { - JSHandle layout_info_handle(thread, js_hclass->GetLayout()); - for (uint32_t i = 0; i < num_of_keys; i++) { - JSTaggedValue key = layout_info_handle->GetKey(i); + JSHandle layoutInfoHandle(thread, jsHclass->GetLayout()); + for (uint32_t i = 0; i < numOfKeys; i++) { + JSTaggedValue key = layoutInfoHandle->GetKey(i); if (key.IsString()) { value.Update(key); - if (layout_info_handle->GetAttr(i).IsEnumerable()) { + if (layoutInfoHandle->GetAttr(i).IsEnumerable()) { TaggedQueue::PushFixedQueue(thread, remaining, value); } } } } } else { - JSHandle name_dic(properties_arr); - int size = name_dic->Size(); - PandaVector> sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = name_dic->GetKey(hash_index); + JSHandle nameDic(propertiesArr); + int size = nameDic->Size(); + PandaVector> sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = nameDic->GetKey(hashIndex); if (key.IsString()) { - PropertyAttributes attr = name_dic->GetAttributes(hash_index); + PropertyAttributes attr = nameDic->GetAttributes(hashIndex); if (attr.IsEnumerable()) { std::pair pair(key, attr); - sort_arr.emplace_back(pair); + sortArr.emplace_back(pair); } } } - std::sort(sort_arr.begin(), sort_arr.end(), NameDictionary::CompKey); - for (const auto &entry : sort_arr) { + std::sort(sortArr.begin(), sortArr.end(), NameDictionary::CompKey); + for (const auto &entry : sortArr) { value.Update(entry.first); TaggedQueue::PushFixedQueue(thread, remaining, value); } @@ -211,13 +211,13 @@ void JSForInIterator::SlowGetAllEnumKeys(JSThread *thread, const JSHandleIsString() && JSTaggedValue::GetOwnProperty(thread, object, value, desc) && !IsInVisitedKeys(JSHandle(thread, value.GetTaggedValue()), visited)) { if (!desc.IsEnumerable()) { - TaggedQueue *new_visited_queue = TaggedQueue::Push(thread, visited, value); - visited.Update(JSTaggedValue(new_visited_queue)); + TaggedQueue *newVisitedQueue = TaggedQueue::Push(thread, visited, value); + visited.Update(JSTaggedValue(newVisitedQueue)); continue; } - TaggedQueue *new_queue = TaggedQueue::Push(thread, remaining, value); - remaining.Update(JSTaggedValue(new_queue)); + TaggedQueue *newQueue = TaggedQueue::Push(thread, remaining, value); + remaining.Update(JSTaggedValue(newQueue)); } } it->SetRemainingKeys(thread, remaining); @@ -236,8 +236,8 @@ static JSTaggedNumber GetTaggedQueueLengthWithStartOffset(const JSHandle JSForInIterator::NextInternal(JSThread *thread, const JSHandle &it) { - bool not_modi_obj_proto = true; - not_modi_obj_proto = CheckObjProto(thread, it); + bool notModiObjProto = true; + notModiObjProto = CheckObjProto(thread, it); while (true) { JSHandle object(thread, it->GetObject()); if (object->IsNull() || object->IsUndefined()) { @@ -246,7 +246,7 @@ std::pair JSForInIterator::NextInternal(JSThread *thread, c JSMutableHandle remaining(thread, it->GetRemainingKeys()); if (it->GetWasVisited().IsFalse()) { - if (object->IsJSObject() && not_modi_obj_proto) { + if (object->IsJSObject() && notModiObjProto) { FastGetAllEnumKeys(thread, it, object); } else { SlowGetAllEnumKeys(thread, it, object); @@ -257,37 +257,37 @@ std::pair JSForInIterator::NextInternal(JSThread *thread, c JSMutableHandle visited(thread, it->GetVisitedKeys()); - uint32_t fast_index = it->GetFastRemainingIndex().GetInt(); - uint32_t remain_length = GetTaggedQueueLengthWithStartOffset(remaining).GetInt(); + uint32_t fastIndex = it->GetFastRemainingIndex().GetInt(); + uint32_t remainLength = GetTaggedQueueLengthWithStartOffset(remaining).GetInt(); - if (fast_index != remain_length) { + if (fastIndex != remainLength) { // Restore correct state of FastRemainingIndex. - uint32_t element_count = remain_length - fast_index; - for (uint32_t i = 0; i < element_count; ++i) { + uint32_t elementCount = remainLength - fastIndex; + for (uint32_t i = 0; i < elementCount; ++i) { JSHandle key(thread, remaining->Pop(thread)); - auto new_queue = JSTaggedValue(TaggedQueue::Push(thread, visited, key)); - visited.Update(new_queue); - it->SetVisitedKeys(thread, new_queue); + auto newQueue = JSTaggedValue(TaggedQueue::Push(thread, visited, key)); + visited.Update(newQueue); + it->SetVisitedKeys(thread, newQueue); } it->SetFastRemainingIndex(GetTaggedQueueLengthWithStartOffset(remaining)); } if (!remaining->Empty()) { JSTaggedValue r = remaining->Pop(thread); - if (object->IsJSObject() && not_modi_obj_proto) { + if (object->IsJSObject() && notModiObjProto) { it->SetFastRemainingIndex(GetTaggedQueueLengthWithStartOffset(remaining)); return std::make_pair(r, false); } JSHandle key(thread, r); - auto new_queue = JSTaggedValue(TaggedQueue::Push(thread, visited, key)); + auto newQueue = JSTaggedValue(TaggedQueue::Push(thread, visited, key)); it->SetFastRemainingIndex(GetTaggedQueueLengthWithStartOffset(remaining)); - visited.Update(new_queue); - it->SetVisitedKeys(thread, new_queue); + visited.Update(newQueue); + it->SetVisitedKeys(thread, newQueue); return std::make_pair(key.GetTaggedValue(), false); } - if (not_modi_obj_proto) { + if (notModiObjProto) { return std::make_pair(JSTaggedValue::Undefined(), true); } @@ -302,7 +302,7 @@ JSTaggedValue JSForInIterator::Next(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. JSHandle it(builtins_common::GetThis(msg)); ASSERT(it->IsForinIterator()); diff --git a/runtime/js_function.cpp b/runtime/js_function.cpp index 14df43f4dc4b4fc0012b33d4b3f07f3a3c15061f..887cf8c8624063b8e2ec414e8754959401480a60 100644 --- a/runtime/js_function.cpp +++ b/runtime/js_function.cpp @@ -33,16 +33,16 @@ namespace panda::ecmascript { void JSFunction::InitializeJSFunction(JSThread *thread, const JSHandle &func, FunctionKind kind, bool strict) { - FunctionMode this_mode; + FunctionMode thisMode; if (IsArrowFunction(kind)) { - this_mode = FunctionMode::LEXICAL; + thisMode = FunctionMode::LEXICAL; } else if (strict) { - this_mode = FunctionMode::STRICT; + thisMode = FunctionMode::STRICT; } else { - this_mode = FunctionMode::GLOBAL; + thisMode = FunctionMode::GLOBAL; } - int32_t flag = FunctionKindBit::Encode(kind) | StrictBit::Encode(strict) | ThisModeBit::Encode(this_mode); + int32_t flag = FunctionKindBit::Encode(kind) | StrictBit::Encode(strict) | ThisModeBit::Encode(thisMode); func->SetProtoOrDynClass(thread, JSTaggedValue::Hole(), SKIP_BARRIER); func->SetHomeObject(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); func->SetLexicalEnv(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); @@ -52,29 +52,29 @@ void JSFunction::InitializeJSFunction(JSThread *thread, const JSHandleSetFunctionInfoFlag(thread, JSTaggedValue(flag)); // Set the [[Realm]] internal slot of F to the running execution context's Realm - auto *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle lexical_env = factory->NewLexicalEnv(0); - lexical_env->SetParentEnv(thread, ecma_vm->GetGlobalEnv().GetTaggedValue()); - func->SetLexicalEnv(thread, lexical_env.GetTaggedValue()); + auto *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle lexicalEnv = factory->NewLexicalEnv(0); + lexicalEnv->SetParentEnv(thread, ecmaVm->GetGlobalEnv().GetTaggedValue()); + func->SetLexicalEnv(thread, lexicalEnv.GetTaggedValue()); ASSERT(!func->IsPropertiesDict()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); if (HasPrototype(kind)) { - JSHandle accessor = global_const->GetHandledFunctionPrototypeAccessor(); + JSHandle accessor = globalConst->GetHandledFunctionPrototypeAccessor(); if (kind == FunctionKind::BASE_CONSTRUCTOR || kind == FunctionKind::GENERATOR_FUNCTION || kind == FunctionKind::ASYNC_GENERATOR_FUNCTION) { func->SetPropertyInlinedProps(thread, PROTOTYPE_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); - accessor = global_const->GetHandledFunctionNameAccessor(); + accessor = globalConst->GetHandledFunctionNameAccessor(); func->SetPropertyInlinedProps(thread, NAME_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); } else if (!JSFunction::IsClassConstructor(kind)) { // class ctor do nothing PropertyDescriptor desc(thread, accessor, kind != FunctionKind::BUILTIN_CONSTRUCTOR, false, false); - [[maybe_unused]] bool success = JSObject::DefineOwnProperty( - thread, JSHandle(func), global_const->GetHandledPrototypeString(), desc); + [[maybe_unused]] bool success = JSObject::DefineOwnProperty(thread, JSHandle(func), + globalConst->GetHandledPrototypeString(), desc); ASSERT(success); } } else if (HasAccessor(kind)) { - JSHandle accessor = global_const->GetHandledFunctionNameAccessor(); + JSHandle accessor = globalConst->GetHandledFunctionNameAccessor(); func->SetPropertyInlinedProps(thread, NAME_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); } } @@ -83,24 +83,24 @@ JSHandle JSFunction::NewJSFunctionPrototype(JSThread *thread, ObjectFa const JSHandle &func) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle fun_pro = factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - func->SetFunctionPrototype(thread, fun_pro.GetTaggedValue()); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + JSHandle funPro = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + func->SetFunctionPrototype(thread, funPro.GetTaggedValue()); // set "constructor" in prototype - JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); PropertyDescriptor descriptor(thread, JSHandle::Cast(func), true, false, true); - JSObject::DefineOwnProperty(thread, fun_pro, constructor_key, descriptor); + JSObject::DefineOwnProperty(thread, funPro, constructorKey, descriptor); - return fun_pro; + return funPro; } JSHClass *JSFunction::GetOrCreateInitialJSHClass(JSThread *thread, const JSHandle &fun) { - JSTaggedValue proto_or_dyn(fun->GetProtoOrDynClass()); - if (proto_or_dyn.IsJSHClass()) { - return reinterpret_cast(proto_or_dyn.GetTaggedObject()); + JSTaggedValue protoOrDyn(fun->GetProtoOrDynClass()); + if (protoOrDyn.IsJSHClass()) { + return reinterpret_cast(protoOrDyn.GetTaggedObject()); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -127,18 +127,18 @@ JSTaggedValue JSFunction::PrototypeGetter(JSThread *thread, const JSHandle &self, const JSHandle &value, - [[maybe_unused]] bool may_throw) + [[maybe_unused]] bool mayThrow) { JSHandle func(self); - JSTaggedValue proto_or_dyn = func->GetProtoOrDynClass(); - if (proto_or_dyn.IsJSHClass()) { + JSTaggedValue protoOrDyn = func->GetProtoOrDynClass(); + if (protoOrDyn.IsJSHClass()) { // need transtion - JSHandle dynclass(thread, proto_or_dyn); - JSHandle new_dynclass = JSHClass::TransitionProto(thread, dynclass, value); + JSHandle dynclass(thread, protoOrDyn); + JSHandle newDynclass = JSHClass::TransitionProto(thread, dynclass, value); if (value->IsECMAObject()) { JSObject::Cast(value->GetTaggedObject())->GetJSHClass()->SetIsPrototype(true); } - func->SetProtoOrDynClass(thread, new_dynclass); + func->SetProtoOrDynClass(thread, newDynclass); } else { func->SetFunctionPrototype(thread, value.GetTaggedValue()); } @@ -151,19 +151,19 @@ JSTaggedValue JSFunction::NameGetter(JSThread *thread, const JSHandle if (target->GetPandaFile() == nullptr) { return JSTaggedValue::Undefined(); } - PandaString func_name = target->ParseFunctionName(); - if (func_name.empty()) { + PandaString funcName = target->ParseFunctionName(); + if (funcName.empty()) { return thread->GlobalConstants()->GetEmptyString(); } if (JSHandle::Cast(self)->GetFunctionKind() == FunctionKind::GETTER_FUNCTION) { - func_name.insert(0, "get "); + funcName.insert(0, "get "); } if (JSHandle::Cast(self)->GetFunctionKind() == FunctionKind::SETTER_FUNCTION) { - func_name.insert(0, "set "); + funcName.insert(0, "set "); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - return factory->NewFromString(func_name).GetTaggedValue(); + return factory->NewFromString(funcName).GetTaggedValue(); } bool JSFunction::OrdinaryHasInstance(JSThread *thread, const JSHandle &constructor, @@ -178,9 +178,9 @@ bool JSFunction::OrdinaryHasInstance(JSThread *thread, const JSHandleIsBoundFunction()) { - JSHandle bound_function(thread, JSBoundFunction::Cast(constructor->GetTaggedObject())); - JSTaggedValue bound_target = bound_function->GetBoundTarget(); - return JSObject::InstanceOf(thread, obj, JSHandle(thread, bound_target)); + JSHandle boundFunction(thread, JSBoundFunction::Cast(constructor->GetTaggedObject())); + JSTaggedValue boundTarget = boundFunction->GetBoundTarget(); + return JSObject::InstanceOf(thread, obj, JSHandle(thread, boundTarget)); } // 3. If Type(O) is not Object, return false if (!obj->IsECMAObject()) { @@ -188,16 +188,16 @@ bool JSFunction::OrdinaryHasInstance(JSThread *thread, const JSHandleGlobalConstants(); - JSHandle constructor_prototype = - JSTaggedValue::GetProperty(thread, constructor, global_const->GetHandledPrototypeString()).GetValue(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle constructorPrototype = + JSTaggedValue::GetProperty(thread, constructor, globalConst->GetHandledPrototypeString()).GetValue(); // 5. ReturnIfAbrupt(P). // no throw exception, so needn't return RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 6. If Type(P) is not Object, throw a TypeError exception. - if (!constructor_prototype->IsECMAObject()) { + if (!constructorPrototype->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "HasInstance: is not Object", false); } @@ -206,12 +206,12 @@ bool JSFunction::OrdinaryHasInstance(JSThread *thread, const JSHandleGetPrototype(thread); + objPrototype = JSObject::Cast(objPrototype)->GetPrototype(thread); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); } return false; @@ -223,24 +223,24 @@ bool JSFunction::MakeConstructor(JSThread *thread, const JSHandle &f ASSERT_PRINT(proto->IsHeapObject() || proto->IsUndefined(), "proto must be JSObject or Undefined"); ASSERT_PRINT(func->IsConstructor(), "func must be Constructor type"); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle constructor_key = global_const->GetHandledConstructorString(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); ASSERT_PRINT(func->GetProtoOrDynClass().IsHole() && func->IsExtensible(), "function doesn't has proto_type property and is extensible object"); - ASSERT_PRINT(JSObject::HasProperty(thread, JSHandle(func), constructor_key), + ASSERT_PRINT(JSObject::HasProperty(thread, JSHandle(func), constructorKey), "function must have constructor"); // proto.constructor = func bool status = false; if (proto->IsUndefined()) { // Let prototype be ObjectCreate(%ObjectPrototype%). - JSHandle obj_prototype = env->GetObjectFunctionPrototype(); - PropertyDescriptor constructor_desc(thread, JSHandle::Cast(func), writable, false, true); - status = JSTaggedValue::DefinePropertyOrThrow(thread, obj_prototype, constructor_key, constructor_desc); + JSHandle objPrototype = env->GetObjectFunctionPrototype(); + PropertyDescriptor constructorDesc(thread, JSHandle::Cast(func), writable, false, true); + status = JSTaggedValue::DefinePropertyOrThrow(thread, objPrototype, constructorKey, constructorDesc); } else { - PropertyDescriptor constructor_desc(thread, JSHandle::Cast(func), writable, false, true); - status = JSTaggedValue::DefinePropertyOrThrow(thread, proto, constructor_key, constructor_desc); + PropertyDescriptor constructorDesc(thread, JSHandle::Cast(func), writable, false, true); + status = JSTaggedValue::DefinePropertyOrThrow(thread, proto, constructorKey, constructorDesc); } ASSERT_PRINT(status, "DefineProperty construct failed"); @@ -299,8 +299,8 @@ JSTaggedValue JSFunction::Invoke(EcmaRuntimeCallInfo *info, const JSHandleGetThread(); - JSHandle this_arg = info->GetThis(); - JSHandle func(JSTaggedValue::GetProperty(thread, this_arg, key).GetValue()); + JSHandle thisArg = info->GetThis(); + JSHandle func(JSTaggedValue::GetProperty(thread, thisArg, key).GetValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetFunction(func.GetTaggedValue()); return JSFunction::Call(info); @@ -315,8 +315,8 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) JSThread *thread = info->GetThread(); JSHandle func(info->GetFunction()); - JSHandle new_target(info->GetNewTarget()); - ASSERT(new_target->IsECMAObject()); + JSHandle newTarget(info->GetNewTarget()); + ASSERT(newTarget->IsECMAObject()); if (!func->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is false", JSTaggedValue::Exception()); } @@ -324,16 +324,16 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) JSHandle obj(thread, JSTaggedValue::Undefined()); if (func->IsBase()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - obj = JSHandle(factory->NewJSObjectByConstructor(func, new_target)); + obj = JSHandle(factory->NewJSObjectByConstructor(func, newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } info->SetThis(obj.GetTaggedValue()); - JSTaggedValue result_value = EcmaInterpreter::Execute(info); + JSTaggedValue resultValue = EcmaInterpreter::Execute(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9.3.2 [[Construct]] (argumentsList, newTarget) - if (result_value.IsECMAObject()) { - return result_value; + if (resultValue.IsECMAObject()) { + return resultValue; } if (func->IsBase()) { @@ -342,10 +342,10 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) // derived ctor(sub class) return the obj which created by base ctor(parent class) if (func->IsDerivedConstructor()) { - return result_value; + return resultValue; } - if (!result_value.IsUndefined()) { + if (!resultValue.IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "function is non-constructor", JSTaggedValue::Exception()); } return obj.GetTaggedValue(); @@ -353,9 +353,9 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) JSHandle JSFunctionBase::GetFunctionName(JSThread *thread, const JSHandle &func) { - JSHandle name_key = thread->GlobalConstants()->GetHandledNameString(); + JSHandle nameKey = thread->GlobalConstants()->GetHandledNameString(); - return JSObject::GetProperty(thread, JSHandle(func), name_key).GetValue(); + return JSObject::GetProperty(thread, JSHandle(func), nameKey).GetValue(); } bool JSFunctionBase::SetFunctionName(JSThread *thread, const JSHandle &func, @@ -363,58 +363,58 @@ bool JSFunctionBase::SetFunctionName(JSThread *thread, const JSHandleIsExtensible(), "Function must be extensible"); ASSERT_PRINT(name->IsStringOrSymbol(), "name must be string or symbol"); - bool need_prefix = false; + bool needPrefix = false; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!prefix->IsUndefined()) { ASSERT_PRINT(prefix->IsString(), "prefix must be string"); - need_prefix = true; + needPrefix = true; } // If Type(name) is Symbol, then // Let description be name’s [[Description]] value. // If description is undefined, let name be the empty String. // Else, let name be the concatenation of "[", description, and "]". - JSHandle function_name; + JSHandle functionName; if (name->IsSymbol()) { JSTaggedValue description = JSHandle::Cast(name)->GetDescription(); - JSHandle description_handle(thread, description); + JSHandle descriptionHandle(thread, description); if (description.IsUndefined()) { - function_name = factory->GetEmptyString(); + functionName = factory->GetEmptyString(); } else { - JSHandle left_brackets = factory->NewFromCanBeCompressString("["); - JSHandle right_brackets = factory->NewFromCanBeCompressString("]"); - function_name = factory->ConcatFromString(left_brackets, description_handle); - function_name = factory->ConcatFromString(function_name, right_brackets); + JSHandle leftBrackets = factory->NewFromCanBeCompressString("["); + JSHandle rightBrackets = factory->NewFromCanBeCompressString("]"); + functionName = factory->ConcatFromString(leftBrackets, descriptionHandle); + functionName = factory->ConcatFromString(functionName, rightBrackets); } } else { - function_name = JSHandle::Cast(name); - } - EcmaString *new_string; - if (need_prefix) { - JSHandle handle_prefix_string = JSTaggedValue::ToString(thread, prefix); - JSHandle space_string(factory->NewFromCanBeCompressString(" ")); - JSHandle concat_string = factory->ConcatFromString(handle_prefix_string, space_string); - new_string = *factory->ConcatFromString(concat_string, function_name); + functionName = JSHandle::Cast(name); + } + EcmaString *newString; + if (needPrefix) { + JSHandle handlePrefixString = JSTaggedValue::ToString(thread, prefix); + JSHandle spaceString(factory->NewFromCanBeCompressString(" ")); + JSHandle concatString = factory->ConcatFromString(handlePrefixString, spaceString); + newString = *factory->ConcatFromString(concatString, functionName); } else { - new_string = *function_name; + newString = *functionName; } - JSHandle name_handle(thread, new_string); - JSHandle name_key = thread->GlobalConstants()->GetHandledNameString(); - PropertyDescriptor name_desc(thread, name_handle, false, false, true); - JSHandle func_handle(func); - return JSTaggedValue::DefinePropertyOrThrow(thread, func_handle, name_key, name_desc); + JSHandle nameHandle(thread, newString); + JSHandle nameKey = thread->GlobalConstants()->GetHandledNameString(); + PropertyDescriptor nameDesc(thread, nameHandle, false, false, true); + JSHandle funcHandle(func); + return JSTaggedValue::DefinePropertyOrThrow(thread, funcHandle, nameKey, nameDesc); } bool JSFunction::SetFunctionLength(JSThread *thread, const JSHandle &func, JSTaggedValue length, bool cfg) { ASSERT_PRINT(func->IsExtensible(), "Function must be extensible"); ASSERT_PRINT(length.IsInteger(), "length must be integer"); - JSHandle length_key_handle = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle length_handle(thread, length); - ASSERT_PRINT(!JSTaggedValue::Less(thread, length_handle, JSHandle(thread, JSTaggedValue(0))), + JSHandle lengthKeyHandle = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthHandle(thread, length); + ASSERT_PRINT(!JSTaggedValue::Less(thread, lengthHandle, JSHandle(thread, JSTaggedValue(0))), "length must be non negtive integer"); - PropertyDescriptor length_desc(thread, length_handle, false, false, cfg); - JSHandle func_handle(func); - return JSTaggedValue::DefinePropertyOrThrow(thread, func_handle, length_key_handle, length_desc); + PropertyDescriptor lengthDesc(thread, lengthHandle, false, false, cfg); + JSHandle funcHandle(func); + return JSTaggedValue::DefinePropertyOrThrow(thread, funcHandle, lengthKeyHandle, lengthDesc); } // 9.4.1.2[[Construct]](argumentsList, new_target) @@ -424,27 +424,27 @@ JSTaggedValue JSBoundFunction::ConstructInternal(EcmaRuntimeCallInfo *info) JSHandle func(info->GetFunction()); JSHandle target(thread, func->GetBoundTarget()); ASSERT(target->IsConstructor()); - JSHandle new_target = info->GetNewTarget(); - JSMutableHandle new_target_mutable(thread, new_target.GetTaggedValue()); - if (JSTaggedValue::SameValue(func.GetTaggedValue(), new_target.GetTaggedValue())) { - new_target_mutable.Update(target.GetTaggedValue()); + JSHandle newTarget = info->GetNewTarget(); + JSMutableHandle newTargetMutable(thread, newTarget.GetTaggedValue()); + if (JSTaggedValue::SameValue(func.GetTaggedValue(), newTarget.GetTaggedValue())) { + newTargetMutable.Update(target.GetTaggedValue()); } - JSHandle bound_args(thread, func->GetBoundArguments()); - const uint32_t bound_length = bound_args->GetLength(); - const uint32_t args_length = info->GetArgsNumber(); + JSHandle boundArgs(thread, func->GetBoundArguments()); + const uint32_t boundLength = boundArgs->GetLength(); + const uint32_t argsLength = info->GetArgsNumber(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - auto runtime_info = NewRuntimeCallInfo(thread, target, undefined, new_target_mutable, bound_length + args_length); + auto runtimeInfo = NewRuntimeCallInfo(thread, target, undefined, newTargetMutable, boundLength + argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (bound_length != 0) { - runtime_info->SetCallArg(bound_length, bound_args->GetData()); + if (boundLength != 0) { + runtimeInfo->SetCallArg(boundLength, boundArgs->GetData()); } - if (args_length != 0) { - runtime_info->SetCallArg( - args_length, reinterpret_cast(info->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS)), - bound_length); + if (argsLength != 0) { + runtimeInfo->SetCallArg( + argsLength, reinterpret_cast(info->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS)), + boundLength); } - return JSFunction::Construct(runtime_info.Get()); + return JSFunction::Construct(runtimeInfo.Get()); } void JSProxyRevocFunction::ProxyRevocFunctions(const JSThread *thread, const JSHandle &revoker) @@ -461,11 +461,11 @@ void JSProxyRevocFunction::ProxyRevocFunctions(const JSThread *thread, const JSH // 4.Assert: p is a Proxy object. ASSERT(proxy.IsJSProxy()); - JSHandle proxy_handle(thread, proxy); + JSHandle proxyHandle(thread, proxy); // 5 ~ 6 Set internal slot of p to null. - proxy_handle->SetTarget(thread, JSTaggedValue::Null()); - proxy_handle->SetHandler(thread, JSTaggedValue::Null()); + proxyHandle->SetTarget(thread, JSTaggedValue::Null()); + proxyHandle->SetHandler(thread, JSTaggedValue::Null()); } JSTaggedValue JSFunction::AccessCallerArgumentsThrowTypeError([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -485,100 +485,99 @@ void JSFunction::SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JST ASSERT_PRINT(func->IsExtensible(), "Function must be extensible"); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle func_handle(thread, func); + JSHandle funcHandle(thread, func); { - JSMutableHandle name_handle(thread, JSTaggedValue::Undefined()); + JSMutableHandle nameHandle(thread, JSTaggedValue::Undefined()); if (!name.IsSymbol()) { - name_handle.Update(name); + nameHandle.Update(name); } else { - JSHandle name_begin(thread, name); + JSHandle nameBegin(thread, name); JSTaggedValue description = JSSymbol::Cast(name.GetTaggedObject())->GetDescription(); if (description.IsUndefined()) { - name_handle.Update(thread->GlobalConstants()->GetEmptyString()); + nameHandle.Update(thread->GlobalConstants()->GetEmptyString()); } else { - JSHandle concat_name; - JSHandle left_brackets = factory->NewFromCanBeCompressString("["); - JSHandle right_brackets = factory->NewFromCanBeCompressString("]"); - concat_name = factory->ConcatFromString( - left_brackets, - JSHandle(thread, JSSymbol::Cast(name_begin->GetHeapObject())->GetDescription())); - concat_name = factory->ConcatFromString(concat_name, right_brackets); - name_handle.Update(concat_name.GetTaggedValue()); + JSHandle concatName; + JSHandle leftBrackets = factory->NewFromCanBeCompressString("["); + JSHandle rightBrackets = factory->NewFromCanBeCompressString("]"); + concatName = factory->ConcatFromString( + leftBrackets, + JSHandle(thread, JSSymbol::Cast(nameBegin->GetHeapObject())->GetDescription())); + concatName = factory->ConcatFromString(concatName, rightBrackets); + nameHandle.Update(concatName.GetTaggedValue()); } } - PropertyDescriptor name_desc(thread, name_handle, false, false, true); - JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(thread, func_handle.GetTaggedValue()), - thread->GlobalConstants()->GetHandledNameString(), name_desc); + PropertyDescriptor nameDesc(thread, nameHandle, false, false, true); + JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(thread, funcHandle.GetTaggedValue()), + thread->GlobalConstants()->GetHandledNameString(), nameDesc); } } JSHandle JSFunction::GetInstanceJSHClass(JSThread *thread, JSHandle constructor, - JSHandle new_target) + JSHandle newTarget) { - JSHandle ctor_initial_js_hclass(thread, JSFunction::GetOrCreateInitialJSHClass(thread, constructor)); + JSHandle ctorInitialJsHclass(thread, JSFunction::GetOrCreateInitialJSHClass(thread, constructor)); // new_target is construct itself - if (new_target.GetTaggedValue() == constructor.GetTaggedValue()) { - return ctor_initial_js_hclass; + if (newTarget.GetTaggedValue() == constructor.GetTaggedValue()) { + return ctorInitialJsHclass; } // new_target is derived-class of constructor - if (new_target->IsJSFunction()) { - JSHandle new_target_func = JSHandle::Cast(new_target); - if (new_target_func->IsDerivedConstructor()) { - JSTaggedValue new_target_proto = JSHandle::Cast(new_target)->GetPrototype(thread); - if (new_target_proto == constructor.GetTaggedValue()) { - return GetOrCreateDerivedJSHClass(thread, new_target_func, constructor, ctor_initial_js_hclass); + if (newTarget->IsJSFunction()) { + JSHandle newTargetFunc = JSHandle::Cast(newTarget); + if (newTargetFunc->IsDerivedConstructor()) { + JSTaggedValue newTargetProto = JSHandle::Cast(newTarget)->GetPrototype(thread); + if (newTargetProto == constructor.GetTaggedValue()) { + return GetOrCreateDerivedJSHClass(thread, newTargetFunc, constructor, ctorInitialJsHclass); } } } // ECMA2015 9.1.15 3.Let proto be Get(constructor, "prototype"). JSMutableHandle prototype(thread, JSTaggedValue::Undefined()); - if (new_target->IsJSFunction()) { - JSHandle new_target_func = JSHandle::Cast(new_target); - FunctionKind kind = new_target_func->GetFunctionKind(); + if (newTarget->IsJSFunction()) { + JSHandle newTargetFunc = JSHandle::Cast(newTarget); + FunctionKind kind = newTargetFunc->GetFunctionKind(); if (HasPrototype(kind)) { - prototype.Update(PrototypeGetter(thread, JSHandle::Cast(new_target_func))); + prototype.Update(PrototypeGetter(thread, JSHandle::Cast(newTargetFunc))); } } else { // Such case: bound function and define a "prototype" property. - JSHandle customize_prototype = - JSTaggedValue::GetProperty(thread, new_target, thread->GlobalConstants()->GetHandledPrototypeString()) + JSHandle customizePrototype = + JSTaggedValue::GetProperty(thread, newTarget, thread->GlobalConstants()->GetHandledPrototypeString()) .GetValue(); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSHClass, thread); - prototype.Update(customize_prototype.GetTaggedValue()); + prototype.Update(customizePrototype.GetTaggedValue()); // Reload JSHClass of constructor, where the lookup of 'prototype' property may change it. - ctor_initial_js_hclass = - JSHandle(thread, JSFunction::GetOrCreateInitialJSHClass(thread, constructor)); + ctorInitialJsHclass = JSHandle(thread, JSFunction::GetOrCreateInitialJSHClass(thread, constructor)); } if (!prototype->IsECMAObject()) { prototype.Update(constructor->GetFunctionPrototype()); } - JSHandle new_jsh_class = JSHClass::Clone(thread, ctor_initial_js_hclass); - new_jsh_class->SetPrototype(thread, prototype); + JSHandle newJshClass = JSHClass::Clone(thread, ctorInitialJsHclass); + newJshClass->SetPrototype(thread, prototype); - return new_jsh_class; + return newJshClass; } JSHandle JSFunction::GetOrCreateDerivedJSHClass(JSThread *thread, JSHandle derived, [[maybe_unused]] JSHandle constructor, - JSHandle ctor_initial_js_hclass) + JSHandle ctorInitialJsHclass) { - JSTaggedValue proto_or_dyn(derived->GetProtoOrDynClass()); + JSTaggedValue protoOrDyn(derived->GetProtoOrDynClass()); // has cached JSHClass, return directly - if (proto_or_dyn.IsJSHClass()) { - return JSHandle(thread, proto_or_dyn); + if (protoOrDyn.IsJSHClass()) { + return JSHandle(thread, protoOrDyn); } - JSHandle new_jsh_class = JSHClass::Clone(thread, ctor_initial_js_hclass); + JSHandle newJshClass = JSHClass::Clone(thread, ctorInitialJsHclass); // guarante derived has function prototype JSHandle prototype(thread, derived->GetProtoOrDynClass()); ASSERT(!prototype->IsHole()); - new_jsh_class->SetPrototype(thread, prototype); - derived->SetProtoOrDynClass(thread, new_jsh_class); - return new_jsh_class; + newJshClass->SetPrototype(thread, prototype); + derived->SetProtoOrDynClass(thread, newJshClass); + return newJshClass; } // Those interface below is discarded @@ -599,18 +598,18 @@ DynClass *JSFunction::GetOrCreateInitialDynClass(JSThread *thread, const JSHandl } JSHandle JSFunction::GetInstanceDynClass(JSThread *thread, JSHandle constructor, - JSHandle new_target) + JSHandle newTarget) { - return JSHandle(JSFunction::GetInstanceJSHClass(thread, constructor, new_target)); + return JSHandle(JSFunction::GetInstanceJSHClass(thread, constructor, newTarget)); } bool JSFunction::NameSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, - [[maybe_unused]] bool may_throw) + [[maybe_unused]] bool mayThrow) { if (self->IsPropertiesDict()) { // replace setter with value - JSHandle name_string = thread->GlobalConstants()->GetHandledNameString(); - return self->UpdatePropertyInDictionary(thread, name_string.GetTaggedValue(), value.GetTaggedValue()); + JSHandle nameString = thread->GlobalConstants()->GetHandledNameString(); + return self->UpdatePropertyInDictionary(thread, nameString.GetTaggedValue(), value.GetTaggedValue()); } self->SetPropertyInlinedProps(thread, NAME_INLINE_PROPERTY_INDEX, value.GetTaggedValue()); return true; diff --git a/runtime/js_function.h b/runtime/js_function.h index f1c5afc8676aa32679921325583b76e75a33a24e..ac7f484209101823a7c4180878b4add29a852f94 100644 --- a/runtime/js_function.h +++ b/runtime/js_function.h @@ -69,7 +69,7 @@ public: const JSHandle &obj); static JSTaggedValue SpeciesConstructor(const JSHandle &func, - const JSHandle &default_constructor); + const JSHandle &defaultConstructor); // ecma6 9.2 // 7.3.12 Call(F, V, argumentsList) @@ -92,26 +92,26 @@ public: static bool IsDynClass(JSTaggedValue object); static JSTaggedValue PrototypeGetter(JSThread *thread, const JSHandle &self); static bool PrototypeSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, - bool may_throw); + bool mayThrow); static JSTaggedValue NameGetter(JSThread *thread, const JSHandle &self); static bool NameSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, - bool may_throw); + bool mayThrow); static JSTaggedValue LengthGetter(JSThread *thread, const JSHandle &self); static bool LengthSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, - bool may_throw); + bool mayThrow); static void SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JSTaggedValue name); static JSHandle GetInstanceDynClass(JSThread *thread, JSHandle constructor, - JSHandle new_target); + JSHandle newTarget); inline JSTaggedValue GetFunctionPrototype() const { ASSERT(HasFunctionPrototype()); - JSTaggedValue proto_or_dyn = GetProtoOrDynClass(); - if (proto_or_dyn.IsJSHClass()) { - return JSHClass::Cast(proto_or_dyn.GetTaggedObject())->GetPrototype(); + JSTaggedValue protoOrDyn = GetProtoOrDynClass(); + if (protoOrDyn.IsJSHClass()) { + return JSHClass::Cast(protoOrDyn.GetTaggedObject())->GetPrototype(); } - return proto_or_dyn; + return protoOrDyn; } inline void SetFunctionPrototype(const JSThread *thread, JSTaggedValue proto) @@ -127,21 +127,21 @@ public: inline bool HasInitialDynClass() const { - JSTaggedValue proto_or_dyn = GetProtoOrDynClass(); - return proto_or_dyn.IsJSHClass(); + JSTaggedValue protoOrDyn = GetProtoOrDynClass(); + return protoOrDyn.IsJSHClass(); } inline bool HasFunctionPrototype() const { - JSTaggedValue proto_or_dyn = GetProtoOrDynClass(); - return !proto_or_dyn.IsHole(); + JSTaggedValue protoOrDyn = GetProtoOrDynClass(); + return !protoOrDyn.IsHole(); } inline DynClass *GetInitialDynClass() const { ASSERT(HasInitialDynClass()); - JSTaggedValue proto_or_dyn = GetProtoOrDynClass(); - return reinterpret_cast(proto_or_dyn.GetTaggedObject()); + JSTaggedValue protoOrDyn = GetProtoOrDynClass(); + return reinterpret_cast(protoOrDyn.GetTaggedObject()); } inline void SetFunctionLength(const JSThread *thread, JSTaggedValue length) @@ -169,20 +169,20 @@ public: inline void SetFunctionKind(const JSThread *thread, FunctionKind kind) { - JSTaggedType old_value = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(FunctionKindBit::Update(old_value, kind))); + JSTaggedType oldValue = GetFunctionInfoFlag().GetRawData(); + SetFunctionInfoFlag(thread, JSTaggedValue(FunctionKindBit::Update(oldValue, kind))); } inline void SetStrict(const JSThread *thread, bool flag) { - JSTaggedType old_value = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(StrictBit::Update(old_value, flag))); + JSTaggedType oldValue = GetFunctionInfoFlag().GetRawData(); + SetFunctionInfoFlag(thread, JSTaggedValue(StrictBit::Update(oldValue, flag))); } inline void SetResolved(const JSThread *thread) { - TaggedType old_value = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(ResolvedBit::Update(old_value, true))); + TaggedType oldValue = GetFunctionInfoFlag().GetRawData(); + SetFunctionInfoFlag(thread, JSTaggedValue(ResolvedBit::Update(oldValue, true))); } inline bool IsResolved() const @@ -192,8 +192,8 @@ public: inline void SetFunctionMode(const JSThread *thread, FunctionMode mode) { - JSTaggedType old_value = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(ThisModeBit::Update(old_value, mode))); + JSTaggedType oldValue = GetFunctionInfoFlag().GetRawData(); + SetFunctionInfoFlag(thread, JSTaggedValue(ThisModeBit::Update(oldValue, mode))); } inline FunctionKind GetFunctionKind() const @@ -261,7 +261,7 @@ public: FunctionKind kind = FunctionKind::NORMAL_FUNCTION, bool strict = true); static JSHClass *GetOrCreateInitialJSHClass(JSThread *thread, const JSHandle &fun); static JSHandle GetInstanceJSHClass(JSThread *thread, JSHandle constructor, - JSHandle new_target); + JSHandle newTarget); ACCESSORS_BASE(JSFunctionBase) ACCESSORS(0, ProtoOrDynClass) @@ -284,7 +284,7 @@ public: private: static JSHandle GetOrCreateDerivedJSHClass(JSThread *thread, JSHandle derived, JSHandle constructor, - JSHandle ctor_initial_js_hclass); + JSHandle ctorInitialJsHclass); }; class JSGeneratorFunction : public JSFunction { diff --git a/runtime/js_generator_object.cpp b/runtime/js_generator_object.cpp index b6de5771461ff445d69c8a8a00d610836ac025b1..d933329bea045b7bfd7cb9d7253eea7db0d3b768 100644 --- a/runtime/js_generator_object.cpp +++ b/runtime/js_generator_object.cpp @@ -26,13 +26,13 @@ JSTaggedValue JSGeneratorObject::GeneratorValidate(JSThread *thread, const JSHan if (!obj->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "", JSTaggedValue::Undefined()); } - JSHandle to_obj = JSTaggedValue::ToObject(thread, obj); - if (!to_obj->IsGeneratorObject()) { + JSHandle toObj = JSTaggedValue::ToObject(thread, obj); + if (!toObj->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "", JSTaggedValue::Undefined()); } // 3.Let state be generator.[[GeneratorState]]. - JSHandle generator(thread, JSGeneratorObject::Cast(*(to_obj))); + JSHandle generator(thread, JSGeneratorObject::Cast(*(toObj))); JSTaggedValue state = generator->GetGeneratorState(); // 4.If state is executing, throw a TypeError exception. if (state == JSTaggedValue(static_cast(JSGeneratorState::EXECUTING))) { @@ -53,8 +53,8 @@ JSHandle JSGeneratorObject::GeneratorResume(JSThread *thread, // 2.If state is completed, return CreateIterResultObject(undefined, true). if (JSGeneratorObject::IsState(state, JSGeneratorState::COMPLETED)) { - JSHandle value_handle(thread, JSTaggedValue::Undefined()); - return JSHandle::Cast(JSIterator::CreateIterResultObject(thread, value_handle, true)); + JSHandle valueHandle(thread, JSTaggedValue::Undefined()); + return JSHandle::Cast(JSIterator::CreateIterResultObject(thread, valueHandle, true)); } // 3.Assert: state is either suspendedStart or suspendedYield. @@ -63,7 +63,7 @@ JSHandle JSGeneratorObject::GeneratorResume(JSThread *thread, "state is neither suspendedStart nor suspendedYield"); // 4.Let genContext be generator.[[GeneratorContext]]. - JSHandle gen_context(thread, generator->GetGeneratorContext()); + JSHandle genContext(thread, generator->GetGeneratorContext()); // 5.Let methodContext be the running execution context. // 6.Suspend methodContext. @@ -78,13 +78,13 @@ JSHandle JSGeneratorObject::GeneratorResume(JSThread *thread, // methodContext is the currently running execution context. // 11.Return Completion(result). JSHandle result = - GeneratorHelper::Continue(thread, gen_context, GeneratorResumeMode::NEXT, value.GetTaggedValue()); + GeneratorHelper::Continue(thread, genContext, GeneratorResumeMode::NEXT, value.GetTaggedValue()); return result; } JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, const JSHandle &generator, - const JSHandle &abrupt_completion) + const JSHandle &abruptCompletion) { // 1.Let state be ? GeneratorValidate(generator). JSHandle gen(thread, generator.GetTaggedValue()); @@ -106,21 +106,21 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *threa // i.Return CreateIterResultObject(abrupt_completion.[[Value]], true). // b.Return Completion(abrupt_completion). if (JSGeneratorObject::IsState(state, JSGeneratorState::COMPLETED)) { - JSHandle value_handle(thread, abrupt_completion->GetValue()); + JSHandle valueHandle(thread, abruptCompletion->GetValue()); JSHandle result = - JSHandle::Cast(JSIterator::CreateIterResultObject(thread, value_handle, true)); + JSHandle::Cast(JSIterator::CreateIterResultObject(thread, valueHandle, true)); - if (abrupt_completion->IsReturn()) { + if (abruptCompletion->IsReturn()) { return result; } - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, value_handle.GetTaggedValue(), result); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, valueHandle.GetTaggedValue(), result); } // 4.Assert: state is suspendedYield. ASSERT_PRINT(JSGeneratorObject::IsState(state, JSGeneratorState::SUSPENDED_YIELD), "state is not suspendedYield"); // 5.Let genContext be generator.[[GeneratorContext]]. - JSHandle gen_context(thread, generator->GetGeneratorContext()); + JSHandle genContext(thread, generator->GetGeneratorContext()); // 6.Let methodContext be the running execution context. // 7.Suspend methodContext. @@ -135,12 +135,12 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *threa // methodContext is the currently running execution context. // 12.Return Completion(result). JSHandle result; - if (abrupt_completion->IsReturn()) { + if (abruptCompletion->IsReturn()) { result = - GeneratorHelper::Continue(thread, gen_context, GeneratorResumeMode::RETURN, abrupt_completion->GetValue()); + GeneratorHelper::Continue(thread, genContext, GeneratorResumeMode::RETURN, abruptCompletion->GetValue()); } else { result = - GeneratorHelper::Continue(thread, gen_context, GeneratorResumeMode::THROW, abrupt_completion->GetValue()); + GeneratorHelper::Continue(thread, genContext, GeneratorResumeMode::THROW, abruptCompletion->GetValue()); } return result; } diff --git a/runtime/js_generator_object.h b/runtime/js_generator_object.h index a4c1f33861c3afcfde7ff102bbe5df4a4a919d85..8f27404289bedffdf37c613e929dbaa47b26a208 100644 --- a/runtime/js_generator_object.h +++ b/runtime/js_generator_object.h @@ -58,16 +58,16 @@ public: // 26.4.3.4 GeneratorResumeAbrupt(generator, abruptCompletion) static JSHandle GeneratorResumeAbrupt(JSThread *thread, const JSHandle &generator, - const JSHandle &abrupt_completion); + const JSHandle &abruptCompletion); inline bool IsSuspendYield() const { return GetGeneratorState() == JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_YIELD)); } - static inline bool IsState(JSTaggedValue state_value, JSGeneratorState state) + static inline bool IsState(JSTaggedValue stateValue, JSGeneratorState state) { - return state_value == JSTaggedValue(static_cast(state)); + return stateValue == JSTaggedValue(static_cast(state)); } inline bool IsExecuting() const diff --git a/runtime/js_handle.h b/runtime/js_handle.h index 59c1eb5533944eb6602129cbb70dfa51b581e7a6..bcfe26638ffe8d4a75f88f1e4e5772204e1d0ab9 100644 --- a/runtime/js_handle.h +++ b/runtime/js_handle.h @@ -215,8 +215,8 @@ public: ~JSSpanHandle() { - ASSERT(thread_->span_handle_ == this); - thread_->span_handle_ = prev_; + ASSERT(thread_->spanHandle_ == this); + thread_->spanHandle_ = prev_; } JSTaggedValue *Data() @@ -236,7 +236,7 @@ public: static void IterateChain(JSThread *thread, const RootRangeVisitor &v0) { - for (auto head = thread->span_handle_; head != nullptr; head = head->prev_) { + for (auto head = thread->spanHandle_; head != nullptr; head = head->prev_) { auto &sp = head->sp_; v0(Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(sp.begin())), ObjectSlot(ToUintPtr(sp.end()))); } @@ -248,8 +248,8 @@ private: void AddToChain() { - prev_ = thread_->span_handle_; - thread_->span_handle_ = this; + prev_ = thread_->spanHandle_; + thread_->spanHandle_ = this; } JSSpanHandle *prev_ {nullptr}; diff --git a/runtime/js_hclass-inl.h b/runtime/js_hclass-inl.h index 018339ec22488163d9cdf8c9af9adaff4e8cb182..9c85a430ffd9b5e3eab16b5618087674536db42b 100644 --- a/runtime/js_hclass-inl.h +++ b/runtime/js_hclass-inl.h @@ -39,14 +39,14 @@ void JSHClass::AddTransitions(const JSThread *thread, const JSHandle & } JSMutableHandle dict(thread, JSTaggedValue::Undefined()); if (transitions.IsJSHClass()) { - auto cached_h_class = JSHClass::Cast(transitions.GetTaggedObject()); - int32_t last = cached_h_class->NumberOfProps() - 1; - LayoutInfo *layout_info = LayoutInfo::Cast(cached_h_class->GetLayout().GetTaggedObject()); - auto attr = JSHandle(thread, JSTaggedValue(layout_info->GetAttr(last).GetPropertyMetaData())); - auto last_key = JSHandle(thread, layout_info->GetKey(last)); - auto last_h_class = JSHandle(thread, cached_h_class); + auto cachedHClass = JSHClass::Cast(transitions.GetTaggedObject()); + int32_t last = cachedHClass->NumberOfProps() - 1; + LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); + auto attr = JSHandle(thread, JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); + auto lastKey = JSHandle(thread, layoutInfo->GetKey(last)); + auto lastHClass = JSHandle(thread, cachedHClass); dict.Update(TransitionsDictionary::Create(thread)); - transitions = TransitionsDictionary::PutIfAbsent(thread, dict, last_key, last_h_class, attr).GetTaggedValue(); + transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, attr).GetTaggedValue(); } auto attr = JSHandle(thread, JSTaggedValue(attributes.GetPropertyMetaData())); dict.Update(transitions); @@ -72,14 +72,14 @@ void JSHClass::AddProtoTransitions(const JSThread *thread, const JSHandleNumberOfProps() - 1; - LayoutInfo *layout_info = LayoutInfo::Cast(cached_h_class->GetLayout().GetTaggedObject()); - auto attr = JSHandle(thread, JSTaggedValue(layout_info->GetAttr(last).GetPropertyMetaData())); - auto last_key = JSHandle(thread, layout_info->GetKey(last)); - auto last_h_class = JSHandle(thread, cached_h_class); + auto cachedHClass = JSHClass::Cast(transitions.GetTaggedObject()); + int32_t last = cachedHClass->NumberOfProps() - 1; + LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); + auto attr = JSHandle(thread, JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); + auto lastKey = JSHandle(thread, layoutInfo->GetKey(last)); + auto lastHClass = JSHandle(thread, cachedHClass); dict.Update(TransitionsDictionary::Create(thread)); - transitions = TransitionsDictionary::PutIfAbsent(thread, dict, last_key, last_h_class, attr).GetTaggedValue(); + transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, attr).GetTaggedValue(); } dict.Update(transitions); @@ -96,13 +96,13 @@ inline JSHClass *JSHClass::FindTransitions(const JSTaggedValue &key, const JSTag return nullptr; } if (transitions.IsJSHClass()) { - auto cached_h_class = JSHClass::Cast(transitions.GetTaggedObject()); - int32_t last = cached_h_class->NumberOfProps() - 1; - LayoutInfo *layout_info = LayoutInfo::Cast(cached_h_class->GetLayout().GetTaggedObject()); - auto attr = layout_info->GetAttr(last).GetPropertyMetaData(); - auto cached_key = layout_info->GetKey(last); - if (attr == attributes.GetInt() && key == cached_key) { - return cached_h_class; + auto cachedHClass = JSHClass::Cast(transitions.GetTaggedObject()); + int32_t last = cachedHClass->NumberOfProps() - 1; + LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); + auto attr = layoutInfo->GetAttr(last).GetPropertyMetaData(); + auto cachedKey = layoutInfo->GetKey(last); + if (attr == attributes.GetInt() && key == cachedKey) { + return cachedHClass; } return nullptr; } @@ -133,14 +133,14 @@ inline JSHClass *JSHClass::FindProtoTransitions(const JSTaggedValue &key, const } inline void JSHClass::UpdatePropertyMetaData(const JSThread *thread, [[maybe_unused]] const JSTaggedValue &key, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { ASSERT(!GetLayout().IsNull()); - LayoutInfo *layout_info = LayoutInfo::Cast(GetLayout().GetTaggedObject()); - ASSERT(layout_info->GetLength() != 0); - int32_t entry = meta_data.GetOffset(); + LayoutInfo *layoutInfo = LayoutInfo::Cast(GetLayout().GetTaggedObject()); + ASSERT(layoutInfo->GetLength() != 0); + int32_t entry = metaData.GetOffset(); - layout_info->SetNormalAttr(thread, entry, meta_data); + layoutInfo->SetNormalAttr(thread, entry, metaData); } inline bool JSHClass::HasReferenceField() diff --git a/runtime/js_hclass.cpp b/runtime/js_hclass.cpp index aaf6847bccb140086ad124e8ef6cf2e37f9f94ba..12a70e5bf349600b9506eafc5931bf0db75f6e25 100644 --- a/runtime/js_hclass.cpp +++ b/runtime/js_hclass.cpp @@ -31,31 +31,31 @@ JSHandle TransitionsDictionary::PutIfAbsent(const JSThrea const JSHandle &dictionary, const JSHandle &key, const JSHandle &value, - const JSHandle &meta_data) + const JSHandle &metaData) { - int hash = TransitionsDictionary::Hash(key.GetTaggedValue(), meta_data.GetTaggedValue()); + int hash = TransitionsDictionary::Hash(key.GetTaggedValue(), metaData.GetTaggedValue()); /* no need to add key if exist */ - int entry = dictionary->FindEntry(key.GetTaggedValue(), meta_data.GetTaggedValue()); + int entry = dictionary->FindEntry(key.GetTaggedValue(), metaData.GetTaggedValue()); if (entry != -1) { return dictionary; } // Check whether the dictionary should be extended. - JSHandle new_dictionary(HashTableT::GrowHashTable(thread, dictionary)); + JSHandle newDictionary(HashTableT::GrowHashTable(thread, dictionary)); // Compute the key object. - entry = new_dictionary->FindInsertIndex(hash); - new_dictionary->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), meta_data.GetTaggedValue()); + entry = newDictionary->FindInsertIndex(hash); + newDictionary->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), metaData.GetTaggedValue()); - new_dictionary->IncreaseEntries(thread); - return new_dictionary; + newDictionary->IncreaseEntries(thread); + return newDictionary; } -int TransitionsDictionary::FindEntry(const JSTaggedValue &key, const JSTaggedValue &meta_data) +int TransitionsDictionary::FindEntry(const JSTaggedValue &key, const JSTaggedValue &metaData) { size_t size = Size(); uint32_t count = 1; - uint32_t hash = TransitionsDictionary::Hash(key, meta_data); + uint32_t hash = TransitionsDictionary::Hash(key, metaData); // GrowHashTable will guarantee the hash table is never full. for (int entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { JSTaggedValue element = GetKey(entry); @@ -66,7 +66,7 @@ int TransitionsDictionary::FindEntry(const JSTaggedValue &key, const JSTaggedVal return -1; } - if (TransitionsDictionary::IsMatch(key, meta_data, element, GetAttributes(entry))) { + if (TransitionsDictionary::IsMatch(key, metaData, element, GetAttributes(entry))) { return entry; } } @@ -76,9 +76,9 @@ int TransitionsDictionary::FindEntry(const JSTaggedValue &key, const JSTaggedVal JSHandle TransitionsDictionary::Remove(const JSThread *thread, const JSHandle &table, const JSHandle &key, - const JSTaggedValue &meta_data) + const JSTaggedValue &metaData) { - int entry = table->FindEntry(key.GetTaggedValue(), meta_data); + int entry = table->FindEntry(key.GetTaggedValue(), metaData); if (entry == -1) { return table; } @@ -87,41 +87,41 @@ JSHandle TransitionsDictionary::Remove(const JSThread *th return TransitionsDictionary::Shrink(thread, table); } -void TransitionsDictionary::Rehash(const JSThread *thread, TransitionsDictionary *new_table) +void TransitionsDictionary::Rehash(const JSThread *thread, TransitionsDictionary *newTable) { - if ((new_table == nullptr) || (new_table->Size() < EntriesCount())) { + if ((newTable == nullptr) || (newTable->Size() < EntriesCount())) { return; } int size = this->Size(); // Rehash elements to new table for (int i = 0; i < size; i++) { - int from_index = GetEntryIndex(i); + int fromIndex = GetEntryIndex(i); JSTaggedValue k = this->GetKey(i); if (!IsKey(k)) { continue; } int hash = TransitionsDictionary::Hash(k, this->GetAttributes(i)); - int insertion_index = GetEntryIndex(new_table->FindInsertIndex(hash)); - JSTaggedValue tv = Get(from_index); - new_table->Set(thread, insertion_index, tv); + int insertionIndex = GetEntryIndex(newTable->FindInsertIndex(hash)); + JSTaggedValue tv = Get(fromIndex); + newTable->Set(thread, insertionIndex, tv); for (int j = 1; j < TransitionsDictionary::ENTRY_SIZE; j++) { - tv = Get(from_index + j); - new_table->Set(thread, insertion_index + j, tv); + tv = Get(fromIndex + j); + newTable->Set(thread, insertionIndex + j, tv); } } - new_table->SetEntriesCount(thread, EntriesCount()); - new_table->SetHoleEntriesCount(thread, 0); + newTable->SetEntriesCount(thread, EntriesCount()); + newTable->SetHoleEntriesCount(thread, 0); } // class JSHClass -void JSHClass::Initialize(const JSThread *thread, uint32_t size, JSType type, uint32_t inlined_props, uint32_t flags) +void JSHClass::Initialize(const JSThread *thread, uint32_t size, JSType type, uint32_t inlinedProps, uint32_t flags) { new (&hclass_) HClass(flags, panda_file::SourceLang::ECMASCRIPT); hclass_.SetManagedObject(this); ClearBitField(); if (JSType::JS_OBJECT_BEGIN <= type && type <= JSType::JS_OBJECT_END) { - SetObjectSize(size + inlined_props * JSTaggedValue::TaggedTypeSize()); + SetObjectSize(size + inlinedProps * JSTaggedValue::TaggedTypeSize()); SetInlinedPropsStart(size); auto env = thread->GetEcmaVM()->GetGlobalEnv(); SetLayout(thread, env->GetEmptyLayoutInfo()); @@ -152,11 +152,11 @@ void JSHClass::Copy(const JSThread *thread, const JSHClass *jshclass) } JSHandle JSHClass::Clone(const JSThread *thread, const JSHandle &jshclass, - bool without_inlined_properties) + bool withoutInlinedProperties) { JSType type = jshclass->GetObjectType(); - uint32_t num_inlined_props = without_inlined_properties ? 0 : jshclass->GetInlinedProperties(); + uint32_t numInlinedProps = withoutInlinedProperties ? 0 : jshclass->GetInlinedProperties(); uint32_t size; if (jshclass->IsJSObject()) { @@ -166,24 +166,24 @@ JSHandle JSHClass::Clone(const JSThread *thread, const JSHandleGetObjectSize() - numInlinedProps * JSTaggedValue::TaggedTypeSize(); #endif } else { - ASSERT(num_inlined_props == 0); + ASSERT(numInlinedProps == 0); size = jshclass->GetObjectSize(); } auto factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_jshclass = factory->NewEcmaDynClass(factory->hclass_class_, size, type, - jshclass->GetHClass()->GetFlags(), num_inlined_props); + JSHandle newJshclass = + factory->NewEcmaDynClass(factory->hclassClass_, size, type, jshclass->GetHClass()->GetFlags(), numInlinedProps); // Copy all - new_jshclass->Copy(thread, *jshclass); - new_jshclass->SetParent(thread, JSTaggedValue::Null()); - new_jshclass->SetTransitions(thread, JSTaggedValue::Null()); - new_jshclass->SetProtoChangeDetails(thread, JSTaggedValue::Null()); - new_jshclass->SetProtoChangeMarker(thread, JSTaggedValue::Null()); - new_jshclass->SetEnumCache(thread, JSTaggedValue::Null()); + newJshclass->Copy(thread, *jshclass); + newJshclass->SetParent(thread, JSTaggedValue::Null()); + newJshclass->SetTransitions(thread, JSTaggedValue::Null()); + newJshclass->SetProtoChangeDetails(thread, JSTaggedValue::Null()); + newJshclass->SetProtoChangeMarker(thread, JSTaggedValue::Null()); + newJshclass->SetEnumCache(thread, JSTaggedValue::Null()); // reuse Attributes first. - new_jshclass->SetLayout(thread, jshclass->GetLayout()); + newJshclass->SetLayout(thread, jshclass->GetLayout()); - return new_jshclass; + return newJshclass; } // use for transition to dictionary @@ -207,72 +207,72 @@ void JSHClass::AddProperty(const JSThread *thread, const JSHandle &obj { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle jshclass(thread, obj->GetJSHClass()); - JSHClass *new_dyn = jshclass->FindTransitions(key.GetTaggedValue(), JSTaggedValue(attr.GetPropertyMetaData())); - if (new_dyn != nullptr) { + JSHClass *newDyn = jshclass->FindTransitions(key.GetTaggedValue(), JSTaggedValue(attr.GetPropertyMetaData())); + if (newDyn != nullptr) { #if ECMASCRIPT_ENABLE_IC - JSHClass::NotifyHclassChanged(thread, jshclass, JSHandle(thread, new_dyn)); + JSHClass::NotifyHclassChanged(thread, jshclass, JSHandle(thread, newDyn)); #endif - obj->SetClass(new_dyn); + obj->SetClass(newDyn); return; } // 2. Create hclass - JSHandle new_jshclass = JSHClass::Clone(thread, jshclass); + JSHandle newJshclass = JSHClass::Clone(thread, jshclass); // 3. Add Property and meta_data int offset = attr.GetOffset(); - new_jshclass->IncNumberOfProps(); + newJshclass->IncNumberOfProps(); { - JSMutableHandle layout_info_handle(thread, new_jshclass->GetLayout()); - - if (layout_info_handle->NumberOfElements() != offset) { - layout_info_handle.Update(factory->CopyAndReSort(layout_info_handle, offset, offset + 1)); - new_jshclass->SetLayout(thread, layout_info_handle); - } else if (layout_info_handle->GetPropertiesCapacity() <= offset) { // need to Grow - layout_info_handle.Update( - factory->ExtendLayoutInfo(layout_info_handle, LayoutInfo::ComputeGrowCapacity(offset))); - new_jshclass->SetLayout(thread, layout_info_handle); + JSMutableHandle layoutInfoHandle(thread, newJshclass->GetLayout()); + + if (layoutInfoHandle->NumberOfElements() != offset) { + layoutInfoHandle.Update(factory->CopyAndReSort(layoutInfoHandle, offset, offset + 1)); + newJshclass->SetLayout(thread, layoutInfoHandle); + } else if (layoutInfoHandle->GetPropertiesCapacity() <= offset) { // need to Grow + layoutInfoHandle.Update( + factory->ExtendLayoutInfo(layoutInfoHandle, LayoutInfo::ComputeGrowCapacity(offset))); + newJshclass->SetLayout(thread, layoutInfoHandle); } - layout_info_handle->AddKey(thread, offset, key.GetTaggedValue(), attr); + layoutInfoHandle->AddKey(thread, offset, key.GetTaggedValue(), attr); } // 4. Add newDynclass to old dynclass's transitions. - AddTransitions(thread, jshclass, new_jshclass, key, attr); + AddTransitions(thread, jshclass, newJshclass, key, attr); // 5. update hclass in object. #if ECMASCRIPT_ENABLE_IC - JSHClass::NotifyHclassChanged(thread, jshclass, new_jshclass); + JSHClass::NotifyHclassChanged(thread, jshclass, newJshclass); #endif - obj->SetClass(*new_jshclass); + obj->SetClass(*newJshclass); } JSHandle JSHClass::TransitionExtension(const JSThread *thread, const JSHandle &jshclass) { JSHandle key(thread->GlobalConstants()->GetHandledPreventExtensionsString()); { - auto *new_dyn = jshclass->FindTransitions(key.GetTaggedValue(), JSTaggedValue(0)); - if (new_dyn != nullptr) { - return JSHandle(thread, new_dyn); + auto *newDyn = jshclass->FindTransitions(key.GetTaggedValue(), JSTaggedValue(0)); + if (newDyn != nullptr) { + return JSHandle(thread, newDyn); } } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 2. new a hclass - JSHandle new_jshclass = JSHClass::Clone(thread, jshclass); - new_jshclass->SetExtensible(false); + JSHandle newJshclass = JSHClass::Clone(thread, jshclass); + newJshclass->SetExtensible(false); - JSTaggedValue attrs = new_jshclass->GetLayout(); + JSTaggedValue attrs = newJshclass->GetLayout(); if (!attrs.IsNull()) { ASSERT(attrs.IsTaggedArray()); - JSMutableHandle layout_info_handle(thread, attrs); - layout_info_handle.Update(factory->CopyLayoutInfo(layout_info_handle).GetTaggedValue()); - new_jshclass->SetLayout(thread, layout_info_handle); + JSMutableHandle layoutInfoHandle(thread, attrs); + layoutInfoHandle.Update(factory->CopyLayoutInfo(layoutInfoHandle).GetTaggedValue()); + newJshclass->SetLayout(thread, layoutInfoHandle); } // 3. Add newDynclass to old dynclass's parent's transitions. - AddExtensionTransitions(thread, jshclass, new_jshclass, key); + AddExtensionTransitions(thread, jshclass, newJshclass, key); // parent is the same as jshclass, already copy - return new_jshclass; + return newJshclass; } JSHandle JSHClass::TransitionProto(const JSThread *thread, const JSHandle &jshclass, @@ -281,29 +281,29 @@ JSHandle JSHClass::TransitionProto(const JSThread *thread, const JSHan JSHandle key(thread->GlobalConstants()->GetHandledPrototypeString()); { - auto *new_dyn = jshclass->FindProtoTransitions(key.GetTaggedValue(), proto.GetTaggedValue()); - if (new_dyn != nullptr) { - return JSHandle(thread, new_dyn); + auto *newDyn = jshclass->FindProtoTransitions(key.GetTaggedValue(), proto.GetTaggedValue()); + if (newDyn != nullptr) { + return JSHandle(thread, newDyn); } } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 2. new a hclass - JSHandle new_jshclass = JSHClass::Clone(thread, jshclass); - new_jshclass->SetPrototype(thread, proto.GetTaggedValue()); + JSHandle newJshclass = JSHClass::Clone(thread, jshclass); + newJshclass->SetPrototype(thread, proto.GetTaggedValue()); - JSTaggedValue attrs = new_jshclass->GetLayout(); + JSTaggedValue attrs = newJshclass->GetLayout(); { - JSMutableHandle layout_info_handle(thread, attrs); - layout_info_handle.Update(factory->CopyLayoutInfo(layout_info_handle).GetTaggedValue()); - new_jshclass->SetLayout(thread, layout_info_handle); + JSMutableHandle layoutInfoHandle(thread, attrs); + layoutInfoHandle.Update(factory->CopyLayoutInfo(layoutInfoHandle).GetTaggedValue()); + newJshclass->SetLayout(thread, layoutInfoHandle); } // 3. Add newJshclass to old jshclass's parent's transitions. - AddProtoTransitions(thread, jshclass, new_jshclass, key, proto); + AddProtoTransitions(thread, jshclass, newJshclass, key, proto); // parent is the same as jshclass, already copy - return new_jshclass; + return newJshclass; } void JSHClass::SetPrototype(const JSThread *thread, JSTaggedValue proto) @@ -323,19 +323,19 @@ void JSHClass::TransitionToDictionary(const JSThread *thread, const JSHandle jshclass(thread, obj->GetJSHClass()); - JSHandle new_jshclass = CloneWithoutInlinedProperties(thread, jshclass); + JSHandle newJshclass = CloneWithoutInlinedProperties(thread, jshclass); { // 2. Copy - new_jshclass->SetNumberOfProps(0); - new_jshclass->SetIsDictionaryMode(true); - ASSERT(new_jshclass->GetInlinedProperties() == 0); + newJshclass->SetNumberOfProps(0); + newJshclass->SetIsDictionaryMode(true); + ASSERT(newJshclass->GetInlinedProperties() == 0); // 3. Add newJshclass to ? #if ECMASCRIPT_ENABLE_IC - JSHClass::NotifyHclassChanged(thread, JSHandle(thread, obj->GetJSHClass()), new_jshclass); + JSHClass::NotifyHclassChanged(thread, JSHandle(thread, obj->GetJSHClass()), newJshclass); #endif - obj->SetClass(new_jshclass); + obj->SetClass(newJshclass); } } @@ -346,46 +346,45 @@ JSHandle JSHClass::EnableProtoChangeMarker(const JSThread *thread // Return JSTaggedValue directly. No proto check is needed. return JSHandle(thread, JSTaggedValue(false)); } - JSHandle proto_handle(thread, proto); - JSHandle proto_dyncalss(thread, proto_handle->GetJSHClass()); - RegisterOnProtoChain(thread, proto_dyncalss); - JSTaggedValue proto_change_marker = proto_dyncalss->GetProtoChangeMarker(); - if (proto_change_marker.IsProtoChangeMarker()) { - JSHandle marker_handle(thread, - ProtoChangeMarker::Cast(proto_change_marker.GetTaggedObject())); - if (!marker_handle->GetHasChanged()) { - return JSHandle(marker_handle); + JSHandle protoHandle(thread, proto); + JSHandle protoDyncalss(thread, protoHandle->GetJSHClass()); + RegisterOnProtoChain(thread, protoDyncalss); + JSTaggedValue protoChangeMarker = protoDyncalss->GetProtoChangeMarker(); + if (protoChangeMarker.IsProtoChangeMarker()) { + JSHandle markerHandle(thread, ProtoChangeMarker::Cast(protoChangeMarker.GetTaggedObject())); + if (!markerHandle->GetHasChanged()) { + return JSHandle(markerHandle); } } - JSHandle marker_handle = thread->GetEcmaVM()->GetFactory()->NewProtoChangeMarker(); - marker_handle->SetHasChanged(false); - proto_dyncalss->SetProtoChangeMarker(thread, marker_handle.GetTaggedValue()); - return JSHandle(marker_handle); + JSHandle markerHandle = thread->GetEcmaVM()->GetFactory()->NewProtoChangeMarker(); + markerHandle->SetHasChanged(false); + protoDyncalss->SetProtoChangeMarker(thread, markerHandle.GetTaggedValue()); + return JSHandle(markerHandle); } -void JSHClass::NotifyHclassChanged(const JSThread *thread, JSHandle old_hclass, JSHandle new_hclass) +void JSHClass::NotifyHclassChanged(const JSThread *thread, JSHandle oldHclass, JSHandle newHclass) { - if (!old_hclass->IsPrototype()) { + if (!oldHclass->IsPrototype()) { return; } // The old hclass is the same as new one - if (old_hclass.GetTaggedValue() == new_hclass.GetTaggedValue()) { + if (oldHclass.GetTaggedValue() == newHclass.GetTaggedValue()) { return; } - new_hclass->SetIsPrototype(true); - JSHClass::NoticeThroughChain(thread, old_hclass); - JSHClass::RefreshUsers(thread, old_hclass, new_hclass); + newHclass->SetIsPrototype(true); + JSHClass::NoticeThroughChain(thread, oldHclass); + JSHClass::RefreshUsers(thread, oldHclass, newHclass); } void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandle &jshclass) { ASSERT(jshclass->IsPrototype()); JSHandle user = jshclass; - JSHandle user_details = GetProtoChangeDetails(thread, user); + JSHandle userDetails = GetProtoChangeDetails(thread, user); while (true) { // Find the prototype chain as far as the hclass has not been registered. - if (user_details->GetRegisterIndex() != JSTaggedValue(ProtoChangeDetails::UNREGISTERED)) { + if (userDetails->GetRegisterIndex() != JSTaggedValue(ProtoChangeDetails::UNREGISTERED)) { return; } @@ -397,22 +396,22 @@ void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandle proto_handle(thread, proto); - JSHandle proto_details = - GetProtoChangeDetails(thread, JSHandle(thread, proto_handle->GetJSHClass())); - JSTaggedValue listeners = proto_details->GetChangeListener(); - JSHandle listeners_handle; + JSHandle protoHandle(thread, proto); + JSHandle protoDetails = + GetProtoChangeDetails(thread, JSHandle(thread, protoHandle->GetJSHClass())); + JSTaggedValue listeners = protoDetails->GetChangeListener(); + JSHandle listenersHandle; if (listeners == JSTaggedValue(0)) { - listeners_handle = JSHandle(ChangeListener::Create(thread)); + listenersHandle = JSHandle(ChangeListener::Create(thread)); } else { - listeners_handle = JSHandle(thread, listeners); + listenersHandle = JSHandle(thread, listeners); } - uint32_t register_index = 0; - JSHandle new_listeners = ChangeListener::Add(thread, listeners_handle, user, ®ister_index); - user_details->SetRegisterIndex(thread, JSTaggedValue(register_index)); - proto_details->SetChangeListener(thread, new_listeners.GetTaggedValue()); - user_details = proto_details; - user = JSHandle(thread, proto_handle->GetJSHClass()); + uint32_t registerIndex = 0; + JSHandle newListeners = ChangeListener::Add(thread, listenersHandle, user, ®isterIndex); + userDetails->SetRegisterIndex(thread, JSTaggedValue(registerIndex)); + protoDetails->SetChangeListener(thread, newListeners.GetTaggedValue()); + userDetails = protoDetails; + user = JSHandle(thread, protoHandle->GetJSHClass()); } } @@ -427,19 +426,18 @@ bool JSHClass::UnregisterOnProtoChain(const JSThread *thread, const JSHandleGetProtoChangeDetails().GetTaggedObject())->GetChangeListener(); return listeners != JSTaggedValue(0); } - JSHandle current_details = GetProtoChangeDetails(thread, jshclass); - uint32_t index = current_details->GetRegisterIndex().GetArrayLength(); + JSHandle currentDetails = GetProtoChangeDetails(thread, jshclass); + uint32_t index = currentDetails->GetRegisterIndex().GetArrayLength(); if (JSTaggedValue(index) == JSTaggedValue(ProtoChangeDetails::UNREGISTERED)) { return false; } JSTaggedValue proto = jshclass->GetPrototype(); ASSERT(proto.IsECMAObject()); - JSTaggedValue proto_details_value = JSObject::Cast(proto.GetTaggedObject())->GetJSHClass()->GetProtoChangeDetails(); - ASSERT(proto_details_value.IsProtoChangeDetails()); - JSTaggedValue listeners_value = - ProtoChangeDetails::Cast(proto_details_value.GetTaggedObject())->GetChangeListener(); - ASSERT(listeners_value != JSTaggedValue(0)); - JSHandle listeners(thread, listeners_value.GetTaggedObject()); + JSTaggedValue protoDetailsValue = JSObject::Cast(proto.GetTaggedObject())->GetJSHClass()->GetProtoChangeDetails(); + ASSERT(protoDetailsValue.IsProtoChangeDetails()); + JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(); + ASSERT(listenersValue != JSTaggedValue(0)); + JSHandle listeners(thread, listenersValue.GetTaggedObject()); ASSERT(listeners->Get(index) == jshclass.GetTaggedValue()); listeners->Delete(thread, index); return true; @@ -447,13 +445,13 @@ bool JSHClass::UnregisterOnProtoChain(const JSThread *thread, const JSHandle JSHClass::GetProtoChangeDetails(const JSThread *thread, const JSHandle &jshclass) { - JSTaggedValue proto_details = jshclass->GetProtoChangeDetails(); - if (proto_details.IsProtoChangeDetails()) { - return JSHandle(thread, proto_details); + JSTaggedValue protoDetails = jshclass->GetProtoChangeDetails(); + if (protoDetails.IsProtoChangeDetails()) { + return JSHandle(thread, protoDetails); } - JSHandle proto_details_handle = thread->GetEcmaVM()->GetFactory()->NewProtoChangeDetails(); - jshclass->SetProtoChangeDetails(thread, proto_details_handle.GetTaggedValue()); - return proto_details_handle; + JSHandle protoDetailsHandle = thread->GetEcmaVM()->GetFactory()->NewProtoChangeDetails(); + jshclass->SetProtoChangeDetails(thread, protoDetailsHandle.GetTaggedValue()); + return protoDetailsHandle; } JSHandle JSHClass::GetProtoChangeDetails(const JSThread *thread, const JSHandle &obj) @@ -465,26 +463,25 @@ JSHandle JSHClass::GetProtoChangeDetails(const JSThread *thr void JSHClass::NoticeRegisteredUser([[maybe_unused]] const JSThread *thread, const JSHandle &jshclass) { ASSERT(jshclass->IsPrototype()); - JSTaggedValue marker_value = jshclass->GetProtoChangeMarker(); - if (marker_value.IsProtoChangeMarker()) { - ProtoChangeMarker *proto_change_marker = ProtoChangeMarker::Cast(marker_value.GetTaggedObject()); - proto_change_marker->SetHasChanged(true); + JSTaggedValue markerValue = jshclass->GetProtoChangeMarker(); + if (markerValue.IsProtoChangeMarker()) { + ProtoChangeMarker *protoChangeMarker = ProtoChangeMarker::Cast(markerValue.GetTaggedObject()); + protoChangeMarker->SetHasChanged(true); } } void JSHClass::NoticeThroughChain(const JSThread *thread, const JSHandle &jshclass) { NoticeRegisteredUser(thread, jshclass); - JSTaggedValue proto_details_value = jshclass->GetProtoChangeDetails(); - if (!proto_details_value.IsProtoChangeDetails()) { + JSTaggedValue protoDetailsValue = jshclass->GetProtoChangeDetails(); + if (!protoDetailsValue.IsProtoChangeDetails()) { return; } - JSTaggedValue listeners_value = - ProtoChangeDetails::Cast(proto_details_value.GetTaggedObject())->GetChangeListener(); - if (!listeners_value.IsTaggedArray()) { + JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(); + if (!listenersValue.IsTaggedArray()) { return; } - ChangeListener *listeners = ChangeListener::Cast(listeners_value.GetTaggedObject()); + ChangeListener *listeners = ChangeListener::Cast(listenersValue.GetTaggedObject()); for (uint32_t i = 0; i < listeners->GetEnd(); i++) { JSTaggedValue temp = listeners->Get(i); if (temp.IsJSHClass()) { @@ -493,21 +490,21 @@ void JSHClass::NoticeThroughChain(const JSThread *thread, const JSHandle &old_hclass, - const JSHandle &new_hclass) +void JSHClass::RefreshUsers(const JSThread *thread, const JSHandle &oldHclass, + const JSHandle &newHclass) { - ASSERT(old_hclass->IsPrototype()); - ASSERT(new_hclass->IsPrototype()); - bool once_registered = UnregisterOnProtoChain(thread, old_hclass); - - new_hclass->SetProtoChangeDetails(thread, old_hclass->GetProtoChangeDetails()); - old_hclass->SetProtoChangeDetails(thread, JSTaggedValue(0)); - if (once_registered) { - if (new_hclass->GetProtoChangeDetails().IsProtoChangeDetails()) { - ProtoChangeDetails::Cast(new_hclass->GetProtoChangeDetails().GetTaggedObject()) + ASSERT(oldHclass->IsPrototype()); + ASSERT(newHclass->IsPrototype()); + bool onceRegistered = UnregisterOnProtoChain(thread, oldHclass); + + newHclass->SetProtoChangeDetails(thread, oldHclass->GetProtoChangeDetails()); + oldHclass->SetProtoChangeDetails(thread, JSTaggedValue(0)); + if (onceRegistered) { + if (newHclass->GetProtoChangeDetails().IsProtoChangeDetails()) { + ProtoChangeDetails::Cast(newHclass->GetProtoChangeDetails().GetTaggedObject()) ->SetRegisterIndex(thread, JSTaggedValue(ProtoChangeDetails::UNREGISTERED)); } - RegisterOnProtoChain(thread, new_hclass); + RegisterOnProtoChain(thread, newHclass); } } } // namespace panda::ecmascript diff --git a/runtime/js_hclass.h b/runtime/js_hclass.h index 72665c65548a07d160c61050ec3ad75d23cf4ebb..a26995b08b0c6189af21b99c4e575428c925aa4c 100644 --- a/runtime/js_hclass.h +++ b/runtime/js_hclass.h @@ -249,10 +249,10 @@ public: inline bool HasReferenceField(); // size need to add inlined property numbers - void Initialize(const JSThread *thread, uint32_t size, JSType type, uint32_t inlined_props, uint32_t flags = 0); + void Initialize(const JSThread *thread, uint32_t size, JSType type, uint32_t inlinedProps, uint32_t flags = 0); static JSHandle Clone(const JSThread *thread, const JSHandle &jshclass, - bool without_inlined_properties = false); + bool withoutInlinedProperties = false); static JSHandle CloneWithoutInlinedProperties(const JSThread *thread, const JSHandle &jshclass); static void TransitionElementsToDictionary(const JSThread *thread, const JSHandle &obj); @@ -266,8 +266,7 @@ public: static JSHandle EnableProtoChangeMarker(const JSThread *thread, const JSHandle &jshclass); - static void NotifyHclassChanged(const JSThread *thread, JSHandle old_hclass, - JSHandle new_hclass); + static void NotifyHclassChanged(const JSThread *thread, JSHandle oldHclass, JSHandle newHclass); static void RegisterOnProtoChain(const JSThread *thread, const JSHandle &jshclass); @@ -279,14 +278,14 @@ public: static JSHandle GetProtoChangeDetails(const JSThread *thread, const JSHandle &obj); inline void UpdatePropertyMetaData(const JSThread *thread, const JSTaggedValue &key, - const PropertyAttributes &meta_data); + const PropertyAttributes &metaData); static void NoticeRegisteredUser(const JSThread *thread, const JSHandle &jshclass); static void NoticeThroughChain(const JSThread *thread, const JSHandle &jshclass); - static void RefreshUsers(const JSThread *thread, const JSHandle &old_hclass, - const JSHandle &new_hclass); + static void RefreshUsers(const JSThread *thread, const JSHandle &oldHclass, + const JSHandle &newHclass); inline void ClearBitField() { @@ -303,8 +302,8 @@ public: inline void SetObjectType(JSType type) { uint32_t bits = GetBitField(); - uint32_t new_val = ObjectTypeBits::Update(bits, type); - SetBitField(new_val); + uint32_t newVal = ObjectTypeBits::Update(bits, type); + SetBitField(newVal); } inline void SetConstructor(bool flag) const @@ -348,14 +347,14 @@ public: inline bool IsJSObject() const { - JSType js_type = GetObjectType(); - return (JSType::JS_OBJECT_BEGIN <= js_type && js_type <= JSType::JS_OBJECT_END); + JSType jsType = GetObjectType(); + return (JSType::JS_OBJECT_BEGIN <= jsType && jsType <= JSType::JS_OBJECT_END); } inline bool IsECMAObject() const { - JSType js_type = GetObjectType(); - return (JSType::ECMA_OBJECT_BEGIN <= js_type && js_type <= JSType::ECMA_OBJECT_END); + JSType jsType = GetObjectType(); + return (JSType::ECMA_OBJECT_BEGIN <= jsType && jsType <= JSType::ECMA_OBJECT_END); } inline bool IsRealm() const @@ -380,14 +379,14 @@ public: inline bool IsStringOrSymbol() const { - JSType js_type = GetObjectType(); - return (js_type == JSType::STRING) || (js_type == JSType::SYMBOL); + JSType jsType = GetObjectType(); + return (jsType == JSType::STRING) || (jsType == JSType::SYMBOL); } inline bool IsTaggedArray() const { - JSType js_type = GetObjectType(); - return (JSType::TAGGED_ARRAY_BEGIN <= js_type && js_type <= JSType::TAGGED_ARRAY_END); + JSType jsType = GetObjectType(); + return (JSType::TAGGED_ARRAY_BEGIN <= jsType && jsType <= JSType::TAGGED_ARRAY_END); } inline bool IsDictionary() const @@ -417,8 +416,8 @@ public: inline bool IsTypedArray() const { - JSType js_type = GetObjectType(); - return (JSType::JS_TYPED_ARRAY_BEGIN < js_type && js_type <= JSType::JS_TYPED_ARRAY_END); + JSType jsType = GetObjectType(); + return (JSType::JS_TYPED_ARRAY_BEGIN < jsType && jsType <= JSType::JS_TYPED_ARRAY_END); } inline bool IsJSTypedArray() const @@ -488,8 +487,8 @@ public: inline bool IsJSFunctionBase() const { - JSType js_type = GetObjectType(); - return js_type >= JSType::JS_FUNCTION_BASE && js_type <= JSType::JS_BOUND_FUNCTION; + JSType jsType = GetObjectType(); + return jsType >= JSType::JS_FUNCTION_BASE && jsType <= JSType::JS_BOUND_FUNCTION; } inline bool IsJsBoundFunction() const @@ -599,8 +598,8 @@ public: inline bool IsJSError() const { - JSType js_type = GetObjectType(); - return js_type >= JSType::JS_ERROR_BEGIN && js_type <= JSType::JS_ERROR_END; + JSType jsType = GetObjectType(); + return jsType >= JSType::JS_ERROR_BEGIN && jsType <= JSType::JS_ERROR_END; } inline bool IsArguments() const @@ -685,8 +684,8 @@ public: inline bool IsIterator() const { - JSType js_type = GetObjectType(); - return js_type >= JSType::JS_ITERATOR_BEGIN && js_type <= JSType::JS_ITERATOR_END; + JSType jsType = GetObjectType(); + return jsType >= JSType::JS_ITERATOR_BEGIN && jsType <= JSType::JS_ITERATOR_END; } inline bool IsForinIterator() const @@ -915,8 +914,8 @@ public: inline bool IsRecord() const { - JSType js_type = GetObjectType(); - return js_type >= JSType::JS_RECORD_BEGIN && js_type <= JSType::JS_RECORD_END; + JSType jsType = GetObjectType(); + return jsType >= JSType::JS_RECORD_BEGIN && jsType <= JSType::JS_RECORD_END; } inline bool IsTemplateMap() const @@ -942,8 +941,8 @@ public: inline void SetElementRepresentation(Representation representation) { uint32_t bits = GetBitField(); - uint32_t new_val = ElementRepresentationBits::Update(bits, representation); - SetBitField(new_val); + uint32_t newVal = ElementRepresentationBits::Update(bits, representation); + SetBitField(newVal); } inline Representation GetElementRepresentation() const @@ -960,8 +959,8 @@ public: inline void SetIsDictionaryElement(bool value) { - JSTaggedType new_val = DictionaryElementBits::Update(GetBitField(), value); - SetBitField(new_val); + JSTaggedType newVal = DictionaryElementBits::Update(GetBitField(), value); + SetBitField(newVal); } inline bool IsDictionaryElement() const { @@ -969,8 +968,8 @@ public: } inline void SetIsStableElements(bool value) { - JSTaggedType new_val = IsStableElementsBit::Update(GetBitField(), value); - SetBitField(new_val); + JSTaggedType newVal = IsStableElementsBit::Update(GetBitField(), value); + SetBitField(newVal); } inline bool IsStableElements() const { @@ -990,8 +989,8 @@ public: } inline void SetHasConstructor(bool value) { - TaggedType new_val = HasConstructorBits::Update(GetBitField(), value); - SetBitField(new_val); + TaggedType newVal = HasConstructorBits::Update(GetBitField(), value); + SetBitField(newVal); } inline bool HasConstructor() const { @@ -1001,8 +1000,8 @@ public: inline void SetNumberOfProps(uint32_t num) { uint32_t bits = GetBitField1(); - uint32_t new_val = NumberOfPropsBits::Update(bits, num); - SetBitField1(new_val); + uint32_t newVal = NumberOfPropsBits::Update(bits, num); + SetBitField1(newVal); } inline void IncNumberOfProps() @@ -1019,20 +1018,20 @@ public: inline int32_t GetNextInlinedPropsIndex() const { - uint32_t inlined_properties = GetInlinedProperties(); - uint32_t number_of_props = NumberOfProps(); - if (number_of_props < inlined_properties) { - return number_of_props; + uint32_t inlinedProperties = GetInlinedProperties(); + uint32_t numberOfProps = NumberOfProps(); + if (numberOfProps < inlinedProperties) { + return numberOfProps; } return -1; } inline int32_t GetNextNonInlinedPropsIndex() const { - uint32_t inlined_properties = GetInlinedProperties(); - uint32_t number_of_props = NumberOfProps(); - if (number_of_props >= inlined_properties) { - return number_of_props - inlined_properties; + uint32_t inlinedProperties = GetInlinedProperties(); + uint32_t numberOfProps = NumberOfProps(); + if (numberOfProps >= inlinedProperties) { + return numberOfProps - inlinedProperties; } return -1; } @@ -1053,8 +1052,8 @@ public: inline void SetInlinedPropsStart(uint32_t num) { uint32_t bits = GetBitField1(); - uint32_t new_val = InlinedPropsStartBits::Update(bits, num / JSTaggedValue::TaggedTypeSize()); - SetBitField1(new_val); + uint32_t newVal = InlinedPropsStartBits::Update(bits, num / JSTaggedValue::TaggedTypeSize()); + SetBitField1(newVal); } inline uint32_t GetInlinedPropsStartSize() const diff --git a/runtime/js_invoker.h b/runtime/js_invoker.h index 64a3a4860a9b72732e69e9abf68cf9f31ae186de..0b0f50c4b0ceaf4d9bb58c1cbecadd7cebfc5168 100644 --- a/runtime/js_invoker.h +++ b/runtime/js_invoker.h @@ -29,10 +29,10 @@ public: { } - JsInvoker(const JSThread *thread, JSTaggedValue func, JSTaggedValue obj, JSTaggedValue new_target) + JsInvoker(const JSThread *thread, JSTaggedValue func, JSTaggedValue obj, JSTaggedValue newTarget) { AddArgument(JSHandle(thread, func)); - AddArgument(JSHandle(thread, new_target)); + AddArgument(JSHandle(thread, newTarget)); AddArgument(JSHandle(thread, obj)); } diff --git a/runtime/js_iterator.cpp b/runtime/js_iterator.cpp index 1b0eadfef98366634d7933603ea0f9c270d2ffda..81611e23a077c6296db5596c2d8e554cc5d2cc7d 100644 --- a/runtime/js_iterator.cpp +++ b/runtime/js_iterator.cpp @@ -50,8 +50,8 @@ JSHandle JSIterator::GetIterator(JSThread *thread, const JSHandle RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, obj); // 2.If method was not passed, then JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSHandle func = JSObject::GetMethod(thread, obj, iterator_symbol); + JSHandle iteratorSymbol = env->GetIteratorSymbol(); + JSHandle func = JSObject::GetMethod(thread, obj, iteratorSymbol); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, obj); return GetIterator(thread, obj, func); @@ -70,8 +70,8 @@ JSHandle JSIterator::GetIterator(JSThread *thread, const JSHandle RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter); // 5.If Type(iterator) is not Object, throw a TypeError exception if (!iter->IsECMAObject()) { - JSHandle undefined_handle(thread, JSTaggedValue::Undefined()); - THROW_TYPE_ERROR_AND_RETURN(thread, "", undefined_handle); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); + THROW_TYPE_ERROR_AND_RETURN(thread, "", undefinedHandle); } return iter; } @@ -96,10 +96,10 @@ JSHandle JSIterator::IteratorNextOld(JSThread *thread, const JSHandle< // 7.4.2 JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandle &iter, - const JSHandle &next_method) + const JSHandle &nextMethod) { // 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). - auto info = NewRuntimeCallInfo(thread, next_method, iter, JSTaggedValue::Undefined(), 0); + auto info = NewRuntimeCallInfo(thread, nextMethod, iter, JSTaggedValue::Undefined(), 0); JSTaggedValue ret = JSFunction::Call(info.Get()); JSHandle result(thread, ret); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result); @@ -114,12 +114,12 @@ JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandl } JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandle &iter, - const JSHandle &next_method, + const JSHandle &nextMethod, const JSHandle &value) { // 2.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »). - auto info = NewRuntimeCallInfo(thread, next_method, iter, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread, nextMethod, iter, JSTaggedValue::Undefined(), 1); info->SetCallArgs(value); JSTaggedValue ret = JSFunction::Call(info.Get()); JSHandle result(thread, ret); @@ -134,24 +134,24 @@ JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandl return result; } // 7.4.3 -bool JSIterator::IteratorComplete(JSThread *thread, const JSHandle &iter_result) +bool JSIterator::IteratorComplete(JSThread *thread, const JSHandle &iterResult) { - ASSERT_PRINT(iter_result->IsECMAObject(), "iterResult must be JSObject"); + ASSERT_PRINT(iterResult->IsECMAObject(), "iterResult must be JSObject"); // Return ToBoolean(Get(iterResult, "done")). - JSHandle done_str = thread->GlobalConstants()->GetHandledDoneString(); - JSHandle done = JSTaggedValue::GetProperty(thread, iter_result, done_str).GetValue(); + JSHandle doneStr = thread->GlobalConstants()->GetHandledDoneString(); + JSHandle done = JSTaggedValue::GetProperty(thread, iterResult, doneStr).GetValue(); if (done->IsException()) { return false; } return done->ToBoolean(); } // 7.4.4 -JSHandle JSIterator::IteratorValue(JSThread *thread, const JSHandle &iter_result) +JSHandle JSIterator::IteratorValue(JSThread *thread, const JSHandle &iterResult) { - ASSERT_PRINT(iter_result->IsECMAObject(), "iterResult must be JSObject"); + ASSERT_PRINT(iterResult->IsECMAObject(), "iterResult must be JSObject"); // Return Get(iterResult, "value"). - JSHandle value_str = thread->GlobalConstants()->GetHandledValueString(); - JSHandle value = JSTaggedValue::GetProperty(thread, iter_result, value_str).GetValue(); + JSHandle valueStr = thread->GlobalConstants()->GetHandledValueString(); + JSHandle value = JSTaggedValue::GetProperty(thread, iterResult, valueStr).GetValue(); return value; } // 7.4.5 @@ -164,12 +164,12 @@ JSHandle JSIterator::IteratorStep(JSThread *thread, const JSHandl // 3.Let done be IteratorComplete(result). bool done = IteratorComplete(thread, result); // 4.ReturnIfAbrupt(done). - JSHandle done_handle(thread, JSTaggedValue(done)); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, done_handle); + JSHandle doneHandle(thread, JSTaggedValue(done)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, doneHandle); // 5.If done is true, return false. if (done) { - JSHandle false_handle(thread, JSTaggedValue::False()); - return false_handle; + JSHandle falseHandle(thread, JSTaggedValue::False()); + return falseHandle; } return result; } @@ -179,53 +179,53 @@ JSHandle JSIterator::IteratorClose(JSThread *thread, const JSHand { // 1.Assert: Type(iterator) is Object. ASSERT_PRINT(iter->IsECMAObject(), "iter must be JSObject"); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle exception_on_thread; + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle exceptionOnThread; if (UNLIKELY(thread->HasPendingException())) { - exception_on_thread = JSHandle(thread, thread->GetException()); + exceptionOnThread = JSHandle(thread, thread->GetException()); thread->ClearException(); } - JSHandle return_str(global_const->GetHandledReturnString()); + JSHandle returnStr(globalConst->GetHandledReturnString()); // 3.Let return be GetMethod(iterator, "return"). - JSHandle return_func(JSObject::GetMethod(thread, iter, return_str)); + JSHandle returnFunc(JSObject::GetMethod(thread, iter, returnStr)); // 4.ReturnIfAbrupt(return). - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, return_func); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, returnFunc); // 5.If return is undefined, return Completion(completion). - if (return_func->IsUndefined()) { - if (!exception_on_thread.IsEmpty()) { - thread->SetException(exception_on_thread.GetTaggedValue()); + if (returnFunc->IsUndefined()) { + if (!exceptionOnThread.IsEmpty()) { + thread->SetException(exceptionOnThread.GetTaggedValue()); } return completion; } // 6.Let innerResult be Call(return, iterator, «‍ »). - auto info = NewRuntimeCallInfo(thread, return_func, iter, JSTaggedValue::Undefined(), 0); + auto info = NewRuntimeCallInfo(thread, returnFunc, iter, JSTaggedValue::Undefined(), 0); JSTaggedValue ret = JSFunction::Call(info.Get()); - if (!exception_on_thread.IsEmpty()) { - thread->SetException(exception_on_thread.GetTaggedValue()); + if (!exceptionOnThread.IsEmpty()) { + thread->SetException(exceptionOnThread.GetTaggedValue()); } - JSHandle inner_result(thread, ret); - JSHandle completion_record(thread, global_const->GetUndefined()); + JSHandle innerResult(thread, ret); + JSHandle completionRecord(thread, globalConst->GetUndefined()); if (completion->IsCompletionRecord()) { - completion_record = JSHandle::Cast(completion); + completionRecord = JSHandle::Cast(completion); } // 7.If completion.[[type]] is throw, return Completion(completion). - if (!completion_record.GetTaggedValue().IsUndefined() && completion_record->IsThrow()) { - if (!exception_on_thread.IsEmpty()) { - thread->SetException(exception_on_thread.GetTaggedValue()); + if (!completionRecord.GetTaggedValue().IsUndefined() && completionRecord->IsThrow()) { + if (!exceptionOnThread.IsEmpty()) { + thread->SetException(exceptionOnThread.GetTaggedValue()); } return completion; } // 8.If innerResult.[[type]] is throw, return Completion(innerResult). if (UNLIKELY(thread->HasPendingException())) { - return inner_result; + return innerResult; } // 9.If Type(innerResult.[[value]]) is not Object, throw a TypeError exception. - if (!inner_result->IsECMAObject()) { - JSHandle undefined_handle(thread, JSTaggedValue::Undefined()); - THROW_TYPE_ERROR_AND_RETURN(thread, "", undefined_handle); + if (!innerResult->IsECMAObject()) { + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); + THROW_TYPE_ERROR_AND_RETURN(thread, "", undefinedHandle); } - if (!exception_on_thread.IsEmpty()) { - thread->SetException(exception_on_thread.GetTaggedValue()); + if (!exceptionOnThread.IsEmpty()) { + thread->SetException(exceptionOnThread.GetTaggedValue()); } return completion; } @@ -234,17 +234,17 @@ JSHandle JSIterator::CreateIterResultObject(JSThread *thread, const JS { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); JSHandle constructor(env->GetObjectFunction()); - JSHandle value_str = global_const->GetHandledValueString(); - JSHandle done_str = global_const->GetHandledDoneString(); - JSHandle done_value(thread, JSTaggedValue(done)); + JSHandle valueStr = globalConst->GetHandledValueString(); + JSHandle doneStr = globalConst->GetHandledDoneString(); + JSHandle doneValue(thread, JSTaggedValue(done)); // 2. Let obj be OrdinaryObjectCreate(%Object.prototype%). JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); // 3. Perform ! CreateDataPropertyOrThrow(obj, "value", value). // 4. Perform ! CreateDataPropertyOrThrow(obj, "done", done). - JSObject::CreateDataPropertyOrThrow(thread, obj, value_str, value); - JSObject::CreateDataPropertyOrThrow(thread, obj, done_str, done_value); + JSObject::CreateDataPropertyOrThrow(thread, obj, valueStr, value); + JSObject::CreateDataPropertyOrThrow(thread, obj, doneStr, doneValue); ASSERT_NO_ABRUPT_COMPLETION(thread); // 5. Return obj. return obj; diff --git a/runtime/js_iterator.h b/runtime/js_iterator.h index dd440f9e7bb9be64b370e15c6428d53f8dfb49dc..dcf856883783e72005b8caeac9662f0b1e224e00 100644 --- a/runtime/js_iterator.h +++ b/runtime/js_iterator.h @@ -34,15 +34,15 @@ public: static JSHandle IteratorNextOld(JSThread *thread, const JSHandle &iter); static JSHandle IteratorNext(JSThread *thread, const JSHandle &iter, - const JSHandle &next_method, + const JSHandle &nextMethod, const JSHandle &value); static JSHandle IteratorNext(JSThread *thread, const JSHandle &iter, - const JSHandle &next_method); + const JSHandle &nextMethod); // 7.4.3 - static bool IteratorComplete(JSThread *thread, const JSHandle &iter_result); + static bool IteratorComplete(JSThread *thread, const JSHandle &iterResult); // 7.4.4 - static JSHandle IteratorValue(JSThread *thread, const JSHandle &iter_result); + static JSHandle IteratorValue(JSThread *thread, const JSHandle &iterResult); // 7.4.5 static JSHandle IteratorStep(JSThread *thread, const JSHandle &iter); // 7.4.6 diff --git a/runtime/js_locale.cpp b/runtime/js_locale.cpp index d40a5d29830fd37d15b1bb2fa6e846b85c97999e..34346e402efac57c1b5d79e84b78e8a94edf41ac 100644 --- a/runtime/js_locale.cpp +++ b/runtime/js_locale.cpp @@ -27,22 +27,22 @@ namespace panda::ecmascript { // 6.2.2 IsStructurallyValidLanguageTag( locale ) bool JSLocale::IsStructurallyValidLanguageTag(const JSHandle &tag) { - std::string tag_collection = ConvertToStdString(tag); + std::string tagCollection = ConvertToStdString(tag); std::vector containers; std::string substring; - std::set unique_subtags; + std::set uniqueSubtags; size_t address = 1; - for (auto it = tag_collection.begin(); it != tag_collection.end(); it++) { - if (*it != '-' && it != tag_collection.end() - 1) { + for (auto it = tagCollection.begin(); it != tagCollection.end(); it++) { + if (*it != '-' && it != tagCollection.end() - 1) { substring += *it; } else { - if (it == tag_collection.end() - 1) { + if (it == tagCollection.end() - 1) { substring += *it; } containers.push_back(substring); if (IsVariantSubtag(substring)) { std::transform(substring.begin(), substring.end(), substring.begin(), AsciiAlphaToLower); - if (!unique_subtags.insert(substring).second) { + if (!uniqueSubtags.insert(substring).second) { return false; } } @@ -53,9 +53,9 @@ bool JSLocale::IsStructurallyValidLanguageTag(const JSHandle &tag) return result; } -std::string JSLocale::ConvertToStdString(const JSHandle &ecma_str) +std::string JSLocale::ConvertToStdString(const JSHandle &ecmaStr) { - return std::string(ConvertToPandaString(*ecma_str, StringConvertedUsage::LOGICOPERATION)); + return std::string(ConvertToPandaString(*ecmaStr, StringConvertedUsage::LOGICOPERATION)); } // 6.2.3 CanonicalizeUnicodeLocaleId( locale ) @@ -70,39 +70,39 @@ JSHandle JSLocale::CanonicalizeUnicodeLocaleId(JSThread *thread, con THROW_RANGE_ERROR_AND_RETURN(thread, "invalid locale", factory->GetEmptyString()); } - std::string locale_c_str = ConvertToStdString(locale); - std::transform(locale_c_str.begin(), locale_c_str.end(), locale_c_str.begin(), AsciiAlphaToLower); + std::string localeCStr = ConvertToStdString(locale); + std::transform(localeCStr.begin(), localeCStr.end(), localeCStr.begin(), AsciiAlphaToLower); UErrorCode status = U_ZERO_ERROR; - icu::Locale formal_locale = icu::Locale::forLanguageTag(locale_c_str.c_str(), status); - if ((U_FAILURE(status) != 0) || (formal_locale.isBogus() != 0)) { + icu::Locale formalLocale = icu::Locale::forLanguageTag(localeCStr.c_str(), status); + if ((U_FAILURE(status) != 0) || (formalLocale.isBogus() != 0)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid locale", factory->GetEmptyString()); } // Resets the LocaleBuilder to match the locale. // Returns an instance of Locale created from the fields set on this builder. - formal_locale = icu::LocaleBuilder().setLocale(formal_locale).build(status); + formalLocale = icu::LocaleBuilder().setLocale(formalLocale).build(status); // Canonicalize the locale ID of this object according to CLDR. - formal_locale.canonicalize(status); - if ((U_FAILURE(status) != 0) || (formal_locale.isBogus() != 0)) { + formalLocale.canonicalize(status); + if ((U_FAILURE(status) != 0) || (formalLocale.isBogus() != 0)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid locale", factory->GetEmptyString()); } - JSHandle language_tag = ToLanguageTag(thread, formal_locale); + JSHandle languageTag = ToLanguageTag(thread, formalLocale); RETURN_HANDLE_IF_ABRUPT_COMPLETION(EcmaString, thread); - return language_tag; + return languageTag; } // 6.2.4 DefaultLocale () JSHandle JSLocale::DefaultLocale(JSThread *thread) { - icu::Locale default_locale; - auto global_const = thread->GlobalConstants(); - if (strcmp(default_locale.getName(), "en_US_POSIX") == 0 || strcmp(default_locale.getName(), "c") == 0) { - return JSHandle::Cast(global_const->GetHandledEnUsString()); + icu::Locale defaultLocale; + auto globalConst = thread->GlobalConstants(); + if (strcmp(defaultLocale.getName(), "en_US_POSIX") == 0 || strcmp(defaultLocale.getName(), "c") == 0) { + return JSHandle::Cast(globalConst->GetHandledEnUsString()); } - if (default_locale.isBogus() != 0) { - return JSHandle::Cast(global_const->GetHandledUndString()); + if (defaultLocale.isBogus() != 0) { + return JSHandle::Cast(globalConst->GetHandledUndString()); } - return ToLanguageTag(thread, default_locale); + return ToLanguageTag(thread, defaultLocale); } // 6.4.1 IsValidTimeZoneName ( timeZone ) @@ -113,11 +113,11 @@ bool JSLocale::IsValidTimeZoneName(const icu::TimeZone &tz) tz.getID(id); icu::UnicodeString canonical; icu::TimeZone::getCanonicalID(id, canonical, status); - UBool canonical_flag = (canonical != icu::UnicodeString("Etc/Unknown", -1, US_INV)); - return (U_SUCCESS(status) != 0) && (canonical_flag != 0); + UBool canonicalFlag = (canonical != icu::UnicodeString("Etc/Unknown", -1, US_INV)); + return (U_SUCCESS(status) != 0) && (canonicalFlag != 0); } -void JSLocale::HandleLocaleExtension(size_t &start, size_t &extension_end, const std::string &result, size_t len) +void JSLocale::HandleLocaleExtension(size_t &start, size_t &extensionEnd, const std::string &result, size_t len) { bool flag = false; while (start < len - INTL_INDEX_TWO) { @@ -126,7 +126,7 @@ void JSLocale::HandleLocaleExtension(size_t &start, size_t &extension_end, const continue; } if (result[start + INTL_INDEX_TWO] == '-') { - extension_end = start; + extensionEnd = start; break; } if (!flag) { @@ -136,41 +136,41 @@ void JSLocale::HandleLocaleExtension(size_t &start, size_t &extension_end, const } } -JSLocale::ParsedLocale JSLocale::HandleLocale(const JSHandle &locale_string) +JSLocale::ParsedLocale JSLocale::HandleLocale(const JSHandle &localeString) { - std::string result = ConvertToStdString(locale_string); + std::string result = ConvertToStdString(localeString); size_t len = result.size(); - ParsedLocale parsed_result; + ParsedLocale parsedResult; // a. The single-character subtag ’x’ as the primary subtag indicates // that the language tag consists solely of subtags whose meaning is // defined by private agreement. // b. Extensions cannot be used in tags that are entirely private use. if (IsPrivateSubTag(result, len)) { - parsed_result.base = result; - return parsed_result; + parsedResult.base = result; + return parsedResult; } // If cannot find "-u-", return the whole string as base. - size_t found_extension = result.find("-u-"); - if (found_extension == std::string::npos) { - parsed_result.base = result; - return parsed_result; + size_t foundExtension = result.find("-u-"); + if (foundExtension == std::string::npos) { + parsedResult.base = result; + return parsedResult; } // Let privateIndex be Call(%StringProto_indexOf%, foundLocale, « "-x-" »). - size_t pravite_index = result.find("-x-"); - if (pravite_index != std::string::npos && pravite_index < found_extension) { - parsed_result.base = result; - return parsed_result; + size_t praviteIndex = result.find("-x-"); + if (praviteIndex != std::string::npos && praviteIndex < foundExtension) { + parsedResult.base = result; + return parsedResult; } - const std::string basis = result.substr(INTL_INDEX_ZERO, found_extension); - size_t extension_end = len; + const std::string basis = result.substr(INTL_INDEX_ZERO, foundExtension); + size_t extensionEnd = len; ASSERT(len > INTL_INDEX_TWO); - size_t start = found_extension + INTL_INDEX_ONE; - HandleLocaleExtension(start, extension_end, result, len); - const std::string end = result.substr(extension_end); - parsed_result.base = basis + end; - parsed_result.extension = result.substr(found_extension, extension_end - found_extension); - return parsed_result; + size_t start = foundExtension + INTL_INDEX_ONE; + HandleLocaleExtension(start, extensionEnd, result, len); + const std::string end = result.substr(extensionEnd); + parsedResult.base = basis + end; + parsedResult.extension = result.substr(foundExtension, extensionEnd - foundExtension); + return parsedResult; } // 9.2.1 CanonicalizeLocaleList ( locales ) @@ -183,7 +183,7 @@ JSHandle JSLocale::CanonicalizeLocaleList(JSThread *thread, const J return factory->EmptyArray(); } // 2. Let seen be a new empty List. - JSHandle locale_seen = factory->NewTaggedArray(1); + JSHandle localeSeen = factory->NewTaggedArray(1); // 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, // then // a. Let O be CreateArrayFromList(« locales »). @@ -194,8 +194,8 @@ JSHandle JSLocale::CanonicalizeLocaleList(JSThread *thread, const J JSHandle temp = factory->NewTaggedArray(1); temp->Set(thread, 0, tag.GetTaggedValue()); JSHandle obj = JSArray::CreateArrayFromList(thread, temp); - JSHandle final_seen = CanonicalizeHelper(thread, locales, obj, locale_seen); - return final_seen; + JSHandle finalSeen = CanonicalizeHelper(thread, locales, obj, localeSeen); + return finalSeen; } if (locales->IsJSLocale()) { JSHandle tag = JSLocale::ToString(thread, JSHandle::Cast(locales)); @@ -203,13 +203,13 @@ JSHandle JSLocale::CanonicalizeLocaleList(JSThread *thread, const J RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); temp->Set(thread, 0, tag.GetTaggedValue()); JSHandle obj = JSArray::CreateArrayFromList(thread, temp); - JSHandle final_seen = CanonicalizeHelper(thread, locales, obj, locale_seen); - return final_seen; + JSHandle finalSeen = CanonicalizeHelper(thread, locales, obj, localeSeen); + return finalSeen; } JSHandle obj = JSTaggedValue::ToObject(thread, locales); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - JSHandle final_seen = CanonicalizeHelper(thread, locales, obj, locale_seen); - return final_seen; + JSHandle finalSeen = CanonicalizeHelper(thread, locales, obj, localeSeen); + return finalSeen; } template @@ -217,65 +217,65 @@ JSHandle JSLocale::CanonicalizeHelper(JSThread *thread, const JSHan JSHandle &obj, JSHandle &seen) { (void)locales; - OperationResult operation_result = JSTaggedValue::GetProperty(thread, JSHandle::Cast(obj), - thread->GlobalConstants()->GetHandledLengthString()); + OperationResult operationResult = JSTaggedValue::GetProperty(thread, JSHandle::Cast(obj), + thread->GlobalConstants()->GetHandledLengthString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - JSTaggedNumber len = JSTaggedValue::ToLength(thread, operation_result.GetValue()); + JSTaggedNumber len = JSTaggedValue::ToLength(thread, operationResult.GetValue()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 2. Let seen be a new empty List. - uint32_t requested_locales_len = len.ToUint32(); - seen = factory->NewTaggedArray(requested_locales_len); + uint32_t requestedLocalesLen = len.ToUint32(); + seen = factory->NewTaggedArray(requestedLocalesLen); // 6. Let k be 0. // 7. Repeat, while k < len JSMutableHandle pk(thread, JSTaggedValue::Undefined()); JSMutableHandle tag(thread, JSTaggedValue::Undefined()); uint32_t index = 0; - JSHandle obj_tagged = JSHandle::Cast(obj); - for (uint32_t k = 0; k < requested_locales_len; k++) { + JSHandle objTagged = JSHandle::Cast(obj); + for (uint32_t k = 0; k < requestedLocalesLen; k++) { // a. Let Pk be ToString(k). - JSHandle k_handle(thread, JSTaggedValue(k)); - JSHandle str = JSTaggedValue::ToString(thread, k_handle); + JSHandle kHandle(thread, JSTaggedValue(k)); + JSHandle str = JSTaggedValue::ToString(thread, kHandle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); pk.Update(str.GetTaggedValue()); // b. Let kPresent be ? HasProperty(O, Pk). - bool k_present = JSTaggedValue::HasProperty(thread, obj_tagged, pk); + bool kPresent = JSTaggedValue::HasProperty(thread, objTagged, pk); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); // c. If kPresent is true, then - if (k_present) { + if (kPresent) { // i. Let kValue be ? Get(O, Pk). - OperationResult result = JSTaggedValue::GetProperty(thread, obj_tagged, pk); + OperationResult result = JSTaggedValue::GetProperty(thread, objTagged, pk); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - JSHandle k_value = result.GetValue(); + JSHandle kValue = result.GetValue(); // ii. If Type(kValue) is not String or Object, throw a TypeError exception. - if (!k_value->IsString() && !k_value->IsJSObject()) { + if (!kValue->IsString() && !kValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "kValue is not String or Object.", factory->EmptyArray()); } // iii. If Type(kValue) is Object and kValue has an [[InitializedLocale]] internal slot, then // 1. Let tag be kValue.[[Locale]]. // iv. Else, // 1. Let tag be ? ToString(kValue). - if (k_value->IsJSLocale()) { - JSHandle k_value_str = JSLocale::ToString(thread, JSHandle::Cast(k_value)); + if (kValue->IsJSLocale()) { + JSHandle kValueStr = JSLocale::ToString(thread, JSHandle::Cast(kValue)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - tag.Update(k_value_str.GetTaggedValue()); + tag.Update(kValueStr.GetTaggedValue()); } else { - JSHandle k_value_string = JSTaggedValue::ToString(thread, k_value); + JSHandle kValueString = JSTaggedValue::ToString(thread, kValue); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - JSHandle str = CanonicalizeUnicodeLocaleId(thread, k_value_string); + JSHandle str = CanonicalizeUnicodeLocaleId(thread, kValueString); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); tag.Update(str.GetTaggedValue()); } // vii. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen. - bool is_exist = false; + bool isExist = false; uint32_t len = seen->GetLength(); for (uint32_t i = 0; i < len; i++) { if (JSTaggedValue::SameValue(seen->Get(thread, i), tag.GetTaggedValue())) { - is_exist = true; + isExist = true; } } - if (!is_exist) { + if (!isExist) { seen->Set(thread, index++, JSHandle::Cast(tag)); } } @@ -288,66 +288,66 @@ JSHandle JSLocale::CanonicalizeHelper(JSThread *thread, const JSHan } // 9.2.2 BestAvailableLocale ( availableLocales, locale ) -std::string JSLocale::BestAvailableLocale(JSThread *thread, const JSHandle &available_locales, +std::string JSLocale::BestAvailableLocale(JSThread *thread, const JSHandle &availableLocales, const std::string &locale) { // 1. Let candidate be locale. - std::string locale_candidate = locale; + std::string localeCandidate = locale; std::string undefined = std::string(); // 2. Repeat, - uint32_t length = available_locales->GetLength(); + uint32_t length = availableLocales->GetLength(); JSMutableHandle item(thread, JSTaggedValue::Undefined()); while (true) { // a. If availableLocales contains an element equal to candidate, return candidate. for (uint32_t i = 0; i < length; ++i) { - item.Update(available_locales->Get(thread, i)); - std::string item_str = ConvertToStdString(item); - if (item_str == locale_candidate) { - return locale_candidate; + item.Update(availableLocales->Get(thread, i)); + std::string itemStr = ConvertToStdString(item); + if (itemStr == localeCandidate) { + return localeCandidate; } } // b. Let pos be the character index of the last occurrence of "-" (U+002D) within candidate. // If that character does not occur, return undefined. - size_t pos = locale_candidate.rfind('-'); + size_t pos = localeCandidate.rfind('-'); if (pos == std::string::npos) { return undefined; } // c. If pos ≥ 2 and the character "-" occurs at index pos-2 of candidate, decrease pos by 2. - if (pos >= INTL_INDEX_TWO && locale_candidate[pos - INTL_INDEX_TWO] == '-') { + if (pos >= INTL_INDEX_TWO && localeCandidate[pos - INTL_INDEX_TWO] == '-') { pos -= INTL_INDEX_TWO; } // d. Let candidate be the substring of candidate from position 0, inclusive, to position pos, exclusive. - locale_candidate = locale_candidate.substr(0, pos); + localeCandidate = localeCandidate.substr(0, pos); } } // 9.2.3 LookupMatcher ( availableLocales, requestedLocales ) -JSHandle JSLocale::LookupMatcher(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales) +JSHandle JSLocale::LookupMatcher(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales) { MatcherResult result = {std::string(), std::string()}; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let result be a new Record. // 2. For each element locale of requestedLocales in List order, do - uint32_t length = requested_locales->GetLength(); + uint32_t length = requestedLocales->GetLength(); JSMutableHandle locale(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; ++i) { - locale.Update(requested_locales->Get(thread, i)); + locale.Update(requestedLocales->Get(thread, i)); // 2. a. Let noExtensionsLocale be the String value that is locale // with all Unicode locale extension sequences removed. - ParsedLocale parsed_result = HandleLocale(locale); + ParsedLocale parsedResult = HandleLocale(locale); // 2. b. Let availableLocale be BestAvailableLocale(availableLocales, noExtensionsLocale). - std::string available_locale = BestAvailableLocale(thread, available_locales, parsed_result.base); + std::string availableLocale = BestAvailableLocale(thread, availableLocales, parsedResult.base); // 2. c. If availableLocale is not undefined, append locale to the end of subset. - if (!available_locale.empty()) { + if (!availableLocale.empty()) { result = {std::string(), std::string()}; // 2. c. i. Set result.[[locale]] to availableLocale. - result.locale = available_locale; + result.locale = availableLocale; // 2. c. ii. If locale and noExtensionsLocale are not the same String value, then // 2. c. ii. 1. Let extension be the String value consisting of the first substring of locale that is a // Unicode locale extension sequence. - if (!parsed_result.extension.empty()) { - result.extension = parsed_result.extension; + if (!parsedResult.extension.empty()) { + result.extension = parsedResult.extension; } // 2. c. ii. 2. Set result.[[extension]] to extension. std::string res = result.locale + result.extension; @@ -359,28 +359,28 @@ JSHandle JSLocale::LookupMatcher(JSThread *thread, const JSHandleNewFromStdString(result.locale); } -icu::LocaleMatcher BuildLocaleMatcher(JSThread *thread, uint32_t *available_length, UErrorCode *status, - const JSHandle &available_locales) +icu::LocaleMatcher BuildLocaleMatcher(JSThread *thread, uint32_t *availableLength, UErrorCode *status, + const JSHandle &availableLocales) { std::string locale = JSLocale::ConvertToStdString(JSLocale::DefaultLocale(thread)); - icu::Locale default_locale = icu::Locale::forLanguageTag(locale, *status); + icu::Locale defaultLocale = icu::Locale::forLanguageTag(locale, *status); ASSERT_PRINT(U_SUCCESS(*status), "icu::Locale::forLanguageTag failed"); icu::LocaleMatcher::Builder builder; - builder.setDefaultLocale(&default_locale); - uint32_t length = available_locales->GetLength(); + builder.setDefaultLocale(&defaultLocale); + uint32_t length = availableLocales->GetLength(); JSMutableHandle item(thread, JSTaggedValue::Undefined()); - for (*available_length = 0; *available_length < length; ++(*available_length)) { - item.Update(available_locales->Get(thread, *available_length)); - std::string item_str = JSLocale::ConvertToStdString(item); - icu::Locale locale_for_language_tag = icu::Locale::forLanguageTag(item_str, *status); + for (*availableLength = 0; *availableLength < length; ++(*availableLength)) { + item.Update(availableLocales->Get(thread, *availableLength)); + std::string itemStr = JSLocale::ConvertToStdString(item); + icu::Locale localeForLanguageTag = icu::Locale::forLanguageTag(itemStr, *status); if (U_SUCCESS(*status) != 0) { - builder.addSupportedLocale(locale_for_language_tag); + builder.addSupportedLocale(localeForLanguageTag); } else { break; } @@ -390,38 +390,38 @@ icu::LocaleMatcher BuildLocaleMatcher(JSThread *thread, uint32_t *available_leng } // 9.2.4 BestFitMatcher ( availableLocales, requestedLocales ) -JSHandle JSLocale::BestFitMatcher(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales) +JSHandle JSLocale::BestFitMatcher(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); UErrorCode status = U_ZERO_ERROR; - uint32_t available_length = available_locales->GetLength(); - icu::LocaleMatcher matcher = BuildLocaleMatcher(thread, &available_length, &status, available_locales); + uint32_t availableLength = availableLocales->GetLength(); + icu::LocaleMatcher matcher = BuildLocaleMatcher(thread, &availableLength, &status, availableLocales); ASSERT(U_SUCCESS(status)); - uint32_t requested_locales_length = requested_locales->GetLength(); - JSIntlIterator iter(requested_locales, requested_locales_length); - auto best_fit = matcher.getBestMatch(iter, status)->toLanguageTag(status); + uint32_t requestedLocalesLength = requestedLocales->GetLength(); + JSIntlIterator iter(requestedLocales, requestedLocalesLength); + auto bestFit = matcher.getBestMatch(iter, status)->toLanguageTag(status); if (U_FAILURE(status) != 0) { return DefaultLocale(thread); } - for (uint32_t i = 0; i < requested_locales_length; ++i) { - if (iter[i] == best_fit) { - return JSHandle(thread, requested_locales->Get(thread, i)); + for (uint32_t i = 0; i < requestedLocalesLength; ++i) { + if (iter[i] == bestFit) { + return JSHandle(thread, requestedLocales->Get(thread, i)); } } - return factory->NewFromStdString(best_fit); + return factory->NewFromStdString(bestFit); } // 9.2.8 LookupSupportedLocales ( availableLocales, requestedLocales ) -JSHandle JSLocale::LookupSupportedLocales(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales) +JSHandle JSLocale::LookupSupportedLocales(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales) { uint32_t index = 0; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t length = requested_locales->GetLength(); + uint32_t length = requestedLocales->GetLength(); // 1. Let subset be a new empty List. JSHandle subset = factory->NewTaggedArray(length); JSMutableHandle item(thread, JSTaggedValue::Undefined()); @@ -431,10 +431,10 @@ JSHandle JSLocale::LookupSupportedLocales(JSThread *thread, const J // b. Let availableLocale be BestAvailableLocale(availableLocales, noExtensionsLocale). // c. If availableLocale is not undefined, append locale to the end of subset. for (uint32_t i = 0; i < length; ++i) { - item.Update(requested_locales->Get(thread, i)); - ParsedLocale foundation_result = HandleLocale(item); - std::string available_locale = BestAvailableLocale(thread, available_locales, foundation_result.base); - if (!available_locale.empty()) { + item.Update(requestedLocales->Get(thread, i)); + ParsedLocale foundationResult = HandleLocale(item); + std::string availableLocale = BestAvailableLocale(thread, availableLocales, foundationResult.base); + if (!availableLocale.empty()) { subset->Set(thread, index++, item.GetTaggedValue()); } } @@ -443,33 +443,32 @@ JSHandle JSLocale::LookupSupportedLocales(JSThread *thread, const J } // 9.2.9 BestFitSupportedLocales ( availableLocales, requestedLocales ) -JSHandle JSLocale::BestFitSupportedLocales(JSThread *thread, - const JSHandle &available_locales, - const JSHandle &requested_locales) +JSHandle JSLocale::BestFitSupportedLocales(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales) { UErrorCode status = U_ZERO_ERROR; - uint32_t request_length = requested_locales->GetLength(); - uint32_t available_length = available_locales->GetLength(); - icu::LocaleMatcher matcher = BuildLocaleMatcher(thread, &available_length, &status, available_locales); + uint32_t requestLength = requestedLocales->GetLength(); + uint32_t availableLength = availableLocales->GetLength(); + icu::LocaleMatcher matcher = BuildLocaleMatcher(thread, &availableLength, &status, availableLocales); ASSERT(U_SUCCESS(status)); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle default_locale = DefaultLocale(thread); - JSHandle result = factory->NewTaggedArray(request_length); + JSHandle defaultLocale = DefaultLocale(thread); + JSHandle result = factory->NewTaggedArray(requestLength); uint32_t index = 0; JSMutableHandle locale(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 0; i < request_length; ++i) { - locale.Update(requested_locales->Get(thread, i)); - if (EcmaString::StringsAreEqual(*locale, *default_locale)) { + for (uint32_t i = 0; i < requestLength; ++i) { + locale.Update(requestedLocales->Get(thread, i)); + if (EcmaString::StringsAreEqual(*locale, *defaultLocale)) { result->Set(thread, index++, locale.GetTaggedValue()); } else { status = U_ZERO_ERROR; - std::string locale_str = ConvertToStdString(locale); - icu::Locale desired = icu::Locale::forLanguageTag(locale_str, status); - auto best_fit = matcher.getBestMatch(desired, status)->toLanguageTag(status); + std::string localeStr = ConvertToStdString(locale); + icu::Locale desired = icu::Locale::forLanguageTag(localeStr, status); + auto bestFit = matcher.getBestMatch(desired, status)->toLanguageTag(status); if ((U_SUCCESS(status) != 0) && - EcmaString::StringsAreEqual(*locale, *(factory->NewFromStdString(best_fit)))) { + EcmaString::StringsAreEqual(*locale, *(factory->NewFromStdString(bestFit)))) { result->Set(thread, index++, locale.GetTaggedValue()); } } @@ -487,52 +486,52 @@ JSHandle JSLocale::ToLanguageTag(JSThread *thread, const icu::Locale if (!flag) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid locale", factory->GetEmptyString()); } - size_t find_beginning = result.find("-u-"); - std::string final_res; - std::string temp_res; - if (find_beginning == std::string::npos) { + size_t findBeginning = result.find("-u-"); + std::string finalRes; + std::string tempRes; + if (findBeginning == std::string::npos) { return factory->NewFromStdString(result); } - size_t special_beginning = find_beginning + INTL_INDEX_THREE; - size_t special_count = 0; - while (special_beginning < result.size() && result[special_beginning] != '-') { - special_count++; - special_beginning++; + size_t specialBeginning = findBeginning + INTL_INDEX_THREE; + size_t specialCount = 0; + while (specialBeginning < result.size() && result[specialBeginning] != '-') { + specialCount++; + specialBeginning++; } - if (find_beginning != std::string::npos) { + if (findBeginning != std::string::npos) { // It begin with "-u-xx" or with more elements. - temp_res = result.substr(0, find_beginning + INTL_INDEX_THREE + special_count); - if (result.size() <= find_beginning + INTL_INDEX_THREE + special_count) { + tempRes = result.substr(0, findBeginning + INTL_INDEX_THREE + specialCount); + if (result.size() <= findBeginning + INTL_INDEX_THREE + specialCount) { return factory->NewFromStdString(result); } - std::string left_str = result.substr(find_beginning + INTL_INDEX_THREE + special_count + INTL_INDEX_ONE); - std::istringstream temp(left_str); + std::string leftStr = result.substr(findBeginning + INTL_INDEX_THREE + specialCount + INTL_INDEX_ONE); + std::istringstream temp(leftStr); std::string buffer; - std::vector res_container; + std::vector resContainer; while (getline(temp, buffer, '-')) { if (buffer != "true" && buffer != "yes") { - res_container.push_back(buffer); + resContainer.push_back(buffer); } } - for (auto &it : res_container) { + for (auto &it : resContainer) { std::string tag = "-"; tag += it; - final_res += tag; + finalRes += tag; } } - if (!final_res.empty()) { - temp_res += final_res; + if (!finalRes.empty()) { + tempRes += finalRes; } - result = temp_res; + result = tempRes; return factory->NewFromStdString(result); } // 9.2.10 SupportedLocales ( availableLocales, requestedLocales, options ) -JSHandle JSLocale::SupportedLocales(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales, +JSHandle JSLocale::SupportedLocales(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales, const JSHandle &options) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. If options is not undefined, then // a. Let options be ? ToObject(options). // b. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). @@ -542,7 +541,7 @@ JSHandle JSLocale::SupportedLocales(JSThread *thread, const JSHandle obj = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); - matcher = GetOptionOfString(thread, obj, global_const->GetHandledLocaleMatcherString(), + matcher = GetOptionOfString(thread, obj, globalConst->GetHandledLocaleMatcherString(), {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); @@ -552,16 +551,15 @@ JSHandle JSLocale::SupportedLocales(JSThread *thread, const JSHandle supported_locales(thread, JSTaggedValue::Undefined()); - bool is_bestfit_support = false; - if (matcher == LocaleMatcherOption::BEST_FIT && is_bestfit_support) { - supported_locales.Update( - BestFitSupportedLocales(thread, available_locales, requested_locales).GetTaggedValue()); + JSMutableHandle supportedLocales(thread, JSTaggedValue::Undefined()); + bool isBestfitSupport = false; + if (matcher == LocaleMatcherOption::BEST_FIT && isBestfitSupport) { + supportedLocales.Update(BestFitSupportedLocales(thread, availableLocales, requestedLocales).GetTaggedValue()); } else { - supported_locales.Update(LookupSupportedLocales(thread, available_locales, requested_locales).GetTaggedValue()); + supportedLocales.Update(LookupSupportedLocales(thread, availableLocales, requestedLocales).GetTaggedValue()); } - JSHandle subset = JSArray::CreateArrayFromList(thread, supported_locales); + JSHandle subset = JSArray::CreateArrayFromList(thread, supportedLocales); // 5. Return CreateArrayFromList(supportedLocales). return subset; } @@ -597,15 +595,15 @@ JSHandle JSLocale::GetOption(JSThread *thread, const JSHandleIsUndefined()) { - bool is_exist = false; - JSHandle values_array = JSHandle::Cast(values); - uint32_t length = values_array->GetLength(); + bool isExist = false; + JSHandle valuesArray = JSHandle::Cast(values); + uint32_t length = valuesArray->GetLength(); for (uint32_t i = 0; i < length; i++) { - if (JSTaggedValue::SameValue(values_array->Get(thread, i), value.GetTaggedValue())) { - is_exist = true; + if (JSTaggedValue::SameValue(valuesArray->Get(thread, i), value.GetTaggedValue())) { + isExist = true; } } - if (!is_exist) { + if (!isExist) { JSHandle exception(thread, JSTaggedValue::Exception()); THROW_RANGE_ERROR_AND_RETURN(thread, "values does not contain an element equal to value", exception); } @@ -619,31 +617,31 @@ JSHandle JSLocale::GetOption(JSThread *thread, const JSHandle &options, const JSHandle &property, const std::vector &values, - std::string *option_value) + std::string *optionValue) { // 1. Let value be ? Get(options, property). - OperationResult operation_result = JSObject::GetProperty(thread, options, property); + OperationResult operationResult = JSObject::GetProperty(thread, options, property); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - JSHandle value = operation_result.GetValue(); + JSHandle value = operationResult.GetValue(); // 2. If value is not undefined, then if (value->IsUndefined()) { return false; } // c. If type is "string" "string", then // i. Let value be ? ToString(value). - JSHandle value_e_str = JSTaggedValue::ToString(thread, value); + JSHandle valueEStr = JSTaggedValue::ToString(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (value_e_str->IsUtf16()) { + if (valueEStr->IsUtf16()) { THROW_RANGE_ERROR_AND_RETURN(thread, "Value out of range for locale options property", false); } - *option_value = JSLocale::ConvertToStdString(value_e_str); + *optionValue = JSLocale::ConvertToStdString(valueEStr); if (values.empty()) { return true; } // d. If values is not undefined, then // i. If values does not contain an element equal to value, throw a RangeError exception. for (const auto &item : values) { - if (item == *option_value) { + if (item == *optionValue) { return true; } } @@ -693,9 +691,9 @@ std::string JSLocale::UnicodeExtensionValue(const std::string &extension, const ASSERT(key.size() == INTL_INDEX_TWO); size_t size = extension.size(); // 3. Let searchValue be the concatenation of "-" , key, and "-". - std::string search_value = "-" + key + "-"; + std::string searchValue = "-" + key + "-"; // 4. Let pos be Call(%StringProto_indexOf%, extension, « searchValue »). - size_t pos = extension.find(search_value); + size_t pos = extension.find(searchValue); // 5. If pos ≠ -1, then if (pos != std::string::npos) { // a. Let start be pos + 4. @@ -741,9 +739,9 @@ std::string JSLocale::UnicodeExtensionValue(const std::string &extension, const return result; } // 6. Let searchValue be the concatenation of "-" and key. - search_value = "-" + key; + searchValue = "-" + key; // 7. Let pos be Call(%StringProto_indexOf%, extension, « searchValue »). - pos = extension.find(search_value); + pos = extension.find(searchValue); // 8. If pos ≠ -1 and pos + 3 = size, then // a. Return the empty String. if (pos != std::string::npos && pos + INTL_INDEX_THREE == size) { @@ -753,15 +751,15 @@ std::string JSLocale::UnicodeExtensionValue(const std::string &extension, const return "undefined"; } -ResolvedLocale JSLocale::ResolveLocale(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales, LocaleMatcherOption matcher, - const std::set &relevant_extension_keys) +ResolvedLocale JSLocale::ResolveLocale(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales, LocaleMatcherOption matcher, + const std::set &relevantExtensionKeys) { - bool is_bestfit_support = false; - std::map> locale_map = {{"hc", {"h11", "h12", "h23", "h24"}}, - {"lb", {"strict", "normal", "loose"}}, - {"kn", {"true", "false"}}, - {"kf", {"upper", "lower", "false"}}}; + bool isBestfitSupport = false; + std::map> localeMap = {{"hc", {"h11", "h12", "h23", "h24"}}, + {"lb", {"strict", "normal", "loose"}}, + {"kn", {"true", "false"}}, + {"kf", {"upper", "lower", "false"}}}; // 1. Let matcher be options.[[localeMatcher]]. // 2. If matcher is "lookup" "lookup", then @@ -769,13 +767,13 @@ ResolvedLocale JSLocale::ResolveLocale(JSThread *thread, const JSHandle locale(thread, JSTaggedValue::Undefined()); - if (available_locales->GetLength() == 0 && requested_locales->GetLength() == 0) { + if (availableLocales->GetLength() == 0 && requestedLocales->GetLength() == 0) { locale.Update(DefaultLocale(thread).GetTaggedValue()); } else { - if (matcher == LocaleMatcherOption::BEST_FIT && is_bestfit_support) { - locale.Update(BestFitMatcher(thread, available_locales, requested_locales).GetTaggedValue()); + if (matcher == LocaleMatcherOption::BEST_FIT && isBestfitSupport) { + locale.Update(BestFitMatcher(thread, availableLocales, requestedLocales).GetTaggedValue()); } else { - locale.Update(LookupMatcher(thread, available_locales, requested_locales).GetTaggedValue()); + locale.Update(LookupMatcher(thread, availableLocales, requestedLocales).GetTaggedValue()); } } @@ -783,28 +781,28 @@ ResolvedLocale JSLocale::ResolveLocale(JSThread *thread, const JSHandle tag = ToLanguageTag(thread, found_locale_data); + result.localeData = foundLocaleData; + JSHandle tag = ToLanguageTag(thread, foundLocaleData); result.locale = ConvertToStdString(tag); - std::string supported_extension = "-u"; - icu::LocaleBuilder locale_builder; - locale_builder.setLocale(found_locale_data).clearExtensions(); + std::string supportedExtension = "-u"; + icu::LocaleBuilder localeBuilder; + localeBuilder.setLocale(foundLocaleData).clearExtensions(); // 8. For each element key of relevantExtensionKeys in List order, do - for (auto &key : relevant_extension_keys) { - auto double_match = found_locale.find(key); - if (double_match == std::string::npos) { + for (auto &key : relevantExtensionKeys) { + auto doubleMatch = foundLocale.find(key); + if (doubleMatch == std::string::npos) { continue; } UErrorCode status = U_ZERO_ERROR; - std::set key_locale_data; - std::unique_ptr well_form_key(found_locale_data.createKeywords(status)); + std::set keyLocaleData; + std::unique_ptr wellFormKey(foundLocaleData.createKeywords(status)); if (U_FAILURE(status) != 0) { return result; } - if (!well_form_key) { + if (!wellFormKey) { return result; } std::string value; @@ -812,124 +810,124 @@ ResolvedLocale JSLocale::ResolveLocale(JSThread *thread, const JSHandle]]. // e. Let value be keyLocaleData[0]. if ((key != "ca") && (key != "co") && (key != "nu")) { - key_locale_data = locale_map[key]; - value = *key_locale_data.begin(); + keyLocaleData = localeMap[key]; + value = *keyLocaleData.begin(); } // g. Let supportedExtensionAddition be "". // h. If r has an [[extension]] field, then - std::string supported_extension_addition; - size_t found = found_locale.find("-u-"); + std::string supportedExtensionAddition; + size_t found = foundLocale.find("-u-"); if (found != std::string::npos) { - std::string extension = found_locale.substr(found + INTL_INDEX_ONE); + std::string extension = foundLocale.substr(found + INTL_INDEX_ONE); // i. Let requestedValue be UnicodeExtensionValue(r.[[extension]], key). - std::string requested_value = UnicodeExtensionValue(extension, key); - if (key == "kn" && requested_value.empty()) { - requested_value = "true"; + std::string requestedValue = UnicodeExtensionValue(extension, key); + if (key == "kn" && requestedValue.empty()) { + requestedValue = "true"; } // ii. If requestedValue is not undefined, then - if (requested_value != "undefined") { + if (requestedValue != "undefined") { // 1. If requestedValue is not the empty String, then - if (!requested_value.empty()) { + if (!requestedValue.empty()) { // a. If keyLocaleData contains requestedValue, then // i. Let value be requestedValue. // ii. Let supportedExtensionAddition be the concatenation of "-", key, "-", and value. if (key == "ca" || key == "co") { if (key == "co") { - bool is_valid_value = IsWellCollation(found_locale_data, requested_value); - if (!is_valid_value) { + bool isValidValue = IsWellCollation(foundLocaleData, requestedValue); + if (!isValidValue) { continue; } - value = requested_value; - supported_extension_addition = std::string("-").append(key).append("-").append(value); - locale_builder.setUnicodeLocaleKeyword(key, requested_value); + value = requestedValue; + supportedExtensionAddition = std::string("-").append(key).append("-").append(value); + localeBuilder.setUnicodeLocaleKeyword(key, requestedValue); } else { - bool is_valid_value = IsWellCalendar(found_locale_data, requested_value); - if (!is_valid_value) { + bool isValidValue = IsWellCalendar(foundLocaleData, requestedValue); + if (!isValidValue) { continue; } - value = requested_value; - supported_extension_addition = std::string("-").append(key).append("-").append(value); - locale_builder.setUnicodeLocaleKeyword(key, requested_value); + value = requestedValue; + supportedExtensionAddition = std::string("-").append(key).append("-").append(value); + localeBuilder.setUnicodeLocaleKeyword(key, requestedValue); } } else if (key == "nu") { - bool is_valid_value = IsWellNumberingSystem(requested_value); - if (!is_valid_value) { + bool isValidValue = IsWellNumberingSystem(requestedValue); + if (!isValidValue) { continue; } - value = requested_value; - supported_extension_addition = std::string("-").append(key).append("-").append(value); - locale_builder.setUnicodeLocaleKeyword(key, requested_value); - } else if (key_locale_data.find(requested_value) != key_locale_data.end()) { - value = requested_value; - supported_extension_addition = std::string("-").append(key).append("-").append(value); - locale_builder.setUnicodeLocaleKeyword(key, requested_value); + value = requestedValue; + supportedExtensionAddition = std::string("-").append(key).append("-").append(value); + localeBuilder.setUnicodeLocaleKeyword(key, requestedValue); + } else if (keyLocaleData.find(requestedValue) != keyLocaleData.end()) { + value = requestedValue; + supportedExtensionAddition = std::string("-").append(key).append("-").append(value); + localeBuilder.setUnicodeLocaleKeyword(key, requestedValue); } } } } result.extensions.insert(std::pair(key, value)); - supported_extension += supported_extension_addition; + supportedExtension += supportedExtensionAddition; } - size_t found = found_locale.find("-u-"); + size_t found = foundLocale.find("-u-"); if (found != std::string::npos) { - found_locale = found_locale.substr(0, found); + foundLocale = foundLocale.substr(0, found); } // 9. If the number of elements in supportedExtension is greater than 2, then - if (supported_extension.size() > 2) { + if (supportedExtension.size() > 2) { // a. Let privateIndex be Call(%StringProto_indexOf%, foundLocale, « "-x-" »). - size_t private_index = found_locale.find("-x-"); + size_t privateIndex = foundLocale.find("-x-"); // b. If privateIndex = -1, then // i. Let foundLocale be the concatenation of foundLocale and supportedExtension. - if (private_index == std::string::npos) { - found_locale = found_locale + supported_extension; + if (privateIndex == std::string::npos) { + foundLocale = foundLocale + supportedExtension; } else { - std::string pre_extension = found_locale.substr(0, private_index); - std::string post_extension = found_locale.substr(private_index); - found_locale = pre_extension + supported_extension + post_extension; + std::string preExtension = foundLocale.substr(0, privateIndex); + std::string postExtension = foundLocale.substr(privateIndex); + foundLocale = preExtension + supportedExtension + postExtension; } - tag = ToLanguageTag(thread, found_locale_data); + tag = ToLanguageTag(thread, foundLocaleData); if (!IsStructurallyValidLanguageTag(tag)) { result.extensions.erase(result.extensions.begin(), result.extensions.end()); - result.locale = found_locale; + result.locale = foundLocale; } tag = CanonicalizeUnicodeLocaleId(thread, tag); - found_locale = ConvertToStdString(tag); + foundLocale = ConvertToStdString(tag); } // 10. Set result.[[locale]] to foundLocale. - result.locale = found_locale; + result.locale = foundLocale; UErrorCode status = U_ZERO_ERROR; - found_locale_data = locale_builder.build(status); - result.locale_data = found_locale_data; + foundLocaleData = localeBuilder.build(status); + result.localeData = foundLocaleData; // 11. Return result. return result; } -icu::Locale JSLocale::BuildICULocale(const std::string &bcp47_locale) +icu::Locale JSLocale::BuildICULocale(const std::string &bcp47Locale) { UErrorCode status = U_ZERO_ERROR; - icu::Locale icu_locale = icu::Locale::forLanguageTag(bcp47_locale, status); + icu::Locale icuLocale = icu::Locale::forLanguageTag(bcp47Locale, status); ASSERT_PRINT(U_SUCCESS(status), "forLanguageTag failed"); - ASSERT_PRINT(!icu_locale.isBogus(), "icuLocale is bogus"); - return icu_locale; + ASSERT_PRINT(!icuLocale.isBogus(), "icuLocale is bogus"); + return icuLocale; } JSHandle JSLocale::ConstructLocaleList(JSThread *thread, - const std::vector &icu_available_locales) + const std::vector &icuAvailableLocales) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle locales = factory->NewTaggedArray(icu_available_locales.size()); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle locales = factory->NewTaggedArray(icuAvailableLocales.size()); int32_t index = 0; - for (const std::string &locale : icu_available_locales) { - JSHandle locale_str = factory->NewFromStdString(locale); - locales->Set(thread, index++, locale_str); + for (const std::string &locale : icuAvailableLocales) { + JSHandle localeStr = factory->NewFromStdString(locale); + locales->Set(thread, index++, localeStr); } return locales; } @@ -946,12 +944,12 @@ JSHandle JSLocale::IcuToString(JSThread *thread, const icu::UnicodeS return IcuToString(thread, string.tempSubStringBetween(begin, end)); } -std::string JSLocale::GetNumberingSystem(const icu::Locale &icu_locale) +std::string JSLocale::GetNumberingSystem(const icu::Locale &icuLocale) { UErrorCode status = U_ZERO_ERROR; - std::unique_ptr numbering_system(icu::NumberingSystem::createInstance(icu_locale, status)); + std::unique_ptr numberingSystem(icu::NumberingSystem::createInstance(icuLocale, status)); if (U_SUCCESS(status) != 0) { - return numbering_system->getName(); + return numberingSystem->getName(); } return "latn"; } @@ -965,20 +963,20 @@ bool JSLocale::IsWellFormedCurrencyCode(const std::string ¤cy) } JSHandle JSLocale::PutElement(JSThread *thread, int index, const JSHandle &array, - const JSHandle &field_type_string, + const JSHandle &fieldTypeString, const JSHandle &value) { - auto ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // Let record be ! ObjectCreate(%ObjectPrototype%). JSHandle record = factory->NewEmptyJSObject(); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); // obj.type = field_type_string - JSObject::CreateDataPropertyOrThrow(thread, record, global_const->GetHandledTypeString(), field_type_string); + JSObject::CreateDataPropertyOrThrow(thread, record, globalConst->GetHandledTypeString(), fieldTypeString); // obj.value = value - JSObject::CreateDataPropertyOrThrow(thread, record, global_const->GetHandledValueString(), value); + JSObject::CreateDataPropertyOrThrow(thread, record, globalConst->GetHandledValueString(), value); JSTaggedValue::SetProperty(thread, JSHandle::Cast(array), index, JSHandle::Cast(record), true); @@ -990,9 +988,9 @@ bool JSLocale::GetOptionOfBool(JSThread *thread, const JSHandle &optio const JSHandle &property, bool fallback, bool *res) { // 1. Let value be ? Get(options, property). - OperationResult operation_result = JSObject::GetProperty(thread, options, property); + OperationResult operationResult = JSObject::GetProperty(thread, options, property); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - JSHandle value = operation_result.GetValue(); + JSHandle value = operationResult.GetValue(); *res = fallback; // 2. If value is not undefined, then if (!value->IsUndefined()) { @@ -1004,53 +1002,53 @@ bool JSLocale::GetOptionOfBool(JSThread *thread, const JSHandle &optio return false; } -JSHandle JSLocale::GetNumberFieldType(JSThread *thread, JSTaggedValue x, int32_t field_id) +JSHandle JSLocale::GetNumberFieldType(JSThread *thread, JSTaggedValue x, int32_t fieldId) { ASSERT(x.IsNumber()); - auto global_const = thread->GlobalConstants(); - switch (static_cast(field_id)) { + auto globalConst = thread->GlobalConstants(); + switch (static_cast(fieldId)) { case UNUM_INTEGER_FIELD: if (std::isfinite(x.GetNumber())) { - return global_const->GetHandledIntegerString(); + return globalConst->GetHandledIntegerString(); } if (std::isnan(x.GetNumber())) { - return global_const->GetHandledNanString(); + return globalConst->GetHandledNanString(); } - return global_const->GetHandledInfinityString(); + return globalConst->GetHandledInfinityString(); case UNUM_FRACTION_FIELD: - return global_const->GetHandledFractionString(); + return globalConst->GetHandledFractionString(); case UNUM_DECIMAL_SEPARATOR_FIELD: - return global_const->GetHandledDecimalString(); + return globalConst->GetHandledDecimalString(); case UNUM_GROUPING_SEPARATOR_FIELD: - return global_const->GetHandledGroupString(); + return globalConst->GetHandledGroupString(); case UNUM_CURRENCY_FIELD: - return global_const->GetHandledCurrencyString(); + return globalConst->GetHandledCurrencyString(); case UNUM_PERCENT_FIELD: - return global_const->GetHandledPercentSignString(); + return globalConst->GetHandledPercentSignString(); case UNUM_SIGN_FIELD: - return std::signbit(x.GetNumber()) ? global_const->GetHandledMinusSignString() - : global_const->GetHandledPlusSignString(); + return std::signbit(x.GetNumber()) ? globalConst->GetHandledMinusSignString() + : globalConst->GetHandledPlusSignString(); case UNUM_EXPONENT_SYMBOL_FIELD: - return global_const->GetHandledExponentSeparatorString(); + return globalConst->GetHandledExponentSeparatorString(); case UNUM_EXPONENT_SIGN_FIELD: - return global_const->GetHandledExponentMinusSignString(); + return globalConst->GetHandledExponentMinusSignString(); case UNUM_EXPONENT_FIELD: - return global_const->GetHandledExponentIntegerString(); + return globalConst->GetHandledExponentIntegerString(); case UNUM_COMPACT_FIELD: - return global_const->GetHandledCompactString(); + return globalConst->GetHandledCompactString(); case UNUM_MEASURE_UNIT_FIELD: - return global_const->GetHandledUnitString(); + return globalConst->GetHandledUnitString(); default: UNREACHABLE(); @@ -1061,11 +1059,11 @@ JSHandle JSLocale::GetNumberFieldType(JSThread *thread, JSTaggedV // 10.1.1 ApplyOptionsToTag( tag, options ) bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &tag, const JSHandle &options, - TagElements &tag_elements) + TagElements &tagElements) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = ecmaVm->GetFactory(); if (*tag == *(factory->GetEmptyString())) { return false; } @@ -1074,29 +1072,29 @@ bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &t return false; } - tag_elements.language = GetOption(thread, options, global_const->GetHandledLanguageString(), OptionType::STRING, - global_const->GetHandledUndefined(), global_const->GetHandledUndefined()); + tagElements.language = GetOption(thread, options, globalConst->GetHandledLanguageString(), OptionType::STRING, + globalConst->GetHandledUndefined(), globalConst->GetHandledUndefined()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 4. If language is not undefined, then // a. If language does not match the unicode_language_subtag production, throw a RangeError exception. - if (!tag_elements.language->IsUndefined()) { - std::string language_str = ConvertToStdString(JSHandle::Cast(tag_elements.language)); - if (language_str[INTL_INDEX_ZERO] == '\0' || IsAlpha(language_str, INTL_INDEX_FOUR, INTL_INDEX_FOUR)) { + if (!tagElements.language->IsUndefined()) { + std::string languageStr = ConvertToStdString(JSHandle::Cast(tagElements.language)); + if (languageStr[INTL_INDEX_ZERO] == '\0' || IsAlpha(languageStr, INTL_INDEX_FOUR, INTL_INDEX_FOUR)) { return false; } } // 5. Let script be ? GetOption(options, "script", "string", undefined, undefined). - tag_elements.script = GetOption(thread, options, global_const->GetHandledScriptString(), OptionType::STRING, - global_const->GetHandledUndefined(), global_const->GetHandledUndefined()); + tagElements.script = GetOption(thread, options, globalConst->GetHandledScriptString(), OptionType::STRING, + globalConst->GetHandledUndefined(), globalConst->GetHandledUndefined()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 6. If script is not undefined, then // a. If script does not match the unicode_script_subtag production, throw a RangeError exception. - if (!tag_elements.script->IsUndefined()) { - std::string script_str = JSLocale::ConvertToStdString((JSHandle::Cast(tag_elements.script))); - if (script_str[INTL_INDEX_ZERO] == '\0') { + if (!tagElements.script->IsUndefined()) { + std::string scriptStr = JSLocale::ConvertToStdString((JSHandle::Cast(tagElements.script))); + if (scriptStr[INTL_INDEX_ZERO] == '\0') { return false; } } @@ -1104,13 +1102,13 @@ bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &t // 7. Let region be ? GetOption(options, "region", "string", undefined, undefined). // 8. If region is not undefined, then // a. If region does not match the unicode_region_subtag production, throw a RangeError exception. - tag_elements.region = GetOption(thread, options, global_const->GetHandledRegionString(), OptionType::STRING, - global_const->GetHandledUndefined(), global_const->GetHandledUndefined()); + tagElements.region = GetOption(thread, options, globalConst->GetHandledRegionString(), OptionType::STRING, + globalConst->GetHandledUndefined(), globalConst->GetHandledUndefined()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!tag_elements.region->IsUndefined()) { - std::string region_str = ConvertToStdString(JSHandle::Cast(tag_elements.region)); - if (region_str[INTL_INDEX_ZERO] == '\0') { + if (!tagElements.region->IsUndefined()) { + std::string regionStr = ConvertToStdString(JSHandle::Cast(tagElements.region)); + if (regionStr[INTL_INDEX_ZERO] == '\0') { return false; } } @@ -1120,10 +1118,10 @@ bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &t bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *builder, JSHandle language, JSHandle script, JSHandle region) { - std::string tag_str = JSLocale::ConvertToStdString(tag); - auto len = static_cast(tag_str.length()); + std::string tagStr = JSLocale::ConvertToStdString(tag); + auto len = static_cast(tagStr.length()); ASSERT(len > 0); - builder->setLanguageTag({tag_str.c_str(), len}); + builder->setLanguageTag({tagStr.c_str(), len}); UErrorCode status = U_ZERO_ERROR; icu::Locale locale = builder->build(status); locale.canonicalize(status); @@ -1133,8 +1131,8 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build builder->setLocale(locale); if (!language->IsUndefined()) { - std::string language_str = JSLocale::ConvertToStdString(JSHandle::Cast(language)); - builder->setLanguage(language_str); + std::string languageStr = JSLocale::ConvertToStdString(JSHandle::Cast(language)); + builder->setLanguage(languageStr); builder->build(status); if ((U_FAILURE(status) != 0)) { return false; @@ -1142,8 +1140,8 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build } if (!script->IsUndefined()) { - std::string script_str = JSLocale::ConvertToStdString((JSHandle::Cast(script))); - builder->setScript(script_str); + std::string scriptStr = JSLocale::ConvertToStdString((JSHandle::Cast(script))); + builder->setScript(scriptStr); builder->build(status); if ((U_FAILURE(status) != 0)) { return false; @@ -1151,8 +1149,8 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build } if (!region->IsUndefined()) { - std::string region_str = JSLocale::ConvertToStdString(JSHandle::Cast(region)); - builder->setRegion(region_str); + std::string regionStr = JSLocale::ConvertToStdString(JSHandle::Cast(region)); + builder->setRegion(regionStr); builder->build(status); if ((U_FAILURE(status) != 0)) { return false; @@ -1163,100 +1161,99 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build bool InsertOptions(JSThread *thread, const JSHandle &options, icu::LocaleBuilder *builder) { - const std::vector hour_cycle_values = {"h11", "h12", "h23", "h24"}; - const std::vector case_first_values = {"upper", "lower", "false"}; - const std::vector empty_values = {}; - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - std::string str_result; - bool findca = JSLocale::GetOptionOfString(thread, options, global_const->GetHandledCalendarString(), empty_values, - &str_result); + const std::vector hourCycleValues = {"h11", "h12", "h23", "h24"}; + const std::vector caseFirstValues = {"upper", "lower", "false"}; + const std::vector emptyValues = {}; + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + std::string strResult; + bool findca = + JSLocale::GetOptionOfString(thread, options, globalConst->GetHandledCalendarString(), emptyValues, &strResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (findca) { - if (!uloc_toLegacyType(uloc_toLegacyKey("ca"), str_result.c_str())) { + if (!uloc_toLegacyType(uloc_toLegacyKey("ca"), strResult.c_str())) { return false; } - builder->setUnicodeLocaleKeyword("ca", str_result.c_str()); + builder->setUnicodeLocaleKeyword("ca", strResult.c_str()); } - bool findco = JSLocale::GetOptionOfString(thread, options, global_const->GetHandledCollationString(), empty_values, - &str_result); + bool findco = + JSLocale::GetOptionOfString(thread, options, globalConst->GetHandledCollationString(), emptyValues, &strResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (findco) { - if (!uloc_toLegacyType(uloc_toLegacyKey("co"), str_result.c_str())) { + if (!uloc_toLegacyType(uloc_toLegacyKey("co"), strResult.c_str())) { return false; } - builder->setUnicodeLocaleKeyword("co", str_result.c_str()); + builder->setUnicodeLocaleKeyword("co", strResult.c_str()); } - bool findhc = JSLocale::GetOptionOfString(thread, options, global_const->GetHandledHourCycleString(), - hour_cycle_values, &str_result); + bool findhc = JSLocale::GetOptionOfString(thread, options, globalConst->GetHandledHourCycleString(), + hourCycleValues, &strResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (findhc) { - if (!uloc_toLegacyType(uloc_toLegacyKey("hc"), str_result.c_str())) { + if (!uloc_toLegacyType(uloc_toLegacyKey("hc"), strResult.c_str())) { return false; } - builder->setUnicodeLocaleKeyword("hc", str_result.c_str()); + builder->setUnicodeLocaleKeyword("hc", strResult.c_str()); } - bool findkf = JSLocale::GetOptionOfString(thread, options, global_const->GetHandledCaseFirstString(), - case_first_values, &str_result); + bool findkf = JSLocale::GetOptionOfString(thread, options, globalConst->GetHandledCaseFirstString(), + caseFirstValues, &strResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (findkf) { - if (!uloc_toLegacyType(uloc_toLegacyKey("kf"), str_result.c_str())) { + if (!uloc_toLegacyType(uloc_toLegacyKey("kf"), strResult.c_str())) { return false; } - builder->setUnicodeLocaleKeyword("kf", str_result.c_str()); + builder->setUnicodeLocaleKeyword("kf", strResult.c_str()); } - bool bool_result = false; + bool boolResult = false; bool findkn = - JSLocale::GetOptionOfBool(thread, options, global_const->GetHandledNumericString(), false, &bool_result); + JSLocale::GetOptionOfBool(thread, options, globalConst->GetHandledNumericString(), false, &boolResult); if (findkn) { - str_result = bool_result ? "true" : "false"; - if (!uloc_toLegacyType(uloc_toLegacyKey("kn"), str_result.c_str())) { + strResult = boolResult ? "true" : "false"; + if (!uloc_toLegacyType(uloc_toLegacyKey("kn"), strResult.c_str())) { return false; } - builder->setUnicodeLocaleKeyword("kn", str_result.c_str()); + builder->setUnicodeLocaleKeyword("kn", strResult.c_str()); } - bool findnu = JSLocale::GetOptionOfString(thread, options, global_const->GetHandledNumberingSystemString(), - empty_values, &str_result); + bool findnu = JSLocale::GetOptionOfString(thread, options, globalConst->GetHandledNumberingSystemString(), + emptyValues, &strResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (findnu) { - if (!uloc_toLegacyType(uloc_toLegacyKey("nu"), str_result.c_str())) { + if (!uloc_toLegacyType(uloc_toLegacyKey("nu"), strResult.c_str())) { return false; } - builder->setUnicodeLocaleKeyword("nu", str_result.c_str()); + builder->setUnicodeLocaleKeyword("nu", strResult.c_str()); } return true; } JSHandle JSLocale::InitializeLocale(JSThread *thread, const JSHandle &locale, - const JSHandle &locale_string, + const JSHandle &localeString, const JSHandle &options) { icu::LocaleBuilder builder; - TagElements tag_elements; - if (!ApplyOptionsToTag(thread, locale_string, options, tag_elements)) { + TagElements tagElements; + if (!ApplyOptionsToTag(thread, localeString, options, tagElements)) { THROW_RANGE_ERROR_AND_RETURN(thread, "apply option to tag failed", locale); } - bool res = - BuildOptionsTags(locale_string, &builder, tag_elements.language, tag_elements.script, tag_elements.region); + bool res = BuildOptionsTags(localeString, &builder, tagElements.language, tagElements.script, tagElements.region); if (!res) { THROW_RANGE_ERROR_AND_RETURN(thread, "apply option to tag failed", locale); } - bool insert_result = InsertOptions(thread, options, &builder); + bool insertResult = InsertOptions(thread, options, &builder); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, locale); UErrorCode status = U_ZERO_ERROR; - icu::Locale icu_locale = builder.build(status); - icu_locale.canonicalize(status); + icu::Locale icuLocale = builder.build(status); + icuLocale.canonicalize(status); - if (!insert_result || (U_FAILURE(status) != 0)) { + if (!insertResult || (U_FAILURE(status) != 0)) { THROW_RANGE_ERROR_AND_RETURN(thread, "insert or build failed", locale); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - factory->NewJSIntlIcuData(locale, icu_locale, JSLocale::FreeIcuLocale); + factory->NewJSIntlIcuData(locale, icuLocale, JSLocale::FreeIcuLocale); return locale; } @@ -1326,12 +1323,12 @@ int ConvertValue(const UErrorCode &status, std::string &value, const std::string JSHandle JSLocale::NormalizeKeywordValue(JSThread *thread, const JSHandle &locale, const std::string &key) { - icu::Locale *icu_locale = locale->GetIcuLocale(); + icu::Locale *icuLocale = locale->GetIcuLocale(); UErrorCode status = U_ZERO_ERROR; - auto value = icu_locale->getUnicodeKeywordValue(key, status); + auto value = icuLocale->getUnicodeKeywordValue(key, status); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); int result = ConvertValue(status, value, key); if (result == 1) { @@ -1345,53 +1342,53 @@ JSHandle JSLocale::NormalizeKeywordValue(JSThread *thread, const JSH JSHandle JSLocale::ToString(JSThread *thread, const JSHandle &locale) { - icu::Locale *icu_locale = locale->GetIcuLocale(); - if (icu_locale == nullptr) { + icu::Locale *icuLocale = locale->GetIcuLocale(); + if (icuLocale == nullptr) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); return factory->GetEmptyString(); } - JSHandle result = ToLanguageTag(thread, *icu_locale); + JSHandle result = ToLanguageTag(thread, *icuLocale); return result; } -JSHandle JSLocale::GetAvailableLocales(JSThread *thread, const char *locale_key, const char *locale_path) +JSHandle JSLocale::GetAvailableLocales(JSThread *thread, const char *localeKey, const char *localePath) { UErrorCode status = U_ZERO_ERROR; - auto global_const = thread->GlobalConstants(); - JSHandle special_value = JSHandle::Cast(global_const->GetHandledEnUsPosixString()); - std::string special_string = ConvertToStdString(special_value); + auto globalConst = thread->GlobalConstants(); + JSHandle specialValue = JSHandle::Cast(globalConst->GetHandledEnUsPosixString()); + std::string specialString = ConvertToStdString(specialValue); UEnumeration *uenum = uloc_openAvailableByType(ULOC_AVAILABLE_WITH_LEGACY_ALIASES, &status); - std::vector all_locales; + std::vector allLocales; const char *loc = nullptr; for (loc = uenum_next(uenum, nullptr, &status); loc != nullptr; loc = uenum_next(uenum, nullptr, &status)) { ASSERT(U_SUCCESS(status)); - std::string loc_str(loc); - std::replace(loc_str.begin(), loc_str.end(), '_', '-'); - if (loc_str == special_string) { - loc_str = "en-US-u-va-posix"; + std::string locStr(loc); + std::replace(locStr.begin(), locStr.end(), '_', '-'); + if (locStr == specialString) { + locStr = "en-US-u-va-posix"; } - if (locale_path != nullptr || locale_key != nullptr) { - icu::Locale loc(loc_str.c_str()); + if (localePath != nullptr || localeKey != nullptr) { + icu::Locale loc(locStr.c_str()); bool res = false; - if (!CheckLocales(loc, locale_key, locale_path, res)) { + if (!CheckLocales(loc, localeKey, localePath, res)) { continue; } } - bool is_script = false; - all_locales.push_back(loc_str); - icu::Locale formal_locale = icu::Locale::createCanonical(loc_str.c_str()); - std::string script_str = formal_locale.getScript(); - is_script = !script_str.empty(); - if (is_script) { - std::string language_str = formal_locale.getLanguage(); - std::string country_str = formal_locale.getCountry(); - std::string short_locale = icu::Locale(language_str.c_str(), country_str.c_str()).getName(); - std::replace(short_locale.begin(), short_locale.end(), '_', '-'); - all_locales.push_back(short_locale); + bool isScript = false; + allLocales.push_back(locStr); + icu::Locale formalLocale = icu::Locale::createCanonical(locStr.c_str()); + std::string scriptStr = formalLocale.getScript(); + isScript = !scriptStr.empty(); + if (isScript) { + std::string languageStr = formalLocale.getLanguage(); + std::string countryStr = formalLocale.getCountry(); + std::string shortLocale = icu::Locale(languageStr.c_str(), countryStr.c_str()).getName(); + std::replace(shortLocale.begin(), shortLocale.end(), '_', '-'); + allLocales.push_back(shortLocale); } } uenum_close(uenum); - return ConstructLocaleList(thread, all_locales); + return ConstructLocaleList(thread, allLocales); } } // namespace panda::ecmascript diff --git a/runtime/js_locale.h b/runtime/js_locale.h index ea25debd04dfd76cdc0a9faa8544a4862041e474..805784f7c6819ef406a923a845fd26755cb5a581 100644 --- a/runtime/js_locale.h +++ b/runtime/js_locale.h @@ -78,16 +78,16 @@ public: UBool hasNext() const override { - return static_cast(cur_idx_ < length_); + return static_cast(curIdx_ < length_); } const icu::Locale &next() override { - ASSERT(cur_idx_ < length_); + ASSERT(curIdx_ < length_); UErrorCode status = U_ZERO_ERROR; - locale_ = icu::Locale::forLanguageTag(data_[cur_idx_].c_str(), status); + locale_ = icu::Locale::forLanguageTag(data_[curIdx_].c_str(), status); ASSERT(U_SUCCESS(status)); - cur_idx_++; + curIdx_++; return locale_; } @@ -100,13 +100,13 @@ public: private: std::vector data_ {}; uint32_t length_ {0}; - uint32_t cur_idx_ {0}; + uint32_t curIdx_ {0}; icu::Locale locale_ {}; }; struct ResolvedLocale { std::string locale {}; - icu::Locale locale_data {}; + icu::Locale localeData {}; std::map extensions {}; }; @@ -118,8 +118,8 @@ struct MatcherResult { struct OptionData { std::string name; std::string key; - std::vector possible_values; - bool is_bool_value = false; + std::vector possibleValues; + bool isBoolValue = false; }; struct TagElements { @@ -159,13 +159,13 @@ public: if (pointer == nullptr) { return; } - auto icu_locale = reinterpret_cast(pointer); + auto icuLocale = reinterpret_cast(pointer); if (data != nullptr) { - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icu_locale); + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuLocale); } } - static std::string ConvertToStdString(const JSHandle &ecma_str); + static std::string ConvertToStdString(const JSHandle &ecmaStr); // 6.2.2 IsStructurallyValidLanguageTag ( locale ) static bool IsStructurallyValidLanguageTag(const JSHandle &tag); @@ -189,50 +189,49 @@ public: JSHandle &obj, JSHandle &seen); // 9.2.2 BestAvailableLocale ( availableLocales, locale ) - static std::string BestAvailableLocale(JSThread *thread, const JSHandle &available_locales, + static std::string BestAvailableLocale(JSThread *thread, const JSHandle &availableLocales, const std::string &locale); // 9.2.3 LookupMatcher ( availableLocales, requestedLocales ) - static JSHandle LookupMatcher(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales); + static JSHandle LookupMatcher(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales); // 9.2.4 BestFitMatcher ( availableLocales, requestedLocales ) - static JSHandle BestFitMatcher(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales); + static JSHandle BestFitMatcher(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales); // 9.2.5 UnicodeExtensionValue ( extension, key ) static std::string UnicodeExtensionValue(const std::string &extension, const std::string &key); // 9.2.7 ResolveLocale ( availableLocales, requestedLocales, options, relevantExtensionKeys, localeData ) - static ResolvedLocale ResolveLocale(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales, LocaleMatcherOption matcher, - const std::set &relevant_extension_keys); + static ResolvedLocale ResolveLocale(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales, LocaleMatcherOption matcher, + const std::set &relevantExtensionKeys); // 9.2.8 LookupSupportedLocales ( availableLocales, requestedLocales ) - static JSHandle LookupSupportedLocales(JSThread *thread, - const JSHandle &available_locales, - const JSHandle &requested_locales); + static JSHandle LookupSupportedLocales(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales); // 9.2.9 BestFitSupportedLocales ( availableLocales, requestedLocales ) static JSHandle BestFitSupportedLocales(JSThread *thread, - const JSHandle &available_locales, - const JSHandle &requested_locales); + const JSHandle &availableLocales, + const JSHandle &requestedLocales); // 9.2.10 SupportedLocales ( availableLocales, requestedLocales, options ) - static JSHandle SupportedLocales(JSThread *thread, const JSHandle &available_locales, - const JSHandle &requested_locales, + static JSHandle SupportedLocales(JSThread *thread, const JSHandle &availableLocales, + const JSHandle &requestedLocales, const JSHandle &options); // 9.2.11 GetOption ( options, property, type, values, fallback ) template static T GetOptionOfString(JSThread *thread, const JSHandle &options, - const JSHandle &property, const std::vector &enum_values, - const std::vector &str_values, T fallback) + const JSHandle &property, const std::vector &enumValues, + const std::vector &strValues, T fallback) { // 1. Let value be ? Get(options, property). - OperationResult operation_result = JSObject::GetProperty(thread, options, property); + OperationResult operationResult = JSObject::GetProperty(thread, options, property); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, T::EXCEPTION); - JSHandle value = operation_result.GetValue(); + JSHandle value = operationResult.GetValue(); if (value->IsUndefined()) { return fallback; @@ -241,26 +240,26 @@ public: // 2. If value is not undefined, then // d. If values is not undefined, then // i. If values does not contain an element equal to value, throw a RangeError exception. - JSHandle value_e_str = JSTaggedValue::ToString(thread, value); + JSHandle valueEStr = JSTaggedValue::ToString(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, T::EXCEPTION); - std::string value_str = ConvertToStdString(value_e_str); - int exist_idx = -1; - if (!enum_values.empty()) { - int str_values_size = str_values.size(); - for (int i = 0; i < str_values_size; i++) { - if (str_values[i] == value_str) { - exist_idx = i; + std::string valueStr = ConvertToStdString(valueEStr); + int existIdx = -1; + if (!enumValues.empty()) { + int strValuesSize = strValues.size(); + for (int i = 0; i < strValuesSize; i++) { + if (strValues[i] == valueStr) { + existIdx = i; } } - if (exist_idx == -1) { + if (existIdx == -1) { THROW_RANGE_ERROR_AND_RETURN(thread, "getStringOption failed", T::EXCEPTION); } } - if (exist_idx == -1) { + if (existIdx == -1) { UNREACHABLE(); } // e.Return value. - return enum_values[exist_idx]; + return enumValues[existIdx]; } static bool GetOptionOfBool(JSThread *thread, const JSHandle &options, @@ -273,7 +272,7 @@ public: static bool GetOptionOfString(JSThread *thread, const JSHandle &options, const JSHandle &property, const std::vector &values, - std::string *option_value); + std::string *optionValue); // 9.2.12 DefaultNumberOption ( value, minimum, maximum, fallback ) static int DefaultNumberOption(JSThread *thread, const JSHandle &value, int minimum, int maximum, @@ -326,22 +325,22 @@ public: static bool IsWellNumberingSystem(const std::string &value) { - std::set irregular_list = {"native", "traditio", "finance"}; - if (irregular_list.find(value) != irregular_list.end()) { + std::set irregularList = {"native", "traditio", "finance"}; + if (irregularList.find(value) != irregularList.end()) { return false; } UErrorCode status = U_ZERO_ERROR; - icu::NumberingSystem *numbering_system = icu::NumberingSystem::createInstanceByName(value.c_str(), status); - bool result = U_SUCCESS(status) != 0 && numbering_system != nullptr; - delete numbering_system; - numbering_system = nullptr; + icu::NumberingSystem *numberingSystem = icu::NumberingSystem::createInstanceByName(value.c_str(), status); + bool result = U_SUCCESS(status) != 0 && numberingSystem != nullptr; + delete numberingSystem; + numberingSystem = nullptr; return result; } static bool IsWellCollation(const icu::Locale &locale, const std::string &value) { - std::set irregular_list = {"standard", "search"}; - if (irregular_list.find(value) != irregular_list.end()) { + std::set irregularList = {"standard", "search"}; + if (irregularList.find(value) != irregularList.end()) { return false; } return IsWellExtension(locale, "collation", value); @@ -356,8 +355,8 @@ public: static bool IsWellExtension(const icu::Locale &locale, const char *key, const std::string &value) { UErrorCode status = U_ZERO_ERROR; - const char *outdated_type = uloc_toLegacyType(key, value.c_str()); - if (outdated_type == nullptr) { + const char *outdatedType = uloc_toLegacyType(key, value.c_str()); + if (outdatedType == nullptr) { return false; } icu::StringEnumeration *sequence = @@ -370,7 +369,7 @@ public: int32_t size; const char *element = sequence->next(&size, status); while (U_SUCCESS(status) && element != nullptr) { - if (strcmp(outdated_type, element) == 0) { + if (strcmp(outdatedType, element) == 0) { delete sequence; sequence = nullptr; return true; @@ -416,8 +415,8 @@ public: if (value.length() < 3) { return false; } - char last_char = value[value.length() - 1]; - if (last_char == '-') { + char lastChar = value[value.length() - 1]; + if (lastChar == '-') { return false; } std::vector items; @@ -434,48 +433,48 @@ public: return true; } - static bool ValidateOtherTags(const icu::Locale &locale, const char *package_name, const char *key, bool &res) + static bool ValidateOtherTags(const icu::Locale &locale, const char *packageName, const char *key, bool &res) { - const char *locale_country = locale.getCountry(); - const char *locale_script = locale.getScript(); + const char *localeCountry = locale.getCountry(); + const char *localeScript = locale.getScript(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (locale_country[0] != '\0' && locale_script[0] != '\0') { - std::string remove_country; - remove_country = locale.getLanguage(); - remove_country.append("-"); - remove_country.append(locale_script); - return CheckLocales(remove_country.c_str(), key, package_name, res); + if (localeCountry[0] != '\0' && localeScript[0] != '\0') { + std::string removeCountry; + removeCountry = locale.getLanguage(); + removeCountry.append("-"); + removeCountry.append(localeScript); + return CheckLocales(removeCountry.c_str(), key, packageName, res); } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (locale_country[0] != '\0' || locale_script[0] != '\0') { + if (localeCountry[0] != '\0' || localeScript[0] != '\0') { std::string language = locale.getLanguage(); - return CheckLocales(language.c_str(), key, package_name, res); + return CheckLocales(language.c_str(), key, packageName, res); } return res; } - static bool CheckLocales(const icu::Locale &locale, const char *key, const char *package_name, bool &res) + static bool CheckLocales(const icu::Locale &locale, const char *key, const char *packageName, bool &res) { res = false; UErrorCode status = U_ZERO_ERROR; - const char *formal_locale = locale.getName(); - UResourceBundle *locale_res = ures_open(package_name, formal_locale, &status); - if (locale_res != nullptr && status == U_ZERO_ERROR) { + const char *formalLocale = locale.getName(); + UResourceBundle *localeRes = ures_open(packageName, formalLocale, &status); + if (localeRes != nullptr && status == U_ZERO_ERROR) { if (key == nullptr) { res = true; } else { - UResourceBundle *key_res = ures_getByKey(locale_res, key, nullptr, &status); - if (key_res != nullptr && status == U_ZERO_ERROR) { + UResourceBundle *keyRes = ures_getByKey(localeRes, key, nullptr, &status); + if (keyRes != nullptr && status == U_ZERO_ERROR) { res = true; } - ures_close(key_res); + ures_close(keyRes); } } - ures_close(locale_res); + ures_close(localeRes); if (res) { return res; } - ValidateOtherTags(locale, package_name, key, res); + ValidateOtherTags(locale, packageName, key, res); return res; } @@ -487,28 +486,28 @@ public: static JSHandle GetAvailableLocales(JSThread *thread, const char *key, const char *path); static JSHandle PutElement(JSThread *thread, int index, const JSHandle &array, - const JSHandle &field_type_string, + const JSHandle &fieldTypeString, const JSHandle &value); static JSHandle ToLanguageTag(JSThread *thread, const icu::Locale &locale); - static std::string GetNumberingSystem(const icu::Locale &icu_locale); + static std::string GetNumberingSystem(const icu::Locale &icuLocale); static bool IsWellFormedCurrencyCode(const std::string ¤cy); - static JSHandle GetNumberFieldType(JSThread *thread, JSTaggedValue x, int32_t field_id); + static JSHandle GetNumberFieldType(JSThread *thread, JSTaggedValue x, int32_t fieldId); static bool ApplyOptionsToTag(JSThread *thread, const JSHandle &tag, const JSHandle &options, - TagElements &tag_elements); + TagElements &tagElements); static JSHandle InitializeLocale(JSThread *thread, const JSHandle &locale, - const JSHandle &locale_string, + const JSHandle &localeString, const JSHandle &options); static JSHandle NormalizeKeywordValue(JSThread *thread, const JSHandle &locale, const std::string &key); - static void HandleLocaleExtension(size_t &start, size_t &extension_end, const std::string &result, size_t len); + static void HandleLocaleExtension(size_t &start, size_t &extensionEnd, const std::string &result, size_t len); static ParsedLocale HandleLocale(const JSHandle &locale); @@ -516,8 +515,8 @@ public: // 12.1.1 SetNumberFormatDigitOptions ( intlObj, options, mnfdDefault, mxfdDefault, notation ) template - static void SetNumberFormatDigitOptions(JSThread *thread, const JSHandle &intl_obj, - const JSHandle &options, int mnfd_default, int mxfd_default, + static void SetNumberFormatDigitOptions(JSThread *thread, const JSHandle &intlObj, + const JSHandle &options, int mnfdDefault, int mxfdDefault, NotationOption notation) { // 1. Assert: Type(intlObj) is Object. @@ -525,38 +524,38 @@ public: // 3. Assert: Type(mnfdDefault) is Number. // 4. Assert: Type(mxfdDefault) is Number. ASSERT(options->IsHeapObject()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); // Set intlObj.[[MinimumFractionDigits]] to 0. - intl_obj->SetMinimumFractionDigits(thread, JSTaggedValue(0)); + intlObj->SetMinimumFractionDigits(thread, JSTaggedValue(0)); // Set intlObj.[[MaximumFractionDigits]] to 0. - intl_obj->SetMaximumFractionDigits(thread, JSTaggedValue(0)); + intlObj->SetMaximumFractionDigits(thread, JSTaggedValue(0)); // Set intlObj.[[MinimumSignificantDigits]] to 0. - intl_obj->SetMinimumSignificantDigits(thread, JSTaggedValue(0)); + intlObj->SetMinimumSignificantDigits(thread, JSTaggedValue(0)); // Set intlObj.[[MaximumSignificantDigits]] to 0. - intl_obj->SetMaximumSignificantDigits(thread, JSTaggedValue(0)); + intlObj->SetMaximumSignificantDigits(thread, JSTaggedValue(0)); // 5. Let mnid be ? GetNumberOption(options, "minimumIntegerDigits,", 1, 21, 1). - JSHandle mnid_key = global_const->GetHandledMinimumIntegerDigitsString(); - int mnid = GetNumberOption(thread, JSHandle::Cast(options), mnid_key, 1, MAX_DIGITS, 1); + JSHandle mnidKey = globalConst->GetHandledMinimumIntegerDigitsString(); + int mnid = GetNumberOption(thread, JSHandle::Cast(options), mnidKey, 1, MAX_DIGITS, 1); // 6. Let mnfd be ? Get(options, "minimumFractionDigits"). - JSHandle mnfd_key = global_const->GetHandledMinimumFractionDigitsString(); - JSHandle mnfd = JSTaggedValue::GetProperty(thread, options, mnfd_key).GetValue(); + JSHandle mnfdKey = globalConst->GetHandledMinimumFractionDigitsString(); + JSHandle mnfd = JSTaggedValue::GetProperty(thread, options, mnfdKey).GetValue(); // 7. Let mxfd be ? Get(options, "maximumFractionDigits"). - JSHandle mxfd_key = global_const->GetHandledMaximumFractionDigitsString(); - JSHandle mxfd = JSTaggedValue::GetProperty(thread, options, mxfd_key).GetValue(); + JSHandle mxfdKey = globalConst->GetHandledMaximumFractionDigitsString(); + JSHandle mxfd = JSTaggedValue::GetProperty(thread, options, mxfdKey).GetValue(); // 8. Let mnsd be ? Get(options, "minimumSignificantDigits"). - JSHandle mnsd_key = global_const->GetHandledMinimumSignificantDigitsString(); - JSHandle mnsd = JSTaggedValue::GetProperty(thread, options, mnsd_key).GetValue(); + JSHandle mnsdKey = globalConst->GetHandledMinimumSignificantDigitsString(); + JSHandle mnsd = JSTaggedValue::GetProperty(thread, options, mnsdKey).GetValue(); // 9. Let mxsd be ? Get(options, "maximumSignificantDigits"). - JSHandle mxsd_key = global_const->GetHandledMaximumSignificantDigitsString(); - JSHandle mxsd = JSTaggedValue::GetProperty(thread, options, mxsd_key).GetValue(); + JSHandle mxsdKey = globalConst->GetHandledMaximumSignificantDigitsString(); + JSHandle mxsd = JSTaggedValue::GetProperty(thread, options, mxsdKey).GetValue(); // 10. Set intlObj.[[MinimumIntegerDigits]] to mnid. - intl_obj->SetMinimumIntegerDigits(thread, JSTaggedValue(mnid)); + intlObj->SetMinimumIntegerDigits(thread, JSTaggedValue(mnid)); // 11. If mnsd is not undefined or mxsd is not undefined, then if (!mnsd->IsUndefined() || !mxsd->IsUndefined()) { // a. Set intlObj.[[RoundingType]] to significantDigits. - intl_obj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::SIGNIFICANTDIGITS))); + intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::SIGNIFICANTDIGITS))); // b. Let mnsd be ? DefaultNumberOption(mnsd, 1, 21, 1). mnsd = JSHandle( thread, JSTaggedValue(JSLocale::DefaultNumberOption(thread, mnsd, 1, MAX_DIGITS, 1))); @@ -564,51 +563,51 @@ public: mxsd = JSHandle(thread, JSTaggedValue(JSLocale::DefaultNumberOption( thread, mxsd, mnsd->GetInt(), MAX_DIGITS, MAX_DIGITS))); // d. Set intlObj.[[MinimumSignificantDigits]] to mnsd. - intl_obj->SetMinimumSignificantDigits(thread, mnsd); + intlObj->SetMinimumSignificantDigits(thread, mnsd); // e. Set intlObj.[[MaximumSignificantDigits]] to mxsd. - intl_obj->SetMaximumSignificantDigits(thread, mxsd); + intlObj->SetMaximumSignificantDigits(thread, mxsd); } else { if (!mnfd->IsUndefined() || !mxfd->IsUndefined()) { // 12. Else if mnfd is not undefined or mxfd is not undefined, then // a. Set intlObj.[[RoundingType]] to fractionDigits. - intl_obj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::FRACTIONDIGITS))); + intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::FRACTIONDIGITS))); if (!mxfd->IsUndefined()) { - auto mxfd_value = JSTaggedValue( - JSLocale::DefaultNumberOption(thread, mxfd, 0, MAX_FRACTION_DIGITS, mxfd_default)); - mxfd = JSHandle(thread, mxfd_value); - mnfd_default = std::min(mnfd_default, mxfd->GetInt()); + auto mxfdValue = + JSTaggedValue(JSLocale::DefaultNumberOption(thread, mxfd, 0, MAX_FRACTION_DIGITS, mxfdDefault)); + mxfd = JSHandle(thread, mxfdValue); + mnfdDefault = std::min(mnfdDefault, mxfd->GetInt()); } // b. Let mnfd be ? DefaultNumberOption(mnfd, 0, 20, mnfdDefault). mnfd = JSHandle( - thread, JSTaggedValue(DefaultNumberOption(thread, mnfd, 0, MAX_FRACTION_DIGITS, mnfd_default))); + thread, JSTaggedValue(DefaultNumberOption(thread, mnfd, 0, MAX_FRACTION_DIGITS, mnfdDefault))); // c. Let mxfdActualDefault be max( mnfd, mxfdDefault ). - int mxfd_actual_default = std::max(mnfd->GetInt(), mxfd_default); + int mxfdActualDefault = std::max(mnfd->GetInt(), mxfdDefault); // d. Let mxfd be ? DefaultNumberOption(mxfd, mnfd, 20, mxfdActualDefault). mxfd = JSHandle( thread, JSTaggedValue(JSLocale::DefaultNumberOption(thread, mxfd, mnfd->GetInt(), - MAX_FRACTION_DIGITS, mxfd_actual_default))); + MAX_FRACTION_DIGITS, mxfdActualDefault))); // e. Set intlObj.[[MinimumFractionDigits]] to mnfd. - intl_obj->SetMinimumFractionDigits(thread, mnfd); + intlObj->SetMinimumFractionDigits(thread, mnfd); // f. Set intlObj.[[MaximumFractionDigits]] to mxfd. - intl_obj->SetMaximumFractionDigits(thread, mxfd); + intlObj->SetMaximumFractionDigits(thread, mxfd); } else if (notation == NotationOption::COMPACT) { // 13. Else if notation is "compact", then // a. Set intlObj.[[RoundingType]] to compactRounding. - intl_obj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::COMPACTROUNDING))); + intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::COMPACTROUNDING))); } else { // 14. else, // a.Set intlObj.[[RoundingType]] to fractionDigits. - intl_obj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::FRACTIONDIGITS))); + intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::FRACTIONDIGITS))); // b.Set intlObj.[[MinimumFractionDigits]] to mnfdDefault. - intl_obj->SetMinimumFractionDigits(thread, JSTaggedValue(mnfd_default)); + intlObj->SetMinimumFractionDigits(thread, JSTaggedValue(mnfdDefault)); // c.Set intlObj.[[MaximumFractionDigits]] to mxfdDefault. - intl_obj->SetMaximumFractionDigits(thread, JSTaggedValue(mxfd_default)); + intlObj->SetMaximumFractionDigits(thread, JSTaggedValue(mxfdDefault)); } } } static JSHandle ConstructLocaleList(JSThread *thread, - const std::vector &icu_available_locales); + const std::vector &icuAvailableLocales); static bool CheckLocales(const icu::Locale &locale, const char *path, const char *key); @@ -622,15 +621,15 @@ public: } private: - static icu::Locale BuildICULocale(const std::string &bcp47_locale); + static icu::Locale BuildICULocale(const std::string &bcp47Locale); - static bool IsCheckRange(const std::string &str, size_t min, size_t max, bool(range_check_func)(char)) + static bool IsCheckRange(const std::string &str, size_t min, size_t max, bool(rangeCheckFunc)(char)) { if (!InRange(str.length(), min, max)) { return false; } for (char i : str) { - if (!range_check_func(i)) { + if (!rangeCheckFunc(i)) { return false; } } @@ -678,8 +677,8 @@ private: static bool IsAToZ(char ch) { - int lower_ch = JSLocale::AsciiAlphaToLower(ch); - return JSLocale::InRange(lower_ch, 'a', 'z'); + int lowerCh = JSLocale::AsciiAlphaToLower(ch); + return JSLocale::InRange(lowerCh, 'a', 'z'); } }; } // namespace panda::ecmascript diff --git a/runtime/js_map.cpp b/runtime/js_map.cpp index 39cd41687e3508f9f37d4fc366f33fa82542f4d6..ef887fb4f9ea9a8ad6eff61687fe396994bf2b73 100644 --- a/runtime/js_map.cpp +++ b/runtime/js_map.cpp @@ -26,34 +26,34 @@ void JSMap::Set(JSThread *thread, const JSHandle &map, const JSHandle map_handle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); - JSHandle new_map = LinkedHashMap::Set(thread, map_handle, key, value); - map->SetLinkedMap(thread, new_map); + JSHandle newMap = LinkedHashMap::Set(thread, mapHandle, key, value); + map->SetLinkedMap(thread, newMap); } bool JSMap::Delete(const JSThread *thread, const JSHandle &map, const JSHandle &key) { - JSHandle map_handle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); if (!LinkedHashMap::IsKey(key.GetTaggedValue())) { return false; } int hash = LinkedHash::Hash(key.GetTaggedValue()); - int entry = map_handle->FindElement(key.GetTaggedValue(), hash); + int entry = mapHandle->FindElement(key.GetTaggedValue(), hash); if (entry == -1) { return false; } - map_handle->RemoveEntry(thread, entry); + mapHandle->RemoveEntry(thread, entry); - JSHandle new_map = LinkedHashMap::Shrink(thread, map_handle); - map->SetLinkedMap(thread, new_map); + JSHandle newMap = LinkedHashMap::Shrink(thread, mapHandle); + map->SetLinkedMap(thread, newMap); return true; } void JSMap::Clear(const JSThread *thread, const JSHandle &map) { - LinkedHashMap *linked_map = LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject()); - linked_map->Clear(thread); + LinkedHashMap *linkedMap = LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject()); + linkedMap->Clear(thread); } bool JSMap::Has(JSTaggedValue key, int hash) const diff --git a/runtime/js_map_iterator.cpp b/runtime/js_map_iterator.cpp index 44a6b3b7cee96af4ae92306031b8aa1f5ebc3551..bf38eed733b09fd84a05d73436e4d086c382c235 100644 --- a/runtime/js_map_iterator.cpp +++ b/runtime/js_map_iterator.cpp @@ -25,7 +25,7 @@ JSTaggedValue JSMapIterator::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.Let O be the this value JSHandle input(builtins_common::GetThis(argv)); @@ -36,66 +36,66 @@ JSTaggedValue JSMapIterator::Next(EcmaRuntimeCallInfo *argv) } JSHandle iter(input); iter->Update(thread); - JSHandle undefined_handle(thread, JSTaggedValue::Undefined()); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); // 4.Let m be O.[[IteratedMap]]. - JSHandle iterated_map(thread, iter->GetIteratedMap()); + JSHandle iteratedMap(thread, iter->GetIteratedMap()); // 5.Let index be O.[[MapNextIndex]]. int index = iter->GetNextIndex().GetInt(); - IterationKind item_kind = IterationKind(iter->GetIterationKind().GetInt()); + IterationKind itemKind = IterationKind(iter->GetIterationKind().GetInt()); // 7.If m is undefined, return CreateIterResultObject(undefined, true). - if (iterated_map->IsUndefined()) { - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + if (iteratedMap->IsUndefined()) { + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); }; - JSHandle map(iterated_map); - int total_elements = map->NumberOfElements() + map->NumberOfDeletedElements(); + JSHandle map(iteratedMap); + int totalElements = map->NumberOfElements() + map->NumberOfDeletedElements(); - JSMutableHandle key_handle(thread, JSTaggedValue::Undefined()); - while (index < total_elements) { + JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); + while (index < totalElements) { JSTaggedValue key = map->GetKey(index); if (!key.IsHole()) { iter->SetNextIndex(thread, JSTaggedValue(index + 1)); - key_handle.Update(key); + keyHandle.Update(key); // If itemKind is key, let result be e.[[Key]] - if (item_kind == IterationKind::KEY) { - return JSIterator::CreateIterResultObject(thread, key_handle, false).GetTaggedValue(); + if (itemKind == IterationKind::KEY) { + return JSIterator::CreateIterResultObject(thread, keyHandle, false).GetTaggedValue(); } JSHandle value(thread, map->GetValue(index)); // Else if itemKind is value, let result be e.[[Value]]. - if (item_kind == IterationKind::VALUE) { + if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } // Else ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle array(factory->NewTaggedArray(2)); // 2 means the length of array - array->Set(thread, 0, key_handle); + array->Set(thread, 0, keyHandle); array->Set(thread, 1, value); - JSHandle key_and_value(JSArray::CreateArrayFromList(thread, array)); - return JSIterator::CreateIterResultObject(thread, key_and_value, false).GetTaggedValue(); + JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); + return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue(); } index++; } // 13.Set O.[[IteratedMap]] to undefined. iter->SetIteratedMap(thread, JSTaggedValue::Undefined()); - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } void JSMapIterator::Update(const JSThread *thread) { - JSTaggedValue iterated_map = GetIteratedMap(); - if (iterated_map.IsUndefined()) { + JSTaggedValue iteratedMap = GetIteratedMap(); + if (iteratedMap.IsUndefined()) { return; } - LinkedHashMap *map = LinkedHashMap::Cast(iterated_map.GetTaggedObject()); + LinkedHashMap *map = LinkedHashMap::Cast(iteratedMap.GetTaggedObject()); if (map->GetNextTable().IsHole()) { return; } int index = GetNextIndex().GetInt(); - JSTaggedValue next_table = map->GetNextTable(); - while (!next_table.IsHole()) { + JSTaggedValue nextTable = map->GetNextTable(); + while (!nextTable.IsHole()) { index -= map->GetDeletedElementsAt(index); - map = LinkedHashMap::Cast(next_table.GetTaggedObject()); - next_table = map->GetNextTable(); + map = LinkedHashMap::Cast(nextTable.GetTaggedObject()); + nextTable = map->GetNextTable(); } SetIteratedMap(thread, JSTaggedValue(map)); SetNextIndex(thread, JSTaggedValue(index)); @@ -106,8 +106,8 @@ JSHandle JSMapIterator::CreateMapIterator(JSThread *thread, const { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!obj->IsJSMap()) { - JSHandle undefined_handle(thread, JSTaggedValue::Undefined()); - THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", undefined_handle); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", undefinedHandle); } JSHandle iter(factory->NewJSMapIterator(JSHandle(obj), kind)); return iter; diff --git a/runtime/js_method.cpp b/runtime/js_method.cpp index 6965d7f619c2ffe26fe09c9dfb07a43f110869b0..5e04ab037b83ba29ca563b23f20707e6f8b73569 100644 --- a/runtime/js_method.cpp +++ b/runtime/js_method.cpp @@ -22,7 +22,7 @@ namespace panda::ecmascript { JSMethod::~JSMethod() { - mem::InternalAllocator<>::GetInternalAllocatorFromRuntime()->Free(ic_mapping_); + mem::InternalAllocator<>::GetInternalAllocatorFromRuntime()->Free(icMapping_); } // It's not allowed '#' token appear in ECMA function(method) name, which discriminates same names in panda methods. @@ -37,19 +37,19 @@ PandaString JSMethod::ParseFunctionName() const void JSMethod::SetCallTypeFromAnnotation() { - const panda_file::File *panda_file = GetPandaFile(); - panda_file::File::EntityId field_id = GetFileId(); - panda_file::MethodDataAccessor mda(*panda_file, field_id); - mda.EnumerateAnnotations([&](panda_file::File::EntityId annotation_id) { - panda_file::AnnotationDataAccessor ada(*panda_file, annotation_id); - auto *annotation_name = reinterpret_cast(panda_file->GetStringData(ada.GetClassId()).data); - if (::strcmp("L_ESCallTypeAnnotation;", annotation_name) == 0) { - uint32_t elem_count = ada.GetCount(); - for (uint32_t i = 0; i < elem_count; i++) { + const panda_file::File *pandaFile = GetPandaFile(); + panda_file::File::EntityId fieldId = GetFileId(); + panda_file::MethodDataAccessor mda(*pandaFile, fieldId); + mda.EnumerateAnnotations([&](panda_file::File::EntityId annotationId) { + panda_file::AnnotationDataAccessor ada(*pandaFile, annotationId); + auto *annotationName = reinterpret_cast(pandaFile->GetStringData(ada.GetClassId()).data); + if (::strcmp("L_ESCallTypeAnnotation;", annotationName) == 0) { + uint32_t elemCount = ada.GetCount(); + for (uint32_t i = 0; i < elemCount; i++) { panda_file::AnnotationDataAccessor::Elem adae = ada.GetElement(i); - auto *elem_name = reinterpret_cast(panda_file->GetStringData(adae.GetNameId()).data); - if (::strcmp("callType", elem_name) == 0) { - call_type_ = adae.GetScalarValue().GetValue(); + auto *elemName = reinterpret_cast(pandaFile->GetStringData(adae.GetNameId()).data); + if (::strcmp("callType", elemName) == 0) { + callType_ = adae.GetScalarValue().GetValue(); } } } @@ -58,23 +58,23 @@ void JSMethod::SetCallTypeFromAnnotation() void JSMethod::InitProfileVector() { - const panda_file::File *panda_file = GetPandaFile(); - panda_file::File::EntityId field_id = GetFileId(); - panda_file::MethodDataAccessor mda(*panda_file, field_id); - auto prof_size = mda.GetProfileSize(); - bool method_too_big = bytecode_array_size_ > compiler::OPTIONS.GetCompilerMaxBytecodeSize(); + const panda_file::File *pandaFile = GetPandaFile(); + panda_file::File::EntityId fieldId = GetFileId(); + panda_file::MethodDataAccessor mda(*pandaFile, fieldId); + auto profSize = mda.GetProfileSize(); + bool methodTooBig = bytecodeArraySize_ > compiler::g_options.GetCompilerMaxBytecodeSize(); #ifndef NDEBUG - auto max_inst_prof_size = profiling::GetOrderedProfileSizes().back(); - auto max_prof_size = bytecode_array_size_ * max_inst_prof_size; - LOG_IF(!method_too_big && !prof_size && max_prof_size > panda_file::MethodItem::MAX_PROFILE_SIZE, WARNING, RUNTIME) + auto maxInstProfSize = profiling::GetOrderedProfileSizes().back(); + auto maxProfSize = bytecodeArraySize_ * maxInstProfSize; + LOG_IF(!methodTooBig && !profSize && maxProfSize > panda_file::MethodItem::MAX_PROFILE_SIZE, WARNING, RUNTIME) << "Method may be compiled but not profiled because profiling size exceeds limit"; #endif - if (prof_size && !method_too_big) { - profile_size_ = prof_size.value(); - size_t size = RoundUp(prof_size.value(), BITS_PER_INTPTR); + if (profSize && !methodTooBig) { + profileSize_ = profSize.value(); + size_t size = RoundUp(profSize.value(), BITS_PER_INTPTR); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - profiling_data_ = MakePandaUnique(size); - std::memset(profiling_data_.get(), 0, size); + profilingData_ = MakePandaUnique(size); + std::memset(profilingData_.get(), 0, size); } } @@ -87,7 +87,7 @@ JSTaggedValue JSMethod::GetLength() const return length; } -std::string JSMethod::GetFullName([[maybe_unused]] bool with_signature) const +std::string JSMethod::GetFullName([[maybe_unused]] bool withSignature) const { auto name = ParseFunctionName(); if (name.empty()) { diff --git a/runtime/js_method.h b/runtime/js_method.h index 8c5029204f4a31dbb6fd017c79b8d00d47d0da15..3a57a387f49015649f01a01e60a1a71a5e92b600 100644 --- a/runtime/js_method.h +++ b/runtime/js_method.h @@ -43,19 +43,18 @@ public: return static_cast(method); } - explicit JSMethod(Class *klass, const panda_file::File *pf, panda_file::File::EntityId file_id, - panda_file::File::EntityId code_id, uint32_t access_flags, uint32_t num_args, - const uint16_t *shorty) - : Method(klass, pf, file_id, code_id, access_flags, num_args, shorty) + explicit JSMethod(Class *klass, const panda_file::File *pf, panda_file::File::EntityId fileId, + panda_file::File::EntityId codeId, uint32_t accessFlags, uint32_t numArgs, const uint16_t *shorty) + : Method(klass, pf, fileId, codeId, accessFlags, numArgs, shorty) { - bytecode_array_ = JSMethod::GetInstructions(); - bytecode_array_size_ = JSMethod::GetCodeSize(); + bytecodeArray_ = JSMethod::GetInstructions(); + bytecodeArraySize_ = JSMethod::GetCodeSize(); } explicit JSMethod(const Method *method) : Method(method) { - bytecode_array_ = JSMethod::GetInstructions(); - bytecode_array_size_ = JSMethod::GetCodeSize(); + bytecodeArray_ = JSMethod::GetInstructions(); + bytecodeArraySize_ = JSMethod::GetCodeSize(); } JSMethod() = delete; @@ -67,61 +66,61 @@ public: static constexpr uint32_t GetBytecodeArrayOffset() { - return MEMBER_OFFSET(JSMethod, bytecode_array_); + return MEMBER_OFFSET(JSMethod, bytecodeArray_); } const uint8_t *GetBytecodeArray() const { - return bytecode_array_; + return bytecodeArray_; } uint32_t GetBytecodeArraySize() const { - return bytecode_array_size_; + return bytecodeArraySize_; } void SetBytecodeArray(const uint8_t *bc) { - bytecode_array_ = bc; + bytecodeArray_ = bc; } uint32_t GetSlotSize() const { - return slot_size_; + return slotSize_; } void AddSlotSize(uint32_t size) { - slot_size_ += size; + slotSize_ += size; } ICMappingType GetICMapping() { - return ic_mapping_; + return icMapping_; } ConstICMappingType GetICMapping() const { - return ic_mapping_; + return icMapping_; } void SetICMapping(ICMappingType mapping) { - ic_mapping_ = mapping; + icMapping_ = mapping; } static constexpr size_t GetICMappingOffset() { - return MEMBER_OFFSET(JSMethod, ic_mapping_); + return MEMBER_OFFSET(JSMethod, icMapping_); } uint32_t GetCallType() const { - return call_type_; + return callType_; } PandaString ParseFunctionName() const; - std::string GetFullName([[maybe_unused]] bool with_signature = false) const; + std::string GetFullName([[maybe_unused]] bool withSignature = false) const; void SetCallTypeFromAnnotation(); void InitProfileVector(); @@ -130,23 +129,23 @@ public: uint8_t *GetProfilingVector() const { - return profiling_data_.get(); + return profilingData_.get(); } uint32_t GetProfileSize() const { - return profile_size_; + return profileSize_; } private: - const uint8_t *bytecode_array_ {nullptr}; + const uint8_t *bytecodeArray_ {nullptr}; // NOLINTNEXTLINE(modernize-avoid-c-arrays) - PandaUniquePtr profiling_data_; - uint32_t bytecode_array_size_ {0}; - uint32_t slot_size_ {0}; - ICMappingType ic_mapping_ {nullptr}; - uint32_t call_type_ {UINT32_MAX}; // UINT32_MAX means not found - uint32_t profile_size_ {0}; + PandaUniquePtr profilingData_; + uint32_t bytecodeArraySize_ {0}; + uint32_t slotSize_ {0}; + ICMappingType icMapping_ {nullptr}; + uint32_t callType_ {UINT32_MAX}; // UINT32_MAX means not found + uint32_t profileSize_ {0}; }; } // namespace panda::ecmascript diff --git a/runtime/js_native_pointer.h b/runtime/js_native_pointer.h index 62c8890ed92321b74a779df1c0e61d596846b517..a0170411a1307e11fc6e441d9060859c11c298a2 100644 --- a/runtime/js_native_pointer.h +++ b/runtime/js_native_pointer.h @@ -31,10 +31,10 @@ public: return reinterpret_cast(object); } - inline void ResetExternalPointer(void *external_pointer) + inline void ResetExternalPointer(void *externalPointer) { DeleteExternalPointer(); - SetExternalPointer(external_pointer); + SetExternalPointer(externalPointer); } inline void Destroy() @@ -54,11 +54,11 @@ public: private: inline void DeleteExternalPointer() { - void *external_pointer = GetExternalPointer(); - if (external_pointer != nullptr) { + void *externalPointer = GetExternalPointer(); + if (externalPointer != nullptr) { DeleteEntryPoint deleter = GetDeleter(); if (deleter != nullptr) { - deleter(external_pointer, GetData()); + deleter(externalPointer, GetData()); } } } diff --git a/runtime/js_number_format.cpp b/runtime/js_number_format.cpp index fcf65633976f4c139fd3b2a36522fdeb8e701e68..1173ee04afa8df194734a01ed0ba779222b5c322 100644 --- a/runtime/js_number_format.cpp +++ b/runtime/js_number_format.cpp @@ -22,19 +22,19 @@ constexpr uint32_t PERUNIT_STRING = 5; JSHandle OptionToEcmaString(JSThread *thread, StyleOption style) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); switch (style) { case StyleOption::DECIMAL: - result.Update(global_const->GetHandledDecimalString().GetTaggedValue()); + result.Update(globalConst->GetHandledDecimalString().GetTaggedValue()); break; case StyleOption::CURRENCY: - result.Update(global_const->GetHandledCurrencyString().GetTaggedValue()); + result.Update(globalConst->GetHandledCurrencyString().GetTaggedValue()); break; case StyleOption::PERCENT: - result.Update(global_const->GetHandledPercentString().GetTaggedValue()); + result.Update(globalConst->GetHandledPercentString().GetTaggedValue()); break; case StyleOption::UNIT: - result.Update(global_const->GetHandledUnitString().GetTaggedValue()); + result.Update(globalConst->GetHandledUnitString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -42,22 +42,22 @@ JSHandle OptionToEcmaString(JSThread *thread, StyleOption style) return result; } -JSHandle OptionToEcmaString(JSThread *thread, CurrencyDisplayOption currency_display) +JSHandle OptionToEcmaString(JSThread *thread, CurrencyDisplayOption currencyDisplay) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); - switch (currency_display) { + auto globalConst = thread->GlobalConstants(); + switch (currencyDisplay) { case CurrencyDisplayOption::CODE: - result.Update(global_const->GetHandledCodeString().GetTaggedValue()); + result.Update(globalConst->GetHandledCodeString().GetTaggedValue()); break; case CurrencyDisplayOption::SYMBOL: - result.Update(global_const->GetHandledSymbolString().GetTaggedValue()); + result.Update(globalConst->GetHandledSymbolString().GetTaggedValue()); break; case CurrencyDisplayOption::NARROWSYMBOL: - result.Update(global_const->GetHandledNarrowSymbolString().GetTaggedValue()); + result.Update(globalConst->GetHandledNarrowSymbolString().GetTaggedValue()); break; case CurrencyDisplayOption::NAME: - result.Update(global_const->GetHandledNameString().GetTaggedValue()); + result.Update(globalConst->GetHandledNameString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -65,16 +65,16 @@ JSHandle OptionToEcmaString(JSThread *thread, CurrencyDisplayOpti return result; } -JSHandle OptionToEcmaString(JSThread *thread, CurrencySignOption currency_sign) +JSHandle OptionToEcmaString(JSThread *thread, CurrencySignOption currencySign) { - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); JSMutableHandle result(thread, JSTaggedValue::Undefined()); - switch (currency_sign) { + switch (currencySign) { case CurrencySignOption::STANDARD: - result.Update(global_const->GetHandledStandardString().GetTaggedValue()); + result.Update(globalConst->GetHandledStandardString().GetTaggedValue()); break; case CurrencySignOption::ACCOUNTING: - result.Update(global_const->GetHandledAccountingString().GetTaggedValue()); + result.Update(globalConst->GetHandledAccountingString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -82,19 +82,19 @@ JSHandle OptionToEcmaString(JSThread *thread, CurrencySignOption return result; } -JSHandle OptionToEcmaString(JSThread *thread, UnitDisplayOption unit_display) +JSHandle OptionToEcmaString(JSThread *thread, UnitDisplayOption unitDisplay) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); - switch (unit_display) { + auto globalConst = thread->GlobalConstants(); + switch (unitDisplay) { case UnitDisplayOption::SHORT: - result.Update(global_const->GetHandledShortString().GetTaggedValue()); + result.Update(globalConst->GetHandledShortString().GetTaggedValue()); break; case UnitDisplayOption::NARROW: - result.Update(global_const->GetHandledNarrowString().GetTaggedValue()); + result.Update(globalConst->GetHandledNarrowString().GetTaggedValue()); break; case UnitDisplayOption::LONG: - result.Update(global_const->GetHandledLongString().GetTaggedValue()); + result.Update(globalConst->GetHandledLongString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -105,19 +105,19 @@ JSHandle OptionToEcmaString(JSThread *thread, UnitDisplayOption u JSHandle OptionToEcmaString(JSThread *thread, NotationOption notation) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); switch (notation) { case NotationOption::STANDARD: - result.Update(global_const->GetHandledStandardString().GetTaggedValue()); + result.Update(globalConst->GetHandledStandardString().GetTaggedValue()); break; case NotationOption::SCIENTIFIC: - result.Update(global_const->GetHandledScientificString().GetTaggedValue()); + result.Update(globalConst->GetHandledScientificString().GetTaggedValue()); break; case NotationOption::ENGINEERING: - result.Update(global_const->GetHandledEngineeringString().GetTaggedValue()); + result.Update(globalConst->GetHandledEngineeringString().GetTaggedValue()); break; case NotationOption::COMPACT: - result.Update(global_const->GetHandledCompactString().GetTaggedValue()); + result.Update(globalConst->GetHandledCompactString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -125,16 +125,16 @@ JSHandle OptionToEcmaString(JSThread *thread, NotationOption nota return result; } -JSHandle OptionToEcmaString(JSThread *thread, CompactDisplayOption compact_display) +JSHandle OptionToEcmaString(JSThread *thread, CompactDisplayOption compactDisplay) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); - switch (compact_display) { + auto globalConst = thread->GlobalConstants(); + switch (compactDisplay) { case CompactDisplayOption::SHORT: - result.Update(global_const->GetHandledShortString().GetTaggedValue()); + result.Update(globalConst->GetHandledShortString().GetTaggedValue()); break; case CompactDisplayOption::LONG: - result.Update(global_const->GetHandledLongString().GetTaggedValue()); + result.Update(globalConst->GetHandledLongString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -142,22 +142,22 @@ JSHandle OptionToEcmaString(JSThread *thread, CompactDisplayOptio return result; } -JSHandle OptionToEcmaString(JSThread *thread, SignDisplayOption sign_display) +JSHandle OptionToEcmaString(JSThread *thread, SignDisplayOption signDisplay) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); - auto global_const = thread->GlobalConstants(); - switch (sign_display) { + auto globalConst = thread->GlobalConstants(); + switch (signDisplay) { case SignDisplayOption::AUTO: - result.Update(global_const->GetHandledAutoString().GetTaggedValue()); + result.Update(globalConst->GetHandledAutoString().GetTaggedValue()); break; case SignDisplayOption::ALWAYS: - result.Update(global_const->GetHandledAlwaysString().GetTaggedValue()); + result.Update(globalConst->GetHandledAlwaysString().GetTaggedValue()); break; case SignDisplayOption::NEVER: - result.Update(global_const->GetHandledNeverString().GetTaggedValue()); + result.Update(globalConst->GetHandledNeverString().GetTaggedValue()); break; case SignDisplayOption::EXCEPTZERO: - result.Update(global_const->GetHandledExceptZeroString().GetTaggedValue()); + result.Update(globalConst->GetHandledExceptZeroString().GetTaggedValue()); break; default: UNREACHABLE(); @@ -165,7 +165,7 @@ JSHandle OptionToEcmaString(JSThread *thread, SignDisplayOption s return result; } -icu::MeasureUnit ToMeasureUnit(const std::string &sanctioned_unit) +icu::MeasureUnit ToMeasureUnit(const std::string &sanctionedUnit) { UErrorCode status = U_ZERO_ERROR; // Get All ICU measure unit @@ -178,7 +178,7 @@ icu::MeasureUnit ToMeasureUnit(const std::string &sanctioned_unit) // Find measure unit according to sanctioned unit // then return measure unit for (auto &unit : units) { - if (std::strcmp(sanctioned_unit.c_str(), unit.getSubtype()) == 0) { + if (std::strcmp(sanctionedUnit.c_str(), unit.getSubtype()) == 0) { return unit; } } @@ -195,24 +195,24 @@ bool IsSanctionedSimpleUnitIdentifier(const std::string &unit) } // 6.5.1 IsWellFormedUnitIdentifier ( unitIdentifier ) -bool IsWellFormedUnitIdentifier(const std::string &unit, icu::MeasureUnit &icu_unit, icu::MeasureUnit &icu_per_unit) +bool IsWellFormedUnitIdentifier(const std::string &unit, icu::MeasureUnit &icuUnit, icu::MeasureUnit &icuPerUnit) { // 1. If the result of IsSanctionedSimpleUnitIdentifier(unitIdentifier) is true, then // a. Return true. icu::MeasureUnit result = icu::MeasureUnit(); - icu::MeasureUnit empty_unit = icu::MeasureUnit(); + icu::MeasureUnit emptyUnit = icu::MeasureUnit(); auto pos = unit.find("-per-"); if (IsSanctionedSimpleUnitIdentifier(unit) && pos == std::string::npos) { result = ToMeasureUnit(unit); - icu_unit = result; - icu_per_unit = empty_unit; + icuUnit = result; + icuPerUnit = emptyUnit; return true; } // 2. If the substring "-per-" does not occur exactly once in unitIdentifier, // a. then false - size_t after_pos = pos + PERUNIT_STRING; - if (pos == std::string::npos || unit.find("-per-", after_pos) != std::string::npos) { + size_t afterPos = pos + PERUNIT_STRING; + if (pos == std::string::npos || unit.find("-per-", afterPos) != std::string::npos) { return false; } @@ -231,159 +231,157 @@ bool IsWellFormedUnitIdentifier(const std::string &unit, icu::MeasureUnit &icu_u // 6. If the result of IsSanctionedUnitIdentifier(denominator) is false, then // a. Return false - icu::MeasureUnit per_result = icu::MeasureUnit(); + icu::MeasureUnit perResult = icu::MeasureUnit(); if (IsSanctionedSimpleUnitIdentifier(denominator)) { - per_result = ToMeasureUnit(denominator); + perResult = ToMeasureUnit(denominator); } else { return false; } // 7. Return true. - icu_unit = result; - icu_per_unit = per_result; + icuUnit = result; + icuPerUnit = perResult; return true; } // 12.1.13 SetNumberFormatUnitOptions ( intlObj, options ) -FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, const JSHandle &number_format, - const JSHandle &options_object, - icu::number::LocalizedNumberFormatter *icu_number_formatter) +FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, const JSHandle &numberFormat, + const JSHandle &optionsObject, + icu::number::LocalizedNumberFormatter *icuNumberFormatter) { - auto global_const = thread->GlobalConstants(); - FractionDigitsOption fraction_digits_option; + auto globalConst = thread->GlobalConstants(); + FractionDigitsOption fractionDigitsOption; // 3. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal"). - JSHandle property = global_const->GetHandledStyleString(); + JSHandle property = globalConst->GetHandledStyleString(); auto style = JSLocale::GetOptionOfString( - thread, options_object, property, + thread, optionsObject, property, {StyleOption::DECIMAL, StyleOption::PERCENT, StyleOption::CURRENCY, StyleOption::UNIT}, {"decimal", "percent", "currency", "unit"}, StyleOption::DECIMAL); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fraction_digits_option); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); // 4. Set intlObj.[[Style]] to style. - JSHandle style_value(thread, JSTaggedValue(static_cast(style))); - number_format->SetStyle(thread, style_value); + JSHandle styleValue(thread, JSTaggedValue(static_cast(style))); + numberFormat->SetStyle(thread, styleValue); // 5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined). - property = global_const->GetHandledCurrencyString(); - JSHandle undefined_value(thread, JSTaggedValue::Undefined()); + property = globalConst->GetHandledCurrencyString(); + JSHandle undefinedValue(thread, JSTaggedValue::Undefined()); JSHandle currency = - JSLocale::GetOption(thread, options_object, property, OptionType::STRING, undefined_value, undefined_value); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fraction_digits_option); + JSLocale::GetOption(thread, optionsObject, property, OptionType::STRING, undefinedValue, undefinedValue); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); // 6. If currency is not undefined, then // a. If the result of IsWellFormedCurrencyCode(currency) is false, throw a RangeError exception. if (!currency->IsUndefined()) { - JSHandle currency_str = JSHandle::Cast(currency); - if (currency_str->IsUtf16()) { - THROW_RANGE_ERROR_AND_RETURN(thread, "not a utf-8", fraction_digits_option); + JSHandle currencyStr = JSHandle::Cast(currency); + if (currencyStr->IsUtf16()) { + THROW_RANGE_ERROR_AND_RETURN(thread, "not a utf-8", fractionDigitsOption); } - std::string currency_c_str = JSLocale::ConvertToStdString(currency_str); - if (!JSLocale::IsWellFormedCurrencyCode(currency_c_str)) { - THROW_RANGE_ERROR_AND_RETURN(thread, "not a wellformed code", fraction_digits_option); + std::string currencyCStr = JSLocale::ConvertToStdString(currencyStr); + if (!JSLocale::IsWellFormedCurrencyCode(currencyCStr)) { + THROW_RANGE_ERROR_AND_RETURN(thread, "not a wellformed code", fractionDigitsOption); } } else { // 7. If style is "currency" and currency is undefined, throw a TypeError exception. if (style == StyleOption::CURRENCY) { - THROW_TYPE_ERROR_AND_RETURN(thread, "style is currency but currency is undefined", fraction_digits_option); + THROW_TYPE_ERROR_AND_RETURN(thread, "style is currency but currency is undefined", fractionDigitsOption); } } // 8. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", // « "code", "symbol", "narrowSymbol", "name" », "symbol"). - property = global_const->GetHandledCurrencyDisplayString(); - auto currency_display = JSLocale::GetOptionOfString( - thread, options_object, property, + property = globalConst->GetHandledCurrencyDisplayString(); + auto currencyDisplay = JSLocale::GetOptionOfString( + thread, optionsObject, property, {CurrencyDisplayOption::CODE, CurrencyDisplayOption::SYMBOL, CurrencyDisplayOption::NARROWSYMBOL, CurrencyDisplayOption::NAME}, {"code", "symbol", "narrowSymbol", "name"}, CurrencyDisplayOption::SYMBOL); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fraction_digits_option); - JSHandle currency_display_value(thread, JSTaggedValue(static_cast(currency_display))); - number_format->SetCurrencyDisplay(thread, currency_display_value); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); + JSHandle currencyDisplayValue(thread, JSTaggedValue(static_cast(currencyDisplay))); + numberFormat->SetCurrencyDisplay(thread, currencyDisplayValue); // 9. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard"). - property = global_const->GetHandledCurrencySignString(); - auto currency_sign = JSLocale::GetOptionOfString( - thread, options_object, property, {CurrencySignOption::STANDARD, CurrencySignOption::ACCOUNTING}, + property = globalConst->GetHandledCurrencySignString(); + auto currencySign = JSLocale::GetOptionOfString( + thread, optionsObject, property, {CurrencySignOption::STANDARD, CurrencySignOption::ACCOUNTING}, {"standard", "accounting"}, CurrencySignOption::STANDARD); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fraction_digits_option); - JSHandle currency_sign_value(thread, JSTaggedValue(static_cast(currency_sign))); - number_format->SetCurrencySign(thread, currency_sign_value); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); + JSHandle currencySignValue(thread, JSTaggedValue(static_cast(currencySign))); + numberFormat->SetCurrencySign(thread, currencySignValue); // 10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined). - property = global_const->GetHandledUnitString(); + property = globalConst->GetHandledUnitString(); JSHandle unit = - JSLocale::GetOption(thread, options_object, property, OptionType::STRING, undefined_value, undefined_value); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fraction_digits_option); - number_format->SetUnit(thread, unit); + JSLocale::GetOption(thread, optionsObject, property, OptionType::STRING, undefinedValue, undefinedValue); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); + numberFormat->SetUnit(thread, unit); // 11. If unit is not undefined, then // If the result of IsWellFormedUnitIdentifier(unit) is false, throw a RangeError exception. - icu::MeasureUnit icu_unit; - icu::MeasureUnit icu_per_unit; + icu::MeasureUnit icuUnit; + icu::MeasureUnit icuPerUnit; if (!unit->IsUndefined()) { - JSHandle unit_str = JSHandle::Cast(unit); - if (unit_str->IsUtf16()) { - THROW_RANGE_ERROR_AND_RETURN(thread, "Unit input is illegal", fraction_digits_option); + JSHandle unitStr = JSHandle::Cast(unit); + if (unitStr->IsUtf16()) { + THROW_RANGE_ERROR_AND_RETURN(thread, "Unit input is illegal", fractionDigitsOption); } - std::string str = JSLocale::ConvertToStdString(unit_str); - if (!IsWellFormedUnitIdentifier(str, icu_unit, icu_per_unit)) { - THROW_RANGE_ERROR_AND_RETURN(thread, "Unit input is illegal", fraction_digits_option); + std::string str = JSLocale::ConvertToStdString(unitStr); + if (!IsWellFormedUnitIdentifier(str, icuUnit, icuPerUnit)) { + THROW_RANGE_ERROR_AND_RETURN(thread, "Unit input is illegal", fractionDigitsOption); } } else { // 15.12. if style is "unit" and unit is undefined, throw a TypeError exception. if (style == StyleOption::UNIT) { - THROW_TYPE_ERROR_AND_RETURN(thread, "style is unit but unit is undefined", fraction_digits_option); + THROW_TYPE_ERROR_AND_RETURN(thread, "style is unit but unit is undefined", fractionDigitsOption); } } // 13. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short"). - property = global_const->GetHandledUnitDisplayString(); - auto unit_display = JSLocale::GetOptionOfString( - thread, options_object, property, - {UnitDisplayOption::SHORT, UnitDisplayOption::NARROW, UnitDisplayOption::LONG}, {"short", "narrow", "long"}, - UnitDisplayOption::SHORT); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fraction_digits_option); - JSHandle unit_display_value(thread, JSTaggedValue(static_cast(unit_display))); - number_format->SetUnitDisplay(thread, unit_display_value); + property = globalConst->GetHandledUnitDisplayString(); + auto unitDisplay = JSLocale::GetOptionOfString( + thread, optionsObject, property, {UnitDisplayOption::SHORT, UnitDisplayOption::NARROW, UnitDisplayOption::LONG}, + {"short", "narrow", "long"}, UnitDisplayOption::SHORT); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); + JSHandle unitDisplayValue(thread, JSTaggedValue(static_cast(unitDisplay))); + numberFormat->SetUnitDisplay(thread, unitDisplayValue); // 14. If style is "currency", then // a. Let currency be the result of converting currency to upper case as specified in 6.1. // b. Set intlObj.[[Currency]] to currency. // c. Set intlObj.[[CurrencyDisplay]] to currencyDisplay. // d. Set intlObj.[[CurrencySign]] to currencySign. - icu::UnicodeString currency_u_str; + icu::UnicodeString currencyUStr; UErrorCode status = U_ZERO_ERROR; if (style == StyleOption::CURRENCY) { - JSHandle currency_str = JSHandle::Cast(currency); - std::string currency_c_str = JSLocale::ConvertToStdString(currency_str); - std::transform(currency_c_str.begin(), currency_c_str.end(), currency_c_str.begin(), toupper); + JSHandle currencyStr = JSHandle::Cast(currency); + std::string currencyCStr = JSLocale::ConvertToStdString(currencyStr); + std::transform(currencyCStr.begin(), currencyCStr.end(), currencyCStr.begin(), toupper); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle currency_value = - JSHandle::Cast(factory->NewFromStdString(currency_c_str)); - number_format->SetCurrency(thread, currency_value); - currency_u_str = currency_c_str.c_str(); - if (!currency_u_str.isEmpty()) { // NOLINT(readability-implicit-bool-conversion) - *icu_number_formatter = icu_number_formatter->unit(icu::CurrencyUnit(currency_u_str.getBuffer(), status)); + JSHandle currencyValue = JSHandle::Cast(factory->NewFromStdString(currencyCStr)); + numberFormat->SetCurrency(thread, currencyValue); + currencyUStr = currencyCStr.c_str(); + if (!currencyUStr.isEmpty()) { // NOLINT(readability-implicit-bool-conversion) + *icuNumberFormatter = icuNumberFormatter->unit(icu::CurrencyUnit(currencyUStr.getBuffer(), status)); ASSERT(U_SUCCESS(status)); - UNumberUnitWidth u_number_unit_width; + UNumberUnitWidth uNumberUnitWidth; // Trans currencyDisplayOption to ICU format number display option - switch (currency_display) { + switch (currencyDisplay) { case CurrencyDisplayOption::CODE: - u_number_unit_width = UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE; + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE; break; case CurrencyDisplayOption::SYMBOL: - u_number_unit_width = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT; + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT; break; case CurrencyDisplayOption::NARROWSYMBOL: - u_number_unit_width = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; break; case CurrencyDisplayOption::NAME: - u_number_unit_width = UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME; + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME; break; default: UNREACHABLE(); } - *icu_number_formatter = icu_number_formatter->unitWidth(u_number_unit_width); + *icuNumberFormatter = icuNumberFormatter->unitWidth(uNumberUnitWidth); } } @@ -391,12 +389,12 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, const JSHandle // if unit is not undefiend set unit to LocalizedNumberFormatter // then if perunit is not undefiend set perunit to LocalizedNumberFormatter if (style == StyleOption::UNIT) { - icu::MeasureUnit empty_unit = icu::MeasureUnit(); - if (icu_unit != empty_unit) { // NOLINT(readability-implicit-bool-conversion) - *icu_number_formatter = icu_number_formatter->unit(icu_unit); + icu::MeasureUnit emptyUnit = icu::MeasureUnit(); + if (icuUnit != emptyUnit) { // NOLINT(readability-implicit-bool-conversion) + *icuNumberFormatter = icuNumberFormatter->unit(icuUnit); } - if (icu_per_unit != empty_unit) { // NOLINT(readability-implicit-bool-conversion) - *icu_number_formatter = icu_number_formatter->perUnit(icu_per_unit); + if (icuPerUnit != emptyUnit) { // NOLINT(readability-implicit-bool-conversion) + *icuNumberFormatter = icuNumberFormatter->perUnit(icuPerUnit); } } @@ -405,9 +403,9 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, const JSHandle // b. Let mnfdDefault be cDigits. // c. Let mxfdDefault be cDigits. if (style == StyleOption::CURRENCY) { - int32_t c_digits = JSNumberFormat::CurrencyDigits(currency_u_str); - fraction_digits_option.mnfd_default = c_digits; - fraction_digits_option.mxfd_default = c_digits; + int32_t cDigits = JSNumberFormat::CurrencyDigits(currencyUStr); + fractionDigitsOption.mnfdDefault = cDigits; + fractionDigitsOption.mxfdDefault = cDigits; } else { // 18. Else, // a. Let mnfdDefault be 0. @@ -415,172 +413,171 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, const JSHandle // i. Let mxfdDefault be 0. // c. else, // i. Let mxfdDefault be 3. - fraction_digits_option.mnfd_default = 0; + fractionDigitsOption.mnfdDefault = 0; if (style == StyleOption::PERCENT) { - fraction_digits_option.mxfd_default = 0; + fractionDigitsOption.mxfdDefault = 0; } else { - fraction_digits_option.mxfd_default = 3; // Max decimal precision is 3 + fractionDigitsOption.mxfdDefault = 3; // Max decimal precision is 3 } } - return fraction_digits_option; + return fractionDigitsOption; } // 12.1.2 InitializeNumberFormat ( numberFormat, locales, options ) // NOLINTNEXTLINE(readability-function-size) -void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle &number_format, +void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle &numberFormat, const JSHandle &locales, const JSHandle &options) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); // 2. If options is undefined, then // a. Let options be ObjectCreate(null). // 3. Else, // a. Let options be ? ToObject(options). - JSHandle options_object; + JSHandle optionsObject; if (options->IsUndefined()) { - options_object = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); + optionsObject = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); } else { - options_object = JSTaggedValue::ToObject(thread, options); + optionsObject = JSTaggedValue::ToObject(thread, options); RETURN_IF_ABRUPT_COMPLETION(thread); } - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - JSHandle property = global_const->GetHandledLocaleMatcherString(); + JSHandle property = globalConst->GetHandledLocaleMatcherString(); auto matcher = JSLocale::GetOptionOfString( - thread, options_object, property, {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, + thread, optionsObject, property, {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); RETURN_IF_ABRUPT_COMPLETION(thread); // 7. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). - property = global_const->GetHandledNumberingSystemString(); - JSHandle undefined_value(thread, JSTaggedValue::Undefined()); - JSHandle numbering_system_tagged_value = - JSLocale::GetOption(thread, options_object, property, OptionType::STRING, undefined_value, undefined_value); + property = globalConst->GetHandledNumberingSystemString(); + JSHandle undefinedValue(thread, JSTaggedValue::Undefined()); + JSHandle numberingSystemTaggedValue = + JSLocale::GetOption(thread, optionsObject, property, OptionType::STRING, undefinedValue, undefinedValue); RETURN_IF_ABRUPT_COMPLETION(thread); - number_format->SetNumberingSystem(thread, numbering_system_tagged_value); + numberFormat->SetNumberingSystem(thread, numberingSystemTaggedValue); // 8. If numberingSystem is not undefined, then // a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, // throw a RangeError exception. `(3*8alphanum) *("-" (3*8alphanum))` - std::string numbering_system_str; - if (!numbering_system_tagged_value->IsUndefined()) { - JSHandle numbering_system_ecma_string = JSHandle::Cast(numbering_system_tagged_value); - if (numbering_system_ecma_string->IsUtf16()) { + std::string numberingSystemStr; + if (!numberingSystemTaggedValue->IsUndefined()) { + JSHandle numberingSystemEcmaString = JSHandle::Cast(numberingSystemTaggedValue); + if (numberingSystemEcmaString->IsUtf16()) { THROW_RANGE_ERROR(thread, "invalid numberingSystem"); } - numbering_system_str = JSLocale::ConvertToStdString(numbering_system_ecma_string); - if (!JSLocale::IsNormativeNumberingSystem(numbering_system_str)) { + numberingSystemStr = JSLocale::ConvertToStdString(numberingSystemEcmaString); + if (!JSLocale::IsNormativeNumberingSystem(numberingSystemStr)) { THROW_RANGE_ERROR(thread, "invalid numberingSystem"); } } // 10. Let localeData be %NumberFormat%.[[LocaleData]]. - JSHandle available_locales; - if (requested_locales->GetLength() == 0) { - available_locales = factory->EmptyArray(); + JSHandle availableLocales; + if (requestedLocales->GetLength() == 0) { + availableLocales = factory->EmptyArray(); } else { - available_locales = GetAvailableLocales(thread); + availableLocales = GetAvailableLocales(thread); } // 11. Let r be ResolveLocale( %NumberFormat%.[[AvailableLocales]], requestedLocales, opt, // %NumberFormat%.[[RelevantExtensionKeys]], localeData). - std::set relevant_extension_keys {"nu"}; + std::set relevantExtensionKeys {"nu"}; ResolvedLocale r = - JSLocale::ResolveLocale(thread, available_locales, requested_locales, matcher, relevant_extension_keys); + JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys); // 12. Set numberFormat.[[Locale]] to r.[[locale]]. - icu::Locale icu_locale = r.locale_data; - JSHandle locale_str = JSLocale::ToLanguageTag(thread, icu_locale); - number_format->SetLocale(thread, locale_str.GetTaggedValue()); + icu::Locale icuLocale = r.localeData; + JSHandle localeStr = JSLocale::ToLanguageTag(thread, icuLocale); + numberFormat->SetLocale(thread, localeStr.GetTaggedValue()); // Set numberingSystemStr to UnicodeKeyWord "nu" UErrorCode status = U_ZERO_ERROR; - if (!numbering_system_str.empty()) { - if (JSLocale::IsWellNumberingSystem(numbering_system_str)) { - icu_locale.setUnicodeKeywordValue("nu", numbering_system_str, status); + if (!numberingSystemStr.empty()) { + if (JSLocale::IsWellNumberingSystem(numberingSystemStr)) { + icuLocale.setUnicodeKeywordValue("nu", numberingSystemStr, status); ASSERT(U_SUCCESS(status)); } } - icu::number::LocalizedNumberFormatter icu_number_formatter = - icu::number::NumberFormatter::withLocale(icu_locale).roundingMode(UNUM_ROUND_HALFUP); + icu::number::LocalizedNumberFormatter icuNumberFormatter = + icu::number::NumberFormatter::withLocale(icuLocale).roundingMode(UNUM_ROUND_HALFUP); // Get default numbering system associated with the specified locale - std::unique_ptr numbering_system_ptr( - icu::NumberingSystem::createInstance(icu_locale, status)); + std::unique_ptr numberingSystemPtr(icu::NumberingSystem::createInstance(icuLocale, status)); - int32_t mnfd_default = 0; - int32_t mxfd_default = 0; - FractionDigitsOption fraction_options = - SetNumberFormatUnitOptions(thread, number_format, options_object, &icu_number_formatter); + int32_t mnfdDefault = 0; + int32_t mxfdDefault = 0; + FractionDigitsOption fractionOptions = + SetNumberFormatUnitOptions(thread, numberFormat, optionsObject, &icuNumberFormatter); RETURN_IF_ABRUPT_COMPLETION(thread); - mnfd_default = fraction_options.mnfd_default; - mxfd_default = fraction_options.mxfd_default; - JSTaggedValue unit_display_value = number_format->GetUnitDisplay(); - auto unit_display = static_cast(unit_display_value.GetInt()); + mnfdDefault = fractionOptions.mnfdDefault; + mxfdDefault = fractionOptions.mxfdDefault; + JSTaggedValue unitDisplayValue = numberFormat->GetUnitDisplay(); + auto unitDisplay = static_cast(unitDisplayValue.GetInt()); // Trans unitDisplay option to ICU display option - UNumberUnitWidth u_number_unit_width; - switch (unit_display) { + UNumberUnitWidth uNumberUnitWidth; + switch (unitDisplay) { case UnitDisplayOption::SHORT: - u_number_unit_width = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT; + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT; break; case UnitDisplayOption::NARROW: - u_number_unit_width = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; break; case UnitDisplayOption::LONG: // UNUM_UNIT_WIDTH_FULL_NAME Print the full name of the unit, without any abbreviations. - u_number_unit_width = UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME; + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME; break; default: UNREACHABLE(); } - icu_number_formatter = icu_number_formatter.unitWidth(u_number_unit_width); + icuNumberFormatter = icuNumberFormatter.unitWidth(uNumberUnitWidth); // 16. Let style be numberFormat.[[Style]]. - JSTaggedValue style_value = number_format->GetStyle(); - auto style = static_cast(style_value.GetInt()); + JSTaggedValue styleValue = numberFormat->GetStyle(); + auto style = static_cast(styleValue.GetInt()); if (style == StyleOption::PERCENT) { - icu_number_formatter = icu_number_formatter.unit(icu::MeasureUnit::getPercent()) - .scale(icu::number::Scale::powerOfTen(2)); // means 10^2 + icuNumberFormatter = icuNumberFormatter.unit(icu::MeasureUnit::getPercent()) + .scale(icu::number::Scale::powerOfTen(2)); // means 10^2 } // 19. Let notation be ? GetOption( // options, "notation", "string", « "standard", "scientific", "engineering", "compact" », "standard"). - property = global_const->GetHandledNotationString(); + property = globalConst->GetHandledNotationString(); auto notation = JSLocale::GetOptionOfString( - thread, options_object, property, + thread, optionsObject, property, {NotationOption::STANDARD, NotationOption::SCIENTIFIC, NotationOption::ENGINEERING, NotationOption::COMPACT}, {"standard", "scientific", "engineering", "compact"}, NotationOption::STANDARD); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle notation_value(thread, JSTaggedValue(static_cast(notation))); - number_format->SetNotation(thread, notation_value); + JSHandle notationValue(thread, JSTaggedValue(static_cast(notation))); + numberFormat->SetNotation(thread, notationValue); // 21. Perform ? SetNumberFormatDigitOptions(numberFormat, options, mnfdDefault, mxfdDefault, notation). - JSLocale::SetNumberFormatDigitOptions(thread, number_format, JSHandle::Cast(options_object), - mnfd_default, mxfd_default, notation); - icu_number_formatter = SetICUFormatterDigitOptions(icu_number_formatter, number_format); + JSLocale::SetNumberFormatDigitOptions(thread, numberFormat, JSHandle::Cast(optionsObject), + mnfdDefault, mxfdDefault, notation); + icuNumberFormatter = SetICUFormatterDigitOptions(icuNumberFormatter, numberFormat); // 22. Let compactDisplay be ? GetOptionOfString(options, "compactDisplay", "string", « "short", "long" », "short"). - property = global_const->GetHandledCompactDisplayString(); - auto compact_display = JSLocale::GetOptionOfString( - thread, options_object, property, {CompactDisplayOption::SHORT, CompactDisplayOption::LONG}, {"short", "long"}, + property = globalConst->GetHandledCompactDisplayString(); + auto compactDisplay = JSLocale::GetOptionOfString( + thread, optionsObject, property, {CompactDisplayOption::SHORT, CompactDisplayOption::LONG}, {"short", "long"}, CompactDisplayOption::SHORT); - JSHandle compact_display_value(thread, JSTaggedValue(static_cast(compact_display))); - number_format->SetCompactDisplay(thread, compact_display_value); + JSHandle compactDisplayValue(thread, JSTaggedValue(static_cast(compactDisplay))); + numberFormat->SetCompactDisplay(thread, compactDisplayValue); // Trans NotationOption to ICU Noation and set to icuNumberFormatter if (notation == NotationOption::COMPACT) { - switch (compact_display) { + switch (compactDisplay) { case CompactDisplayOption::SHORT: - icu_number_formatter = icu_number_formatter.notation(icu::number::Notation::compactShort()); + icuNumberFormatter = icuNumberFormatter.notation(icu::number::Notation::compactShort()); break; case CompactDisplayOption::LONG: - icu_number_formatter = icu_number_formatter.notation(icu::number::Notation::compactLong()); + icuNumberFormatter = icuNumberFormatter.notation(icu::number::Notation::compactLong()); break; default: break; @@ -588,76 +585,76 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetHandledUserGroupingString(); - bool use_grouping = false; - [[maybe_unused]] bool find = JSLocale::GetOptionOfBool(thread, options_object, property, true, &use_grouping); + property = globalConst->GetHandledUserGroupingString(); + bool useGrouping = false; + [[maybe_unused]] bool find = JSLocale::GetOptionOfBool(thread, optionsObject, property, true, &useGrouping); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle use_grouping_value(thread, JSTaggedValue(use_grouping)); - number_format->SetUseGrouping(thread, use_grouping_value); + JSHandle useGroupingValue(thread, JSTaggedValue(useGrouping)); + numberFormat->SetUseGrouping(thread, useGroupingValue); // 25. Set numberFormat.[[UseGrouping]] to useGrouping. - if (!use_grouping) { - icu_number_formatter = icu_number_formatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_OFF); + if (!useGrouping) { + icuNumberFormatter = icuNumberFormatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_OFF); } // 26. Let signDisplay be ? // GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero" », "auto"). - property = global_const->GetHandledSignDisplayString(); - auto sign_display = JSLocale::GetOptionOfString( - thread, options_object, property, + property = globalConst->GetHandledSignDisplayString(); + auto signDisplay = JSLocale::GetOptionOfString( + thread, optionsObject, property, {SignDisplayOption::AUTO, SignDisplayOption::NEVER, SignDisplayOption::ALWAYS, SignDisplayOption::EXCEPTZERO}, {"auto", "never", "always", "exceptZero"}, SignDisplayOption::AUTO); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle sign_display_value(thread, JSTaggedValue(static_cast(sign_display))); - number_format->SetSignDisplay(thread, sign_display_value); + JSHandle signDisplayValue(thread, JSTaggedValue(static_cast(signDisplay))); + numberFormat->SetSignDisplay(thread, signDisplayValue); // 27. Set numberFormat.[[SignDisplay]] to signDisplay. // The default sign in ICU is UNUM_SIGN_AUTO which is mapped from // SignDisplay::AUTO and CurrencySign::STANDARD so we can skip setting // under that values for optimization. - JSTaggedValue currency_sign_value = number_format->GetCurrencySign(); - auto currency_sign = static_cast(currency_sign_value.GetInt()); + JSTaggedValue currencySignValue = numberFormat->GetCurrencySign(); + auto currencySign = static_cast(currencySignValue.GetInt()); // Trans SignDisPlayOption to ICU UNumberSignDisplay and set to icuNumberFormatter - switch (sign_display) { + switch (signDisplay) { case SignDisplayOption::AUTO: // if CurrencySign is ACCOUNTING, Use the locale-dependent accounting format on negative numbers - if (currency_sign == CurrencySignOption::ACCOUNTING) { - icu_number_formatter = icu_number_formatter.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING); + if (currencySign == CurrencySignOption::ACCOUNTING) { + icuNumberFormatter = icuNumberFormatter.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING); } else { - icu_number_formatter = icu_number_formatter.sign(UNumberSignDisplay::UNUM_SIGN_AUTO); + icuNumberFormatter = icuNumberFormatter.sign(UNumberSignDisplay::UNUM_SIGN_AUTO); } break; case SignDisplayOption::NEVER: - icu_number_formatter = icu_number_formatter.sign(UNumberSignDisplay::UNUM_SIGN_NEVER); + icuNumberFormatter = icuNumberFormatter.sign(UNumberSignDisplay::UNUM_SIGN_NEVER); break; case SignDisplayOption::ALWAYS: // if CurrencySign is ACCOUNTING, Use the locale-dependent accounting format on negative numbers - if (currency_sign == CurrencySignOption::ACCOUNTING) { - icu_number_formatter = icu_number_formatter.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS); + if (currencySign == CurrencySignOption::ACCOUNTING) { + icuNumberFormatter = icuNumberFormatter.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS); } else { - icu_number_formatter = icu_number_formatter.sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS); + icuNumberFormatter = icuNumberFormatter.sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS); } break; case SignDisplayOption::EXCEPTZERO: // if CurrencySign is ACCOUNTING, Use the locale-dependent accounting format on negative numbers - if (currency_sign == CurrencySignOption::ACCOUNTING) { - icu_number_formatter = icu_number_formatter.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO); + if (currencySign == CurrencySignOption::ACCOUNTING) { + icuNumberFormatter = icuNumberFormatter.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO); } else { - icu_number_formatter = icu_number_formatter.sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO); + icuNumberFormatter = icuNumberFormatter.sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO); } break; default: @@ -665,9 +662,9 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleNewJSIntlIcuData(number_format, icu_number_formatter, JSNumberFormat::FreeIcuNumberformat); + factory->NewJSIntlIcuData(numberFormat, icuNumberFormatter, JSNumberFormat::FreeIcuNumberformat); // Set numberFormat.[[BoundFormat]] to undefinedValue - number_format->SetBoundFormat(thread, undefined_value); + numberFormat->SetBoundFormat(thread, undefinedValue); } // 12.1.3 CurrencyDigits ( currency ) @@ -676,66 +673,66 @@ int32_t JSNumberFormat::CurrencyDigits(const icu::UnicodeString ¤cy) UErrorCode status = U_ZERO_ERROR; // If the ISO 4217 currency and funds code list contains currency as an alphabetic code, // return the minor unit value corresponding to the currency from the list; otherwise, return 2. - int32_t fraction_digits = + int32_t fractionDigits = ucurr_getDefaultFractionDigits(reinterpret_cast(currency.getBuffer()), &status); if (U_SUCCESS(status) != 0) { - return fraction_digits; + return fractionDigits; } return DEFAULT_FRACTION_DIGITS; } // 12.1.8 FormatNumeric( numberFormat, x ) -JSHandle JSNumberFormat::FormatNumeric(JSThread *thread, const JSHandle &number_format, +JSHandle JSNumberFormat::FormatNumeric(JSThread *thread, const JSHandle &numberFormat, JSTaggedValue x) { - icu::number::LocalizedNumberFormatter *icu_number_format = number_format->GetIcuCallTarget(); - ASSERT(icu_number_format != nullptr); + icu::number::LocalizedNumberFormatter *icuNumberFormat = numberFormat->GetIcuCallTarget(); + ASSERT(icuNumberFormat != nullptr); UErrorCode status = U_ZERO_ERROR; - icu::number::FormattedNumber formatted_number; + icu::number::FormattedNumber formattedNumber; if (x.IsBigInt()) { [[maybe_unused]] EcmaHandleScope scope(thread); JSHandle bigint(thread, x); - JSHandle bigint_str = BigInt::ToString(thread, bigint); - std::string std_string = bigint_str->GetCString().get(); - formatted_number = icu_number_format->formatDecimal(icu::StringPiece(std_string), status); + JSHandle bigintStr = BigInt::ToString(thread, bigint); + std::string stdString = bigintStr->GetCString().get(); + formattedNumber = icuNumberFormat->formatDecimal(icu::StringPiece(stdString), status); } else { double number = x.GetNumber(); - formatted_number = icu_number_format->formatDouble(number, status); + formattedNumber = icuNumberFormat->formatDouble(number, status); } if (U_FAILURE(status) != 0) { - JSHandle error_result(thread, JSTaggedValue::Exception()); - THROW_RANGE_ERROR_AND_RETURN(thread, "icu formatter format failed", error_result); + JSHandle errorResult(thread, JSTaggedValue::Exception()); + THROW_RANGE_ERROR_AND_RETURN(thread, "icu formatter format failed", errorResult); } - icu::UnicodeString result = formatted_number.toString(status); + icu::UnicodeString result = formattedNumber.toString(status); if (U_FAILURE(status) != 0) { - JSHandle error_result(thread, JSTaggedValue::Exception()); - THROW_RANGE_ERROR_AND_RETURN(thread, "formatted number toString failed", error_result); + JSHandle errorResult(thread, JSTaggedValue::Exception()); + THROW_RANGE_ERROR_AND_RETURN(thread, "formatted number toString failed", errorResult); } - JSHandle string_value = JSLocale::IcuToString(thread, result); - return JSHandle::Cast(string_value); + JSHandle stringValue = JSLocale::IcuToString(thread, result); + return JSHandle::Cast(stringValue); } void GroupToParts(JSThread *thread, const icu::number::FormattedNumber &formatted, const JSHandle &receiver, - const JSHandle &number_format, JSTaggedValue x) + const JSHandle &numberFormat, JSTaggedValue x) { UErrorCode status = U_ZERO_ERROR; - icu::UnicodeString formatted_text = formatted.toString(status); + icu::UnicodeString formattedText = formatted.toString(status); if (U_FAILURE(status) != 0) { // NOLINT(readability-implicit-bool-conversion) THROW_TYPE_ERROR(thread, "formattedNumber toString failed"); } ASSERT(x.IsNumber()); - StyleOption style_option = static_cast(number_format->GetStyle().GetInt()); + StyleOption styleOption = static_cast(numberFormat->GetStyle().GetInt()); icu::ConstrainedFieldPosition cfpo; // Set constrainCategory to UFIELD_CATEGORY_NUMBER which is specified for UNumberFormatFields cfpo.constrainCategory(UFIELD_CATEGORY_NUMBER); - auto global_const = thread->GlobalConstants(); - JSMutableHandle type_string(thread, JSTaggedValue::Undefined()); + auto globalConst = thread->GlobalConstants(); + JSMutableHandle typeString(thread, JSTaggedValue::Undefined()); int index = 0; - int previous_limit = 0; + int previousLimit = 0; /** * From ICU header file document @unumberformatter.h * Sets a constraint on the field category. @@ -753,93 +750,93 @@ void GroupToParts(JSThread *thread, const icu::number::FormattedNumber &formatte * // handle the number-related field position * } */ - bool last_field_group = false; - int group_leap_length = 0; + bool lastFieldGroup = false; + int groupLeapLength = 0; while (formatted.nextPosition(cfpo, status) != 0) { - int32_t field_id = cfpo.getField(); + int32_t fieldId = cfpo.getField(); int32_t start = cfpo.getStart(); int32_t limit = cfpo.getLimit(); - type_string.Update(global_const->GetLiteralString()); + typeString.Update(globalConst->GetLiteralString()); // If start greater than previousLimit, means a literal type exists before number fields // so add a literal type with value of formattedText.sub(0, start) // Special case when fieldId is UNUM_GROUPING_SEPARATOR_FIELD - if (static_cast(field_id) == UNUM_GROUPING_SEPARATOR_FIELD) { - JSHandle substring = JSLocale::IcuToString(thread, formatted_text, previous_limit, start); - type_string.Update(global_const->GetIntegerString()); - JSLocale::PutElement(thread, index, receiver, type_string, JSHandle::Cast(substring)); + if (static_cast(fieldId) == UNUM_GROUPING_SEPARATOR_FIELD) { + JSHandle substring = JSLocale::IcuToString(thread, formattedText, previousLimit, start); + typeString.Update(globalConst->GetIntegerString()); + JSLocale::PutElement(thread, index, receiver, typeString, JSHandle::Cast(substring)); RETURN_IF_ABRUPT_COMPLETION(thread); index++; { // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue // (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - type_string.Update(JSLocale::GetNumberFieldType(thread, x, field_id).GetTaggedValue()); - substring = JSLocale::IcuToString(thread, formatted_text, start, limit); - JSLocale::PutElement(thread, index, receiver, type_string, JSHandle::Cast(substring)); + typeString.Update(JSLocale::GetNumberFieldType(thread, x, fieldId).GetTaggedValue()); + substring = JSLocale::IcuToString(thread, formattedText, start, limit); + JSLocale::PutElement(thread, index, receiver, typeString, JSHandle::Cast(substring)); RETURN_IF_ABRUPT_COMPLETION(thread); index++; } - last_field_group = true; - group_leap_length = start - previous_limit + 1; - previous_limit = limit; + lastFieldGroup = true; + groupLeapLength = start - previousLimit + 1; + previousLimit = limit; continue; } - if (start > previous_limit) { - JSHandle substring = JSLocale::IcuToString(thread, formatted_text, previous_limit, start); - JSLocale::PutElement(thread, index, receiver, type_string, JSHandle::Cast(substring)); + if (start > previousLimit) { + JSHandle substring = JSLocale::IcuToString(thread, formattedText, previousLimit, start); + JSLocale::PutElement(thread, index, receiver, typeString, JSHandle::Cast(substring)); RETURN_IF_ABRUPT_COMPLETION(thread); index++; } - if (last_field_group) { - start = start + group_leap_length; - last_field_group = false; + if (lastFieldGroup) { + start = start + groupLeapLength; + lastFieldGroup = false; } // Special case in ICU when style is unit and unit is percent - if (style_option == StyleOption::UNIT && static_cast(field_id) == UNUM_PERCENT_FIELD) { - type_string.Update(global_const->GetUnitString()); + if (styleOption == StyleOption::UNIT && static_cast(fieldId) == UNUM_PERCENT_FIELD) { + typeString.Update(globalConst->GetUnitString()); } else { // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - type_string.Update(JSLocale::GetNumberFieldType(thread, x, field_id).GetTaggedValue()); + typeString.Update(JSLocale::GetNumberFieldType(thread, x, fieldId).GetTaggedValue()); } - JSHandle substring = JSLocale::IcuToString(thread, formatted_text, start, limit); - JSLocale::PutElement(thread, index, receiver, type_string, JSHandle::Cast(substring)); + JSHandle substring = JSLocale::IcuToString(thread, formattedText, start, limit); + JSLocale::PutElement(thread, index, receiver, typeString, JSHandle::Cast(substring)); RETURN_IF_ABRUPT_COMPLETION(thread); index++; - previous_limit = limit; + previousLimit = limit; } // If iterated length is smaller than formattedText.length, means a literal type exists after number fields // so add a literal type with value of formattedText.sub(previousLimit, formattedText.length) - if (formatted_text.length() > previous_limit) { - type_string.Update(global_const->GetLiteralString()); + if (formattedText.length() > previousLimit) { + typeString.Update(globalConst->GetLiteralString()); JSHandle substring = - JSLocale::IcuToString(thread, formatted_text, previous_limit, formatted_text.length()); - JSLocale::PutElement(thread, index, receiver, type_string, JSHandle::Cast(substring)); + JSLocale::IcuToString(thread, formattedText, previousLimit, formattedText.length()); + JSLocale::PutElement(thread, index, receiver, typeString, JSHandle::Cast(substring)); } } // 12.1.9 FormatNumericToParts( numberFormat, x ) -JSHandle JSNumberFormat::FormatNumericToParts(JSThread *thread, const JSHandle &number_format, +JSHandle JSNumberFormat::FormatNumericToParts(JSThread *thread, const JSHandle &numberFormat, JSTaggedValue x) { ASSERT(x.IsNumber()); - icu::number::LocalizedNumberFormatter *icu_number_formatter = number_format->GetIcuCallTarget(); - ASSERT(icu_number_formatter != nullptr); + icu::number::LocalizedNumberFormatter *icuNumberFormatter = numberFormat->GetIcuCallTarget(); + ASSERT(icuNumberFormatter != nullptr); UErrorCode status = U_ZERO_ERROR; double number = x.GetNumber(); - icu::number::FormattedNumber formatted_number = icu_number_formatter->formatDouble(number, status); + icu::number::FormattedNumber formattedNumber = icuNumberFormatter->formatDouble(number, status); if (U_FAILURE(status) != 0) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle empty_array = factory->NewJSArray(); - THROW_RANGE_ERROR_AND_RETURN(thread, "icu formatter format failed", empty_array); + JSHandle emptyArray = factory->NewJSArray(); + THROW_RANGE_ERROR_AND_RETURN(thread, "icu formatter format failed", emptyArray); } JSHandle arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)); JSHandle result = JSHandle::Cast(arr); // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - GroupToParts(thread, formatted_number, result, number_format, x); + GroupToParts(thread, formattedNumber, result, numberFormat, x); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); return result; } @@ -853,21 +850,21 @@ JSHandle JSNumberFormat::UnwrapNumberFormat(JSThread *thread, con // 2. If nf does not have an [[InitializedNumberFormat]] internal slot and ? // InstanceofOperator(nf, %NumberFormat%) is true, then Let nf be ? Get(nf, %Intl%.[[FallbackSymbol]]). JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - bool has_istance = JSObject::InstanceOf(thread, nf, env->GetNumberFormatFunction()); + bool hasIstance = JSObject::InstanceOf(thread, nf, env->GetNumberFormatFunction()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Undefined())); - bool is_js_number_format = nf->IsJSNumberFormat(); + bool isJsNumberFormat = nf->IsJSNumberFormat(); // If nf does not have an [[InitializedNumberFormat]] internal slot and ? // InstanceofOperator(nf, %NumberFormat%) is true, then // a. Let nf be ? Get(nf, %Intl%.[[FallbackSymbol]]). - if (!is_js_number_format && has_istance) { + if (!isJsNumberFormat && hasIstance) { JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - OperationResult operation_result = JSTaggedValue::GetProperty(thread, nf, key); + OperationResult operationResult = JSTaggedValue::GetProperty(thread, nf, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Undefined())); - return operation_result.GetValue(); + return operationResult.GetValue(); } // 3. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]). - if (!is_js_number_format) { + if (!isJsNumberFormat) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSHandle(thread, JSTaggedValue::Exception())); } @@ -877,18 +874,18 @@ JSHandle JSNumberFormat::UnwrapNumberFormat(JSThread *thread, con JSHandle JSNumberFormat::GetAvailableLocales(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle number_format_locales = env->GetNumberFormatLocales(); - if (!number_format_locales->IsUndefined()) { - return JSHandle::Cast(number_format_locales); + JSHandle numberFormatLocales = env->GetNumberFormatLocales(); + if (!numberFormatLocales->IsUndefined()) { + return JSHandle::Cast(numberFormatLocales); } const char *key = "NumberElements"; const char *path = nullptr; - JSHandle available_locales = JSLocale::GetAvailableLocales(thread, key, path); - env->SetNumberFormatLocales(thread, available_locales); - return available_locales; + JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, key, path); + env->SetNumberFormatLocales(thread, availableLocales); + return availableLocales; } -void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandle &number_format, +void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandle &numberFormat, const JSHandle &options) { // Table 5: Resolved Options of NumberFormat Instances @@ -911,113 +908,113 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGlobalConstants(); - JSHandle property = global_const->GetHandledLocaleString(); - JSHandle locale(thread, number_format->GetLocale()); + auto globalConst = thread->GlobalConstants(); + JSHandle property = globalConst->GetHandledLocaleString(); + JSHandle locale(thread, numberFormat->GetLocale()); JSObject::CreateDataPropertyOrThrow(thread, options, property, locale); // [[NumberingSystem]] - JSHandle numbering_system(thread, number_format->GetNumberingSystem()); - if (numbering_system->IsUndefined()) { - numbering_system = global_const->GetHandledLatnString(); + JSHandle numberingSystem(thread, numberFormat->GetNumberingSystem()); + if (numberingSystem->IsUndefined()) { + numberingSystem = globalConst->GetHandledLatnString(); } - property = global_const->GetHandledNumberingSystemString(); - JSObject::CreateDataPropertyOrThrow(thread, options, property, numbering_system); + property = globalConst->GetHandledNumberingSystemString(); + JSObject::CreateDataPropertyOrThrow(thread, options, property, numberingSystem); // [[Style]] - StyleOption style = static_cast(number_format->GetStyle().GetInt()); - property = global_const->GetHandledStyleString(); - JSHandle style_string = OptionToEcmaString(thread, style); - JSObject::CreateDataPropertyOrThrow(thread, options, property, style_string); + StyleOption style = static_cast(numberFormat->GetStyle().GetInt()); + property = globalConst->GetHandledStyleString(); + JSHandle styleString = OptionToEcmaString(thread, style); + JSObject::CreateDataPropertyOrThrow(thread, options, property, styleString); // [[currency]] JSHandle currency(thread, JSTaggedValue::Undefined()); // If style is not currency the currency should be undefined if (style == StyleOption::CURRENCY) { - currency = JSHandle(thread, number_format->GetCurrency()); + currency = JSHandle(thread, numberFormat->GetCurrency()); } if (!currency->IsUndefined()) { // NOLINT(readability-implicit-bool-conversion) - property = global_const->GetHandledCurrencyString(); + property = globalConst->GetHandledCurrencyString(); JSObject::CreateDataPropertyOrThrow(thread, options, property, currency); // [[CurrencyDisplay]] - property = global_const->GetHandledCurrencyDisplayString(); - CurrencyDisplayOption currency_display = - static_cast(number_format->GetCurrencyDisplay().GetInt()); - JSHandle currency_display_string = OptionToEcmaString(thread, currency_display); - JSObject::CreateDataPropertyOrThrow(thread, options, property, currency_display_string); + property = globalConst->GetHandledCurrencyDisplayString(); + CurrencyDisplayOption currencyDisplay = + static_cast(numberFormat->GetCurrencyDisplay().GetInt()); + JSHandle currencyDisplayString = OptionToEcmaString(thread, currencyDisplay); + JSObject::CreateDataPropertyOrThrow(thread, options, property, currencyDisplayString); // [[CurrencySign]] - property = global_const->GetHandledCurrencySignString(); - CurrencySignOption currency_sign = static_cast(number_format->GetCurrencySign().GetInt()); - JSHandle currency_sign_string = OptionToEcmaString(thread, currency_sign); - JSObject::CreateDataPropertyOrThrow(thread, options, property, currency_sign_string); + property = globalConst->GetHandledCurrencySignString(); + CurrencySignOption currencySign = static_cast(numberFormat->GetCurrencySign().GetInt()); + JSHandle currencySignString = OptionToEcmaString(thread, currencySign); + JSObject::CreateDataPropertyOrThrow(thread, options, property, currencySignString); } if (style == StyleOption::UNIT) { - JSHandle unit(thread, number_format->GetUnit()); + JSHandle unit(thread, numberFormat->GetUnit()); if (!unit->IsUndefined()) { // [[Unit]] - property = global_const->GetHandledUnitString(); + property = globalConst->GetHandledUnitString(); JSObject::CreateDataPropertyOrThrow(thread, options, property, unit); } // [[UnitDisplay]] - property = global_const->GetHandledUnitDisplayString(); - UnitDisplayOption unit_display = static_cast(number_format->GetUnitDisplay().GetInt()); - JSHandle unit_display_string = OptionToEcmaString(thread, unit_display); - JSObject::CreateDataPropertyOrThrow(thread, options, property, unit_display_string); + property = globalConst->GetHandledUnitDisplayString(); + UnitDisplayOption unitDisplay = static_cast(numberFormat->GetUnitDisplay().GetInt()); + JSHandle unitDisplayString = OptionToEcmaString(thread, unitDisplay); + JSObject::CreateDataPropertyOrThrow(thread, options, property, unitDisplayString); } // [[MinimumIntegerDigits]] - property = global_const->GetHandledMinimumIntegerDigitsString(); - JSHandle minimum_integer_digits(thread, number_format->GetMinimumIntegerDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, minimum_integer_digits); + property = globalConst->GetHandledMinimumIntegerDigitsString(); + JSHandle minimumIntegerDigits(thread, numberFormat->GetMinimumIntegerDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumIntegerDigits); - RoundingType rounding_type = static_cast(number_format->GetRoundingType().GetInt()); - if (rounding_type == RoundingType::SIGNIFICANTDIGITS) { + RoundingType roundingType = static_cast(numberFormat->GetRoundingType().GetInt()); + if (roundingType == RoundingType::SIGNIFICANTDIGITS) { // [[MinimumSignificantDigits]] - property = global_const->GetHandledMinimumSignificantDigitsString(); - JSHandle minimum_significant_digits(thread, number_format->GetMinimumSignificantDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, minimum_significant_digits); + property = globalConst->GetHandledMinimumSignificantDigitsString(); + JSHandle minimumSignificantDigits(thread, numberFormat->GetMinimumSignificantDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumSignificantDigits); // [[MaximumSignificantDigits]] - property = global_const->GetHandledMaximumSignificantDigitsString(); - JSHandle maximum_significant_digits(thread, number_format->GetMaximumSignificantDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, maximum_significant_digits); + property = globalConst->GetHandledMaximumSignificantDigitsString(); + JSHandle maximumSignificantDigits(thread, numberFormat->GetMaximumSignificantDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumSignificantDigits); } else { // [[MinimumFractionDigits]] - property = global_const->GetHandledMinimumFractionDigitsString(); - JSHandle minimum_fraction_digits(thread, number_format->GetMinimumFractionDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, minimum_fraction_digits); + property = globalConst->GetHandledMinimumFractionDigitsString(); + JSHandle minimumFractionDigits(thread, numberFormat->GetMinimumFractionDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumFractionDigits); // [[MaximumFractionDigits]] - property = global_const->GetHandledMaximumFractionDigitsString(); - JSHandle maximum_fraction_digits(thread, number_format->GetMaximumFractionDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, maximum_fraction_digits); + property = globalConst->GetHandledMaximumFractionDigitsString(); + JSHandle maximumFractionDigits(thread, numberFormat->GetMaximumFractionDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumFractionDigits); } // [[UseGrouping]] - property = global_const->GetHandledUserGroupingString(); + property = globalConst->GetHandledUserGroupingString(); JSObject::CreateDataPropertyOrThrow(thread, options, property, - JSHandle(thread, number_format->GetUseGrouping())); + JSHandle(thread, numberFormat->GetUseGrouping())); // [[Notation]] - property = global_const->GetHandledNotationString(); - NotationOption notation = static_cast(number_format->GetNotation().GetInt()); - JSHandle notation_string = OptionToEcmaString(thread, notation); - JSObject::CreateDataPropertyOrThrow(thread, options, property, notation_string); + property = globalConst->GetHandledNotationString(); + NotationOption notation = static_cast(numberFormat->GetNotation().GetInt()); + JSHandle notationString = OptionToEcmaString(thread, notation); + JSObject::CreateDataPropertyOrThrow(thread, options, property, notationString); // Only output compactDisplay when notation is compact. if (notation == NotationOption::COMPACT) { // [[CompactDisplay]] - property = global_const->GetHandledCompactDisplayString(); - CompactDisplayOption compact_display = - static_cast(number_format->GetCompactDisplay().GetInt()); - JSHandle compact_display_string = OptionToEcmaString(thread, compact_display); - JSObject::CreateDataPropertyOrThrow(thread, options, property, compact_display_string); + property = globalConst->GetHandledCompactDisplayString(); + CompactDisplayOption compactDisplay = + static_cast(numberFormat->GetCompactDisplay().GetInt()); + JSHandle compactDisplayString = OptionToEcmaString(thread, compactDisplay); + JSObject::CreateDataPropertyOrThrow(thread, options, property, compactDisplayString); } // [[SignDisplay]] - property = global_const->GetHandledSignDisplayString(); - SignDisplayOption sign_display = static_cast(number_format->GetSignDisplay().GetInt()); - JSHandle sign_display_string = OptionToEcmaString(thread, sign_display); - JSObject::CreateDataPropertyOrThrow(thread, options, property, sign_display_string); + property = globalConst->GetHandledSignDisplayString(); + SignDisplayOption signDisplay = static_cast(numberFormat->GetSignDisplay().GetInt()); + JSHandle signDisplayString = OptionToEcmaString(thread, signDisplay); + JSObject::CreateDataPropertyOrThrow(thread, options, property, signDisplayString); } } // namespace panda::ecmascript diff --git a/runtime/js_number_format.h b/runtime/js_number_format.h index 6cd901f6bbbc7ecd7bde55750a97a6ceb9dd3c60..90af6c6b9b0290d669bb2e7818e88e69811f5909 100644 --- a/runtime/js_number_format.h +++ b/runtime/js_number_format.h @@ -37,8 +37,8 @@ enum class CurrencySignOption : uint8_t { STANDARD = 0x01, ACCOUNTING, EXCEPTION enum class UnitDisplayOption : uint8_t { SHORT = 0x01, NARROW, LONG, EXCEPTION }; struct FractionDigitsOption { - int32_t mnfd_default = 0; - int32_t mxfd_default = 0; + int32_t mnfdDefault = 0; + int32_t mxfdDefault = 0; }; // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) @@ -99,65 +99,65 @@ public: if (pointer == nullptr) { return; } - auto icu_numberformat = reinterpret_cast(pointer); + auto icuNumberformat = reinterpret_cast(pointer); if (data != nullptr) { - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icu_numberformat); + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuNumberformat); } } // 12.1.2 InitializeNumberFormat ( numberFormat, locales, options ) - static void InitializeNumberFormat(JSThread *thread, const JSHandle &number_format, + static void InitializeNumberFormat(JSThread *thread, const JSHandle &numberFormat, const JSHandle &locales, const JSHandle &options); // 12.1.3 CurrencyDigits ( currency ) static int32_t CurrencyDigits(const icu::UnicodeString ¤cy); // 12.1.8 FormatNumeric( numberFormat, x ) - static JSHandle FormatNumeric(JSThread *thread, const JSHandle &number_format, + static JSHandle FormatNumeric(JSThread *thread, const JSHandle &numberFormat, JSTaggedValue x); // 12.1.9 FormatNumericToParts( numberFormat, x ) - static JSHandle FormatNumericToParts(JSThread *thread, const JSHandle &number_format, + static JSHandle FormatNumericToParts(JSThread *thread, const JSHandle &numberFormat, JSTaggedValue x); // 12.1.12 UnwrapNumberFormat( nf ) static JSHandle UnwrapNumberFormat(JSThread *thread, const JSHandle &nf); static JSHandle GetAvailableLocales(JSThread *thread); - static void ResolvedOptions(JSThread *thread, const JSHandle &number_format, + static void ResolvedOptions(JSThread *thread, const JSHandle &numberFormat, const JSHandle &options); template static icu::number::LocalizedNumberFormatter SetICUFormatterDigitOptions( - icu::number::LocalizedNumberFormatter &icu_numberformatter, const JSHandle &formatter) + icu::number::LocalizedNumberFormatter &icuNumberformatter, const JSHandle &formatter) { - int minimum_integer_digits = formatter->GetMinimumIntegerDigits().GetInt(); + int minimumIntegerDigits = formatter->GetMinimumIntegerDigits().GetInt(); // Set ICU formatter IntegerWidth to MinimumIntegerDigits - icu_numberformatter = - icu_numberformatter.integerWidth(icu::number::IntegerWidth::zeroFillTo(minimum_integer_digits)); + icuNumberformatter = + icuNumberformatter.integerWidth(icu::number::IntegerWidth::zeroFillTo(minimumIntegerDigits)); - int minimum_significant_digits = formatter->GetMinimumSignificantDigits().GetInt(); - int maximum_significant_digits = formatter->GetMaximumSignificantDigits().GetInt(); - int minimum_fraction_digits = formatter->GetMinimumFractionDigits().GetInt(); - int maximum_fraction_digits = formatter->GetMaximumFractionDigits().GetInt(); + int minimumSignificantDigits = formatter->GetMinimumSignificantDigits().GetInt(); + int maximumSignificantDigits = formatter->GetMaximumSignificantDigits().GetInt(); + int minimumFractionDigits = formatter->GetMinimumFractionDigits().GetInt(); + int maximumFractionDigits = formatter->GetMaximumFractionDigits().GetInt(); // If roundingtype is "compact-rounding" return ICU formatter - auto rounding_type = static_cast(formatter->GetRoundingType().GetInt()); - if (rounding_type == RoundingType::COMPACTROUNDING) { - return icu_numberformatter; + auto roundingType = static_cast(formatter->GetRoundingType().GetInt()); + if (roundingType == RoundingType::COMPACTROUNDING) { + return icuNumberformatter; } // Else, Set ICU formatter FractionDigits and SignificantDigits // a. Set ICU formatter minFraction, maxFraction to MinimumFractionDigits, MaximumFractionDigits icu::number::Precision precision = - icu::number::Precision::minMaxFraction(minimum_fraction_digits, maximum_fraction_digits); + icu::number::Precision::minMaxFraction(minimumFractionDigits, maximumFractionDigits); // b. if MinimumSignificantDigits is not 0, // Set ICU formatter minSignificantDigits, maxSignificantDigits to MinimumSignificantDigits, // MaximumSignificantDigits - if (minimum_significant_digits != 0) { + if (minimumSignificantDigits != 0) { precision = - icu::number::Precision::minMaxSignificantDigits(minimum_significant_digits, maximum_significant_digits); + icu::number::Precision::minMaxSignificantDigits(minimumSignificantDigits, maximumSignificantDigits); } - return icu_numberformatter.precision(precision); + return icuNumberformatter.precision(precision); } }; } // namespace panda::ecmascript diff --git a/runtime/js_object-inl.h b/runtime/js_object-inl.h index c838b0216a545f92736cf2328bac2fd2c280eb96..242fdf0ed3e7deeff9ad901f914da56b0ca30f0c 100644 --- a/runtime/js_object-inl.h +++ b/runtime/js_object-inl.h @@ -245,16 +245,16 @@ inline bool JSObject::ShouldTransToDict(uint32_t capacity, uint32_t index) return false; } -inline uint32_t JSObject::ComputeElementCapacity(uint32_t old_capacity) +inline uint32_t JSObject::ComputeElementCapacity(uint32_t oldCapacity) { - uint32_t new_capacity = old_capacity + (old_capacity >> 1U); - return new_capacity > MIN_ELEMENTS_LENGTH ? new_capacity : MIN_ELEMENTS_LENGTH; + uint32_t newCapacity = oldCapacity + (oldCapacity >> 1U); + return newCapacity > MIN_ELEMENTS_LENGTH ? newCapacity : MIN_ELEMENTS_LENGTH; } -inline uint32_t JSObject::ComputePropertyCapacity(uint32_t old_capacity) +inline uint32_t JSObject::ComputePropertyCapacity(uint32_t oldCapacity) { - uint32_t new_capacity = old_capacity + PROPERTIES_GROW_SIZE; - return new_capacity > JSHClass::MAX_CAPACITY_OF_OUT_OBJECTS ? JSHClass::MAX_CAPACITY_OF_OUT_OBJECTS : new_capacity; + uint32_t newCapacity = oldCapacity + PROPERTIES_GROW_SIZE; + return newCapacity > JSHClass::MAX_CAPACITY_OF_OUT_OBJECTS ? JSHClass::MAX_CAPACITY_OF_OUT_OBJECTS : newCapacity; } // static @@ -267,9 +267,9 @@ JSHandle JSObject::CreateListFromArrayLike(JSThread *thread, cons JSHandle(thread, JSTaggedValue::Exception())); } // 4. Let len be ToLength(Get(obj, "length")). - JSHandle length_key_handle = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle value = GetProperty(thread, obj, length_key_handle).GetValue(); + JSHandle value = GetProperty(thread, obj, lengthKeyHandle).GetValue(); JSTaggedNumber number = JSTaggedValue::ToLength(thread, value); // 5. ReturnIfAbrupt(len). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); diff --git a/runtime/js_object.cpp b/runtime/js_object.cpp index 3da751356e65cbf423e55f8a5786d0ca87d97e58..22dbfe975912ee2af08801430467e82d5cda61d2 100644 --- a/runtime/js_object.cpp +++ b/runtime/js_object.cpp @@ -68,14 +68,14 @@ JSMethod *ECMAObject::GetCallTarget() const JSHandle JSObject::GrowElementsCapacity(const JSThread *thread, const JSHandle &obj, uint32_t capacity) { - uint32_t new_capacity = ComputeElementCapacity(capacity); + uint32_t newCapacity = ComputeElementCapacity(capacity); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle old_elements(thread, obj->GetElements()); - uint32_t old_length = old_elements->GetLength(); - JSHandle new_elements = factory->CopyArray(old_elements, old_length, new_capacity); + JSHandle oldElements(thread, obj->GetElements()); + uint32_t oldLength = oldElements->GetLength(); + JSHandle newElements = factory->CopyArray(oldElements, oldLength, newCapacity); - obj->SetElements(thread, new_elements); - return new_elements; + obj->SetElements(thread, newElements); + return newElements; } bool JSObject::IsRegExp(JSThread *thread, const JSHandle &argument) @@ -83,14 +83,14 @@ bool JSObject::IsRegExp(JSThread *thread, const JSHandle &argumen if (!argument->IsECMAObject()) { return false; } - JSHandle match_symbol = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchSymbol(); - JSHandle is_regexp = JSObject::GetProperty(thread, argument, match_symbol).GetValue(); + JSHandle matchSymbol = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchSymbol(); + JSHandle isRegexp = JSObject::GetProperty(thread, argument, matchSymbol).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!is_regexp->IsUndefined()) { - return is_regexp->ToBoolean(); + if (!isRegexp->IsUndefined()) { + return isRegexp->ToBoolean(); } - JSHandle argument_obj = JSHandle::Cast(argument); - return argument_obj->IsJSRegExp(); + JSHandle argumentObj = JSHandle::Cast(argument); + return argumentObj->IsJSRegExp(); } JSHandle JSObject::TransitionToDictionary(const JSThread *thread, const JSHandle &receiver) @@ -98,33 +98,33 @@ JSHandle JSObject::TransitionToDictionary(const JSThread *thread JSHandle array(thread, receiver->GetProperties()); JSHandle jshclass(thread, receiver->GetJSHClass()); ASSERT(!jshclass->IsDictionaryMode()); - uint32_t prop_number = jshclass->NumberOfProps(); + uint32_t propNumber = jshclass->NumberOfProps(); ASSERT(!jshclass->GetLayout().IsNull()); - JSHandle layout_info_handle(thread, jshclass->GetLayout()); - ASSERT(layout_info_handle->GetLength() != 0); + JSHandle layoutInfoHandle(thread, jshclass->GetLayout()); + ASSERT(layoutInfoHandle->GetLength() != 0); JSMutableHandle dict( - thread, NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(prop_number))); - JSMutableHandle value_handle(thread, JSTaggedValue::Undefined()); - JSMutableHandle key_handle(thread, JSTaggedValue::Undefined()); - uint32_t number_inlined_props = jshclass->GetInlinedProperties(); - for (uint32_t i = 0; i < prop_number; i++) { - JSTaggedValue key = layout_info_handle->GetKey(i); - PropertyAttributes attr = layout_info_handle->GetAttr(i); + thread, NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(propNumber))); + JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); + JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); + uint32_t numberInlinedProps = jshclass->GetInlinedProperties(); + for (uint32_t i = 0; i < propNumber; i++) { + JSTaggedValue key = layoutInfoHandle->GetKey(i); + PropertyAttributes attr = layoutInfoHandle->GetAttr(i); ASSERT(i == attr.GetOffset()); JSTaggedValue value; - if (i < number_inlined_props) { + if (i < numberInlinedProps) { value = receiver->GetPropertyInlinedProps(i); } else { - value = array->Get(i - number_inlined_props); + value = array->Get(i - numberInlinedProps); } attr.SetBoxType(PropertyBoxType::UNDEFINED); - value_handle.Update(value); - key_handle.Update(key); - JSHandle new_dict = NameDictionary::PutIfAbsent(thread, dict, key_handle, value_handle, attr); - dict.Update(new_dict); + valueHandle.Update(value); + keyHandle.Update(key); + JSHandle newDict = NameDictionary::PutIfAbsent(thread, dict, keyHandle, valueHandle, attr); + dict.Update(newDict); } receiver->SetProperties(thread, dict); @@ -132,12 +132,12 @@ JSHandle JSObject::TransitionToDictionary(const JSThread *thread JSHClass::TransitionToDictionary(thread, receiver); // trim in-obj properties space - if (number_inlined_props > 0) { + if (numberInlinedProps > 0) { #ifndef ECMA_DISABLE_FREEOBJECTS - uint32_t free_offs = receiver->GetClass()->GetObjectSize(); - uint32_t free_bytes = number_inlined_props * JSTaggedValue::TaggedTypeSize(); + uint32_t freeOffs = receiver->GetClass()->GetObjectSize(); + uint32_t freeBytes = numberInlinedProps * JSTaggedValue::TaggedTypeSize(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - factory->FillFreeObject(ToUintPtr(*receiver) + free_offs, free_bytes, RemoveSlots::YES); + factory->FillFreeObject(ToUintPtr(*receiver) + freeOffs, freeBytes, RemoveSlots::YES); #else uint32_t free_offs = receiver->GetClass()->GetObjectSize() - numberInlinedProps * JSTaggedValue::TaggedTypeSize(); @@ -159,16 +159,16 @@ void JSObject::ElementsToDictionary(const JSThread *thread, JSHandle o JSMutableHandle dict(thread, NumberDictionary::Create(thread)); auto attr = PropertyAttributes(PropertyAttributes::GetDefaultAttributes()); JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle value_handle(thread, JSTaggedValue ::Undefined()); + JSMutableHandle valueHandle(thread, JSTaggedValue ::Undefined()); for (int i = 0; i < length; i++) { JSTaggedValue value = elements->Get(i); if (value.IsHole()) { continue; } key.Update(JSTaggedValue(i)); - value_handle.Update(value); - JSHandle new_dict = NumberDictionary::PutIfAbsent(thread, dict, key, value_handle, attr); - dict.Update(new_dict); + valueHandle.Update(value); + JSHandle newDict = NumberDictionary::PutIfAbsent(thread, dict, key, valueHandle, attr); + dict.Update(newDict); } obj->SetElements(thread, dict); @@ -179,23 +179,23 @@ bool JSObject::IsArrayLengthWritable(JSThread *thread, const JSHandle { auto *hclass = receiver->GetJSHClass(); if (!hclass->IsDictionaryMode()) { - LayoutInfo *layout_info = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layout_info->GetAttr(JSArray::LENGTH_INLINE_PROPERTY_INDEX)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(JSArray::LENGTH_INLINE_PROPERTY_INDEX)); return attr.IsWritable(); } - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - ObjectOperator op(thread, receiver, length_key, OperatorType::OWN); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + ObjectOperator op(thread, receiver, lengthKey, OperatorType::OWN); return op.GetAttr().IsWritable(); } bool JSObject::AddElementInternal(JSThread *thread, const JSHandle &receiver, uint32_t index, const JSHandle &value, PropertyAttributes attr) { - bool is_dictionary = receiver->GetJSHClass()->IsDictionaryElement(); + bool isDictionary = receiver->GetJSHClass()->IsDictionaryElement(); if (receiver->IsJSArray()) { JSHandle arr(receiver); - uint32_t old_length = arr->GetArrayLength(); - if (index >= old_length) { + uint32_t oldLength = arr->GetArrayLength(); + if (index >= oldLength) { if (!IsArrayLengthWritable(thread, receiver)) { return false; } @@ -205,12 +205,12 @@ bool JSObject::AddElementInternal(JSThread *thread, const JSHandle &re thread->NotifyStableArrayElementsGuardians(receiver); TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); - if (is_dictionary) { + if (isDictionary) { ASSERT(elements->IsDictionaryMode()); - JSHandle key_handle(thread, JSTaggedValue(static_cast(index))); - JSHandle new_dict = - NumberDictionary::Put(thread, JSHandle(thread, elements), key_handle, value, attr); - receiver->SetElements(thread, new_dict); + JSHandle keyHandle(thread, JSTaggedValue(static_cast(index))); + JSHandle newDict = + NumberDictionary::Put(thread, JSHandle(thread, elements), keyHandle, value, attr); + receiver->SetElements(thread, newDict); return true; } @@ -218,10 +218,10 @@ bool JSObject::AddElementInternal(JSThread *thread, const JSHandle &re if (index >= capacity || !attr.IsDefaultAttributes()) { if (ShouldTransToDict(capacity, index) || !attr.IsDefaultAttributes()) { JSObject::ElementsToDictionary(thread, receiver); - JSHandle key_handle(thread, JSTaggedValue(static_cast(index))); + JSHandle keyHandle(thread, JSTaggedValue(static_cast(index))); JSHandle dict(thread, receiver->GetElements()); - JSHandle new_key = NumberDictionary::Put(thread, dict, key_handle, value, attr); - receiver->SetElements(thread, new_key); + JSHandle newKey = NumberDictionary::Put(thread, dict, keyHandle, value, attr); + receiver->SetElements(thread, newKey); return true; } elements = *JSObject::GrowElementsCapacity(thread, receiver, index + 1); @@ -237,28 +237,28 @@ void JSObject::DeletePropertyInternal(JSThread *thread, const JSHandle JSHandle array(thread, obj->GetProperties()); if (obj->IsJSGlobalObject()) { - JSHandle dict_handle(thread, obj->GetProperties()); - JSHandle new_dict = GlobalDictionary::Remove(thread, dict_handle, index); - obj->SetProperties(thread, new_dict); + JSHandle dictHandle(thread, obj->GetProperties()); + JSHandle newDict = GlobalDictionary::Remove(thread, dictHandle, index); + obj->SetProperties(thread, newDict); return; } if (!array->IsDictionaryMode()) { - JSHandle dict_handle(TransitionToDictionary(thread, obj)); - int entry = dict_handle->FindEntry(key.GetTaggedValue()); + JSHandle dictHandle(TransitionToDictionary(thread, obj)); + int entry = dictHandle->FindEntry(key.GetTaggedValue()); ASSERT(entry != -1); - JSHandle new_dict = NameDictionary::Remove(thread, dict_handle, entry); - obj->SetProperties(thread, new_dict); + JSHandle newDict = NameDictionary::Remove(thread, dictHandle, entry); + obj->SetProperties(thread, newDict); return; } - JSHandle dict_handle(array); - JSHandle new_dict = NameDictionary::Remove(thread, dict_handle, index); - obj->SetProperties(thread, new_dict); + JSHandle dictHandle(array); + JSHandle newDict = NameDictionary::Remove(thread, dictHandle, index); + obj->SetProperties(thread, newDict); } void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array) + const JSHandle &keyArray) { TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); @@ -266,152 +266,152 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, int end = obj->GetJSHClass()->NumberOfProps(); if (end > 0) { LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject()) - ->GetAllKeys(thread, end, offset, *key_array); + ->GetAllKeys(thread, end, offset, *keyArray); } return; } if (obj->IsJSGlobalObject()) { GlobalDictionary *dict = GlobalDictionary::Cast(array); - return dict->GetAllKeys(thread, offset, *key_array); + return dict->GetAllKeys(thread, offset, *keyArray); } NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); - dict->GetAllKeys(thread, offset, *key_array); + dict->GetAllKeys(thread, offset, *keyArray); } // For Serialization use. Does not support JSGlobalObject -void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, std::vector &key_vector) +void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, std::vector &keyVector) { ASSERT_PRINT(!obj->IsJSGlobalObject(), "Do not support get key of JSGlobal Object"); TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); if (!array->IsDictionaryMode()) { int end = obj->GetJSHClass()->NumberOfProps(); if (end > 0) { - LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject())->GetAllKeys(thread, end, key_vector); + LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject())->GetAllKeys(thread, end, keyVector); } } else { NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); - dict->GetAllKeysIntoVector(thread, key_vector); + dict->GetAllKeysIntoVector(thread, keyVector); } } JSHandle JSObject::GetAllEnumKeys(const JSThread *thread, const JSHandle &obj, int offset, - uint32_t num_of_keys, uint32_t *keys) + uint32_t numOfKeys, uint32_t *keys) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (obj->IsJSGlobalObject()) { - JSHandle key_array = factory->NewTaggedArray(num_of_keys); + JSHandle keyArray = factory->NewTaggedArray(numOfKeys); GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties().GetTaggedObject()); - dict->GetEnumAllKeys(thread, offset, *key_array, keys); - return key_array; + dict->GetEnumAllKeys(thread, offset, *keyArray, keys); + return keyArray; } TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); if (!array->IsDictionaryMode()) { - JSTaggedValue enum_cache = obj->GetJSHClass()->GetEnumCache(); - if (!enum_cache.IsNull()) { - auto key_array = JSHandle(thread, enum_cache); - *keys = key_array->GetLength(); - return key_array; + JSTaggedValue enumCache = obj->GetJSHClass()->GetEnumCache(); + if (!enumCache.IsNull()) { + auto keyArray = JSHandle(thread, enumCache); + *keys = keyArray->GetLength(); + return keyArray; } - JSHandle key_array = factory->NewTaggedArray(num_of_keys); + JSHandle keyArray = factory->NewTaggedArray(numOfKeys); int end = obj->GetJSHClass()->NumberOfProps(); if (end > 0) { LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject()) - ->GetAllEnumKeys(thread, end, offset, *key_array, keys); - if (*keys == key_array->GetLength()) { - obj->GetJSHClass()->SetEnumCache(thread, key_array.GetTaggedValue()); + ->GetAllEnumKeys(thread, end, offset, *keyArray, keys); + if (*keys == keyArray->GetLength()) { + obj->GetJSHClass()->SetEnumCache(thread, keyArray.GetTaggedValue()); } } - return key_array; + return keyArray; } - JSHandle key_array = factory->NewTaggedArray(num_of_keys); + JSHandle keyArray = factory->NewTaggedArray(numOfKeys); NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); - dict->GetAllEnumKeys(thread, offset, *key_array, keys); - return key_array; + dict->GetAllEnumKeys(thread, offset, *keyArray, keys); + return keyArray; } void JSObject::GetAllElementKeys(JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array) + const JSHandle &keyArray) { - uint32_t element_index = 0; + uint32_t elementIndex = 0; if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) { - element_index = JSPrimitiveRef::Cast(*obj)->GetStringLength() + offset; - for (uint32_t i = offset; i < element_index; ++i) { + elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength() + offset; + for (uint32_t i = offset; i < elementIndex; ++i) { auto key = base::NumberHelper::NumberToString(thread, JSTaggedValue(i)); - key_array->Set(thread, i, key); + keyArray->Set(thread, i, key); } } JSHandle elements(thread, obj->GetElements()); if (!elements->IsDictionaryMode()) { - uint32_t elements_len = elements->GetLength(); - for (uint32_t i = 0, j = element_index; i < elements_len; ++i) { + uint32_t elementsLen = elements->GetLength(); + for (uint32_t i = 0, j = elementIndex; i < elementsLen; ++i) { if (!elements->Get(i).IsHole()) { auto key = base::NumberHelper::NumberToString(thread, JSTaggedValue(i)); - key_array->Set(thread, j++, key); + keyArray->Set(thread, j++, key); } } } else { - NumberDictionary::GetAllKeys(thread, JSHandle(elements), element_index, key_array); + NumberDictionary::GetAllKeys(thread, JSHandle(elements), elementIndex, keyArray); } } void JSObject::GetALLElementKeysIntoVector(const JSThread *thread, const JSHandle &obj, - std::vector &key_vector) + std::vector &keyVector) { JSHandle elements(thread, obj->GetElements()); if (!elements->IsDictionaryMode()) { - uint32_t elements_len = elements->GetLength(); - for (uint32_t i = 0; i < elements_len; ++i) { + uint32_t elementsLen = elements->GetLength(); + for (uint32_t i = 0; i < elementsLen; ++i) { if (!elements->Get(i).IsHole()) { - key_vector.emplace_back(JSTaggedValue(i)); + keyVector.emplace_back(JSTaggedValue(i)); } } } else { JSHandle dict = JSHandle::Cast(elements); - dict->GetAllKeysIntoVector(thread, key_vector); + dict->GetAllKeysIntoVector(thread, keyVector); } } JSHandle JSObject::GetEnumElementKeys(JSThread *thread, const JSHandle &obj, int offset, - uint32_t num_of_elements, uint32_t *keys) + uint32_t numOfElements, uint32_t *keys) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle element_array = factory->NewTaggedArray(num_of_elements); - uint32_t element_index = 0; - JSMutableHandle key_handle(thread, JSTaggedValue::Undefined()); + JSHandle elementArray = factory->NewTaggedArray(numOfElements); + uint32_t elementIndex = 0; + JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) { - element_index = JSPrimitiveRef::Cast(*obj)->GetStringLength(); - *keys += element_index; - element_index += offset; - for (uint32_t i = offset; i < element_index; ++i) { - key_handle.Update(JSTaggedValue(i)); - auto key = JSTaggedValue::ToString(thread, key_handle); - element_array->Set(thread, i, key); + elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength(); + *keys += elementIndex; + elementIndex += offset; + for (uint32_t i = offset; i < elementIndex; ++i) { + keyHandle.Update(JSTaggedValue(i)); + auto key = JSTaggedValue::ToString(thread, keyHandle); + elementArray->Set(thread, i, key); } } JSHandle arr(thread, obj->GetElements()); if (!arr->IsDictionaryMode()) { - uint32_t elements_len = arr->GetLength(); - uint32_t pre_element_index = element_index; - for (uint32_t i = 0; i < elements_len; ++i) { + uint32_t elementsLen = arr->GetLength(); + uint32_t preElementIndex = elementIndex; + for (uint32_t i = 0; i < elementsLen; ++i) { if (!arr->Get(i).IsHole()) { - key_handle.Update(JSTaggedValue(i)); - auto key = JSTaggedValue::ToString(thread, key_handle); - element_array->Set(thread, element_index++, key); + keyHandle.Update(JSTaggedValue(i)); + auto key = JSTaggedValue::ToString(thread, keyHandle); + elementArray->Set(thread, elementIndex++, key); } } - *keys += (element_index - pre_element_index); + *keys += (elementIndex - preElementIndex); } else { - NumberDictionary::GetAllEnumKeys(thread, JSHandle(arr), element_index, element_array, keys); + NumberDictionary::GetAllEnumKeys(thread, JSHandle(arr), elementIndex, elementArray, keys); } - return element_array; + return elementArray; } uint32_t JSObject::GetNumberOfKeys() @@ -426,7 +426,7 @@ uint32_t JSObject::GetNumberOfKeys() } bool JSObject::GlobalSetProperty(JSThread *thread, const JSHandle &key, - const JSHandle &value, bool may_throw) + const JSHandle &value, bool mayThrow) { ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); @@ -435,75 +435,74 @@ bool JSObject::GlobalSetProperty(JSThread *thread, const JSHandle PropertyAttributes attr = PropertyAttributes::Default(true, true, false); op.SetAttr(attr); } - return SetProperty(&op, value, may_throw); + return SetProperty(&op, value, mayThrow); } uint32_t JSObject::GetNumberOfElements() { - uint32_t num_of_elements = 0; + uint32_t numOfElements = 0; if (IsJSPrimitiveRef() && JSPrimitiveRef::Cast(this)->IsString()) { - num_of_elements = JSPrimitiveRef::Cast(this)->GetStringLength(); + numOfElements = JSPrimitiveRef::Cast(this)->GetStringLength(); } TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); if (!elements->IsDictionaryMode()) { - uint32_t elements_len = elements->GetLength(); - for (uint32_t i = 0; i < elements_len; ++i) { + uint32_t elementsLen = elements->GetLength(); + for (uint32_t i = 0; i < elementsLen; ++i) { if (!elements->Get(i).IsHole()) { - num_of_elements++; + numOfElements++; } } } else { - num_of_elements += NumberDictionary::Cast(elements)->EntriesCount(); + numOfElements += NumberDictionary::Cast(elements)->EntriesCount(); } - return num_of_elements; + return numOfElements; } // 9.1.9 [[Set]] ( P, V, Receiver) bool JSObject::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, - const JSHandle &value, const JSHandle &receiver, - bool may_throw) + const JSHandle &value, const JSHandle &receiver, bool mayThrow) { ASSERT_PRINT(!(obj->IsUndefined() || obj->IsNull() || obj->IsHole()), "Obj is not a valid object"); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); // 2 ~ 4 findProperty in Receiver, Obj and its parents ObjectOperator op(thread, obj, receiver, key); - return SetProperty(&op, value, may_throw); + return SetProperty(&op, value, mayThrow); } bool JSObject::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, - const JSHandle &value, bool may_throw) + const JSHandle &value, bool mayThrow) { ASSERT_PRINT(obj->IsECMAObject(), "Obj is not a valid JSObject"); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); ObjectOperator op(thread, obj, key); - return SetProperty(&op, value, may_throw); + return SetProperty(&op, value, mayThrow); } bool JSObject::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, - const JSHandle &value, bool may_throw) + const JSHandle &value, bool mayThrow) { ASSERT_PRINT(!(obj->IsUndefined() || obj->IsNull() || obj->IsHole()), "Obj is not a valid object"); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); // 2 ~ 4 findProperty in Receiver, Obj and its parents ObjectOperator op(thread, obj, key); - return SetProperty(&op, value, may_throw); + return SetProperty(&op, value, mayThrow); } bool JSObject::SetProperty(JSThread *thread, const JSHandle &obj, uint32_t index, - const JSHandle &value, bool may_throw) + const JSHandle &value, bool mayThrow) { ASSERT_PRINT(!(obj->IsUndefined() || obj->IsNull() || obj->IsHole()), "Obj is not a valid object"); ObjectOperator op(thread, obj, index); - return SetProperty(&op, value, may_throw); + return SetProperty(&op, value, mayThrow); } -bool JSObject::SetProperty(ObjectOperator *op, const JSHandle &value, bool may_throw) +bool JSObject::SetProperty(ObjectOperator *op, const JSHandle &value, bool mayThrow) { JSThread *thread = op->GetThread(); @@ -512,9 +511,9 @@ bool JSObject::SetProperty(ObjectOperator *op, const JSHandle &va if (holder->IsJSProxy()) { if (op->IsElement()) { JSHandle key(thread, JSTaggedValue(op->GetElementIndex())); - return JSProxy::SetProperty(thread, JSHandle::Cast(holder), key, value, receiver, may_throw); + return JSProxy::SetProperty(thread, JSHandle::Cast(holder), key, value, receiver, mayThrow); } - return JSProxy::SetProperty(thread, JSHandle::Cast(holder), op->GetKey(), value, receiver, may_throw); + return JSProxy::SetProperty(thread, JSHandle::Cast(holder), op->GetKey(), value, receiver, mayThrow); } // When op is not found and is not set extra attributes @@ -522,23 +521,23 @@ bool JSObject::SetProperty(ObjectOperator *op, const JSHandle &va op->SetAsDefaultAttr(); } - bool is_internal_accessor = false; + bool isInternalAccessor = false; if (op->IsAccessorDescriptor()) { - is_internal_accessor = AccessorData::Cast(op->GetValue().GetTaggedObject())->IsInternal(); + isInternalAccessor = AccessorData::Cast(op->GetValue().GetTaggedObject())->IsInternal(); } // 5. If IsDataDescriptor(ownDesc) is true, then - if (!op->IsAccessorDescriptor() || is_internal_accessor) { - bool is_success = true; + if (!op->IsAccessorDescriptor() || isInternalAccessor) { + bool isSuccess = true; if (!op->IsWritable()) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot assign to read only property", false); } return false; } if (!receiver->IsECMAObject()) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Receiver is not a JSObject", false); } return false; @@ -552,86 +551,86 @@ bool JSObject::SetProperty(ObjectOperator *op, const JSHandle &va key.Update(op->GetKey().GetTaggedValue()); } - PropertyDescriptor exist_desc(thread); - JSProxy::GetOwnProperty(thread, JSHandle::Cast(receiver), key, exist_desc); + PropertyDescriptor existDesc(thread); + JSProxy::GetOwnProperty(thread, JSHandle::Cast(receiver), key, existDesc); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!exist_desc.IsEmpty()) { - if (exist_desc.IsAccessorDescriptor()) { + if (!existDesc.IsEmpty()) { + if (existDesc.IsAccessorDescriptor()) { return false; } - if (!exist_desc.IsWritable()) { + if (!existDesc.IsWritable()) { return false; } - PropertyDescriptor value_desc(thread, value); - return JSProxy::DefineOwnProperty(thread, JSHandle::Cast(receiver), key, value_desc); + PropertyDescriptor valueDesc(thread, value); + return JSProxy::DefineOwnProperty(thread, JSHandle::Cast(receiver), key, valueDesc); } - is_success = CreateDataProperty(thread, JSHandle(receiver), key, value); + isSuccess = CreateDataProperty(thread, JSHandle(receiver), key, value); - if (!is_success && may_throw) { + if (!isSuccess && mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "", false); } - return is_success; + return isSuccess; } // 5e. If existingDescriptor is not undefined, then - bool has_receiver = false; + bool hasReceiver = false; if (op->HasReceiver()) { op->ReLookupPropertyInReceiver(); - has_receiver = true; + hasReceiver = true; } if (op->IsFound() && !op->IsOnPrototype()) { // i. If IsAccessorDescriptor(existingDescriptor) is true, return false. - if (op->IsAccessorDescriptor() && !is_internal_accessor) { + if (op->IsAccessorDescriptor() && !isInternalAccessor) { return false; } // ii. If existingDescriptor.[[Writable]] is false, return false. if (!op->IsWritable()) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot assign to read only property", false); } return false; } - is_success = op->UpdateDataValue(JSHandle(receiver), value, is_internal_accessor, may_throw); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, is_success); + isSuccess = op->UpdateDataValue(JSHandle(receiver), value, isInternalAccessor, mayThrow); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, isSuccess); } else { // 5f. Else if Receiver does not currently have a property P, Return CreateDataProperty(Receiver, P, V). if (!receiver->IsExtensible(thread)) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "receiver is not Extensible", false); } return false; } - if (LIKELY(!has_receiver)) { + if (LIKELY(!hasReceiver)) { return op->AddProperty(JSHandle(receiver), value, op->GetAttr()); } PropertyAttributes attr; attr.SetDefaultAttributes(); return op->AddProperty(JSHandle(receiver), value, attr); } - return is_success; + return isSuccess; } // 6. Assert: IsAccessorDescriptor(ownDesc) is true. ASSERT(op->IsAccessorDescriptor()); // 8. If setter is undefined, return false. AccessorData *accessor = AccessorData::Cast(op->GetValue().GetTaggedObject()); - return CallSetter(thread, *accessor, receiver, value, may_throw); + return CallSetter(thread, *accessor, receiver, value, mayThrow); } bool JSObject::CallSetter(JSThread *thread, const AccessorData &accessor, const JSHandle &receiver, - const JSHandle &value, bool may_throw) + const JSHandle &value, bool mayThrow) { if (UNLIKELY(accessor.IsInternal())) { - return accessor.CallInternalSet(thread, JSHandle::Cast(receiver), value, may_throw); + return accessor.CallInternalSet(thread, JSHandle::Cast(receiver), value, mayThrow); } JSTaggedValue setter = accessor.GetSetter(); // 8. If setter is undefined, return false. if (setter.IsUndefined()) { - if (may_throw) { + if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set property when setter is undefined", false); } return false; @@ -797,8 +796,8 @@ bool JSObject::GlobalGetOwnProperty(JSThread *thread, const JSHandle value_handle(thread, cell->GetValue()); - desc.SetValue(value_handle); + JSHandle valueHandle(thread, cell->GetValue()); + desc.SetValue(valueHandle); } ASSERT(!desc.GetValue()->IsInternalAccessor()); return true; @@ -818,8 +817,8 @@ bool JSObject::OrdinaryGetOwnProperty(JSThread *thread, const JSHandle if (desc.HasValue() && obj->IsJSGlobalObject()) { PropertyBox *cell = PropertyBox::Cast(desc.GetValue().GetTaggedValue().GetTaggedObject()); - JSHandle value_handle(thread, cell->GetValue()); - desc.SetValue(value_handle); + JSHandle valueHandle(thread, cell->GetValue()); + desc.SetValue(valueHandle); } return true; @@ -843,8 +842,8 @@ bool JSObject::OrdinaryDefineOwnProperty(JSThread *thread, const JSHandle obj_value(obj); - ObjectOperator op(thread, obj_value, key, OperatorType::OWN); + JSHandle objValue(obj); + ObjectOperator op(thread, objValue, key, OperatorType::OWN); bool extensible = obj->IsExtensible(); PropertyDescriptor current(thread); @@ -856,8 +855,8 @@ bool JSObject::OrdinaryDefineOwnProperty(JSThread *thread, const JSHandle &obj, uint32_t index, const PropertyDescriptor &desc) { - JSHandle obj_value(obj); - ObjectOperator op(thread, obj_value, index, OperatorType::OWN); + JSHandle objValue(obj); + ObjectOperator op(thread, objValue, index, OperatorType::OWN); bool extensible = obj->IsExtensible(); PropertyDescriptor current(thread); @@ -1018,24 +1017,24 @@ bool JSObject::SetPrototype(JSThread *thread, const JSHandle &obj, con return false; } bool done = false; - JSTaggedValue temp_proto = proto.GetTaggedValue(); + JSTaggedValue tempProto = proto.GetTaggedValue(); while (!done) { - if (temp_proto.IsNull() || !temp_proto.IsECMAObject()) { + if (tempProto.IsNull() || !tempProto.IsECMAObject()) { done = true; - } else if (JSTaggedValue::SameValue(temp_proto, obj.GetTaggedValue())) { + } else if (JSTaggedValue::SameValue(tempProto, obj.GetTaggedValue())) { return false; } else { - if (temp_proto.IsJSProxy()) { + if (tempProto.IsJSProxy()) { break; } - temp_proto = JSObject::Cast(temp_proto.GetTaggedObject())->GetPrototype(thread); + tempProto = JSObject::Cast(tempProto.GetTaggedObject())->GetPrototype(thread); } } // map transition JSHandle dynclass(thread, obj->GetJSHClass()); - JSHandle new_dynclass = JSHClass::TransitionProto(thread, dynclass, proto); - JSHClass::NotifyHclassChanged(thread, dynclass, new_dynclass); - obj->SetClass(new_dynclass); + JSHandle newDynclass = JSHClass::TransitionProto(thread, dynclass, proto); + JSHClass::NotifyHclassChanged(thread, dynclass, newDynclass); + obj->SetClass(newDynclass); thread->NotifyStableArrayElementsGuardians(obj); return true; } @@ -1043,8 +1042,8 @@ bool JSObject::SetPrototype(JSThread *thread, const JSHandle &obj, con bool JSObject::HasProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key) { ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); - JSHandle obj_value(obj); - ObjectOperator op(thread, obj_value, key); + JSHandle objValue(obj); + ObjectOperator op(thread, objValue, key); JSHandle holder = op.GetHolder(); if (holder->IsJSProxy()) { @@ -1056,8 +1055,8 @@ bool JSObject::HasProperty(JSThread *thread, const JSHandle &obj, cons bool JSObject::HasProperty(JSThread *thread, const JSHandle &obj, uint32_t index) { - JSHandle obj_value(obj); - ObjectOperator op(thread, obj_value, index); + JSHandle objValue(obj); + ObjectOperator op(thread, objValue, index); JSHandle holder = op.GetHolder(); if (holder->IsJSProxy()) { @@ -1072,8 +1071,8 @@ bool JSObject::PreventExtensions(JSThread *thread, const JSHandle &obj { if (obj->IsExtensible()) { JSHandle jshclass(thread, obj->GetJSHClass()); - JSHandle new_hclass = JSHClass::TransitionExtension(thread, jshclass); - obj->SetClass(new_hclass); + JSHandle newHclass = JSHClass::TransitionExtension(thread, jshclass); + obj->SetClass(newHclass); } return true; @@ -1082,28 +1081,28 @@ bool JSObject::PreventExtensions(JSThread *thread, const JSHandle &obj // 9.1.12 [[OwnPropertyKeys]] ( ) JSHandle JSObject::GetOwnPropertyKeys(JSThread *thread, const JSHandle &obj) { - [[maybe_unused]] uint32_t element_index = 0; - uint32_t num_of_elements = obj->GetNumberOfElements(); - uint32_t key_len = num_of_elements + obj->GetNumberOfKeys(); + [[maybe_unused]] uint32_t elementIndex = 0; + uint32_t numOfElements = obj->GetNumberOfElements(); + uint32_t keyLen = numOfElements + obj->GetNumberOfKeys(); - JSHandle key_array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(key_len); + JSHandle keyArray = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(keyLen); - if (num_of_elements > 0) { - GetAllElementKeys(thread, obj, 0, key_array); + if (numOfElements > 0) { + GetAllElementKeys(thread, obj, 0, keyArray); } - GetAllKeys(thread, obj, static_cast(num_of_elements), key_array); - return key_array; + GetAllKeys(thread, obj, static_cast(numOfElements), keyArray); + return keyArray; } JSHandle JSObject::ObjectCreate(JSThread *thread, const JSHandle &proto) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle constructor = env->GetObjectFunction(); - JSHandle obj_handle = + JSHandle objHandle = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), constructor); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - SetPrototype(thread, obj_handle, JSHandle(proto)); - return obj_handle; + SetPrototype(thread, objHandle, JSHandle(proto)); + return objHandle; } // 7.3.4 CreateDataProperty (O, P, V) @@ -1198,46 +1197,46 @@ bool JSObject::SetIntegrityLevel(JSThread *thread, const JSHandle &obj return false; } - JSHandle jshandle_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle(obj)); + JSHandle jshandleKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle(obj)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - PropertyDescriptor desc_no_conf(thread); - desc_no_conf.SetConfigurable(false); - PropertyDescriptor desc_no_conf_write(thread); - desc_no_conf_write.SetWritable(false); - desc_no_conf_write.SetConfigurable(false); + PropertyDescriptor descNoConf(thread); + descNoConf.SetConfigurable(false); + PropertyDescriptor descNoConfWrite(thread); + descNoConfWrite.SetWritable(false); + descNoConfWrite.SetConfigurable(false); if (level == IntegrityLevel::SEALED) { - uint32_t length = jshandle_keys->GetLength(); + uint32_t length = jshandleKeys->GetLength(); if (length == 0) { return true; } - auto key = jshandle_keys->Get(0); - JSMutableHandle handle_key(thread, key); + auto key = jshandleKeys->Get(0); + JSMutableHandle handleKey(thread, key); for (uint32_t i = 0; i < length; i++) { - auto tagged_key = JSTaggedValue(jshandle_keys->Get(i)); - handle_key.Update(tagged_key); + auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); + handleKey.Update(taggedKey); [[maybe_unused]] bool success = - JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(obj), handle_key, desc_no_conf); + JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(obj), handleKey, descNoConf); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); } } else { - uint32_t length = jshandle_keys->GetLength(); + uint32_t length = jshandleKeys->GetLength(); if (length == 0) { return true; } - auto key = jshandle_keys->Get(0); - JSMutableHandle handle_key(thread, key); + auto key = jshandleKeys->Get(0); + JSMutableHandle handleKey(thread, key); for (uint32_t i = 0; i < length; i++) { - auto tagged_key = JSTaggedValue(jshandle_keys->Get(i)); - handle_key.Update(tagged_key); - PropertyDescriptor current_desc(thread); - bool cur_desc_status = - JSTaggedValue::GetOwnProperty(thread, JSHandle(obj), handle_key, current_desc); + auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); + handleKey.Update(taggedKey); + PropertyDescriptor currentDesc(thread); + bool curDescStatus = + JSTaggedValue::GetOwnProperty(thread, JSHandle(obj), handleKey, currentDesc); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (cur_desc_status) { - PropertyDescriptor desc = current_desc.IsAccessorDescriptor() ? desc_no_conf : desc_no_conf_write; + if (curDescStatus) { + PropertyDescriptor desc = currentDesc.IsAccessorDescriptor() ? descNoConf : descNoConfWrite; [[maybe_unused]] bool success = - JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(obj), handle_key, desc); + JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(obj), handleKey, desc); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); } } @@ -1252,32 +1251,32 @@ bool JSObject::TestIntegrityLevel(JSThread *thread, const JSHandle &ob ASSERT_PRINT((level == IntegrityLevel::SEALED || level == IntegrityLevel::FROZEN), "level is not a valid IntegrityLevel"); - auto obj_val = JSHandle(obj); - bool status = obj_val->IsExtensible(thread); + auto objVal = JSHandle(obj); + bool status = objVal->IsExtensible(thread); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (status) { return false; } - JSHandle jshandle_keys = JSTaggedValue::GetOwnPropertyKeys(thread, obj_val); + JSHandle jshandleKeys = JSTaggedValue::GetOwnPropertyKeys(thread, objVal); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - uint32_t length = jshandle_keys->GetLength(); + uint32_t length = jshandleKeys->GetLength(); if (length == 0) { return true; } - auto key = jshandle_keys->Get(0); - JSMutableHandle handle_key(thread, key); + auto key = jshandleKeys->Get(0); + JSMutableHandle handleKey(thread, key); for (uint32_t i = 0; i < length; i++) { - auto tagged_key = JSTaggedValue(jshandle_keys->Get(i)); - handle_key.Update(tagged_key); - PropertyDescriptor current_desc(thread); - bool cur_desc_status = JSTaggedValue::GetOwnProperty(thread, obj_val, handle_key, current_desc); + auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); + handleKey.Update(taggedKey); + PropertyDescriptor currentDesc(thread); + bool curDescStatus = JSTaggedValue::GetOwnProperty(thread, objVal, handleKey, currentDesc); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (cur_desc_status) { - if (current_desc.IsConfigurable()) { + if (curDescStatus) { + if (currentDesc.IsConfigurable()) { return false; } - if (level == IntegrityLevel::FROZEN && current_desc.IsDataDescriptor() && current_desc.IsWritable()) { + if (level == IntegrityLevel::FROZEN && currentDesc.IsDataDescriptor() && currentDesc.IsWritable()) { return false; } } @@ -1291,35 +1290,35 @@ JSHandle JSObject::EnumerableOwnNames(JSThread *thread, const JSHan ASSERT_PRINT(obj->IsECMAObject(), "obj is not object"); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle keys; - JSHandle tag_obj(obj); - uint32_t copy_length = 0; + JSHandle tagObj(obj); + uint32_t copyLength = 0; // fast mode - if (tag_obj->IsJSObject() && !tag_obj->IsTypedArray()) { - uint32_t num_of_keys = obj->GetNumberOfKeys(); - uint32_t num_of_elements = obj->GetNumberOfElements(); - JSHandle element_array; - if (num_of_elements > 0) { - element_array = JSObject::GetEnumElementKeys(thread, obj, 0, num_of_elements, ©_length); + if (tagObj->IsJSObject() && !tagObj->IsTypedArray()) { + uint32_t numOfKeys = obj->GetNumberOfKeys(); + uint32_t numOfElements = obj->GetNumberOfElements(); + JSHandle elementArray; + if (numOfElements > 0) { + elementArray = JSObject::GetEnumElementKeys(thread, obj, 0, numOfElements, ©Length); } - JSHandle key_array; - if (num_of_keys > 0) { - key_array = JSObject::GetAllEnumKeys(thread, obj, 0, num_of_keys, ©_length); + JSHandle keyArray; + if (numOfKeys > 0) { + keyArray = JSObject::GetAllEnumKeys(thread, obj, 0, numOfKeys, ©Length); } - if (num_of_keys != 0 && num_of_elements != 0) { - keys = TaggedArray::AppendSkipHole(thread, element_array, key_array, copy_length); - } else if (num_of_keys != 0) { - keys = factory->CopyArray(key_array, copy_length, copy_length); - } else if (num_of_elements != 0) { - keys = factory->CopyArray(element_array, copy_length, copy_length); + if (numOfKeys != 0 && numOfElements != 0) { + keys = TaggedArray::AppendSkipHole(thread, elementArray, keyArray, copyLength); + } else if (numOfKeys != 0) { + keys = factory->CopyArray(keyArray, copyLength, copyLength); + } else if (numOfElements != 0) { + keys = factory->CopyArray(elementArray, copyLength, copyLength); } else { keys = factory->EmptyArray(); } return keys; } - keys = JSTaggedValue::GetOwnPropertyKeys(thread, tag_obj); + keys = JSTaggedValue::GetOwnPropertyKeys(thread, tagObj); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); uint32_t length = keys->GetLength(); @@ -1333,27 +1332,27 @@ JSHandle JSObject::EnumerableOwnNames(JSThread *thread, const JSHan RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); if (status && desc.IsEnumerable()) { - names->Set(thread, copy_length, key); - copy_length++; + names->Set(thread, copyLength, key); + copyLength++; } } } - return factory->CopyArray(names, length, copy_length); + return factory->CopyArray(names, length, copyLength); } JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, const JSHandle &obj, - PropertyKind kind, ArraySizeT *length_out) + PropertyKind kind, ArraySizeT *lengthOut) { // 1. Assert: Type(O) is Object. ASSERT_PRINT(obj->IsECMAObject(), "obj is not object"); // 2. Let ownKeys be ? O.[[OwnPropertyKeys]](). - JSHandle own_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle(obj)); + JSHandle ownKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle(obj)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); // 3. Let properties be a new empty List. - uint32_t length = own_keys->GetLength(); + uint32_t length = ownKeys->GetLength(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle properties = factory->NewTaggedArray(length); @@ -1372,7 +1371,7 @@ JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, con JSMutableHandle key(thread, JSTaggedValue::Undefined()); uint32_t index = 0; for (uint32_t i = 0; i < length; i++) { - key.Update(own_keys->Get(thread, i)); + key.Update(ownKeys->Get(thread, i)); if (key->IsString()) { PropertyDescriptor desc(thread); bool status = @@ -1390,10 +1389,10 @@ JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, con properties->Set(thread, index++, value); } else { ASSERT_PRINT(kind == PropertyKind::KEY_VALUE, "kind is invalid"); - JSHandle key_value = factory->NewTaggedArray(2); // 2: key-value pair - key_value->Set(thread, 0, key.GetTaggedValue()); - key_value->Set(thread, 1, value.GetTaggedValue()); - JSHandle entry = JSArray::CreateArrayFromList(thread, key_value); + JSHandle keyValue = factory->NewTaggedArray(2); // 2: key-value pair + keyValue->Set(thread, 0, key.GetTaggedValue()); + keyValue->Set(thread, 1, value.GetTaggedValue()); + JSHandle entry = JSArray::CreateArrayFromList(thread, keyValue); properties->Set(thread, index++, entry.GetTaggedValue()); } } @@ -1401,7 +1400,7 @@ JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, con } } - *length_out = index; + *lengthOut = index; // 5. Return properties. return properties; @@ -1427,17 +1426,17 @@ JSHandle JSObject::GetFunctionRealm(JSThread *thread, const JSHandle< JSHandle(thread, JSTaggedValue::Exception())); } // b. Let proxyTarget be the value of obj’s [[ProxyTarget]] internal slot. - JSHandle proxy_target(thread, JSHandle(object)->GetTarget()); - return GetFunctionRealm(thread, proxy_target); + JSHandle proxyTarget(thread, JSHandle(object)->GetTarget()); + return GetFunctionRealm(thread, proxyTarget); } - JSTaggedValue maybe_global_env = JSHandle(object)->GetLexicalEnv(); - if (maybe_global_env.IsUndefined()) { + JSTaggedValue maybeGlobalEnv = JSHandle(object)->GetLexicalEnv(); + if (maybeGlobalEnv.IsUndefined()) { return thread->GetEcmaVM()->GetGlobalEnv(); } - while (!maybe_global_env.IsJSGlobalEnv()) { - maybe_global_env = LexicalEnv::Cast(maybe_global_env.GetTaggedObject())->GetParentEnv(); + while (!maybeGlobalEnv.IsJSGlobalEnv()) { + maybeGlobalEnv = LexicalEnv::Cast(maybeGlobalEnv.GetTaggedObject())->GetParentEnv(); } - return JSHandle(thread, maybe_global_env); + return JSHandle(thread, maybeGlobalEnv); } bool JSObject::InstanceOf(JSThread *thread, const JSHandle &object, @@ -1450,16 +1449,16 @@ bool JSObject::InstanceOf(JSThread *thread, const JSHandle &objec EcmaVM *vm = thread->GetEcmaVM(); // 2. Let instOfHandler be GetMethod(target, @@hasInstance). - JSHandle inst_of_handler = GetMethod(thread, target, vm->GetGlobalEnv()->GetHasInstanceSymbol()); + JSHandle instOfHandler = GetMethod(thread, target, vm->GetGlobalEnv()->GetHasInstanceSymbol()); // 3. ReturnIfAbrupt(instOfHandler). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 4. If instOfHandler is not undefined, then - if (!inst_of_handler->IsUndefined()) { + if (!instOfHandler->IsUndefined()) { // a. Return ! ToBoolean(? Call(instOfHandler, target, «object»)). - auto info = NewRuntimeCallInfo(thread, inst_of_handler, target, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread, instOfHandler, target, JSTaggedValue::Undefined(), 1); info->SetCallArgs(object); JSTaggedValue tagged = JSFunction::Call(info.Get()); @@ -1485,67 +1484,67 @@ JSHandle JSObject::FromPropertyDescriptor(JSThread *thread, const // 2. Let obj be ObjectCreate(%ObjectPrototype%). JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle obj_func = env->GetObjectFunction(); - JSHandle obj_handle = - thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle objFunc = env->GetObjectFunction(); + JSHandle objHandle = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); // 4. If Desc has a [[Value]] field, then Perform CreateDataProperty(obj, "value", Desc.[[Value]]). if (desc.HasValue()) { - JSHandle value_str = global_const->GetHandledValueString(); - bool success = CreateDataProperty(thread, obj_handle, value_str, desc.GetValue()); + JSHandle valueStr = globalConst->GetHandledValueString(); + bool success = CreateDataProperty(thread, objHandle, valueStr, desc.GetValue()); RASSERT_PRINT(success, "CreateDataProperty must be success"); } // 5. If Desc has a [[Writable]] field, then Perform CreateDataProperty(obj, "writable", Desc.[[Writable]]). if (desc.HasWritable()) { - JSHandle writable_str = global_const->GetHandledWritableString(); + JSHandle writableStr = globalConst->GetHandledWritableString(); JSHandle writable(thread, JSTaggedValue(desc.IsWritable())); - [[maybe_unused]] bool success = CreateDataProperty(thread, obj_handle, writable_str, writable); + [[maybe_unused]] bool success = CreateDataProperty(thread, objHandle, writableStr, writable); ASSERT_PRINT(success, "CreateDataProperty must be success"); } // 6. If Desc has a [[Get]] field, then Perform CreateDataProperty(obj, "get", Desc.[[Get]]). if (desc.HasGetter()) { - JSHandle get_str = global_const->GetHandledGetString(); - bool success = CreateDataProperty(thread, obj_handle, get_str, desc.GetGetter()); + JSHandle getStr = globalConst->GetHandledGetString(); + bool success = CreateDataProperty(thread, objHandle, getStr, desc.GetGetter()); RASSERT_PRINT(success, "CreateDataProperty must be success"); } // 7. If Desc has a [[Set]] field, then Perform CreateDataProperty(obj, "set", Desc.[[Set]]) if (desc.HasSetter()) { - JSHandle set_str = global_const->GetHandledSetString(); - bool success = CreateDataProperty(thread, obj_handle, set_str, desc.GetSetter()); + JSHandle setStr = globalConst->GetHandledSetString(); + bool success = CreateDataProperty(thread, objHandle, setStr, desc.GetSetter()); RASSERT_PRINT(success, "CreateDataProperty must be success"); } // 8. If Desc has an [[Enumerable]] field, then Perform CreateDataProperty(obj, "enumerable", // Desc.[[Enumerable]]). if (desc.HasEnumerable()) { - JSHandle enumerable_str = global_const->GetHandledEnumerableString(); + JSHandle enumerableStr = globalConst->GetHandledEnumerableString(); JSHandle enumerable(thread, JSTaggedValue(desc.IsEnumerable())); - [[maybe_unused]] bool success = CreateDataProperty(thread, obj_handle, enumerable_str, enumerable); + [[maybe_unused]] bool success = CreateDataProperty(thread, objHandle, enumerableStr, enumerable); ASSERT_PRINT(success, "CreateDataProperty must be success"); } // 9. If Desc has a [[Configurable]] field, then Perform CreateDataProperty(obj , "configurable", // Desc.[[Configurable]]). if (desc.HasConfigurable()) { - JSHandle configurable_str = global_const->GetHandledConfigurableString(); + JSHandle configurableStr = globalConst->GetHandledConfigurableString(); JSHandle configurable(thread, JSTaggedValue(desc.IsConfigurable())); - [[maybe_unused]] bool success = CreateDataProperty(thread, obj_handle, configurable_str, configurable); + [[maybe_unused]] bool success = CreateDataProperty(thread, objHandle, configurableStr, configurable); ASSERT_PRINT(success, "CreateDataProperty must be success"); } - return JSHandle(obj_handle); + return JSHandle(objHandle); } bool JSObject::ToPropertyDescriptorFast(JSThread *thread, const JSHandle &obj, PropertyDescriptor &desc) { auto *hclass = obj->GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - if (js_type != JSType::JS_OBJECT) { + JSType jsType = hclass->GetObjectType(); + if (jsType != JSType::JS_OBJECT) { return false; } if (hclass->IsDictionaryMode()) { return false; } auto env = thread->GetEcmaVM()->GetGlobalEnv(); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); if (hclass->GetPrototype() != env->GetObjectFunctionPrototype().GetTaggedValue()) { return false; } @@ -1553,34 +1552,34 @@ bool JSObject::ToPropertyDescriptorFast(JSThread *thread, const JSHandleGetObjectFunctionPrototypeClass().GetObject()) { return false; } - LayoutInfo *layout_info = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - int props_number = hclass->NumberOfProps(); - for (int i = 0; i < props_number; i++) { - auto attr = layout_info->GetAttr(i); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + int propsNumber = hclass->NumberOfProps(); + for (int i = 0; i < propsNumber; i++) { + auto attr = layoutInfo->GetAttr(i); if (attr.IsAccessor()) { return false; } - auto key = layout_info->GetKey(i); + auto key = layoutInfo->GetKey(i); auto value = JSObject::Cast(obj->GetTaggedObject())->GetProperty(hclass, attr); - if (key == global_const->GetEnumerableString()) { + if (key == globalConst->GetEnumerableString()) { bool enumerable = value.ToBoolean(); desc.SetEnumerable(enumerable); - } else if (key == global_const->GetConfigurableString()) { + } else if (key == globalConst->GetConfigurableString()) { bool configurable = value.ToBoolean(); desc.SetConfigurable(configurable); - } else if (key == global_const->GetValueString()) { - auto handle_value = JSHandle(thread, value); - desc.SetValue(handle_value); - } else if (key == global_const->GetWritableString()) { + } else if (key == globalConst->GetValueString()) { + auto handleValue = JSHandle(thread, value); + desc.SetValue(handleValue); + } else if (key == globalConst->GetWritableString()) { bool writable = value.ToBoolean(); desc.SetWritable(writable); - } else if (key == global_const->GetGetString()) { + } else if (key == globalConst->GetGetString()) { if (!value.IsCallable()) { return false; } auto getter = JSHandle(thread, value); desc.SetGetter(getter); - } else if (key == global_const->GetSetString()) { + } else if (key == globalConst->GetSetString()) { if (!value.IsCallable()) { return false; } @@ -1609,12 +1608,12 @@ void JSObject::ToPropertyDescriptor(JSThread *thread, const JSHandleGlobalConstants(); + auto globalConst = thread->GlobalConstants(); // 3. Let desc be a new Property Descriptor that initially has no fields. // 4. Let hasEnumerable be HasProperty(Obj, "enumerable") - JSHandle enumerable_str = global_const->GetHandledEnumerableString(); + JSHandle enumerableStr = globalConst->GetHandledEnumerableString(); { - ObjectOperator op(thread, obj.GetTaggedValue(), enumerable_str.GetTaggedValue()); + ObjectOperator op(thread, obj.GetTaggedValue(), enumerableStr.GetTaggedValue()); if (op.IsFound()) { auto value = op.FastGetValue(); bool enumerable = value->IsException() ? false : value->ToBoolean(); @@ -1622,9 +1621,9 @@ void JSObject::ToPropertyDescriptor(JSThread *thread, const JSHandle configurable_str = global_const->GetHandledConfigurableString(); + JSHandle configurableStr = globalConst->GetHandledConfigurableString(); { - ObjectOperator op(thread, obj.GetTaggedValue(), configurable_str.GetTaggedValue()); + ObjectOperator op(thread, obj.GetTaggedValue(), configurableStr.GetTaggedValue()); if (op.IsFound()) { auto value = op.FastGetValue(); bool conf = value->IsException() ? false : value->ToBoolean(); @@ -1632,18 +1631,18 @@ void JSObject::ToPropertyDescriptor(JSThread *thread, const JSHandle value_str = global_const->GetHandledValueString(); + JSHandle valueStr = globalConst->GetHandledValueString(); { - ObjectOperator op(thread, obj.GetTaggedValue(), value_str.GetTaggedValue()); + ObjectOperator op(thread, obj.GetTaggedValue(), valueStr.GetTaggedValue()); if (op.IsFound()) { JSHandle prop = op.FastGetValue(); desc.SetValue(prop); } } // 13. Let hasWritable be HasProperty(Obj, "writable"). - JSHandle writable_str = global_const->GetHandledWritableString(); + JSHandle writableStr = globalConst->GetHandledWritableString(); { - ObjectOperator op(thread, obj.GetTaggedValue(), writable_str.GetTaggedValue()); + ObjectOperator op(thread, obj.GetTaggedValue(), writableStr.GetTaggedValue()); if (op.IsFound()) { auto value = op.FastGetValue(); bool writable = value->IsException() ? false : value->ToBoolean(); @@ -1651,9 +1650,9 @@ void JSObject::ToPropertyDescriptor(JSThread *thread, const JSHandle get_str = global_const->GetHandledGetString(); + JSHandle getStr = globalConst->GetHandledGetString(); { - ObjectOperator op(thread, obj.GetTaggedValue(), get_str.GetTaggedValue()); + ObjectOperator op(thread, obj.GetTaggedValue(), getStr.GetTaggedValue()); if (op.IsFound()) { JSHandle getter = op.FastGetValue(); if (!getter->IsCallable() && !getter->IsUndefined()) { @@ -1664,9 +1663,9 @@ void JSObject::ToPropertyDescriptor(JSThread *thread, const JSHandle set_str = global_const->GetHandledSetString(); + JSHandle setStr = globalConst->GetHandledSetString(); { - ObjectOperator op(thread, obj.GetTaggedValue(), set_str.GetTaggedValue()); + ObjectOperator op(thread, obj.GetTaggedValue(), setStr.GetTaggedValue()); if (op.IsFound()) { JSHandle setter = op.FastGetValue(); if (!setter->IsCallable() && !setter->IsUndefined()) { @@ -1687,40 +1686,39 @@ void JSObject::ToPropertyDescriptor(JSThread *thread, const JSHandle JSObject::SpeciesConstructor(JSThread *thread, const JSHandle &obj, - const JSHandle &default_constructort) + const JSHandle &defaultConstructort) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // Assert: Type(O) is Object. ASSERT_PRINT(obj->IsECMAObject(), "obj must be js object"); // Let C be Get(O, "constructor"). - JSHandle contructor_key = global_const->GetHandledConstructorString(); - JSHandle obj_constructor( - GetProperty(thread, JSHandle(obj), contructor_key).GetValue()); + JSHandle contructorKey = globalConst->GetHandledConstructorString(); + JSHandle objConstructor(GetProperty(thread, JSHandle(obj), contructorKey).GetValue()); // ReturnIfAbrupt(C). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // If C is undefined, return defaultConstructor. - if (obj_constructor->IsUndefined()) { - return default_constructort; + if (objConstructor->IsUndefined()) { + return defaultConstructort; } // If Type(C) is not Object, throw a TypeError exception. - if (!obj_constructor->IsECMAObject()) { + if (!objConstructor->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is not Object", JSHandle(thread, JSTaggedValue::Exception())); } // Let S be Get(C, @@species). - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle species_constructor(GetProperty(thread, obj_constructor, species_symbol).GetValue()); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + JSHandle speciesConstructor(GetProperty(thread, objConstructor, speciesSymbol).GetValue()); // ReturnIfAbrupt(S). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // If S is either undefined or null, return defaultConstructor. - if (species_constructor->IsUndefined() || species_constructor->IsNull()) { - return default_constructort; + if (speciesConstructor->IsUndefined() || speciesConstructor->IsNull()) { + return defaultConstructort; } // If IsConstructor(S) is true, return S. - if (species_constructor->IsConstructor()) { - return species_constructor; + if (speciesConstructor->IsConstructor()) { + return speciesConstructor; } // Throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "Is not Constructor", @@ -1779,12 +1777,12 @@ JSHandle JSObject::EnumerateObjectProperties(JSThread *thread, void JSObject::DefinePropertyByLiteral(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, - bool use_for_class) + bool useForClass) { ASSERT_PRINT(obj->IsECMAObject(), "Obj is not a valid object"); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attr = - use_for_class ? PropertyAttributes::Default(true, false, true) : PropertyAttributes::Default(); + useForClass ? PropertyAttributes::Default(true, false, true) : PropertyAttributes::Default(); if (value->IsAccessorData()) { attr.SetIsAccessor(true); @@ -1819,36 +1817,36 @@ void JSObject::DefineGetter(JSThread *thread, const JSHandle &obj } JSHandle JSObject::CreateObjectFromProperties(const JSThread *thread, const JSHandle &properties, - panda::SpaceType space_type) + panda::SpaceType spaceType) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); size_t length = properties->GetLength(); - uint32_t props_len = 0; + uint32_t propsLen = 0; for (size_t i = 0; i < length; i += 2) { // 2: skip a pair of key and value if (properties->Get(i).IsHole()) { break; } - props_len++; + propsLen++; } - if (props_len <= PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES) { - JSHandle obj = factory->NewJSObjectByClass(properties, props_len, space_type); + if (propsLen <= PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES) { + JSHandle obj = factory->NewJSObjectByClass(properties, propsLen, spaceType); ASSERT_PRINT(obj->IsECMAObject(), "Obj is not a valid object"); - for (size_t i = 0; i < props_len; i++) { + for (size_t i = 0; i < propsLen; i++) { // 2: literal contains a pair of key-value obj->SetPropertyInlinedProps(thread, i, properties->Get(i * 2 + 1)); } return obj; } - JSHandle obj = factory->NewEmptyJSObject(space_type); + JSHandle obj = factory->NewEmptyJSObject(spaceType); JSHandle jshclass(thread, obj->GetJSHClass()); - uint32_t number_inlined_props = jshclass->GetInlinedProperties(); + uint32_t numberInlinedProps = jshclass->GetInlinedProperties(); JSHClass::TransitionToDictionary(thread, obj); // trim in-obj properties space - if (number_inlined_props > 0) { + if (numberInlinedProps > 0) { #ifndef ECMA_DISABLE_FREEOBJECTS - uint32_t free_offs = obj->GetClass()->GetObjectSize(); - uint32_t free_bytes = number_inlined_props * JSTaggedValue::TaggedTypeSize(); - factory->FillFreeObject(ToUintPtr(*obj) + free_offs, free_bytes, RemoveSlots::YES); + uint32_t freeOffs = obj->GetClass()->GetObjectSize(); + uint32_t freeBytes = numberInlinedProps * JSTaggedValue::TaggedTypeSize(); + factory->FillFreeObject(ToUintPtr(*obj) + freeOffs, freeBytes, RemoveSlots::YES); #else uint32_t free_offs = obj->GetClass()->GetObjectSize() - numberInlinedProps * JSTaggedValue::TaggedTypeSize(); for (size_t i = 0; i < numberInlinedProps; ++i) { @@ -1859,17 +1857,17 @@ JSHandle JSObject::CreateObjectFromProperties(const JSThread *thread, } JSMutableHandle dict( - thread, NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(props_len))); - JSMutableHandle value_handle(thread, JSTaggedValue::Undefined()); - JSMutableHandle key_handle(thread, JSTaggedValue::Undefined()); - for (size_t i = 0; i < props_len; i++) { + thread, NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(propsLen))); + JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); + JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); + for (size_t i = 0; i < propsLen; i++) { PropertyAttributes attr = PropertyAttributes::Default(); // 2: literal contains a pair of key-value - value_handle.Update(properties->Get(i * 2 + 1)); + valueHandle.Update(properties->Get(i * 2 + 1)); // 2: literal contains a pair of key-value - key_handle.Update(properties->Get(i * 2)); - JSHandle new_dict = NameDictionary::PutIfAbsent(thread, dict, key_handle, value_handle, attr); - dict.Update(new_dict); + keyHandle.Update(properties->Get(i * 2)); + JSHandle newDict = NameDictionary::PutIfAbsent(thread, dict, keyHandle, valueHandle, attr); + dict.Update(newDict); } obj->SetProperties(thread, dict); return obj; @@ -1899,8 +1897,8 @@ bool JSObject::UpdatePropertyInDictionary(const JSThread *thread, JSTaggedValue void ECMAObject::SetHash(int32_t hash) { - auto hash_field = Barriers::GetDynValue(this, HASH_OFFSET); - JSTaggedValue value(hash_field); + auto hashField = Barriers::GetDynValue(this, HASH_OFFSET); + JSTaggedValue value(hashField); JSThread *thread = this->GetJSThread(); if (value.IsHeapObject()) { ASSERT(value.IsTaggedArray()); @@ -1913,21 +1911,21 @@ void ECMAObject::SetHash(int32_t hash) int32_t ECMAObject::GetHash() const { - auto hash_field = Barriers::GetDynValue(this, HASH_OFFSET); - JSTaggedValue value(hash_field); + auto hashField = Barriers::GetDynValue(this, HASH_OFFSET); + JSTaggedValue value(hashField); if (value.IsHeapObject()) { TaggedArray *array = TaggedArray::Cast(value.GetHeapObject()); return array->Get(0).GetInt(); } JSThread *thread = this->GetJSThread(); - JSHandle value_handle(thread, value); - return JSTaggedValue::ToInt32(thread, value_handle); + JSHandle valueHandle(thread, value); + return JSTaggedValue::ToInt32(thread, valueHandle); } void *ECMAObject::GetNativePointerField(int32_t index) const { - auto hash_field = Barriers::GetDynValue(this, HASH_OFFSET); - JSTaggedValue value(hash_field); + auto hashField = Barriers::GetDynValue(this, HASH_OFFSET); + JSTaggedValue value(hashField); if (value.IsHeapObject()) { JSThread *thread = this->GetJSThread(); JSHandle array(thread, value); @@ -1939,11 +1937,10 @@ void *ECMAObject::GetNativePointerField(int32_t index) const return nullptr; } -void ECMAObject::SetNativePointerField(int32_t index, void *native_pointer, const DeleteEntryPoint &call_back, - void *data) +void ECMAObject::SetNativePointerField(int32_t index, void *nativePointer, const DeleteEntryPoint &callBack, void *data) { - auto hash_field = Barriers::GetDynValue(this, HASH_OFFSET); - JSTaggedValue value(hash_field); + auto hashField = Barriers::GetDynValue(this, HASH_OFFSET); + JSTaggedValue value(hashField); if (!value.IsHeapObject()) { return; } @@ -1957,15 +1954,15 @@ void ECMAObject::SetNativePointerField(int32_t index, void *native_pointer, cons EcmaVM *vm = thread->GetEcmaVM(); JSHandle current = JSHandle(thread, array->Get(thread, index + 1)); - if (!current->IsHole() && native_pointer == nullptr) { + if (!current->IsHole() && nativePointer == nullptr) { // Try to remove native pointer if exists. vm->RemoveArrayDataList(*JSHandle(current)); array->Set(thread, index + 1, JSTaggedValue::Hole()); return; } - JSHandle pointer = vm->GetFactory()->NewJSNativePointer(native_pointer, call_back, data); - if (call_back != nullptr) { + JSHandle pointer = vm->GetFactory()->NewJSNativePointer(nativePointer, callBack, data); + if (callBack != nullptr) { vm->PushToArrayDataList(*pointer); } array->Set(thread, index + 1, pointer.GetTaggedValue()); @@ -1974,8 +1971,8 @@ void ECMAObject::SetNativePointerField(int32_t index, void *native_pointer, cons int32_t ECMAObject::GetNativePointerFieldCount() const { int32_t len = 0; - auto hash_field = Barriers::GetDynValue(this, HASH_OFFSET); - JSTaggedValue value(hash_field); + auto hashField = Barriers::GetDynValue(this, HASH_OFFSET); + JSTaggedValue value(hashField); if (value.IsHeapObject()) { TaggedArray *array = TaggedArray::Cast(value.GetHeapObject()); len = array->GetLength() - 1; @@ -1985,14 +1982,14 @@ int32_t ECMAObject::GetNativePointerFieldCount() const void ECMAObject::SetNativePointerFieldCount(int32_t count) { - auto hash_field = Barriers::GetDynValue(this, HASH_OFFSET); - JSTaggedValue value(hash_field); + auto hashField = Barriers::GetDynValue(this, HASH_OFFSET); + JSTaggedValue value(hashField); if (!value.IsHeapObject()) { JSThread *thread = this->GetJSThread(); JSHandle obj(thread, this); - JSHandle new_array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(count + 1); - new_array->Set(thread, 0, value); - ObjectAccessor::SetDynValue(thread, *obj, HASH_OFFSET, new_array.GetTaggedValue().GetRawData()); + JSHandle newArray = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(count + 1); + newArray->Set(thread, 0, value); + ObjectAccessor::SetDynValue(thread, *obj, HASH_OFFSET, newArray.GetTaggedValue().GetRawData()); } } } // namespace panda::ecmascript diff --git a/runtime/js_object.h b/runtime/js_object.h index 92a11e620126ae36257972053b8f299d2d093577..14f7c77d366e717fe7a256d4189e52fcc019b50a 100644 --- a/runtime/js_object.h +++ b/runtime/js_object.h @@ -71,9 +71,9 @@ public: writable_(w), enumerable_(e), configurable_(c), - has_writable_(true), - has_enumerable_(true), - has_configurable_(true), + hasWritable_(true), + hasEnumerable_(true), + hasConfigurable_(true), value_(v) { } @@ -104,7 +104,7 @@ public: inline void SetWritable(bool flag) { writable_ = flag; - has_writable_ = true; + hasWritable_ = true; } inline bool IsEnumerable() const @@ -115,7 +115,7 @@ public: inline void SetEnumerable(bool flag) { enumerable_ = flag; - has_enumerable_ = true; + hasEnumerable_ = true; } inline bool IsConfigurable() const @@ -126,7 +126,7 @@ public: inline void SetConfigurable(bool flag) { configurable_ = flag; - has_configurable_ = true; + hasConfigurable_ = true; } inline bool HasValue() const @@ -136,17 +136,17 @@ public: inline bool HasWritable() const { - return has_writable_; + return hasWritable_; } inline bool HasConfigurable() const { - return has_configurable_; + return hasConfigurable_; } inline bool HasEnumerable() const { - return has_enumerable_; + return hasEnumerable_; } inline bool HasGetter() const @@ -195,7 +195,7 @@ public: inline bool IsDataDescriptor() const { // 2. If both Desc.[[Value]] and Desc.[[Writable]] are absent, return false. - return !(value_.IsEmpty() && !has_writable_); + return !(value_.IsEmpty() && !hasWritable_); } inline bool IsGenericDescriptor() const @@ -206,7 +206,7 @@ public: inline bool IsEmpty() const { - return !has_writable_ && !has_enumerable_ && !has_configurable_ && !HasValue() && !HasGetter() && !HasSetter(); + return !hasWritable_ && !hasEnumerable_ && !hasConfigurable_ && !HasValue() && !HasGetter() && !HasSetter(); } static void CompletePropertyDescriptor(const JSThread *thread, PropertyDescriptor &desc); @@ -217,9 +217,9 @@ private: bool writable_ {false}; bool enumerable_ {false}; bool configurable_ {false}; - bool has_writable_ {false}; - bool has_enumerable_ {false}; - bool has_configurable_ {false}; + bool hasWritable_ {false}; + bool hasEnumerable_ {false}; + bool hasConfigurable_ {false}; JSHandle value_ {}; JSHandle getter_ {}; @@ -235,65 +235,65 @@ public: using RepresentationField = IsInlinedPropsField::NextField; using OffsetField = RepresentationField::NextField; - explicit PropertyMetaData(uint32_t meta_data) : meta_data_(meta_data) {} + explicit PropertyMetaData(uint32_t metaData) : metaData_(metaData) {} ~PropertyMetaData() = default; DEFAULT_NOEXCEPT_MOVE_SEMANTIC(PropertyMetaData); DEFAULT_COPY_SEMANTIC(PropertyMetaData); - explicit PropertyMetaData(bool is_found) + explicit PropertyMetaData(bool isFound) { - SetFound(is_found); + SetFound(isFound); } inline bool IsFound() const { - return IsFoundField::Get(meta_data_); + return IsFoundField::Get(metaData_); } inline void SetFound(bool flag) { - IsFoundField::Set(flag, &meta_data_); + IsFoundField::Set(flag, &metaData_); } inline bool GetIsInlinedProps() const { - return IsInlinedPropsField::Get(meta_data_); + return IsInlinedPropsField::Get(metaData_); } inline void SetIsInlinedProps(bool flag) { - IsInlinedPropsField::Set(flag, &meta_data_); + IsInlinedPropsField::Set(flag, &metaData_); } inline Representation GetRepresentation() const { - return RepresentationField::Get(meta_data_); + return RepresentationField::Get(metaData_); } inline void SetRepresentation(Representation representation) { - RepresentationField::Set(representation, &meta_data_); + RepresentationField::Set(representation, &metaData_); } inline void SetOffset(uint32_t offset) { - OffsetField::Set(offset, &meta_data_); + OffsetField::Set(offset, &metaData_); } inline uint32_t GetOffset() const { - return OffsetField::Get(meta_data_); + return OffsetField::Get(metaData_); } private: - uint32_t meta_data_ {0}; + uint32_t metaData_ {0}; }; class OperationResult { public: - explicit OperationResult(const JSThread *thread, JSTaggedValue value, PropertyMetaData meta_data) - : meta_data_(meta_data) + explicit OperationResult(const JSThread *thread, JSTaggedValue value, PropertyMetaData metaData) + : metaData_(metaData) { thread_ = thread; value_ = JSHandle(thread_, value); @@ -319,13 +319,13 @@ public: const PropertyMetaData &GetPropertyMetaData() const { - return meta_data_; + return metaData_; } private: const JSThread *thread_ {nullptr}; JSHandle value_ {}; - PropertyMetaData meta_data_ {0U}; + PropertyMetaData metaData_ {0U}; }; class ECMAObject : public TaggedObject { @@ -350,7 +350,7 @@ public: } void *GetNativePointerField(int32_t index) const; - void SetNativePointerField(int32_t index, void *native_pointer, const DeleteEntryPoint &call_back, void *data); + void SetNativePointerField(int32_t index, void *nativePointer, const DeleteEntryPoint &callBack, void *data); int32_t GetNativePointerFieldCount() const; void SetNativePointerFieldCount(int32_t count); }; @@ -399,7 +399,7 @@ public: // 7.3.23 EnumerableOwnPropertyNames ( O, kind ) static JSHandle EnumerableOwnPropertyNames(JSThread *thread, const JSHandle &obj, - PropertyKind kind, ArraySizeT *length_out); + PropertyKind kind, ArraySizeT *lengthOut); static JSHandle GetFunctionRealm(JSThread *thread, const JSHandle &object); @@ -408,7 +408,7 @@ public: static bool TestIntegrityLevel(JSThread *thread, const JSHandle &obj, IntegrityLevel level); static JSHandle SpeciesConstructor(JSThread *thread, const JSHandle &obj, - const JSHandle &default_constructort); + const JSHandle &defaultConstructort); // 7.3.17 template static JSHandle CreateListFromArrayLike(JSThread *thread, const JSHandle &obj); @@ -468,21 +468,21 @@ public: static OperationResult GetPropertyFromGlobal(JSThread *thread, const JSHandle &key); static bool SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, - const JSHandle &value, bool may_throw = false); + const JSHandle &value, bool mayThrow = false); PANDA_PUBLIC_API static bool SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, - bool may_throw = false); + bool mayThrow = false); static bool SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, const JSHandle &receiver, - bool may_throw = false); + bool mayThrow = false); static bool SetProperty(JSThread *thread, const JSHandle &obj, uint32_t index, - const JSHandle &value, bool may_throw = false); + const JSHandle &value, bool mayThrow = false); static bool GlobalSetProperty(JSThread *thread, const JSHandle &key, - const JSHandle &value, bool may_throw); + const JSHandle &value, bool mayThrow); // [[HasProperty]] PANDA_PUBLIC_API static bool HasProperty(JSThread *thread, const JSHandle &obj, @@ -511,7 +511,7 @@ public: static JSTaggedValue CallGetter(JSThread *thread, const AccessorData *accessor, const JSHandle &receiver); static bool CallSetter(JSThread *thread, const AccessorData &accessor, const JSHandle &receiver, - const JSHandle &value, bool may_throw = false); + const JSHandle &value, bool mayThrow = false); void FillElementsWithHoles(const JSThread *thread, uint32_t start, uint32_t end); @@ -547,29 +547,29 @@ public: static void DefinePropertyByLiteral(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, - bool use_for_class = false); + bool useForClass = false); static void DefineSetter(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value); static void DefineGetter(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value); static JSHandle CreateObjectFromProperties(const JSThread *thread, const JSHandle &properties, - panda::SpaceType space_type); + panda::SpaceType spaceType); static void GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array); + const JSHandle &keyArray); static void GetAllKeys(const JSThread *thread, const JSHandle &obj, - std::vector &key_vector); + std::vector &keyVector); static void GetAllElementKeys(JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array); + const JSHandle &keyArray); static void GetALLElementKeysIntoVector(const JSThread *thread, const JSHandle &obj, - std::vector &key_vector); + std::vector &keyVector); uint32_t GetNumberOfKeys(); uint32_t GetNumberOfElements(); static JSHandle GetEnumElementKeys(JSThread *thread, const JSHandle &obj, int offset, - uint32_t num_of_elements, uint32_t *keys); + uint32_t numOfElements, uint32_t *keys); static JSHandle GetAllEnumKeys(const JSThread *thread, const JSHandle &obj, int offset, - uint32_t num_of_keys, uint32_t *keys); + uint32_t numOfKeys, uint32_t *keys); static void AddAccessor(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, PropertyAttributes attr); @@ -615,13 +615,13 @@ private: PropertyAttributes attr = PropertyAttributes(PropertyAttributes::GetDefaultAttributes())); static JSTaggedValue GetProperty(JSThread *thread, ObjectOperator *op); - static bool SetProperty(ObjectOperator *op, const JSHandle &value, bool may_throw); + static bool SetProperty(ObjectOperator *op, const JSHandle &value, bool mayThrow); static void DeletePropertyInternal(JSThread *thread, const JSHandle &obj, const JSHandle &key, uint32_t index); int FindProperty(const JSHandle &key); - static uint32_t ComputeElementCapacity(uint32_t old_capacity); - static uint32_t ComputePropertyCapacity(uint32_t old_capacity); + static uint32_t ComputeElementCapacity(uint32_t oldCapacity); + static uint32_t ComputePropertyCapacity(uint32_t oldCapacity); }; } // namespace panda::ecmascript diff --git a/runtime/js_plural_rules.cpp b/runtime/js_plural_rules.cpp index a641bc6b82db499c43e2e644569ea4ec9c7952ef..f75ab55fa983d0bf8c85d34a4228cb2023409036 100644 --- a/runtime/js_plural_rules.cpp +++ b/runtime/js_plural_rules.cpp @@ -37,30 +37,30 @@ void JSPluralRules::FreeIcuNumberFormatter(void *pointer, [[maybe_unused]] void if (pointer == nullptr) { return; } - auto icu_number_formatter = reinterpret_cast(pointer); - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icu_number_formatter); + auto icuNumberFormatter = reinterpret_cast(pointer); + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuNumberFormatter); } -void JSPluralRules::SetIcuNumberFormatter(JSThread *thread, const JSHandle &plural_rules, - const icu::number::LocalizedNumberFormatter &icu_nf, +void JSPluralRules::SetIcuNumberFormatter(JSThread *thread, const JSHandle &pluralRules, + const icu::number::LocalizedNumberFormatter &icuNf, const DeleteEntryPoint &callback) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); - icu::number::LocalizedNumberFormatter *icu_pointer = - Runtime::GetCurrent()->GetInternalAllocator()->New(icu_nf); - ASSERT(icu_pointer != nullptr); - JSTaggedValue data = plural_rules->GetIcuNF(); + icu::number::LocalizedNumberFormatter *icuPointer = + Runtime::GetCurrent()->GetInternalAllocator()->New(icuNf); + ASSERT(icuPointer != nullptr); + JSTaggedValue data = pluralRules->GetIcuNF(); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); - native->ResetExternalPointer(icu_pointer); + native->ResetExternalPointer(icuPointer); return; } - JSHandle pointer = factory->NewJSNativePointer(icu_pointer); + JSHandle pointer = factory->NewJSNativePointer(icuPointer); pointer->SetDeleter(callback); - plural_rules->SetIcuNF(thread, pointer.GetTaggedValue()); - ecma_vm->PushToArrayDataList(*pointer); + pluralRules->SetIcuNF(thread, pointer.GetTaggedValue()); + ecmaVm->PushToArrayDataList(*pointer); } icu::PluralRules *JSPluralRules::GetIcuPluralRules() const @@ -75,56 +75,55 @@ void JSPluralRules::FreeIcuPluralRules(void *pointer, [[maybe_unused]] void *hin if (pointer == nullptr) { return; } - auto icu_plural_rules = reinterpret_cast(pointer); - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icu_plural_rules); + auto icuPluralRules = reinterpret_cast(pointer); + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuPluralRules); } -void JSPluralRules::SetIcuPluralRules(JSThread *thread, const JSHandle &plural_rules, - const icu::PluralRules &icu_pr, const DeleteEntryPoint &callback) +void JSPluralRules::SetIcuPluralRules(JSThread *thread, const JSHandle &pluralRules, + const icu::PluralRules &icuPr, const DeleteEntryPoint &callback) { [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); - icu::PluralRules *icu_pointer = Runtime::GetCurrent()->GetInternalAllocator()->New(icu_pr); - ASSERT(icu_pointer != nullptr); - JSTaggedValue data = plural_rules->GetIcuPR(); + icu::PluralRules *icuPointer = Runtime::GetCurrent()->GetInternalAllocator()->New(icuPr); + ASSERT(icuPointer != nullptr); + JSTaggedValue data = pluralRules->GetIcuPR(); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); - native->ResetExternalPointer(icu_pointer); + native->ResetExternalPointer(icuPointer); return; } - JSHandle pointer = factory->NewJSNativePointer(icu_pointer); + JSHandle pointer = factory->NewJSNativePointer(icuPointer); pointer->SetDeleter(callback); - plural_rules->SetIcuPR(thread, pointer.GetTaggedValue()); - ecma_vm->PushToArrayDataList(*pointer); + pluralRules->SetIcuPR(thread, pointer.GetTaggedValue()); + ecmaVm->PushToArrayDataList(*pointer); } -JSHandle JSPluralRules::BuildLocaleSet(JSThread *thread, - const std::set &icu_available_locales) +JSHandle JSPluralRules::BuildLocaleSet(JSThread *thread, const std::set &icuAvailableLocales) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle locales = factory->NewTaggedArray(icu_available_locales.size()); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle locales = factory->NewTaggedArray(icuAvailableLocales.size()); int32_t index = 0; - for (const std::string &locale : icu_available_locales) { - JSHandle locale_str = factory->NewFromStdString(locale); - locales->Set(thread, index++, locale_str); + for (const std::string &locale : icuAvailableLocales) { + JSHandle localeStr = factory->NewFromStdString(locale); + locales->Set(thread, index++, localeStr); } return locales; } -bool GetNextLocale(icu::StringEnumeration *locales, std::string &locale_str, int32_t *len) +bool GetNextLocale(icu::StringEnumeration *locales, std::string &localeStr, int32_t *len) { UErrorCode status = U_ZERO_ERROR; const char *locale = nullptr; locale = locales->next(len, status); if ((U_SUCCESS(status) == 0) || locale == nullptr) { - locale_str = ""; + localeStr = ""; return false; } - locale_str = std::string(locale); + localeStr = std::string(locale); return true; } @@ -134,150 +133,150 @@ JSHandle JSPluralRules::GetAvailableLocales(JSThread *thread) std::unique_ptr locales(icu::PluralRules::getAvailableLocales(status)); ASSERT(U_SUCCESS(status)); std::set set; - std::string locale_str; + std::string localeStr; int32_t len = 0; - while (GetNextLocale(locales.get(), locale_str, &len)) { + while (GetNextLocale(locales.get(), localeStr, &len)) { if (len >= STRING_SEPARATOR_LENGTH) { - std::replace(locale_str.begin(), locale_str.end(), '_', '-'); + std::replace(localeStr.begin(), localeStr.end(), '_', '-'); } - set.insert(locale_str); + set.insert(localeStr); } return BuildLocaleSet(thread, set); } // InitializePluralRules ( pluralRules, locales, options ) JSHandle JSPluralRules::InitializePluralRules(JSThread *thread, - const JSHandle &plural_rules, + const JSHandle &pluralRules, const JSHandle &locales, const JSHandle &options) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - auto global_const = thread->GlobalConstants(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + auto globalConst = thread->GlobalConstants(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); // 2&3. If options is undefined, then Let options be ObjectCreate(null). else Let options be ? ToObject(options). - JSHandle pr_options; + JSHandle prOptions; if (!options->IsUndefined()) { - pr_options = JSTaggedValue::ToObject(thread, options); + prOptions = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); } else { - pr_options = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); + prOptions = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); } // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). LocaleMatcherOption matcher = - JSLocale::GetOptionOfString(thread, pr_options, global_const->GetHandledLocaleMatcherString(), + JSLocale::GetOptionOfString(thread, prOptions, globalConst->GetHandledLocaleMatcherString(), {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); // 7. Let t be ? GetOption(options, "type", "string", « "cardinal", "ordinal" », "cardinal"). - JSHandle property = JSHandle::Cast(global_const->GetHandledTypeString()); + JSHandle property = JSHandle::Cast(globalConst->GetHandledTypeString()); TypeOption type = - JSLocale::GetOptionOfString(thread, pr_options, property, {TypeOption::CARDINAL, TypeOption::ORDINAL}, + JSLocale::GetOptionOfString(thread, prOptions, property, {TypeOption::CARDINAL, TypeOption::ORDINAL}, {"cardinal", "ordinal"}, TypeOption::CARDINAL); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); // set pluralRules.[[type]] to type - JSHandle type_value; + JSHandle typeValue; if (type == TypeOption::CARDINAL) { - type_value = global_const->GetHandledCardinalString(); + typeValue = globalConst->GetHandledCardinalString(); } else { - type_value = global_const->GetHandledOrdinalString(); + typeValue = globalConst->GetHandledOrdinalString(); } - plural_rules->SetType(thread, type_value.GetTaggedValue()); + pluralRules->SetType(thread, typeValue.GetTaggedValue()); // Let r be ResolveLocale(%PluralRules%.[[AvailableLocales]], requestedLocales, opt, // %PluralRules%.[[RelevantExtensionKeys]], localeData). - JSHandle available_locales; - if (requested_locales->GetLength() == 0) { - available_locales = factory->EmptyArray(); + JSHandle availableLocales; + if (requestedLocales->GetLength() == 0) { + availableLocales = factory->EmptyArray(); } else { - available_locales = GetAvailableLocales(thread); + availableLocales = GetAvailableLocales(thread); } - std::set relevant_extension_keys {""}; + std::set relevantExtensionKeys {""}; ResolvedLocale r = - JSLocale::ResolveLocale(thread, available_locales, requested_locales, matcher, relevant_extension_keys); + JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); - icu::Locale icu_locale = r.locale_data; + icu::Locale icuLocale = r.localeData; // Get ICU numberFormatter with given locale - icu::number::LocalizedNumberFormatter icu_number_formatter = - icu::number::NumberFormatter::withLocale(icu_locale).roundingMode(UNUM_ROUND_HALFUP); + icu::number::LocalizedNumberFormatter icuNumberFormatter = + icu::number::NumberFormatter::withLocale(icuLocale).roundingMode(UNUM_ROUND_HALFUP); bool sucess = true; UErrorCode status = U_ZERO_ERROR; - UPluralType icu_type = UPLURAL_TYPE_CARDINAL; + UPluralType icuType = UPLURAL_TYPE_CARDINAL; // Trans typeOption to ICU typeOption switch (type) { case TypeOption::ORDINAL: - icu_type = UPLURAL_TYPE_ORDINAL; + icuType = UPLURAL_TYPE_ORDINAL; break; case TypeOption::CARDINAL: - icu_type = UPLURAL_TYPE_CARDINAL; + icuType = UPLURAL_TYPE_CARDINAL; break; default: UNREACHABLE(); } - std::unique_ptr icu_plural_rules(icu::PluralRules::forLocale(icu_locale, icu_type, status)); + std::unique_ptr icuPluralRules(icu::PluralRules::forLocale(icuLocale, icuType, status)); if (U_FAILURE(status) != 0) { // NOLINT(readability-implicit-bool-conversion) sucess = false; } // Trans typeOption to ICU typeOption - if (!sucess || icu_plural_rules == nullptr) { - icu::Locale no_extension_locale(icu_locale.getBaseName()); + if (!sucess || icuPluralRules == nullptr) { + icu::Locale noExtensionLocale(icuLocale.getBaseName()); status = U_ZERO_ERROR; switch (type) { case TypeOption::ORDINAL: - icu_type = UPLURAL_TYPE_ORDINAL; + icuType = UPLURAL_TYPE_ORDINAL; break; case TypeOption::CARDINAL: - icu_type = UPLURAL_TYPE_CARDINAL; + icuType = UPLURAL_TYPE_CARDINAL; break; default: UNREACHABLE(); } - icu_plural_rules.reset(icu::PluralRules::forLocale(icu_locale, icu_type, status)); + icuPluralRules.reset(icu::PluralRules::forLocale(icuLocale, icuType, status)); } - if (U_FAILURE(status) || icu_plural_rules == nullptr) { // NOLINT(readability-implicit-bool-conversion) - THROW_RANGE_ERROR_AND_RETURN(thread, "cannot create icuPluralRules", plural_rules); + if (U_FAILURE(status) || icuPluralRules == nullptr) { // NOLINT(readability-implicit-bool-conversion) + THROW_RANGE_ERROR_AND_RETURN(thread, "cannot create icuPluralRules", pluralRules); } // 9. Perform ? SetNumberFormatDigitOptions(pluralRules, options, 0, 3, "standard"). - JSLocale::SetNumberFormatDigitOptions(thread, plural_rules, JSHandle::Cast(pr_options), MNFD_DEFAULT, + JSLocale::SetNumberFormatDigitOptions(thread, pluralRules, JSHandle::Cast(prOptions), MNFD_DEFAULT, MXFD_DEFAULT, NotationOption::STANDARD); - icu_number_formatter = JSNumberFormat::SetICUFormatterDigitOptions(icu_number_formatter, plural_rules); + icuNumberFormatter = JSNumberFormat::SetICUFormatterDigitOptions(icuNumberFormatter, pluralRules); // Set pluralRules.[[IcuPluralRules]] to icuPluralRules - SetIcuPluralRules(thread, plural_rules, *icu_plural_rules, JSPluralRules::FreeIcuPluralRules); + SetIcuPluralRules(thread, pluralRules, *icuPluralRules, JSPluralRules::FreeIcuPluralRules); // Set pluralRules.[[IcuNumberFormat]] to icuNumberFormatter - SetIcuNumberFormatter(thread, plural_rules, icu_number_formatter, JSPluralRules::FreeIcuNumberFormatter); + SetIcuNumberFormatter(thread, pluralRules, icuNumberFormatter, JSPluralRules::FreeIcuNumberFormatter); // 12. Set pluralRules.[[Locale]] to the value of r.[[locale]]. - JSHandle locale_str = JSLocale::ToLanguageTag(thread, icu_locale); - plural_rules->SetLocale(thread, locale_str.GetTaggedValue()); + JSHandle localeStr = JSLocale::ToLanguageTag(thread, icuLocale); + pluralRules->SetLocale(thread, localeStr.GetTaggedValue()); // 13. Return pluralRules. - return plural_rules; + return pluralRules; } -JSHandle FormatNumericToString(JSThread *thread, const icu::number::LocalizedNumberFormatter *icu_formatter, - const icu::PluralRules *icu_plural_rules, double n) +JSHandle FormatNumericToString(JSThread *thread, const icu::number::LocalizedNumberFormatter *icuFormatter, + const icu::PluralRules *icuPluralRules, double n) { UErrorCode status = U_ZERO_ERROR; - icu::number::FormattedNumber formatted = icu_formatter->formatDouble(n, status); + icu::number::FormattedNumber formatted = icuFormatter->formatDouble(n, status); if (U_FAILURE(status) != 0) { // NOLINT(readability-implicit-bool-conversion) JSHandle exception(thread, JSTaggedValue::Exception()); THROW_RANGE_ERROR_AND_RETURN(thread, "invalid resolve number", JSHandle::Cast(exception)); } - icu::UnicodeString u_string = icu_plural_rules->select(formatted, status); + icu::UnicodeString uString = icuPluralRules->select(formatted, status); if (U_FAILURE(status) != 0) { // NOLINT(readability-implicit-bool-conversion) JSHandle exception(thread, JSTaggedValue::Exception()); THROW_RANGE_ERROR_AND_RETURN(thread, "invalid resolve number", JSHandle::Cast(exception)); @@ -285,65 +284,65 @@ JSHandle FormatNumericToString(JSThread *thread, const icu::number:: ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle result = - factory->NewFromUtf16(reinterpret_cast(u_string.getBuffer()), u_string.length()); + factory->NewFromUtf16(reinterpret_cast(uString.getBuffer()), uString.length()); return result; } -JSHandle JSPluralRules::ResolvePlural(JSThread *thread, const JSHandle &plural_rules, +JSHandle JSPluralRules::ResolvePlural(JSThread *thread, const JSHandle &pluralRules, double n) { - icu::PluralRules *icu_plural_rules = plural_rules->GetIcuPluralRules(); - icu::number::LocalizedNumberFormatter *icu_formatter = plural_rules->GetIcuNumberFormatter(); - if (icu_plural_rules == nullptr || icu_formatter == nullptr) { + icu::PluralRules *icuPluralRules = pluralRules->GetIcuPluralRules(); + icu::number::LocalizedNumberFormatter *icuFormatter = pluralRules->GetIcuNumberFormatter(); + if (icuPluralRules == nullptr || icuFormatter == nullptr) { return JSHandle(thread, JSTaggedValue::Undefined()); } - JSHandle result = FormatNumericToString(thread, icu_formatter, icu_plural_rules, n); + JSHandle result = FormatNumericToString(thread, icuFormatter, icuPluralRules, n); RETURN_HANDLE_IF_ABRUPT_COMPLETION(EcmaString, thread); return result; } -void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandle &plural_rules, +void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandle &pluralRules, const JSHandle &options) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - auto global_const = thread->GlobalConstants(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + auto globalConst = thread->GlobalConstants(); // [[Locale]] - JSHandle property = JSHandle::Cast(global_const->GetHandledLocaleString()); - JSHandle locale(thread, plural_rules->GetLocale()); - PropertyDescriptor locale_desc(thread, JSHandle::Cast(locale), true, true, true); - JSObject::DefineOwnProperty(thread, options, property, locale_desc); + JSHandle property = JSHandle::Cast(globalConst->GetHandledLocaleString()); + JSHandle locale(thread, pluralRules->GetLocale()); + PropertyDescriptor localeDesc(thread, JSHandle::Cast(locale), true, true, true); + JSObject::DefineOwnProperty(thread, options, property, localeDesc); // [[type]] - property = JSHandle::Cast(global_const->GetHandledTypeString()); - PropertyDescriptor type_desc(thread, JSHandle(thread, plural_rules->GetType()), true, true, true); - JSObject::DefineOwnProperty(thread, options, property, type_desc); + property = JSHandle::Cast(globalConst->GetHandledTypeString()); + PropertyDescriptor typeDesc(thread, JSHandle(thread, pluralRules->GetType()), true, true, true); + JSObject::DefineOwnProperty(thread, options, property, typeDesc); // [[MinimumIntegerDigits]] - property = JSHandle::Cast(global_const->GetHandledMinimumIntegerDigitsString()); - JSHandle minimum_integer_digits(thread, plural_rules->GetMinimumIntegerDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, minimum_integer_digits); + property = JSHandle::Cast(globalConst->GetHandledMinimumIntegerDigitsString()); + JSHandle minimumIntegerDigits(thread, pluralRules->GetMinimumIntegerDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumIntegerDigits); - RoundingType rounding_type = static_cast(plural_rules->GetRoundingType().GetInt()); - if (rounding_type == RoundingType::SIGNIFICANTDIGITS) { + RoundingType roundingType = static_cast(pluralRules->GetRoundingType().GetInt()); + if (roundingType == RoundingType::SIGNIFICANTDIGITS) { // [[MinimumSignificantDigits]] - property = global_const->GetHandledMinimumSignificantDigitsString(); - JSHandle minimum_significant_digits(thread, plural_rules->GetMinimumSignificantDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, minimum_significant_digits); + property = globalConst->GetHandledMinimumSignificantDigitsString(); + JSHandle minimumSignificantDigits(thread, pluralRules->GetMinimumSignificantDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumSignificantDigits); // [[MaximumSignificantDigits]] - property = global_const->GetHandledMaximumSignificantDigitsString(); - JSHandle maximum_significant_digits(thread, plural_rules->GetMaximumSignificantDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, maximum_significant_digits); + property = globalConst->GetHandledMaximumSignificantDigitsString(); + JSHandle maximumSignificantDigits(thread, pluralRules->GetMaximumSignificantDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumSignificantDigits); } else { // [[MinimumFractionDigits]] - property = global_const->GetHandledMinimumFractionDigitsString(); - JSHandle minimum_fraction_digits(thread, plural_rules->GetMinimumFractionDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, minimum_fraction_digits); + property = globalConst->GetHandledMinimumFractionDigitsString(); + JSHandle minimumFractionDigits(thread, pluralRules->GetMinimumFractionDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumFractionDigits); // [[MaximumFractionDigits]] - property = global_const->GetHandledMaximumFractionDigitsString(); - JSHandle maximum_fraction_digits(thread, plural_rules->GetMaximumFractionDigits()); - JSObject::CreateDataPropertyOrThrow(thread, options, property, maximum_fraction_digits); + property = globalConst->GetHandledMaximumFractionDigitsString(); + JSHandle maximumFractionDigits(thread, pluralRules->GetMaximumFractionDigits()); + JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumFractionDigits); } // 5. Let pluralCategories be a List of Strings representing the possible results of PluralRuleSelect @@ -351,22 +350,22 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandleGetIcuPluralRules(); - ASSERT(icu_plural_rules != nullptr); - std::unique_ptr categories(icu_plural_rules->getKeywords(status)); + icu::PluralRules *icuPluralRules = pluralRules->GetIcuPluralRules(); + ASSERT(icuPluralRules != nullptr); + std::unique_ptr categories(icuPluralRules->getKeywords(status)); int32_t count = categories->count(status); ASSERT(U_SUCCESS(status)); - JSHandle plural_categories = factory->NewTaggedArray(count); + JSHandle pluralCategories = factory->NewTaggedArray(count); for (int32_t i = 0; i < count; i++) { const icu::UnicodeString *category = categories->snext(status); ASSERT(U_SUCCESS(status)); JSHandle value = JSLocale::IcuToString(thread, *category); - plural_categories->Set(thread, i, value); + pluralCategories->Set(thread, i, value); } // 6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)). - property = global_const->GetHandledPluralCategoriesString(); - JSHandle js_plural_categories = JSArray::CreateArrayFromList(thread, plural_categories); - JSObject::CreateDataPropertyOrThrow(thread, options, property, JSHandle::Cast(js_plural_categories)); + property = globalConst->GetHandledPluralCategoriesString(); + JSHandle jsPluralCategories = JSArray::CreateArrayFromList(thread, pluralCategories); + JSObject::CreateDataPropertyOrThrow(thread, options, property, JSHandle::Cast(jsPluralCategories)); } } // namespace panda::ecmascript diff --git a/runtime/js_plural_rules.h b/runtime/js_plural_rules.h index 1c590829fdd770cbbc551e9d38300c0095e3d525..39f2d97e9efd3dfd9d9f2db973ae196bf806c8b0 100644 --- a/runtime/js_plural_rules.h +++ b/runtime/js_plural_rules.h @@ -49,32 +49,32 @@ public: icu::number::LocalizedNumberFormatter *GetIcuNumberFormatter() const; - static void SetIcuNumberFormatter(JSThread *thread, const JSHandle &plural_rules, - const icu::number::LocalizedNumberFormatter &icu_nf, + static void SetIcuNumberFormatter(JSThread *thread, const JSHandle &pluralRules, + const icu::number::LocalizedNumberFormatter &icuNf, const DeleteEntryPoint &callback); static void FreeIcuNumberFormatter(void *pointer, [[maybe_unused]] void *hint = nullptr); icu::PluralRules *GetIcuPluralRules() const; - static void SetIcuPluralRules(JSThread *thread, const JSHandle &plural_rules, - const icu::PluralRules &icu_pr, const DeleteEntryPoint &callback); + static void SetIcuPluralRules(JSThread *thread, const JSHandle &pluralRules, + const icu::PluralRules &icuPr, const DeleteEntryPoint &callback); static void FreeIcuPluralRules(void *pointer, [[maybe_unused]] void *hint = nullptr); - static JSHandle BuildLocaleSet(JSThread *thread, const std::set &icu_available_locales); + static JSHandle BuildLocaleSet(JSThread *thread, const std::set &icuAvailableLocales); static JSHandle GetAvailableLocales(JSThread *thread); // 15.1.1 InitializePluralRules ( pluralRules, locales, options ) - static JSHandle InitializePluralRules(JSThread *thread, const JSHandle &plural_rules, + static JSHandle InitializePluralRules(JSThread *thread, const JSHandle &pluralRules, const JSHandle &locales, const JSHandle &options); // 15.1.4 ResolvePlural ( pluralRules, n ) - static JSHandle ResolvePlural(JSThread *thread, const JSHandle &plural_rules, double n); + static JSHandle ResolvePlural(JSThread *thread, const JSHandle &pluralRules, double n); - static void ResolvedOptions(JSThread *thread, const JSHandle &plural_rules, + static void ResolvedOptions(JSThread *thread, const JSHandle &pluralRules, const JSHandle &options); }; } // namespace panda::ecmascript diff --git a/runtime/js_primitive_ref.cpp b/runtime/js_primitive_ref.cpp index c2290a272114be55f9728089f32cf62064a9e008..045a37517acfe0219fd7641786e4360bb7fab7b4 100644 --- a/runtime/js_primitive_ref.cpp +++ b/runtime/js_primitive_ref.cpp @@ -33,11 +33,11 @@ JSHandle JSPrimitiveRef::StringCreate(JSThread *thread, const JS // 11. Let length be the number of code unit elements in value. // 12. Let status be DefinePropertyOrThrow(S, "length", PropertyDescriptor{[[Value]]: length, [[Writable]]: // false, [[Enumerable]]: false, [[Configurable]]: false }). - JSHandle length_str = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthStr = thread->GlobalConstants()->GetHandledLengthString(); int32_t length = EcmaString::Cast(value->GetTaggedObject())->GetLength(); PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(length)), false, false, false); - [[maybe_unused]] bool status = JSTaggedValue::DefinePropertyOrThrow(thread, str, length_str, desc); + [[maybe_unused]] bool status = JSTaggedValue::DefinePropertyOrThrow(thread, str, lengthStr, desc); // 13. Assert: status is not an abrupt completion. // 14. Return S. ASSERT(status); @@ -47,7 +47,7 @@ JSHandle JSPrimitiveRef::StringCreate(JSThread *thread, const JS bool JSPrimitiveRef::StringGetIndexProperty(const JSThread *thread, const JSHandle &obj, uint32_t index, PropertyDescriptor *desc) { - uint16_t tmp_char; + uint16_t tmpChar; { EcmaString *str = EcmaString::Cast(JSPrimitiveRef::Cast(*obj)->GetValue().GetTaggedObject()); if (str->GetLength() <= index) { @@ -55,9 +55,9 @@ bool JSPrimitiveRef::StringGetIndexProperty(const JSThread *thread, const JSHand } // 10. Let resultStr be a String value of length 1, containing one code unit from str, specifically the code // unit at index index - tmp_char = str->At(index); + tmpChar = str->At(index); } - JSHandle value(thread->GetEcmaVM()->GetFactory()->NewFromUtf16(&tmp_char, 1)); + JSHandle value(thread->GetEcmaVM()->GetFactory()->NewFromUtf16(&tmpChar, 1)); // 11. Return a PropertyDescriptor{ [[Value]]: resultStr, [[Enumerable]]: true, [[Writable]]: false, // [[Configurable]]: false }. desc->SetValue(value); diff --git a/runtime/js_promise.cpp b/runtime/js_promise.cpp index 2209ae09dc9375940a1897787f25d4c661aff631..cc92524148e20d131fdca4988b94e7710c86dd79 100644 --- a/runtime/js_promise.cpp +++ b/runtime/js_promise.cpp @@ -60,10 +60,10 @@ JSHandle JSPromise::CreateResolvingFunctions(JSThread JSTaggedValue JSPromise::FulfillPromise(JSThread *thread, const JSHandle &promise, const JSHandle &value) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Assert: the value of promise's [[PromiseState]] internal slot is "pending". - JSHandle handle_status(thread, promise->GetPromiseState()); - ASSERT_PRINT(JSTaggedValue::SameValue(handle_status.GetTaggedValue(), + JSHandle handleStatus(thread, promise->GetPromiseState()); + ASSERT_PRINT(JSTaggedValue::SameValue(handleStatus.GetTaggedValue(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), "FulfillPromise: state must be pending"); // 2. Let reactions be the value of promise's [[PromiseFulfillReactions]] internal slot. @@ -71,9 +71,9 @@ JSTaggedValue JSPromise::FulfillPromise(JSThread *thread, const JSHandleSetPromiseResult(thread, value); // 4. Set the value of promise's [[PromiseFulfillReactions]] internal slot to undefined. - promise->SetPromiseFulfillReactions(thread, global_const->GetHandledUndefined()); + promise->SetPromiseFulfillReactions(thread, globalConst->GetHandledUndefined()); // 5. Set the value of promise's [[PromiseRejectReactions]] internal slot to undefined. - promise->SetPromiseRejectReactions(thread, global_const->GetHandledUndefined()); + promise->SetPromiseRejectReactions(thread, globalConst->GetHandledUndefined()); // 6. Set the value of promise's [[PromiseState]] internal slot to "fulfilled". promise->SetPromiseState(thread, JSTaggedValue(static_cast(PromiseStatus::FULFILLED))); // 7. Return TriggerPromiseReactions(reactions, reason). @@ -92,36 +92,36 @@ JSHandle JSPromise::NewPromiseCapability(JSThread *thread, co // constructor (see 25.4.3.1). // 3. Let promiseCapability be a new PromiseCapability { [[Promise]]: undefined, [[Resolve]]: undefined, // [[Reject]]: undefined }. - JSHandle promise_capability = factory->NewPromiseCapability(); + JSHandle promiseCapability = factory->NewPromiseCapability(); // 4. Let executor be a new built-in function object as defined in GetCapabilitiesExecutor Functions // (25.4.1.5.1). JSHandle executor = factory->CreateJSPromiseExecutorFunction(reinterpret_cast(builtins::promise_handler::Executor)); // 5. Set the [[Capability]] internal slot of executor to promiseCapability. - executor->SetCapability(thread, promise_capability.GetTaggedValue()); + executor->SetCapability(thread, promiseCapability.GetTaggedValue()); // 6. Let promise be Construct(C, «executor»). // 7. ReturnIfAbrupt(promise). - JSHandle new_target(thread, JSTaggedValue::Undefined()); + JSHandle newTarget(thread, JSTaggedValue::Undefined()); - auto info = NewRuntimeCallInfo(thread, obj, JSTaggedValue::Undefined(), new_target, 1); + auto info = NewRuntimeCallInfo(thread, obj, JSTaggedValue::Undefined(), newTarget, 1); info->SetCallArgs(executor); JSTaggedValue result = JSFunction::Construct(info.Get()); JSHandle promise(thread, result); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, factory->NewPromiseCapability()); // 8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception. - if (!promise_capability->GetResolve().IsCallable()) { + if (!promiseCapability->GetResolve().IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "NewPromiseCapability: resolve is not a callable function!", factory->NewPromiseCapability()); } // 9. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception. - if (!promise_capability->GetReject().IsCallable()) { + if (!promiseCapability->GetReject().IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "NewPromiseCapability: reject is not a callable function!", factory->NewPromiseCapability()); } // 10. Set promiseCapability.[[Promise]] to promise. - promise_capability->SetPromise(thread, promise); + promiseCapability->SetPromise(thread, promise); // 11. Return promiseCapability. - return promise_capability; + return promiseCapability; } bool JSPromise::IsPromise(const JSHandle &value) @@ -140,52 +140,52 @@ bool JSPromise::IsPromise(const JSHandle &value) // 27.2.4.7.1 PromiseResolve ( C, x ) JSTaggedValue JSPromise::PromiseResolve(JSThread *thread, const JSHandle &constructor, - const JSHandle &x_value) + const JSHandle &xValue) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let C be the this value. ASSERT_PRINT(constructor->IsECMAObject(), "Constructor must is not object"); // 2. If IsPromise(x) is true, - if (x_value->IsJSPromise()) { + if (xValue->IsJSPromise()) { // a. Let xConstructor be Get(x, "constructor"). - JSHandle ctor_key(global_const->GetHandledConstructorString()); - JSHandle x_constructor = JSObject::GetProperty(thread, x_value, ctor_key).GetValue(); + JSHandle ctorKey(globalConst->GetHandledConstructorString()); + JSHandle xConstructor = JSObject::GetProperty(thread, xValue, ctorKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If SameValue(xConstructor, C) is true, return x. - if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), x_constructor.GetTaggedValue())) { - JSHandle value = JSHandle::Cast(x_value); + if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), xConstructor.GetTaggedValue())) { + JSHandle value = JSHandle::Cast(xValue); return value.GetTaggedValue(); } } // 3. Let promiseCapability be NewPromiseCapability(C). - JSHandle promise_capability = JSPromise::NewPromiseCapability(thread, constructor); + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, constructor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Perform ? Call(promiseCapability.[[Resolve]], undefined, « x »). - JSHandle this_arg = global_const->GetHandledUndefined(); - JSHandle resolve(thread, promise_capability->GetResolve()); + JSHandle thisArg = globalConst->GetHandledUndefined(); + JSHandle resolve(thread, promiseCapability->GetResolve()); - auto info = NewRuntimeCallInfo(thread, resolve, this_arg, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(x_value); + auto info = NewRuntimeCallInfo(thread, resolve, thisArg, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(xValue); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return promiseCapability.[[Promise]]. - return promise_capability->GetPromise(); + return promiseCapability->GetPromise(); } JSTaggedValue JSPromise::RejectPromise(JSThread *thread, const JSHandle &promise, const JSHandle &reason) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Assert: the value of promise's [[PromiseState]] internal slot is "pending". - JSHandle handle_status(thread, promise->GetPromiseState()); + JSHandle handleStatus(thread, promise->GetPromiseState()); - ASSERT_PRINT(JSTaggedValue::SameValue(handle_status.GetTaggedValue(), + ASSERT_PRINT(JSTaggedValue::SameValue(handleStatus.GetTaggedValue(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), "RejectPromise: state must be pending"); // 2. Let reactions be the value of promise's [[PromiseRejectReactions]] internal slot. @@ -193,9 +193,9 @@ JSTaggedValue JSPromise::RejectPromise(JSThread *thread, const JSHandleSetPromiseResult(thread, reason); // 4. Set the value of promise's [[PromiseFulfillReactions]] internal slot to undefined. - promise->SetPromiseFulfillReactions(thread, global_const->GetHandledUndefined()); + promise->SetPromiseFulfillReactions(thread, globalConst->GetHandledUndefined()); // 5. Set the value of promise's [[PromiseRejectReactions]] internal slot to undefined. - promise->SetPromiseRejectReactions(thread, global_const->GetHandledUndefined()); + promise->SetPromiseRejectReactions(thread, globalConst->GetHandledUndefined()); // 6. Set the value of promise's [[PromiseState]] internal slot to "rejected". promise->SetPromiseState(thread, JSTaggedValue(static_cast(PromiseStatus::REJECTED))); // 7. When a promise is rejected without any handlers, it is called with its operation argument set to "reject". @@ -212,28 +212,28 @@ JSTaggedValue JSPromise::TriggerPromiseReactions(JSThread *thread, const JSHandl // 1. Repeat for each reaction in reactions, in original insertion order // a. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, «reaction, argument»). JSHandle job = thread->GetEcmaVM()->GetMicroJobQueue(); - JSHandle global_env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle promise_reactions_job(global_env->GetPromiseReactionJob()); + JSHandle promiseReactionsJob(globalEnv->GetPromiseReactionJob()); JSMutableHandle reaction(thread, JSTaggedValue::Undefined()); while (!reactions->Empty()) { reaction.Update(reactions->Pop(thread)); JSHandle arguments = factory->NewTaggedArray(2); // 2 means the length of new array arguments->Set(thread, 0, reaction); arguments->Set(thread, 1, argument); - job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promise_reactions_job, arguments); + job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, arguments); } // 2. Return undefined. - return global_const->GetUndefined(); + return globalConst->GetUndefined(); } JSHandle JSPromise::IfThrowGetThrowValue(JSThread *thread) { if (thread->GetException().IsObjectWrapper()) { - JSHandle wrapper_value(thread, thread->GetException()); - JSHandle throw_value(thread, wrapper_value->GetValue()); - return throw_value; + JSHandle wrapperValue(thread, thread->GetException()); + JSHandle throwValue(thread, wrapperValue->GetValue()); + return throwValue; } return JSHandle(thread, thread->GetException()); } diff --git a/runtime/js_proxy.cpp b/runtime/js_proxy.cpp index bcf17d21a52ac59bfabe4309f5523c383d192fe6..654d7c23507985b742e883f9dcc0887771eb7c3e 100644 --- a/runtime/js_proxy.cpp +++ b/runtime/js_proxy.cpp @@ -66,7 +66,7 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle &p // 3. Assert: Type(handler) is Object. ASSERT(handler->IsECMAObject()); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); // 5. Let trap be GetMethod(handler, "getPrototypeOf"). JSHandle name(thread->GlobalConstants()->GetHandledGetPrototypeOfString()); JSHandle trap = JSObject::GetMethod(thread, handler, name); @@ -75,39 +75,39 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle &p // 7. If trap is undefined, then Return target.[[GetPrototypeOf]](). if (trap->IsUndefined()) { - return JSHandle(target_handle)->GetPrototype(thread); + return JSHandle(targetHandle)->GetPrototype(thread); } // 8. Let handlerProto be Call(trap, handler, «target»). auto info = NewRuntimeCallInfo(thread, trap, handler, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(target_handle.GetTaggedValue()); - JSHandle handler_proto(thread, JSFunction::Call(info.Get())); + info->SetCallArgs(targetHandle.GetTaggedValue()); + JSHandle handlerProto(thread, JSFunction::Call(info.Get())); // 9. ReturnIfAbrupt(handlerProto). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. If Type(handlerProto) is neither Object nor Null, throw a TypeError exception. - if (!handler_proto->IsECMAObject() && !handler_proto->IsNull()) { + if (!handlerProto->IsECMAObject() && !handlerProto->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetPrototype: Type(handlerProto) is neither Object nor Null", JSTaggedValue::Exception()); } // 11. Let extensibleTarget be IsExtensible(target). // 12. ReturnIfAbrupt(extensibleTarget). // 13. If extensibleTarget is true, return handlerProto. - if (target_handle->IsExtensible(thread)) { - return handler_proto.GetTaggedValue(); + if (targetHandle->IsExtensible(thread)) { + return handlerProto.GetTaggedValue(); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 14. Let targetProto be target.[[GetPrototypeOf]](). - JSTaggedValue target_proto = JSHandle(target_handle)->GetPrototype(thread); + JSTaggedValue targetProto = JSHandle(targetHandle)->GetPrototype(thread); // 15. ReturnIfAbrupt(targetProto). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. If SameValue(handlerProto, targetProto) is false, throw a TypeError exception. - if (!JSTaggedValue::SameValue(handler_proto.GetTaggedValue(), target_proto)) { + if (!JSTaggedValue::SameValue(handlerProto.GetTaggedValue(), targetProto)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetPrototype: SameValue(handlerProto, targetProto) is false", JSTaggedValue::Exception()); } // 17. Return handlerProto. - return handler_proto.GetTaggedValue(); + return handlerProto.GetTaggedValue(); } // ES6 9.5.2 [[SetPrototypeOf]] (V) @@ -124,7 +124,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle &proxy, con // 4. Assert: Type(handler) is Object. ASSERT(handler.IsECMAObject()); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); // 6. Let trap be GetMethod(handler, "setPrototypeOf"). JSHandle name = thread->GlobalConstants()->GetHandledSetPrototypeOfString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); @@ -133,40 +133,40 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle &proxy, con // 7. If trap is undefined, then Return target.[[SetPrototypeOf]](V). if (trap->IsUndefined()) { - return JSTaggedValue::SetPrototype(thread, target_handle, proto); + return JSTaggedValue::SetPrototype(thread, targetHandle, proto); }; - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(target_handle.GetTaggedValue(), proto.GetTaggedValue()); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(targetHandle.GetTaggedValue(), proto.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). // If booleanTrapResult is false, return false - bool boolean_trap_result = trap_result.ToBoolean(); - if (!boolean_trap_result) { + bool booleanTrapResult = trapResult.ToBoolean(); + if (!booleanTrapResult) { return false; } // 10. ReturnIfAbrupt(booleanTrapResult). // 11. Let extensibleTarget be IsExtensible(target). // 12. ReturnIfAbrupt(extensibleTarget). // 13. If extensibleTarget is true, return booleanTrapResult - if (target_handle->IsExtensible(thread)) { - return boolean_trap_result; + if (targetHandle->IsExtensible(thread)) { + return booleanTrapResult; } RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 14. Let targetProto be target.[[GetPrototypeOf]](). - JSTaggedValue target_proto = JSHandle(target_handle)->GetPrototype(thread); + JSTaggedValue targetProto = JSHandle(targetHandle)->GetPrototype(thread); // 15. ReturnIfAbrupt(targetProto). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 16. If booleanTrapResult is true and SameValue(V, targetProto) is false, throw a TypeError exception. - if (boolean_trap_result && !JSTaggedValue::SameValue(proto.GetTaggedValue(), target_proto)) { + if (booleanTrapResult && !JSTaggedValue::SameValue(proto.GetTaggedValue(), targetProto)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetPrototype: TypeError of targetProto and Result", false); } // 17. Return handlerProto. - return boolean_trap_result; + return booleanTrapResult; } // ES6 9.5.3 [[IsExtensible]] ( ) @@ -181,7 +181,7 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle &proxy) // 3. Assert: Type(handler) is Object. ASSERT(handler.IsECMAObject()); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); // 5. Let trap be GetMethod(handler, "isExtensible"). JSHandle name = thread->GlobalConstants()->GetHandledIsExtensibleString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); @@ -190,17 +190,17 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle &proxy) // 7. If trap is undefined, then Return target.[[IsExtensible]](). if (trap->IsUndefined()) { - return target_handle->IsExtensible(thread); + return targetHandle->IsExtensible(thread); } // 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). - JSHandle new_tgt(thread, JSTaggedValue::Undefined()); - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle newTgt(thread, JSTaggedValue::Undefined()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(target_handle); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(targetHandle); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); - bool boolean_trap_result = trap_result.ToBoolean(); + bool booleanTrapResult = trapResult.ToBoolean(); // 9. ReturnIfAbrupt(booleanTrapResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -208,11 +208,11 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle &proxy) // 11. ReturnIfAbrupt(targetResult). // 12. If SameValue(booleanTrapResult, targetResult) is false, throw a TypeError exception. // 13. Return booleanTrapResult. - if (target_handle->IsExtensible(thread) != boolean_trap_result) { + if (targetHandle->IsExtensible(thread) != booleanTrapResult) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::IsExtensible: TypeError of targetResult", false); } - return boolean_trap_result; + return booleanTrapResult; } // ES6 9.5.4 [[PreventExtensions]] ( ) @@ -233,33 +233,33 @@ bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle &proxy THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::PreventExtensions: handler is null", false); } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); JSHandle name = thread->GlobalConstants()->GetHandledPreventExtensionsString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 6. ReturnIfAbrupt(trap). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (trap->IsUndefined()) { - return JSTaggedValue::PreventExtensions(thread, target_handle); + return JSTaggedValue::PreventExtensions(thread, targetHandle); } - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(target_handle); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(targetHandle); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); - bool boolean_trap_result = trap_result.ToBoolean(); + bool booleanTrapResult = trapResult.ToBoolean(); // 9. ReturnIfAbrupt(booleanTrapResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 10. If booleanTrapResult is true, then // a. Let targetIsExtensible be target.[[IsExtensible]](). // b. ReturnIfAbrupt(targetIsExtensible). // c. If targetIsExtensible is true, throw a TypeError exception. - if (boolean_trap_result && target_handle->IsExtensible(thread)) { + if (booleanTrapResult && targetHandle->IsExtensible(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::PreventExtensions: targetIsExtensible is true", false); } // 11. Return booleanTrapResult. - return boolean_trap_result; + return booleanTrapResult; } // ES6 9.5.5 [[GetOwnProperty]] (P) @@ -268,7 +268,7 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle &proxy, c { // 1. Assert: IsPropertyKey(P) is true. ASSERT(JSTaggedValue::IsPropertyKey(key)); - const auto prop_key = ToPropertyKey(thread, key); + const auto propKey = ToPropertyKey(thread, key); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. // 3. If handler is null, throw a TypeError exception. // 4. Assert: Type(handler) is Object. @@ -285,48 +285,48 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle &proxy, c THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: handler is null", false); } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); JSHandle name = thread->GlobalConstants()->GetHandledGetOwnPropertyDescriptorString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (trap->IsUndefined()) { - return JSTaggedValue::GetOwnProperty(thread, target_handle, prop_key, desc); + return JSTaggedValue::GetOwnProperty(thread, targetHandle, propKey, desc); } - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(target_handle, prop_key); - JSTaggedValue trap_result_obj = JSFunction::Call(info.Get()); // 2: target and key + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(targetHandle, propKey); + JSTaggedValue trapResultObj = JSFunction::Call(info.Get()); // 2: target and key - JSHandle result_handle(thread, trap_result_obj); + JSHandle resultHandle(thread, trapResultObj); // 11. If Type(trapResultObj) is neither Object nor Undefined, throw a TypeError exception. - if (!trap_result_obj.IsECMAObject() && !trap_result_obj.IsUndefined()) { + if (!trapResultObj.IsECMAObject() && !trapResultObj.IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: TypeError of trapResultObj", false); } // 12. Let targetDesc be target.[[GetOwnProperty]](P). - PropertyDescriptor target_desc(thread); - bool found = JSTaggedValue::GetOwnProperty(thread, target_handle, prop_key, target_desc); + PropertyDescriptor targetDesc(thread); + bool found = JSTaggedValue::GetOwnProperty(thread, targetHandle, propKey, targetDesc); // 13. ReturnIfAbrupt(targetDesc). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 14. If trapResultObj is undefined, then - if (result_handle->IsUndefined()) { + if (resultHandle->IsUndefined()) { // a. If targetDesc is undefined, return undefined. if (!found) { return false; } // b. If targetDesc.[[Configurable]] is false, throw a TypeError exception. - if (!target_desc.IsConfigurable()) { + if (!targetDesc.IsConfigurable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: targetDesc.[[Configurable]] is false", false); } // c. Let extensibleTarget be IsExtensible(target). // d. ReturnIfAbrupt(extensibleTarget). // e. Assert: Type(extensibleTarget) is Boolean. // f. If extensibleTarget is false, throw a TypeError exception. - if (!target_handle->IsExtensible(thread)) { + if (!targetHandle->IsExtensible(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: extensibleTarget is false", false); } // g. Return undefined. @@ -335,32 +335,31 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle &proxy, c // 15. Let extensibleTarget be IsExtensible(target). // 16. ReturnIfAbrupt(extensibleTarget). // 17. Let resultDesc be ToPropertyDescriptor(trapResultObj). - PropertyDescriptor &result_desc = desc; - JSObject::ToPropertyDescriptor(thread, result_handle, result_desc); + PropertyDescriptor &resultDesc = desc; + JSObject::ToPropertyDescriptor(thread, resultHandle, resultDesc); // 18. ReturnIfAbrupt(resultDesc) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 19. Call CompletePropertyDescriptor(resultDesc). - PropertyDescriptor::CompletePropertyDescriptor(thread, result_desc); + PropertyDescriptor::CompletePropertyDescriptor(thread, resultDesc); // 20. Let valid be IsCompatiblePropertyDescriptor (extensibleTarget, resultDesc, targetDesc). - bool valid = - JSObject::IsCompatiblePropertyDescriptor(target_handle->IsExtensible(thread), result_desc, target_desc); + bool valid = JSObject::IsCompatiblePropertyDescriptor(targetHandle->IsExtensible(thread), resultDesc, targetDesc); if (!valid) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: TypeError of valid", false); } // 22. If resultDesc.[[Configurable]] is false, then - if (!result_desc.IsConfigurable()) { + if (!resultDesc.IsConfigurable()) { // a. If targetDesc is undefined or targetDesc.[[Configurable]] is true, then - if (!found || target_desc.IsConfigurable()) { + if (!found || targetDesc.IsConfigurable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: TypeError of targetDesc configurable", false); } // b. If resultDesc has a [[Writable]] field and resultDesc.[[Writable]] is false, then // If targetDesc.[[Writable]] is true, throw a TypeError exception. - if (result_desc.HasWritable() && !result_desc.IsWritable() && target_desc.IsWritable()) { + if (resultDesc.HasWritable() && !resultDesc.IsWritable() && targetDesc.IsWritable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: TypeError of targetDesc writable", false); } // b. If resultDesc has a [[Writable]] field and resultDesc.[[Writable]] is false, then // If targetDesc.[[Writable]] is true, throw a TypeError exception. - if (result_desc.HasWritable() && !result_desc.IsWritable() && target_desc.IsWritable()) { + if (resultDesc.HasWritable() && !resultDesc.IsWritable() && targetDesc.IsWritable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "", false); } } @@ -374,38 +373,38 @@ bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle &proxy { // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - const auto prop_key = ToPropertyKey(thread, key); + const auto propKey = ToPropertyKey(thread, key); JSTaggedValue handler = proxy->GetHandler(); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DefineOwnProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); JSHandle name = thread->GlobalConstants()->GetHandledDefinePropertyString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (trap->IsUndefined()) { - return JSTaggedValue::DefineOwnProperty(thread, target_handle, prop_key, desc); + return JSTaggedValue::DefineOwnProperty(thread, targetHandle, propKey, desc); } // 9. Let descObj be FromPropertyDescriptor(Desc). - JSHandle desc_obj = JSObject::FromPropertyDescriptor(thread, desc); - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle descObj = JSObject::FromPropertyDescriptor(thread, desc); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(target_handle, prop_key, desc_obj); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); // 3: target, key and desc + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(targetHandle, propKey, descObj); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); // 3: target, key and desc - bool boolean_trap_result = trap_result.ToBoolean(); + bool booleanTrapResult = trapResult.ToBoolean(); // 11. ReturnIfAbrupt(booleanTrapResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!boolean_trap_result) { + if (!booleanTrapResult) { return false; } // 13. Let targetDesc be target.[[GetOwnProperty]](P). - PropertyDescriptor target_desc(thread); - bool found = JSTaggedValue::GetOwnProperty(thread, target_handle, prop_key, target_desc); + PropertyDescriptor targetDesc(thread); + bool found = JSTaggedValue::GetOwnProperty(thread, targetHandle, propKey, targetDesc); // 14. ReturnIfAbrupt(targetDesc). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -414,39 +413,39 @@ bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle &proxy // 17. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, then Let settingConfigFalse be // true. // 18. Else let settingConfigFalse be false. - bool setting_config_false = false; + bool settingConfigFalse = false; if (desc.HasConfigurable() && !desc.IsConfigurable()) { - setting_config_false = true; + settingConfigFalse = true; } // 19. If targetDesc is undefined, then if (!found) { // a. If extensibleTarget is false, throw a TypeError exception. - if (!target_handle->IsExtensible(thread)) { + if (!targetHandle->IsExtensible(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DefineOwnProperty: extensibleTarget is false", false); } // b. If settingConfigFalse is true, throw a TypeError exception. - if (setting_config_false) { + if (settingConfigFalse) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DefineOwnProperty: settingConfigFalse is true", false); } } else { // a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc , targetDesc) is false, throw a TypeError // exception. - if (!JSObject::IsCompatiblePropertyDescriptor(target_handle->IsExtensible(thread), desc, target_desc)) { + if (!JSObject::IsCompatiblePropertyDescriptor(targetHandle->IsExtensible(thread), desc, targetDesc)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DefineOwnProperty: CompatiblePropertyDescriptor err", false); } // b. If settingConfigFalse is true and targetDesc.[[Configurable]] is true, throw a TypeError exception. - if (setting_config_false && target_desc.IsConfigurable()) { + if (settingConfigFalse && targetDesc.IsConfigurable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DefineOwnProperty: TypeError of settingConfigFalse", false); } // c. If IsDataDescriptor(targetDesc) is true, targetDesc.[[Configurable]] is false, and targetDesc.[[Writable]] // is true, then If Desc has a [[Writable]] field and Desc.[[Writable]] is false, throw a TypeError exception. - if (target_desc.IsDataDescriptor() && !target_desc.IsConfigurable() && target_desc.IsWritable() && + if (targetDesc.IsDataDescriptor() && !targetDesc.IsConfigurable() && targetDesc.IsWritable() && desc.HasWritable() && !desc.IsWritable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DefineOwnProperty: TypeError of DataDescriptor", false); } // c. If IsDataDescriptor(targetDesc) is true, targetDesc.[[Configurable]] is false, and targetDesc.[[Writable]] // is true, then If Desc has a [[Writable]] field and Desc.[[Writable]] is false, throw a TypeError exception. - if (target_desc.IsDataDescriptor() && !target_desc.IsConfigurable() && target_desc.IsWritable() && + if (targetDesc.IsDataDescriptor() && !targetDesc.IsConfigurable() && targetDesc.IsWritable() && desc.HasWritable() && !desc.IsWritable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "", false); } @@ -460,54 +459,54 @@ bool JSProxy::HasProperty(JSThread *thread, const JSHandle &proxy, cons { // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - const auto prop_key = ToPropertyKey(thread, key); + const auto propKey = ToPropertyKey(thread, key); JSTaggedValue handler = proxy->GetHandler(); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::HasProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); JSHandle name = thread->GlobalConstants()->GetHandledHasString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (trap->IsUndefined()) { - return JSTaggedValue::HasProperty(thread, target_handle, prop_key); + return JSTaggedValue::HasProperty(thread, targetHandle, propKey); } // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(target_handle, prop_key); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); // 2: target and key + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(targetHandle, propKey); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); // 2: target and key - bool boolean_trap_result = trap_result.ToBoolean(); + bool booleanTrapResult = trapResult.ToBoolean(); // 10. ReturnIfAbrupt(booleanTrapResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 11. If booleanTrapResult is false, then - if (!boolean_trap_result) { + if (!booleanTrapResult) { // a. Let targetDesc be target.[[GetOwnProperty]](P). - PropertyDescriptor target_desc(thread); - bool found = JSTaggedValue::GetOwnProperty(thread, target_handle, prop_key, target_desc); + PropertyDescriptor targetDesc(thread); + bool found = JSTaggedValue::GetOwnProperty(thread, targetHandle, propKey, targetDesc); // b. ReturnIfAbrupt(targetDesc). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // c. If targetDesc is not undefined, then if (found) { // i. If targetDesc.[[Configurable]] is false, throw a TypeError exception. - if (!target_desc.IsConfigurable()) { + if (!targetDesc.IsConfigurable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::HasProperty: TypeError of targetDesc", false); } // ii. Let extensibleTarget be IsExtensible(target). // iii. ReturnIfAbrupt(extensibleTarget). // iv. If extensibleTarget is false, throw a TypeError exception. - if (!target_handle->IsExtensible(thread)) { + if (!targetHandle->IsExtensible(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::HasProperty: extensibleTarget is false", false); } } } - return boolean_trap_result; + return booleanTrapResult; } // ES6 9.5.8 [[Get]] (P, Receiver) @@ -516,123 +515,122 @@ OperationResult JSProxy::GetProperty(JSThread *thread, const JSHandle & { // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - const auto prop_key = ToPropertyKey(thread, key); + const auto propKey = ToPropertyKey(thread, key); JSTaggedValue handler = proxy->GetHandler(); - JSHandle exception_handle(thread, JSTaggedValue::Exception()); + JSHandle exceptionHandle(thread, JSTaggedValue::Exception()); if (handler.IsNull()) { - THROW_TYPE_ERROR_AND_RETURN( - thread, "JSProxy::GetProperty: handler is Null", - OperationResult(thread, exception_handle.GetTaggedValue(), PropertyMetaData(false))); + THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetProperty: handler is Null", + OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); JSHandle name = thread->GlobalConstants()->GetHandledGetString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). RETURN_VALUE_IF_ABRUPT_COMPLETION( - thread, OperationResult(thread, exception_handle.GetTaggedValue(), PropertyMetaData(false))); + thread, OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); if (trap->IsUndefined()) { - return JSTaggedValue::GetProperty(thread, target_handle, prop_key, receiver); + return JSTaggedValue::GetProperty(thread, targetHandle, propKey, receiver); } // 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(target_handle, prop_key, receiver); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); // 3: «target, P, Receiver» - JSHandle result_handle(thread, trap_result); + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(targetHandle, propKey, receiver); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); // 3: «target, P, Receiver» + JSHandle resultHandle(thread, trapResult); // 10. ReturnIfAbrupt(trapResult). RETURN_VALUE_IF_ABRUPT_COMPLETION( - thread, OperationResult(thread, exception_handle.GetTaggedValue(), PropertyMetaData(false))); + thread, OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); // 11. Let targetDesc be target.[[GetOwnProperty]](P). - PropertyDescriptor target_desc(thread); - bool found = JSTaggedValue::GetOwnProperty(thread, target_handle, prop_key, target_desc); + PropertyDescriptor targetDesc(thread); + bool found = JSTaggedValue::GetOwnProperty(thread, targetHandle, propKey, targetDesc); // 12. ReturnIfAbrupt(targetDesc). RETURN_VALUE_IF_ABRUPT_COMPLETION( - thread, OperationResult(thread, exception_handle.GetTaggedValue(), PropertyMetaData(false))); + thread, OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); // 13. If targetDesc is not undefined, then if (found) { // a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is false and targetDesc.[[Writable]] is // false, then - if (target_desc.IsDataDescriptor() && !target_desc.IsConfigurable() && !target_desc.IsWritable()) { + if (targetDesc.IsDataDescriptor() && !targetDesc.IsConfigurable() && !targetDesc.IsWritable()) { // i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a TypeError exception. - if (!JSTaggedValue::SameValue(result_handle.GetTaggedValue(), target_desc.GetValue().GetTaggedValue())) { + if (!JSTaggedValue::SameValue(resultHandle.GetTaggedValue(), targetDesc.GetValue().GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN( thread, "JSProxy::GetProperty: TypeError of trapResult", - OperationResult(thread, exception_handle.GetTaggedValue(), PropertyMetaData(false))); + OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); } } // b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] is false and targetDesc.[[Get]] is // undefined, then - if (target_desc.IsAccessorDescriptor() && !target_desc.IsConfigurable() && - target_desc.GetGetter()->IsUndefined()) { + if (targetDesc.IsAccessorDescriptor() && !targetDesc.IsConfigurable() && + targetDesc.GetGetter()->IsUndefined()) { // i. If trapResult is not undefined, throw a TypeError exception. - if (!result_handle.GetTaggedValue().IsUndefined()) { + if (!resultHandle.GetTaggedValue().IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN( thread, "JSProxy::GetProperty: trapResult is not undefined", - OperationResult(thread, exception_handle.GetTaggedValue(), PropertyMetaData(false))); + OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); } } } // 14. Return trapResult. - return OperationResult(thread, result_handle.GetTaggedValue(), PropertyMetaData(true)); + return OperationResult(thread, resultHandle.GetTaggedValue(), PropertyMetaData(true)); } // ES6 9.5.9 [[Set]] ( P, V, Receiver) bool JSProxy::SetProperty(JSThread *thread, const JSHandle &proxy, const JSHandle &key, - const JSHandle &value, const JSHandle &receiver, bool may_throw) + const JSHandle &value, const JSHandle &receiver, bool mayThrow) { // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - const auto prop_key = ToPropertyKey(thread, key); + const auto propKey = ToPropertyKey(thread, key); JSTaggedValue handler = proxy->GetHandler(); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); JSHandle name = thread->GlobalConstants()->GetHandledSetString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (trap->IsUndefined()) { - return JSTaggedValue::SetProperty(thread, target_handle, prop_key, value, receiver, may_throw); + return JSTaggedValue::SetProperty(thread, targetHandle, propKey, value, receiver, mayThrow); } // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, Receiver»)) - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 4); - info->SetCallArgs(target_handle, prop_key, value, receiver); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); // 4: «target, P, V, Receiver» + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 4); + info->SetCallArgs(targetHandle, propKey, value, receiver); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); // 4: «target, P, V, Receiver» - bool boolean_trap_result = trap_result.ToBoolean(); + bool booleanTrapResult = trapResult.ToBoolean(); // 11. ReturnIfAbrupt(booleanTrapResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!boolean_trap_result) { + if (!booleanTrapResult) { return false; } // 13. Let targetDesc be target.[[GetOwnProperty]](P). - PropertyDescriptor target_desc(thread); - bool found = JSTaggedValue::GetOwnProperty(thread, target_handle, prop_key, target_desc); + PropertyDescriptor targetDesc(thread); + bool found = JSTaggedValue::GetOwnProperty(thread, targetHandle, propKey, targetDesc); // 14. If targetDesc is not undefined, then if (found) { // a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is false and targetDesc.[[Writable]] is // false, then - if (target_desc.IsDataDescriptor() && !target_desc.IsConfigurable() && !target_desc.IsWritable()) { + if (targetDesc.IsDataDescriptor() && !targetDesc.IsConfigurable() && !targetDesc.IsWritable()) { // i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a TypeError exception. - if (!JSTaggedValue::SameValue(value, target_desc.GetValue())) { + if (!JSTaggedValue::SameValue(value, targetDesc.GetValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetProperty: TypeError of trapResult", false); } } // b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] is false, then // i. If targetDesc.[[Set]] is undefined, throw a TypeError exception. - if (target_desc.IsAccessorDescriptor() && !target_desc.IsConfigurable() && - target_desc.GetSetter()->IsUndefined()) { + if (targetDesc.IsAccessorDescriptor() && !targetDesc.IsConfigurable() && + targetDesc.GetSetter()->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetProperty: TypeError of AccessorDescriptor", false); } } @@ -649,44 +647,44 @@ bool JSProxy::DeleteProperty(JSThread *thread, const JSHandle &proxy, c THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DeleteProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); JSHandle name = thread->GlobalConstants()->GetHandledDeletePropertyString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (trap->IsUndefined()) { - return JSTaggedValue::DeleteProperty(thread, target_handle, key); + return JSTaggedValue::DeleteProperty(thread, targetHandle, key); } // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). - JSHandle new_tgt(thread, JSTaggedValue::Undefined()); - JSHandle handler_tag(thread, proxy->GetHandler()); + JSHandle newTgt(thread, JSTaggedValue::Undefined()); + JSHandle handlerTag(thread, proxy->GetHandler()); - auto info = NewRuntimeCallInfo(thread, trap, handler_tag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(target_handle, key); - JSTaggedValue trap_result = JSFunction::Call(info.Get()); // 2: target and key + auto info = NewRuntimeCallInfo(thread, trap, handlerTag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(targetHandle, key); + JSTaggedValue trapResult = JSFunction::Call(info.Get()); // 2: target and key - bool boolean_trap_result = trap_result.ToBoolean(); + bool booleanTrapResult = trapResult.ToBoolean(); // 11. ReturnIfAbrupt(booleanTrapResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!boolean_trap_result) { + if (!booleanTrapResult) { return false; } // 13. Let targetDesc be target.[[GetOwnProperty]](P). - PropertyDescriptor target_desc(thread); - bool found = JSTaggedValue::GetOwnProperty(thread, target_handle, key, target_desc); + PropertyDescriptor targetDesc(thread); + bool found = JSTaggedValue::GetOwnProperty(thread, targetHandle, key, targetDesc); // 14. If targetDesc is undefined, return true. if (!found) { return true; } // 15. If targetDesc.[[Configurable]] is false, throw a TypeError exception. - if (!target_desc.IsConfigurable()) { + if (!targetDesc.IsConfigurable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DeleteProperty: targetDesc is not Configurable", false); } - if (!target_handle->IsExtensible(thread)) { + if (!targetHandle->IsExtensible(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DeleteProperty: targetHandle is not Extensible", false); } - if (!target_handle->IsExtensible(thread)) { + if (!targetHandle->IsExtensible(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "", false); } // 16. Return true. @@ -704,12 +702,12 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< } ASSERT(handler.IsECMAObject()); - JSHandle target_handle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget()); // 5.Let trap be GetMethod(handler, "ownKeys"). JSHandle key = thread->GlobalConstants()->GetHandledOwnKeysString(); - JSHandle handler_handle(thread, handler); - JSHandle trap(JSObject::GetMethod(thread, handler_handle, key)); + JSHandle handlerHandle(thread, handler); + JSHandle trap(JSObject::GetMethod(thread, handlerHandle, key)); // 6.ReturnIfAbrupt(trap). RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); @@ -717,37 +715,37 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // 7.If trap is undefined, then // a.Return target.[[OwnPropertyKeys]](). if (trap->IsUndefined()) { - return JSTaggedValue::GetOwnPropertyKeys(thread, target_handle); + return JSTaggedValue::GetOwnPropertyKeys(thread, targetHandle); } // 8.Let trapResultArray be Call(trap, handler, «target»). - JSHandle tag_func(target_handle); + JSHandle tagFunc(targetHandle); - auto info = NewRuntimeCallInfo(thread, trap, handler_handle, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(target_handle); + auto info = NewRuntimeCallInfo(thread, trap, handlerHandle, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(targetHandle); JSTaggedValue res = JSFunction::Call(info.Get()); - JSHandle trap_res_arr(thread, res); + JSHandle trapResArr(thread, res); // 9.Let trapResult be CreateListFromArrayLike(trapResultArray, «String, Symbol»). // 10.ReturnIfAbrupt(trapResult) // If trapResult contains any duplicate entries, throw a TypeError exception. - JSHandle trap_res( - JSObject::CreateListFromArrayLike(thread, trap_res_arr)); + JSHandle trapRes( + JSObject::CreateListFromArrayLike(thread, trapResArr)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - if (trap_res->HasDuplicateEntry()) { + if (trapRes->HasDuplicateEntry()) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: contains duplicate entries", JSHandle(thread, JSTaggedValue::Exception())); } // 11.Let extensibleTarget be IsExtensible(target). - bool extensible_target = target_handle->IsExtensible(thread); + bool extensibleTarget = targetHandle->IsExtensible(thread); // 12.ReturnIfAbrupt(extensibleTarget). RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); // 13.Let targetKeys be target.[[OwnPropertyKeys]](). - JSHandle target_keys = JSTaggedValue::GetOwnPropertyKeys(thread, target_handle); + JSHandle targetKeys = JSTaggedValue::GetOwnPropertyKeys(thread, targetHandle); // 14.ReturnIfAbrupt(targetKeys). RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); @@ -762,86 +760,86 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // i.Append key as an element of targetNonconfigurableKeys. // d.Else, // i.Append key as an element of targetConfigurableKeys. - uint32_t length = target_keys->GetLength(); - JSHandle tgt_cfig_keys = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); - JSHandle tgt_no_cfig_keys = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); + uint32_t length = targetKeys->GetLength(); + JSHandle tgtCfigKeys = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); + JSHandle tgtNoCfigKeys = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); - uint32_t cfig_length = 0; - uint32_t no_cfig_length = 0; + uint32_t cfigLength = 0; + uint32_t noCfigLength = 0; for (uint32_t i = 0; i < length; i++) { - JSHandle target_key(thread, target_keys->Get(i)); - ASSERT(target_key->IsStringOrSymbol()); + JSHandle targetKey(thread, targetKeys->Get(i)); + ASSERT(targetKey->IsStringOrSymbol()); PropertyDescriptor desc(thread); - JSTaggedValue::GetOwnProperty(thread, target_handle, target_key, desc); + JSTaggedValue::GetOwnProperty(thread, targetHandle, targetKey, desc); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); if (!desc.IsEmpty() && !desc.IsConfigurable()) { - tgt_no_cfig_keys->Set(thread, no_cfig_length, target_key); - no_cfig_length++; + tgtNoCfigKeys->Set(thread, noCfigLength, targetKey); + noCfigLength++; } else { - tgt_cfig_keys->Set(thread, cfig_length, target_key); - cfig_length++; + tgtCfigKeys->Set(thread, cfigLength, targetKey); + cfigLength++; } } // 19.If extensibleTarget is true and targetNonconfigurableKeys is empty, then // a.Return trapResult. - if (extensible_target && (no_cfig_length == 0)) { - return trap_res; + if (extensibleTarget && (noCfigLength == 0)) { + return trapRes; } // 20.Let uncheckedResultKeys be a new List which is a copy of trapResult. - JSHandle uncheck_fes_keys = - thread->GetEcmaVM()->GetFactory()->CopyArray(trap_res, trap_res->GetLength(), trap_res->GetLength()); - uint32_t uncheck_length = uncheck_fes_keys->GetLength(); + JSHandle uncheckFesKeys = + thread->GetEcmaVM()->GetFactory()->CopyArray(trapRes, trapRes->GetLength(), trapRes->GetLength()); + uint32_t uncheckLength = uncheckFesKeys->GetLength(); // 21.Repeat, for each key that is an element of targetNonconfigurableKeys, // a.If key is not an element of uncheckedResultKeys, throw a TypeError exception. // b.Remove key from uncheckedResultKeys - for (uint32_t i = 0; i < no_cfig_length; i++) { - uint32_t idx = uncheck_fes_keys->GetIdx(tgt_no_cfig_keys->Get(i)); + for (uint32_t i = 0; i < noCfigLength; i++) { + uint32_t idx = uncheckFesKeys->GetIdx(tgtNoCfigKeys->Get(i)); if (idx == TaggedArray::MAX_ARRAY_INDEX) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: key is not an element of uncheckedResultKeys", JSHandle(thread, JSTaggedValue::Exception())); } - uncheck_fes_keys->Set(thread, idx, JSTaggedValue::Hole()); - uncheck_length--; + uncheckFesKeys->Set(thread, idx, JSTaggedValue::Hole()); + uncheckLength--; } // 22.If extensibleTarget is true, return trapResult. - if (extensible_target) { - return trap_res; + if (extensibleTarget) { + return trapRes; } // 23.Repeat, for each key that is an element of targetConfigurableKeys, // a.If key is not an element of uncheckedResultKeys, throw a TypeError exception. // b.Remove key from uncheckedResultKeys - for (uint32_t i = 0; i < cfig_length; i++) { - uint32_t idx = uncheck_fes_keys->GetIdx(tgt_cfig_keys->Get(i)); + for (uint32_t i = 0; i < cfigLength; i++) { + uint32_t idx = uncheckFesKeys->GetIdx(tgtCfigKeys->Get(i)); if (idx == TaggedArray::MAX_ARRAY_INDEX) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: key is not an element of uncheckedResultKeys", JSHandle(thread, JSTaggedValue::Exception())); } - uncheck_fes_keys->Set(thread, idx, JSTaggedValue::Hole()); - uncheck_length--; + uncheckFesKeys->Set(thread, idx, JSTaggedValue::Hole()); + uncheckLength--; } // 24.If uncheckedResultKeys is not empty, throw a TypeError exception. - if (uncheck_length != 0) { + if (uncheckLength != 0) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: uncheckedResultKeys is not empty", JSHandle(thread, JSTaggedValue::Exception())); } // 25.Return trapResult. - return trap_res; + return trapRes; } // ES6 9.5.13 [[Call]] (thisArgument, argumentsList) JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info) { JSThread *thread = info->GetThread(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle proxy(info->GetFunction()); // step 1 ~ 4 get ProxyHandler and ProxyTarget JSHandle handler(thread, proxy->GetHandler()); @@ -852,46 +850,46 @@ JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info) JSHandle target(thread, proxy->GetTarget()); // 5.Let trap be GetMethod(handler, "apply"). - JSHandle key(global_const->GetHandledApplyString()); + JSHandle key(globalConst->GetHandledApplyString()); JSHandle method = JSObject::GetMethod(thread, handler, key); // 6.ReturnIfAbrupt(trap). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint32_t argc = info->GetArgsNumber(); - JSHandle this_arg = info->GetThis(); - JSHandle undefined = global_const->GetHandledUndefined(); + JSHandle thisArg = info->GetThis(); + JSHandle undefined = globalConst->GetHandledUndefined(); // 7.If trap is undefined, then // a.Return Call(target, thisArgument, argumentsList). if (method->IsUndefined()) { - auto runtime_info = NewRuntimeCallInfo(thread, target, this_arg, undefined, argc); + auto runtimeInfo = NewRuntimeCallInfo(thread, target, thisArg, undefined, argc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (argc > 0) { - runtime_info->SetCallArg( + runtimeInfo->SetCallArg( argc, reinterpret_cast(info->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS))); } - return JSFunction::Call(runtime_info.Get()); + return JSFunction::Call(runtimeInfo.Get()); } // 8.Let argArray be CreateArrayFromList(argumentsList). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle tagged_array = factory->NewTaggedArray(argc); + JSHandle taggedArray = factory->NewTaggedArray(argc); for (uint32_t index = 0; index < argc; ++index) { - tagged_array->Set(thread, index, info->GetCallArg(index)); + taggedArray->Set(thread, index, info->GetCallArg(index)); } - JSHandle arr_handle = JSArray::CreateArrayFromList(thread, tagged_array); + JSHandle arrHandle = JSArray::CreateArrayFromList(thread, taggedArray); // 9.Return Call(trap, handler, «target, thisArgument, argArray»). - const uint32_t args_length = 3; // 3: «target, thisArgument, argArray» - auto runtime_info = NewRuntimeCallInfo(thread, method, handler, undefined, args_length); + const uint32_t argsLength = 3; // 3: «target, thisArgument, argArray» + auto runtimeInfo = NewRuntimeCallInfo(thread, method, handler, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - runtime_info->SetCallArgs(target.GetTaggedValue(), this_arg.GetTaggedValue(), arr_handle.GetTaggedValue()); - return JSFunction::Call(runtime_info.Get()); + runtimeInfo->SetCallArgs(target.GetTaggedValue(), thisArg.GetTaggedValue(), arrHandle.GetTaggedValue()); + return JSFunction::Call(runtimeInfo.Get()); } // ES6 9.5.14 [[Construct]] ( argumentsList, new_target) JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info) { JSThread *thread = info->GetThread(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 4 get ProxyHandler and ProxyTarget JSHandle proxy(info->GetFunction()); JSHandle handler(thread, proxy->GetHandler()); @@ -902,7 +900,7 @@ JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info) JSHandle target(thread, proxy->GetTarget()); // 5.Let trap be GetMethod(handler, "construct"). - JSHandle key(global_const->GetHandledProxyConstructString()); + JSHandle key(globalConst->GetHandledProxyConstructString()); JSHandle method = JSObject::GetMethod(thread, handler, key); // 6.ReturnIfAbrupt(trap). @@ -919,28 +917,28 @@ JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info) // 8.Let argArray be CreateArrayFromList(argumentsList). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); uint32_t argc = info->GetArgsNumber(); - JSHandle tagged_array = factory->NewTaggedArray(argc); + JSHandle taggedArray = factory->NewTaggedArray(argc); for (uint32_t index = 0; index < argc; ++index) { - tagged_array->Set(thread, index, info->GetCallArg(index)); + taggedArray->Set(thread, index, info->GetCallArg(index)); } - JSHandle arr_handle = JSArray::CreateArrayFromList(thread, tagged_array); + JSHandle arrHandle = JSArray::CreateArrayFromList(thread, taggedArray); // step 8 ~ 9 Call(trap, handler, «target, argArray, newTarget »). - JSHandle new_target(info->GetNewTarget()); - const int32_t args_length = 3; // 3: «target, argArray, newTarget » - JSHandle undefined = global_const->GetHandledUndefined(); - auto runtime_info = NewRuntimeCallInfo(thread, method, handler, undefined, args_length); - runtime_info->SetCallArgs(target.GetTaggedValue(), arr_handle.GetTaggedValue(), new_target.GetTaggedValue()); - JSTaggedValue new_obj = JSFunction::Call(runtime_info.Get()); + JSHandle newTarget(info->GetNewTarget()); + const int32_t argsLength = 3; // 3: «target, argArray, newTarget » + JSHandle undefined = globalConst->GetHandledUndefined(); + auto runtimeInfo = NewRuntimeCallInfo(thread, method, handler, undefined, argsLength); + runtimeInfo->SetCallArgs(target.GetTaggedValue(), arrHandle.GetTaggedValue(), newTarget.GetTaggedValue()); + JSTaggedValue newObj = JSFunction::Call(runtimeInfo.Get()); // 10.ReturnIfAbrupt(newObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11.If Type(newObj) is not Object, throw a TypeError exception. - if (!new_obj.IsECMAObject()) { + if (!newObj.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new object is not object", JSTaggedValue::Exception()); } // 12.Return newObj. - return new_obj; + return newObj; } bool JSProxy::IsArray(JSThread *thread) const diff --git a/runtime/js_proxy.h b/runtime/js_proxy.h index 1256bee34a481c116afc8dd1ed0ad43fbf97aedf..78e36ae9a52404d825da5556e2593bdaf87d231d 100644 --- a/runtime/js_proxy.h +++ b/runtime/js_proxy.h @@ -53,13 +53,13 @@ public: const JSHandle &key, const JSHandle &receiver); // ES6 9.5.9 [[Set]] ( P, V, Receiver) static inline bool SetProperty(JSThread *thread, const JSHandle &proxy, const JSHandle &key, - const JSHandle &value, bool may_throw = false) + const JSHandle &value, bool mayThrow = false) { - return SetProperty(thread, proxy, key, value, JSHandle::Cast(proxy), may_throw); + return SetProperty(thread, proxy, key, value, JSHandle::Cast(proxy), mayThrow); } static bool SetProperty(JSThread *thread, const JSHandle &proxy, const JSHandle &key, const JSHandle &value, const JSHandle &receiver, - bool may_throw = false); + bool mayThrow = false); // ES6 9.5.10 [[Delete]] (P) static bool DeleteProperty(JSThread *thread, const JSHandle &proxy, const JSHandle &key); diff --git a/runtime/js_regexp_iterator.cpp b/runtime/js_regexp_iterator.cpp index 90ce22ccd451f185badb02bb3f5f53e266f0a39e..2a20a10e33f3de97bdd9b4220edd90b2e5830edb 100644 --- a/runtime/js_regexp_iterator.cpp +++ b/runtime/js_regexp_iterator.cpp @@ -26,7 +26,7 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. JSHandle input(builtins_common::GetThis(argv)); @@ -37,80 +37,78 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not a regExp iterator", JSTaggedValue::Exception()); } - JSHandle undefined_handle(thread->GlobalConstants()->GetHandledUndefined()); - JSHandle js_iterator = JSHandle::Cast(input); + JSHandle undefinedHandle(thread->GlobalConstants()->GetHandledUndefined()); + JSHandle jsIterator = JSHandle::Cast(input); // 4. If O.[[Done]] is true, then // a. Return ! CreateIterResultObject(undefined, true). - if (js_iterator->GetDone()) { - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + if (jsIterator->GetDone()) { + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } // 5. Let R be O.[[IteratingRegExp]]. // 6. Let S be O.[[IteratedString]]. // 7. Let global be O.[[Global]]. // 8. Let fullUnicode be O.[[Unicode]]. - JSHandle regex_handle(thread, js_iterator->GetIteratingRegExp()); - JSHandle input_str(thread, js_iterator->GetIteratedString()); - bool global = js_iterator->GetGlobal(); - bool full_unicode = js_iterator->GetUnicode(); + JSHandle regexHandle(thread, jsIterator->GetIteratingRegExp()); + JSHandle inputStr(thread, jsIterator->GetIteratedString()); + bool global = jsIterator->GetGlobal(); + bool fullUnicode = jsIterator->GetUnicode(); // 9. Let match be ? RegExpExec(R, S). - JSTaggedValue match = builtins::reg_exp::RegExpExec(thread, regex_handle, input_str, false); - JSHandle match_handle(thread, match); + JSTaggedValue match = builtins::reg_exp::RegExpExec(thread, regexHandle, inputStr, false); + JSHandle matchHandle(thread, match); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. If match is null, then // a. Set O.[[Done]] to true. // b. Return ! CreateIterResultObject(undefined, true). // Else, - if (match_handle->IsNull()) { - js_iterator->SetDone(true); - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + if (matchHandle->IsNull()) { + jsIterator->SetDone(true); + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } // a. If global is true, then // i. Let matchStr be ? ToString(? Get(match, "0")). if (global) { - const GlobalEnvConstants *global_constants = thread->GlobalConstants(); - JSHandle zero_string(global_constants->GetHandledZeroString()); - JSHandle get_zero(JSObject::GetProperty(thread, match_handle, zero_string).GetValue()); - JSHandle match_str = JSTaggedValue::ToString(thread, get_zero); + const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); + JSHandle zeroString(globalConstants->GetHandledZeroString()); + JSHandle getZero(JSObject::GetProperty(thread, matchHandle, zeroString).GetValue()); + JSHandle matchStr = JSTaggedValue::ToString(thread, getZero); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // ii. If matchStr is the empty String, then // 1. Let thisIndex be ? ToLength(? Get(R, "lastIndex")). // 2. Let nextIndex be ! AdvanceStringIndex(S, thisIndex, fullUnicode). // 3. Perform ? Set(R, "lastIndex", 𝔽(nextIndex), true). - if (match_str->GetLength() == 0) { - JSHandle last_index_string(global_constants->GetHandledLastIndexString()); - JSHandle get_last_index( - JSObject::GetProperty(thread, regex_handle, last_index_string).GetValue()); - JSTaggedNumber this_index = JSTaggedValue::ToLength(thread, get_last_index); + if (matchStr->GetLength() == 0) { + JSHandle lastIndexString(globalConstants->GetHandledLastIndexString()); + JSHandle getLastIndex( + JSObject::GetProperty(thread, regexHandle, lastIndexString).GetValue()); + JSTaggedNumber thisIndex = JSTaggedValue::ToLength(thread, getLastIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue next_index( - builtins::reg_exp::AdvanceStringIndex(input_str, this_index.ToUint32(), full_unicode)); - FastRuntimeStub::FastSetPropertyByValue(thread, regex_handle, last_index_string, - HandleFromLocal(&next_index)); + JSTaggedValue nextIndex(builtins::reg_exp::AdvanceStringIndex(inputStr, thisIndex.ToUint32(), fullUnicode)); + FastRuntimeStub::FastSetPropertyByValue(thread, regexHandle, lastIndexString, HandleFromLocal(&nextIndex)); } // iii. Return ! CreateIterResultObject(match, false). - return JSIterator::CreateIterResultObject(thread, match_handle, false).GetTaggedValue(); + return JSIterator::CreateIterResultObject(thread, matchHandle, false).GetTaggedValue(); } // b. Else, // i. Set O.[[Done]] to true. // ii. Return ! CreateIterResultObject(match, false). - js_iterator->SetDone(true); - return JSIterator::CreateIterResultObject(thread, match_handle, false).GetTaggedValue(); + jsIterator->SetDone(true); + return JSIterator::CreateIterResultObject(thread, matchHandle, false).GetTaggedValue(); } JSHandle JSRegExpIterator::CreateRegExpStringIterator(JSThread *thread, const JSHandle &matcher, - const JSHandle &input_str, bool global, - bool full_unicode) + const JSHandle &inputStr, bool global, + bool fullUnicode) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!matcher->IsJSRegExp()) { - JSHandle undefined_handle(thread->GlobalConstants()->GetHandledUndefined()); - THROW_TYPE_ERROR_AND_RETURN(thread, "matcher is not JSRegExp", undefined_handle); + JSHandle undefinedHandle(thread->GlobalConstants()->GetHandledUndefined()); + THROW_TYPE_ERROR_AND_RETURN(thread, "matcher is not JSRegExp", undefinedHandle); } - JSHandle iter(factory->NewJSRegExpIterator(matcher, input_str, global, full_unicode)); + JSHandle iter(factory->NewJSRegExpIterator(matcher, inputStr, global, fullUnicode)); return iter; } } // namespace panda::ecmascript diff --git a/runtime/js_regexp_iterator.h b/runtime/js_regexp_iterator.h index 7ffe3142b4a76aeee63267835326ed287fc48d63..e70a1e3ae2c9b8004abf8567437a7dc8b0be05f6 100644 --- a/runtime/js_regexp_iterator.h +++ b/runtime/js_regexp_iterator.h @@ -26,8 +26,8 @@ public: // 22.2.7.1 CreateRegExpStringIterator ( R, S, global, fullUnicode ) static JSHandle CreateRegExpStringIterator(JSThread *thread, const JSHandle &matcher, - const JSHandle &input_str, bool global, - bool full_unicode); + const JSHandle &inputStr, bool global, + bool fullUnicode); static JSTaggedValue Next(EcmaRuntimeCallInfo *argv); diff --git a/runtime/js_relative_time_format.cpp b/runtime/js_relative_time_format.cpp index 86bc1b6d07e3d6c536a823fa8afd228661ecf173..356baf053ea6d55713a8a8c9ae599b840820d88e 100644 --- a/runtime/js_relative_time_format.cpp +++ b/runtime/js_relative_time_format.cpp @@ -25,148 +25,148 @@ enum class NumericOption : uint8_t { ALWAYS = 0x01, AUTO, EXCEPTION }; // 14.1.1 InitializeRelativeTimeFormat ( relativeTimeFormat, locales, options ) JSHandle JSRelativeTimeFormat::InitializeRelativeTimeFormat( - JSThread *thread, const JSHandle &relative_time_format, - const JSHandle &locales, const JSHandle &options) + JSThread *thread, const JSHandle &relativeTimeFormat, const JSHandle &locales, + const JSHandle &options) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); // 1.Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // 2&3. If options is undefined, then Let options be ObjectCreate(null). else Let options be ? ToObject(options). - JSHandle rtf_options; + JSHandle rtfOptions; if (!options->IsUndefined()) { - rtf_options = JSTaggedValue::ToObject(thread, options); + rtfOptions = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); } else { - rtf_options = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); + rtfOptions = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); } // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); LocaleMatcherOption matcher = - JSLocale::GetOptionOfString(thread, rtf_options, global_const->GetHandledLocaleMatcherString(), + JSLocale::GetOptionOfString(thread, rtfOptions, globalConst->GetHandledLocaleMatcherString(), {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // 7. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). - JSHandle property = JSHandle::Cast(global_const->GetHandledNumberingSystemString()); - JSHandle undefined_value(thread, JSTaggedValue::Undefined()); - JSHandle numbering_system_value = - JSLocale::GetOption(thread, rtf_options, property, OptionType::STRING, undefined_value, undefined_value); + JSHandle property = JSHandle::Cast(globalConst->GetHandledNumberingSystemString()); + JSHandle undefinedValue(thread, JSTaggedValue::Undefined()); + JSHandle numberingSystemValue = + JSLocale::GetOption(thread, rtfOptions, property, OptionType::STRING, undefinedValue, undefinedValue); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // Check whether numberingSystem is well formed and set to %RelativeTimeFormat%.[[numberingSystem]] - std::string numbering_system_std_str; - if (!numbering_system_value->IsUndefined()) { - JSHandle numbering_system_string = JSHandle::Cast(numbering_system_value); - if (numbering_system_string->IsUtf16()) { - THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", relative_time_format); + std::string numberingSystemStdStr; + if (!numberingSystemValue->IsUndefined()) { + JSHandle numberingSystemString = JSHandle::Cast(numberingSystemValue); + if (numberingSystemString->IsUtf16()) { + THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", relativeTimeFormat); } - numbering_system_std_str = JSLocale::ConvertToStdString(numbering_system_string); - if (!JSLocale::IsNormativeNumberingSystem(numbering_system_std_str)) { - THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", relative_time_format); + numberingSystemStdStr = JSLocale::ConvertToStdString(numberingSystemString); + if (!JSLocale::IsNormativeNumberingSystem(numberingSystemStdStr)) { + THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", relativeTimeFormat); } } else { - relative_time_format->SetNumberingSystem(thread, global_const->GetHandledLatnString()); + relativeTimeFormat->SetNumberingSystem(thread, globalConst->GetHandledLatnString()); } // 10. Let localeData be %RelativeTimeFormat%.[[LocaleData]]. // 11. Let r be ResolveLocale(%RelativeTimeFormat%.[[AvailableLocales]], requestedLocales, opt, // %RelativeTimeFormat%.[[RelevantExtensionKeys]], localeData). - JSHandle available_locales; - if (requested_locales->GetLength() == 0) { - available_locales = factory->EmptyArray(); + JSHandle availableLocales; + if (requestedLocales->GetLength() == 0) { + availableLocales = factory->EmptyArray(); } else { - available_locales = JSLocale::GetAvailableLocales(thread, "calendar", nullptr); + availableLocales = JSLocale::GetAvailableLocales(thread, "calendar", nullptr); } - std::set relevant_extension_keys {"nu"}; + std::set relevantExtensionKeys {"nu"}; ResolvedLocale r = - JSLocale::ResolveLocale(thread, available_locales, requested_locales, matcher, relevant_extension_keys); + JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); - icu::Locale icu_locale = r.locale_data; + icu::Locale icuLocale = r.localeData; // 12. Let locale be r.[[Locale]]. - JSHandle locale_str = JSLocale::ToLanguageTag(thread, icu_locale); + JSHandle localeStr = JSLocale::ToLanguageTag(thread, icuLocale); // 13. Set relativeTimeFormat.[[Locale]] to locale. - relative_time_format->SetLocale(thread, locale_str.GetTaggedValue()); + relativeTimeFormat->SetLocale(thread, localeStr.GetTaggedValue()); // 15. Set relativeTimeFormat.[[NumberingSystem]] to r.[[nu]]. UErrorCode status = U_ZERO_ERROR; - if (!numbering_system_std_str.empty()) { - if (JSLocale::IsWellNumberingSystem(numbering_system_std_str)) { - icu_locale.setUnicodeKeywordValue("nu", numbering_system_std_str, status); + if (!numberingSystemStdStr.empty()) { + if (JSLocale::IsWellNumberingSystem(numberingSystemStdStr)) { + icuLocale.setUnicodeKeywordValue("nu", numberingSystemStdStr, status); ASSERT(U_SUCCESS(status)); } } // 16. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long"). - property = JSHandle::Cast(global_const->GetHandledStyleString()); - StyleOption style_option = JSLocale::GetOptionOfString(thread, rtf_options, property, - {StyleOption::LONG, StyleOption::SHORT, StyleOption::NARROW}, - {"long", "short", "narrow"}, StyleOption::LONG); + property = JSHandle::Cast(globalConst->GetHandledStyleString()); + StyleOption styleOption = JSLocale::GetOptionOfString(thread, rtfOptions, property, + {StyleOption::LONG, StyleOption::SHORT, StyleOption::NARROW}, + {"long", "short", "narrow"}, StyleOption::LONG); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // 17. Set relativeTimeFormat.[[Style]] to s. - JSTaggedValue style_value(static_cast(style_option)); - relative_time_format->SetStyle(thread, JSHandle(thread, style_value)); + JSTaggedValue styleValue(static_cast(styleOption)); + relativeTimeFormat->SetStyle(thread, JSHandle(thread, styleValue)); // 18. Let numeric be ? GetOption(options, "numeric", "string", ?"always", "auto"?, "always"). - property = JSHandle::Cast(global_const->GetHandledNumericString()); - NumericOption numeric_option = - JSLocale::GetOptionOfString(thread, rtf_options, property, {NumericOption::ALWAYS, NumericOption::AUTO}, + property = JSHandle::Cast(globalConst->GetHandledNumericString()); + NumericOption numericOption = + JSLocale::GetOptionOfString(thread, rtfOptions, property, {NumericOption::ALWAYS, NumericOption::AUTO}, {"always", "auto"}, NumericOption::ALWAYS); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // 19. Set relativeTimeFormat.[[Numeric]] to numeric. - JSTaggedValue numeric_value(static_cast(numeric_option)); - relative_time_format->SetNumeric(thread, JSHandle(thread, numeric_value)); + JSTaggedValue numericValue(static_cast(numericOption)); + relativeTimeFormat->SetNumeric(thread, JSHandle(thread, numericValue)); // 20. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »). - icu::NumberFormat *icu_number_format = icu::NumberFormat::createInstance(icu_locale, UNUM_DECIMAL, status); + icu::NumberFormat *icuNumberFormat = icu::NumberFormat::createInstance(icuLocale, UNUM_DECIMAL, status); if (U_FAILURE(status) != 0) { - delete icu_number_format; - THROW_RANGE_ERROR_AND_RETURN(thread, "icu Number Format Error", relative_time_format); + delete icuNumberFormat; + THROW_RANGE_ERROR_AND_RETURN(thread, "icu Number Format Error", relativeTimeFormat); } // Trans StyleOption to ICU Style - UDateRelativeDateTimeFormatterStyle u_style; - switch (style_option) { + UDateRelativeDateTimeFormatterStyle uStyle; + switch (styleOption) { case StyleOption::LONG: - u_style = UDAT_STYLE_LONG; + uStyle = UDAT_STYLE_LONG; break; case StyleOption::SHORT: - u_style = UDAT_STYLE_SHORT; + uStyle = UDAT_STYLE_SHORT; break; case StyleOption::NARROW: - u_style = UDAT_STYLE_NARROW; + uStyle = UDAT_STYLE_NARROW; break; default: UNREACHABLE(); } - icu::RelativeDateTimeFormatter rtf_formatter(icu_locale, icu_number_format, u_style, UDISPCTX_CAPITALIZATION_NONE, - status); + icu::RelativeDateTimeFormatter rtfFormatter(icuLocale, icuNumberFormat, uStyle, UDISPCTX_CAPITALIZATION_NONE, + status); if (U_FAILURE(status) != 0) { - THROW_RANGE_ERROR_AND_RETURN(thread, "icu Formatter Error", relative_time_format); + THROW_RANGE_ERROR_AND_RETURN(thread, "icu Formatter Error", relativeTimeFormat); } - std::string numbering_system = JSLocale::GetNumberingSystem(icu_locale); - auto result = factory->NewFromStdString(numbering_system); - relative_time_format->SetNumberingSystem(thread, result); + std::string numberingSystem = JSLocale::GetNumberingSystem(icuLocale); + auto result = factory->NewFromStdString(numberingSystem); + relativeTimeFormat->SetNumberingSystem(thread, result); // Set RelativeTimeFormat.[[IcuRelativeTimeFormatter]] - factory->NewJSIntlIcuData(relative_time_format, rtf_formatter, JSRelativeTimeFormat::FreeIcuRTFFormatter); + factory->NewJSIntlIcuData(relativeTimeFormat, rtfFormatter, JSRelativeTimeFormat::FreeIcuRTFFormatter); // 22. Return relativeTimeFormat. - return relative_time_format; + return relativeTimeFormat; } // 14.1.2 SingularRelativeTimeUnit ( unit ) -bool SingularUnitToIcuUnit(JSThread *thread, const JSHandle &unit, URelativeDateTimeUnit *unit_enum) +bool SingularUnitToIcuUnit(JSThread *thread, const JSHandle &unit, URelativeDateTimeUnit *unitEnum) { // 1. Assert: Type(unit) is String. ASSERT(JSHandle::Cast(unit)->IsString()); @@ -179,41 +179,41 @@ bool SingularUnitToIcuUnit(JSThread *thread, const JSHandle &unit, U // 7. If unit is "months" or "month", return "month". // 8. If unit is "quarters" or "quarter", return "quarter". // 9. If unit is "years" or "year", return "year". - auto global_const = thread->GlobalConstants(); - JSHandle second = JSHandle::Cast(global_const->GetHandledSecondString()); - JSHandle minute = JSHandle::Cast(global_const->GetHandledMinuteString()); - JSHandle hour = JSHandle::Cast(global_const->GetHandledHourString()); - JSHandle day = JSHandle::Cast(global_const->GetHandledDayString()); - JSHandle week = JSHandle::Cast(global_const->GetHandledWeekString()); - JSHandle month = JSHandle::Cast(global_const->GetHandledMonthString()); - JSHandle quarter = JSHandle::Cast(global_const->GetHandledQuarterString()); - JSHandle year = JSHandle::Cast(global_const->GetHandledYearString()); - - JSHandle seconds = JSHandle::Cast(global_const->GetHandledSecondsString()); - JSHandle minutes = JSHandle::Cast(global_const->GetHandledMinutesString()); - JSHandle hours = JSHandle::Cast(global_const->GetHandledHoursString()); - JSHandle days = JSHandle::Cast(global_const->GetHandledDaysString()); - JSHandle weeks = JSHandle::Cast(global_const->GetHandledWeeksString()); - JSHandle months = JSHandle::Cast(global_const->GetHandledMonthsString()); - JSHandle quarters = JSHandle::Cast(global_const->GetHandledQuartersString()); - JSHandle years = JSHandle::Cast(global_const->GetHandledYearsString()); + auto globalConst = thread->GlobalConstants(); + JSHandle second = JSHandle::Cast(globalConst->GetHandledSecondString()); + JSHandle minute = JSHandle::Cast(globalConst->GetHandledMinuteString()); + JSHandle hour = JSHandle::Cast(globalConst->GetHandledHourString()); + JSHandle day = JSHandle::Cast(globalConst->GetHandledDayString()); + JSHandle week = JSHandle::Cast(globalConst->GetHandledWeekString()); + JSHandle month = JSHandle::Cast(globalConst->GetHandledMonthString()); + JSHandle quarter = JSHandle::Cast(globalConst->GetHandledQuarterString()); + JSHandle year = JSHandle::Cast(globalConst->GetHandledYearString()); + + JSHandle seconds = JSHandle::Cast(globalConst->GetHandledSecondsString()); + JSHandle minutes = JSHandle::Cast(globalConst->GetHandledMinutesString()); + JSHandle hours = JSHandle::Cast(globalConst->GetHandledHoursString()); + JSHandle days = JSHandle::Cast(globalConst->GetHandledDaysString()); + JSHandle weeks = JSHandle::Cast(globalConst->GetHandledWeeksString()); + JSHandle months = JSHandle::Cast(globalConst->GetHandledMonthsString()); + JSHandle quarters = JSHandle::Cast(globalConst->GetHandledQuartersString()); + JSHandle years = JSHandle::Cast(globalConst->GetHandledYearsString()); if (EcmaString::StringsAreEqual(*second, *unit) || EcmaString::StringsAreEqual(*seconds, *unit)) { - *unit_enum = UDAT_REL_UNIT_SECOND; + *unitEnum = UDAT_REL_UNIT_SECOND; } else if (EcmaString::StringsAreEqual(*minute, *unit) || EcmaString::StringsAreEqual(*minutes, *unit)) { - *unit_enum = UDAT_REL_UNIT_MINUTE; + *unitEnum = UDAT_REL_UNIT_MINUTE; } else if (EcmaString::StringsAreEqual(*hour, *unit) || EcmaString::StringsAreEqual(*hours, *unit)) { - *unit_enum = UDAT_REL_UNIT_HOUR; + *unitEnum = UDAT_REL_UNIT_HOUR; } else if (EcmaString::StringsAreEqual(*day, *unit) || EcmaString::StringsAreEqual(*days, *unit)) { - *unit_enum = UDAT_REL_UNIT_DAY; + *unitEnum = UDAT_REL_UNIT_DAY; } else if (EcmaString::StringsAreEqual(*week, *unit) || EcmaString::StringsAreEqual(*weeks, *unit)) { - *unit_enum = UDAT_REL_UNIT_WEEK; + *unitEnum = UDAT_REL_UNIT_WEEK; } else if (EcmaString::StringsAreEqual(*month, *unit) || EcmaString::StringsAreEqual(*months, *unit)) { - *unit_enum = UDAT_REL_UNIT_MONTH; + *unitEnum = UDAT_REL_UNIT_MONTH; } else if (EcmaString::StringsAreEqual(*quarter, *unit) || EcmaString::StringsAreEqual(*quarters, *unit)) { - *unit_enum = UDAT_REL_UNIT_QUARTER; + *unitEnum = UDAT_REL_UNIT_QUARTER; } else if (EcmaString::StringsAreEqual(*year, *unit) || EcmaString::StringsAreEqual(*years, *unit)) { - *unit_enum = UDAT_REL_UNIT_YEAR; + *unitEnum = UDAT_REL_UNIT_YEAR; } else { return false; } @@ -228,13 +228,13 @@ JSHandle JSRelativeTimeFormat::UnwrapRelativeTimeFormat(JSThread ASSERT_PRINT(rtf->IsJSObject(), "rtf is not a JSObject"); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - bool is_instance_of = JSFunction::InstanceOf(thread, rtf, env->GetRelativeTimeFormatFunction()); + bool isInstanceOf = JSFunction::InstanceOf(thread, rtf, env->GetRelativeTimeFormatFunction()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, rtf); - if (!rtf->IsJSRelativeTimeFormat() && is_instance_of) { + if (!rtf->IsJSRelativeTimeFormat() && isInstanceOf) { JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - OperationResult operation_result = JSTaggedValue::GetProperty(thread, rtf, key); + OperationResult operationResult = JSTaggedValue::GetProperty(thread, rtf, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, rtf); - return operation_result.GetValue(); + return operationResult.GetValue(); } // Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). @@ -246,10 +246,10 @@ JSHandle JSRelativeTimeFormat::UnwrapRelativeTimeFormat(JSThread // CommonFormat icu::FormattedRelativeDateTime GetIcuFormatted(JSThread *thread, - const JSHandle &relative_time_format, double value, + const JSHandle &relativeTimeFormat, double value, const JSHandle &unit) { - icu::RelativeDateTimeFormatter *formatter = relative_time_format->GetIcuRTFFormatter(); + icu::RelativeDateTimeFormatter *formatter = relativeTimeFormat->GetIcuRTFFormatter(); ASSERT_PRINT(formatter != nullptr, "rtfFormatter is null"); // If isFinite(value) is false, then throw a RangeError exception. @@ -259,21 +259,21 @@ icu::FormattedRelativeDateTime GetIcuFormatted(JSThread *thread, // 10. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", or "year", throw a // RangeError exception. - URelativeDateTimeUnit unit_enum; - if (!SingularUnitToIcuUnit(thread, unit, &unit_enum)) { + URelativeDateTimeUnit unitEnum; + if (!SingularUnitToIcuUnit(thread, unit, &unitEnum)) { THROW_RANGE_ERROR_AND_RETURN(thread, "", icu::FormattedRelativeDateTime()); } UErrorCode status = U_ZERO_ERROR; - NumericOption numeric = static_cast(relative_time_format->GetNumeric().GetNumber()); + NumericOption numeric = static_cast(relativeTimeFormat->GetNumeric().GetNumber()); icu::FormattedRelativeDateTime formatted; switch (numeric) { case NumericOption::ALWAYS: - formatted = formatter->formatNumericToValue(value, unit_enum, status); + formatted = formatter->formatNumericToValue(value, unitEnum, status); ASSERT_PRINT(U_SUCCESS(status), "icu format to value error"); break; case NumericOption::AUTO: - formatted = formatter->formatToValue(value, unit_enum, status); + formatted = formatter->formatToValue(value, unitEnum, status); ASSERT_PRINT(U_SUCCESS(status), "icu format to value error"); break; default: @@ -285,23 +285,23 @@ icu::FormattedRelativeDateTime GetIcuFormatted(JSThread *thread, // 14.1.2 SingularRelativeTimeUnit ( unit ) JSHandle SingularUnitString(JSThread *thread, const JSHandle &unit) { - auto global_const = thread->GlobalConstants(); - JSHandle second = JSHandle::Cast(global_const->GetHandledSecondString()); - JSHandle minute = JSHandle::Cast(global_const->GetHandledMinuteString()); - JSHandle hour = JSHandle::Cast(global_const->GetHandledHourString()); - JSHandle day = JSHandle::Cast(global_const->GetHandledDayString()); - JSHandle week = JSHandle::Cast(global_const->GetHandledWeekString()); - JSHandle month = JSHandle::Cast(global_const->GetHandledMonthString()); - JSHandle quarter = JSHandle::Cast(global_const->GetHandledQuarterString()); - JSHandle year = JSHandle::Cast(global_const->GetHandledYearString()); - JSHandle seconds = JSHandle::Cast(global_const->GetHandledSecondsString()); - JSHandle minutes = JSHandle::Cast(global_const->GetHandledMinutesString()); - JSHandle hours = JSHandle::Cast(global_const->GetHandledHoursString()); - JSHandle days = JSHandle::Cast(global_const->GetHandledDaysString()); - JSHandle weeks = JSHandle::Cast(global_const->GetHandledWeeksString()); - JSHandle months = JSHandle::Cast(global_const->GetHandledMonthsString()); - JSHandle quarters = JSHandle::Cast(global_const->GetHandledQuartersString()); - JSHandle years = JSHandle::Cast(global_const->GetHandledYearsString()); + auto globalConst = thread->GlobalConstants(); + JSHandle second = JSHandle::Cast(globalConst->GetHandledSecondString()); + JSHandle minute = JSHandle::Cast(globalConst->GetHandledMinuteString()); + JSHandle hour = JSHandle::Cast(globalConst->GetHandledHourString()); + JSHandle day = JSHandle::Cast(globalConst->GetHandledDayString()); + JSHandle week = JSHandle::Cast(globalConst->GetHandledWeekString()); + JSHandle month = JSHandle::Cast(globalConst->GetHandledMonthString()); + JSHandle quarter = JSHandle::Cast(globalConst->GetHandledQuarterString()); + JSHandle year = JSHandle::Cast(globalConst->GetHandledYearString()); + JSHandle seconds = JSHandle::Cast(globalConst->GetHandledSecondsString()); + JSHandle minutes = JSHandle::Cast(globalConst->GetHandledMinutesString()); + JSHandle hours = JSHandle::Cast(globalConst->GetHandledHoursString()); + JSHandle days = JSHandle::Cast(globalConst->GetHandledDaysString()); + JSHandle weeks = JSHandle::Cast(globalConst->GetHandledWeeksString()); + JSHandle months = JSHandle::Cast(globalConst->GetHandledMonthsString()); + JSHandle quarters = JSHandle::Cast(globalConst->GetHandledQuartersString()); + JSHandle years = JSHandle::Cast(globalConst->GetHandledYearsString()); // 2. If unit is "seconds" or "second", return "second". if (EcmaString::StringsAreEqual(*second, *unit) || EcmaString::StringsAreEqual(*seconds, *unit)) { @@ -336,24 +336,24 @@ JSHandle SingularUnitString(JSThread *thread, const JSHandle undefined_value(thread, JSTaggedValue::Undefined()); - return JSHandle::Cast(undefined_value); + JSHandle undefinedValue(thread, JSTaggedValue::Undefined()); + return JSHandle::Cast(undefinedValue); } // 14.1.5 FormatRelativeTime ( relativeTimeFormat, value, unit ) JSHandle JSRelativeTimeFormat::Format(JSThread *thread, double value, const JSHandle &unit, - const JSHandle &relative_time_format) + const JSHandle &relativeTimeFormat) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - icu::FormattedRelativeDateTime formatted = GetIcuFormatted(thread, relative_time_format, value, unit); + icu::FormattedRelativeDateTime formatted = GetIcuFormatted(thread, relativeTimeFormat, value, unit); RETURN_HANDLE_IF_ABRUPT_COMPLETION(EcmaString, thread); UErrorCode status = U_ZERO_ERROR; - icu::UnicodeString u_string = formatted.toString(status); + icu::UnicodeString uString = formatted.toString(status); if (U_FAILURE(status) != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "icu formatted toString error", factory->GetEmptyString()); } JSHandle string = - factory->NewFromUtf16(reinterpret_cast(u_string.getBuffer()), u_string.length()); + factory->NewFromUtf16(reinterpret_cast(uString.getBuffer()), uString.length()); return string; } @@ -361,7 +361,7 @@ void FormatToArray(JSThread *thread, const JSHandle &array, const icu:: double value, const JSHandle &unit) { UErrorCode status = U_ZERO_ERROR; - icu::UnicodeString formatted_text = formatted.toString(status); + icu::UnicodeString formattedText = formatted.toString(status); if (U_FAILURE(status) != 0) { THROW_TYPE_ERROR(thread, "formattedRelativeDateTime toString failed"); } @@ -370,12 +370,12 @@ void FormatToArray(JSThread *thread, const JSHandle &array, const icu:: // Set constrainCategory to UFIELD_CATEGORY_NUMBER which is specified for UNumberFormatFields cfpo.constrainCategory(UFIELD_CATEGORY_NUMBER); int32_t index = 0; - int32_t previous_limit = 0; - auto global_const = thread->GlobalConstants(); - JSHandle tagged_value(thread, JSTaggedValue(value)); - JSMutableHandle type_string(thread, JSTaggedValue::Undefined()); - JSHandle unit_string = global_const->GetHandledUnitString(); - std::vector> separator_fields; + int32_t previousLimit = 0; + auto globalConst = thread->GlobalConstants(); + JSHandle taggedValue(thread, JSTaggedValue(value)); + JSMutableHandle typeString(thread, JSTaggedValue::Undefined()); + JSHandle unitString = globalConst->GetHandledUnitString(); + std::vector> separatorFields; /** * From ICU header file document @unumberformatter.h * Sets a constraint on the field category. @@ -394,132 +394,130 @@ void FormatToArray(JSThread *thread, const JSHandle &array, const icu:: * } */ while ((formatted.nextPosition(cfpo, status) != 0)) { - int32_t field_id = cfpo.getField(); + int32_t fieldId = cfpo.getField(); int32_t start = cfpo.getStart(); int32_t limit = cfpo.getLimit(); // Special case when fieldId is UNUM_GROUPING_SEPARATOR_FIELD - if (static_cast(field_id) == UNUM_GROUPING_SEPARATOR_FIELD) { - separator_fields.emplace_back(std::pair(start, limit)); + if (static_cast(fieldId) == UNUM_GROUPING_SEPARATOR_FIELD) { + separatorFields.emplace_back(std::pair(start, limit)); continue; } // If start greater than previousLimit, means a literal type exists before number fields // so add a literal type with value of formattedText.sub(0, start) - if (start > previous_limit) { - type_string.Update(global_const->GetLiteralString()); - JSHandle substring = JSLocale::IcuToString(thread, formatted_text, previous_limit, start); - JSLocale::PutElement(thread, index++, array, type_string, JSHandle::Cast(substring)); + if (start > previousLimit) { + typeString.Update(globalConst->GetLiteralString()); + JSHandle substring = JSLocale::IcuToString(thread, formattedText, previousLimit, start); + JSLocale::PutElement(thread, index++, array, typeString, JSHandle::Cast(substring)); RETURN_IF_ABRUPT_COMPLETION(thread); } // Add part when type is unit // Iterate former grouping separator vector and add unit element to array - for (auto &separator_field : separator_fields) { - if (separator_field.first > start) { + for (auto &separatorField : separatorFields) { + if (separatorField.first > start) { // Add Integer type element - JSHandle res_string = - JSLocale::IcuToString(thread, formatted_text, start, separator_field.first); - type_string.Update( - JSLocale::GetNumberFieldType(thread, tagged_value.GetTaggedValue(), field_id).GetTaggedValue()); - JSHandle record = JSLocale::PutElement(thread, index++, array, type_string, - JSHandle::Cast(res_string)); + JSHandle resString = + JSLocale::IcuToString(thread, formattedText, start, separatorField.first); + typeString.Update( + JSLocale::GetNumberFieldType(thread, taggedValue.GetTaggedValue(), fieldId).GetTaggedValue()); + JSHandle record = + JSLocale::PutElement(thread, index++, array, typeString, JSHandle::Cast(resString)); RETURN_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, record, unit_string, JSHandle::Cast(unit)); + JSObject::CreateDataPropertyOrThrow(thread, record, unitString, JSHandle::Cast(unit)); RETURN_IF_ABRUPT_COMPLETION(thread); // Add Group type element - res_string = - JSLocale::IcuToString(thread, formatted_text, separator_field.first, separator_field.second); - type_string.Update( - JSLocale::GetNumberFieldType(thread, tagged_value.GetTaggedValue(), UNUM_GROUPING_SEPARATOR_FIELD) + resString = JSLocale::IcuToString(thread, formattedText, separatorField.first, separatorField.second); + typeString.Update( + JSLocale::GetNumberFieldType(thread, taggedValue.GetTaggedValue(), UNUM_GROUPING_SEPARATOR_FIELD) .GetTaggedValue()); - record = JSLocale::PutElement(thread, index++, array, type_string, - JSHandle::Cast(res_string)); + record = + JSLocale::PutElement(thread, index++, array, typeString, JSHandle::Cast(resString)); RETURN_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, record, unit_string, JSHandle::Cast(unit)); + JSObject::CreateDataPropertyOrThrow(thread, record, unitString, JSHandle::Cast(unit)); RETURN_IF_ABRUPT_COMPLETION(thread); - start = separator_field.second; + start = separatorField.second; } } // Add current field unit - JSHandle sub_string = JSLocale::IcuToString(thread, formatted_text, start, limit); - type_string.Update( - JSLocale::GetNumberFieldType(thread, tagged_value.GetTaggedValue(), field_id).GetTaggedValue()); + JSHandle subString = JSLocale::IcuToString(thread, formattedText, start, limit); + typeString.Update(JSLocale::GetNumberFieldType(thread, taggedValue.GetTaggedValue(), fieldId).GetTaggedValue()); JSHandle record = - JSLocale::PutElement(thread, index++, array, type_string, JSHandle::Cast(sub_string)); + JSLocale::PutElement(thread, index++, array, typeString, JSHandle::Cast(subString)); RETURN_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, record, unit_string, JSHandle::Cast(unit)); + JSObject::CreateDataPropertyOrThrow(thread, record, unitString, JSHandle::Cast(unit)); RETURN_IF_ABRUPT_COMPLETION(thread); - previous_limit = limit; + previousLimit = limit; } // If iterated length is smaller than formattedText.length, means a literal type exists after number fields // so add a literal type with value of formattedText.sub(previousLimit, formattedText.length) - if (formatted_text.length() > previous_limit) { - type_string.Update(global_const->GetLiteralString()); + if (formattedText.length() > previousLimit) { + typeString.Update(globalConst->GetLiteralString()); JSHandle substring = - JSLocale::IcuToString(thread, formatted_text, previous_limit, formatted_text.length()); - JSLocale::PutElement(thread, index, array, type_string, JSHandle::Cast(substring)); + JSLocale::IcuToString(thread, formattedText, previousLimit, formattedText.length()); + JSLocale::PutElement(thread, index, array, typeString, JSHandle::Cast(substring)); RETURN_IF_ABRUPT_COMPLETION(thread); } } // 14.1.6 FormatRelativeTimeToParts ( relativeTimeFormat, value, unit ) JSHandle JSRelativeTimeFormat::FormatToParts(JSThread *thread, double value, const JSHandle &unit, - const JSHandle &relative_time_format) + const JSHandle &relativeTimeFormat) { - icu::FormattedRelativeDateTime formatted = GetIcuFormatted(thread, relative_time_format, value, unit); + icu::FormattedRelativeDateTime formatted = GetIcuFormatted(thread, relativeTimeFormat, value, unit); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); - JSHandle singular_unit = SingularUnitString(thread, unit); + JSHandle singularUnit = SingularUnitString(thread, unit); JSHandle array = JSHandle::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); - FormatToArray(thread, array, formatted, value, singular_unit); + FormatToArray(thread, array, formatted, value, singularUnit); return array; } -void JSRelativeTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle &relative_time_format, +void JSRelativeTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle &relativeTimeFormat, const JSHandle &options) { - if (relative_time_format->GetIcuRTFFormatter() != nullptr) { - [[maybe_unused]] icu::RelativeDateTimeFormatter *formatter = relative_time_format->GetIcuRTFFormatter(); + if (relativeTimeFormat->GetIcuRTFFormatter() != nullptr) { + [[maybe_unused]] icu::RelativeDateTimeFormatter *formatter = relativeTimeFormat->GetIcuRTFFormatter(); } else { THROW_RANGE_ERROR(thread, "rtf is not initialized"); } - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); // [[locale]] - JSHandle property = JSHandle::Cast(global_const->GetHandledLocaleString()); - JSHandle locale(thread, relative_time_format->GetLocale()); - PropertyDescriptor locale_desc(thread, JSHandle::Cast(locale), true, true, true); - JSObject::DefineOwnProperty(thread, options, property, locale_desc); + JSHandle property = JSHandle::Cast(globalConst->GetHandledLocaleString()); + JSHandle locale(thread, relativeTimeFormat->GetLocale()); + PropertyDescriptor localeDesc(thread, JSHandle::Cast(locale), true, true, true); + JSObject::DefineOwnProperty(thread, options, property, localeDesc); // [[Style]] - property = JSHandle::Cast(global_const->GetHandledStyleString()); - StyleOption style = static_cast(relative_time_format->GetStyle().GetNumber()); - JSHandle style_value; + property = JSHandle::Cast(globalConst->GetHandledStyleString()); + StyleOption style = static_cast(relativeTimeFormat->GetStyle().GetNumber()); + JSHandle styleValue; if (style == StyleOption::LONG) { - style_value = global_const->GetHandledLongString(); + styleValue = globalConst->GetHandledLongString(); } else if (style == StyleOption::SHORT) { - style_value = global_const->GetHandledShortString(); + styleValue = globalConst->GetHandledShortString(); } else if (style == StyleOption::NARROW) { - style_value = global_const->GetHandledNarrowString(); + styleValue = globalConst->GetHandledNarrowString(); } - PropertyDescriptor style_desc(thread, style_value, true, true, true); - JSObject::DefineOwnProperty(thread, options, property, style_desc); + PropertyDescriptor styleDesc(thread, styleValue, true, true, true); + JSObject::DefineOwnProperty(thread, options, property, styleDesc); // [[Numeric]] - property = JSHandle::Cast(global_const->GetHandledNumericString()); - NumericOption numeric = static_cast(relative_time_format->GetNumeric().GetNumber()); - JSHandle numeric_value; + property = JSHandle::Cast(globalConst->GetHandledNumericString()); + NumericOption numeric = static_cast(relativeTimeFormat->GetNumeric().GetNumber()); + JSHandle numericValue; if (numeric == NumericOption::ALWAYS) { - numeric_value = global_const->GetHandledAlwaysString(); + numericValue = globalConst->GetHandledAlwaysString(); } else if (numeric == NumericOption::AUTO) { - numeric_value = global_const->GetHandledAutoString(); + numericValue = globalConst->GetHandledAutoString(); } else { THROW_RANGE_ERROR(thread, "numeric is exception"); } - PropertyDescriptor numeric_desc(thread, numeric_value, true, true, true); - JSObject::DefineOwnProperty(thread, options, property, numeric_desc); + PropertyDescriptor numericDesc(thread, numericValue, true, true, true); + JSObject::DefineOwnProperty(thread, options, property, numericDesc); // [[NumberingSystem]] - property = JSHandle::Cast(global_const->GetHandledNumberingSystemString()); - JSHandle numbering_system(thread, relative_time_format->GetNumberingSystem()); - PropertyDescriptor numbering_system_desc(thread, numbering_system, true, true, true); - JSObject::DefineOwnProperty(thread, options, property, numbering_system_desc); + property = JSHandle::Cast(globalConst->GetHandledNumberingSystemString()); + JSHandle numberingSystem(thread, relativeTimeFormat->GetNumberingSystem()); + PropertyDescriptor numberingSystemDesc(thread, numberingSystem, true, true, true); + JSObject::DefineOwnProperty(thread, options, property, numberingSystemDesc); } } // namespace panda::ecmascript \ No newline at end of file diff --git a/runtime/js_relative_time_format.h b/runtime/js_relative_time_format.h index b13fe5f24ad74a4c2d0583df3b17d37dab8c998c..e3ad6b52090943364d7f9b8a68c5d17e2ce292be 100644 --- a/runtime/js_relative_time_format.h +++ b/runtime/js_relative_time_format.h @@ -52,7 +52,7 @@ public: // 14.1.1 InitializeRelativeTimeFormat ( relativeTimeFormat, locales, options ) static JSHandle InitializeRelativeTimeFormat( - JSThread *thread, const JSHandle &relative_time_format, + JSThread *thread, const JSHandle &relativeTimeFormat, const JSHandle &locales, const JSHandle &options); // UnwrapRelativeTimeFormat @@ -71,20 +71,20 @@ public: if (pointer == nullptr) { return; } - auto icu_formatter = reinterpret_cast(pointer); + auto icuFormatter = reinterpret_cast(pointer); if (data != nullptr) { - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icu_formatter); + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuFormatter); } } - static void ResolvedOptions(JSThread *thread, const JSHandle &relative_time_format, + static void ResolvedOptions(JSThread *thread, const JSHandle &relativeTimeFormat, const JSHandle &options); static JSHandle Format(JSThread *thread, double value, const JSHandle &unit, - const JSHandle &relative_time_format); + const JSHandle &relativeTimeFormat); static JSHandle FormatToParts(JSThread *thread, double value, const JSHandle &unit, - const JSHandle &relative_time_format); + const JSHandle &relativeTimeFormat); }; } // namespace panda::ecmascript diff --git a/runtime/js_runtime_options.h b/runtime/js_runtime_options.h index ae47bc2760021673ecb7a9b06189a877a9d9f7e7..e2e8f84e386f66e72e9feb475e63b4c818297766 100644 --- a/runtime/js_runtime_options.h +++ b/runtime/js_runtime_options.h @@ -28,7 +28,7 @@ enum ArkProperties { class JSRuntimeOptions : public RuntimeOptions { public: - explicit JSRuntimeOptions(const std::string &exe_path = "") : RuntimeOptions(exe_path) {} + explicit JSRuntimeOptions(const std::string &exePath = "") : RuntimeOptions(exePath) {} explicit JSRuntimeOptions(RuntimeOptions options) : RuntimeOptions(std::move(options)) {} ~JSRuntimeOptions() = default; DEFAULT_COPY_SEMANTIC(JSRuntimeOptions); @@ -37,29 +37,29 @@ public: void AddOptions(PandArgParser *parser) { RuntimeOptions::AddOptions(parser); - parser->Add(&enable_ark_tools_); - parser->Add(&ark_properties_); + parser->Add(&enableArkTools_); + parser->Add(&arkProperties_); } bool IsEnableArkTools() const { - return enable_ark_tools_.GetValue(); + return enableArkTools_.GetValue(); } void SetEnableArkTools(bool value) { - enable_ark_tools_.SetValue(value); + enableArkTools_.SetValue(value); } bool WasSetEnableArkTools() const { - return enable_ark_tools_.WasSet(); + return enableArkTools_.WasSet(); } void SetArkProperties(int prop) { if (prop != ArkProperties::DEFAULT) { - ark_properties_.SetValue(prop); + arkProperties_.SetValue(prop); } } @@ -70,18 +70,18 @@ public: int GetArkProperties() { - return ark_properties_.GetValue(); + return arkProperties_.GetValue(); } bool IsEnableOptionalLog() const { // NOLINTNEXTLINE(hicpp-signed-bitwise) - return (ark_properties_.GetValue() & ArkProperties::OPTIONAL_LOG) != 0; + return (arkProperties_.GetValue() & ArkProperties::OPTIONAL_LOG) != 0; } private: - PandArg enable_ark_tools_ {"enable-ark-tools", false, R"(Enable ark tools to debug. Default: false)"}; - PandArg ark_properties_ {"ark-properties", GetDefaultProperties(), R"(set ark properties)"}; + PandArg enableArkTools_ {"enable-ark-tools", false, R"(Enable ark tools to debug. Default: false)"}; + PandArg arkProperties_ {"ark-properties", GetDefaultProperties(), R"(set ark properties)"}; }; } // namespace panda::ecmascript diff --git a/runtime/js_serializer.cpp b/runtime/js_serializer.cpp index 447e1a1df1c72167d301c7b3f03cab4c16add991..a905739b705b4f6cfeb4f7f22d44cbe5c5d3278c 100644 --- a/runtime/js_serializer.cpp +++ b/runtime/js_serializer.cpp @@ -36,8 +36,8 @@ constexpr int CAPACITY_INCREASE_RATE = 2; bool JSSerializer::WriteType(SerializationUID id) { - auto raw_id = static_cast(id); - return WriteRawData(&raw_id, sizeof(raw_id)); + auto rawId = static_cast(id); + return WriteRawData(&rawId, sizeof(rawId)); } // Write JSTaggedValue could be either a pointer to a HeapObject or a value @@ -85,12 +85,12 @@ bool JSSerializer::WritePrimitiveValue(const JSHandle &value) bool JSSerializer::WriteInt(int32_t value) { - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::INT32)) { return false; } if (!WriteRawData(&value, sizeof(value))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } return true; @@ -98,12 +98,12 @@ bool JSSerializer::WriteInt(int32_t value) bool JSSerializer::WriteInt(uint32_t value) { - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::UINT32)) { return false; } if (!WriteRawData(&value, sizeof(value))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } return true; @@ -111,12 +111,12 @@ bool JSSerializer::WriteInt(uint32_t value) bool JSSerializer::WriteDouble(double value) { - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::DOUBLE)) { return false; } if (!WriteRawData(&value, sizeof(value))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } return true; @@ -141,40 +141,40 @@ bool JSSerializer::WriteRawData(const void *data, size_t length) if (length <= 0) { return false; } - if ((buffer_size_ + length) > buffer_capacity_) { + if ((bufferSize_ + length) > bufferCapacity_) { if (!AllocateBuffer(length)) { return false; } } errno_t rc; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - rc = memcpy_s(buffer_ + buffer_size_, buffer_capacity_ - buffer_size_, data, length); + rc = memcpy_s(buffer_ + bufferSize_, bufferCapacity_ - bufferSize_, data, length); if (rc != EOK) { LOG(ERROR, RUNTIME) << "Failed to memcpy_s Data"; return false; } - buffer_size_ += length; + bufferSize_ += length; return true; } bool JSSerializer::AllocateBuffer(size_t bytes) { // Get internal heap size - if (size_limit_ == 0) { - uint64_t heap_size = thread_->GetEcmaVM()->GetJSOptions().GetInternalMemorySizeLimit(); - size_limit_ = heap_size; + if (sizeLimit_ == 0) { + uint64_t heapSize = thread_->GetEcmaVM()->GetJSOptions().GetInternalMemorySizeLimit(); + sizeLimit_ = heapSize; } - size_t old_size = buffer_size_; - size_t new_size = old_size + bytes; - if (new_size > size_limit_) { + size_t oldSize = bufferSize_; + size_t newSize = oldSize + bytes; + if (newSize > sizeLimit_) { return false; } - if (buffer_capacity_ == 0) { + if (bufferCapacity_ == 0) { if (bytes < INITIAL_CAPACITY) { // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) buffer_ = reinterpret_cast(malloc(INITIAL_CAPACITY)); if (buffer_ != nullptr) { - buffer_capacity_ = INITIAL_CAPACITY; + bufferCapacity_ = INITIAL_CAPACITY; return true; } return false; @@ -182,67 +182,67 @@ bool JSSerializer::AllocateBuffer(size_t bytes) // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) buffer_ = reinterpret_cast(malloc(bytes)); if (buffer_ != nullptr) { - buffer_capacity_ = bytes; + bufferCapacity_ = bytes; return true; } return false; } - if (new_size > buffer_capacity_) { - if (!ExpandBuffer(new_size)) { + if (newSize > bufferCapacity_) { + if (!ExpandBuffer(newSize)) { return false; } } return true; } -bool JSSerializer::ExpandBuffer([[maybe_unused]] size_t requested_size) +bool JSSerializer::ExpandBuffer([[maybe_unused]] size_t requestedSize) { - size_t new_capacity = buffer_capacity_ * CAPACITY_INCREASE_RATE; - new_capacity = std::max(new_capacity, requested_size); - if (new_capacity > size_limit_) { + size_t newCapacity = bufferCapacity_ * CAPACITY_INCREASE_RATE; + newCapacity = std::max(newCapacity, requestedSize); + if (newCapacity > sizeLimit_) { return false; } // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) - auto *new_buffer = reinterpret_cast(malloc(new_capacity)); - if (new_buffer == nullptr) { + auto *newBuffer = reinterpret_cast(malloc(newCapacity)); + if (newBuffer == nullptr) { return false; } errno_t rc; - rc = memcpy_s(new_buffer, new_capacity, buffer_, buffer_size_); + rc = memcpy_s(newBuffer, newCapacity, buffer_, bufferSize_); if (rc != EOK) { LOG(ERROR, RUNTIME) << "Failed to memcpy_s Data"; // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) - free(new_buffer); + free(newBuffer); return false; } // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) free(buffer_); - buffer_ = new_buffer; - buffer_capacity_ = new_capacity; + buffer_ = newBuffer; + bufferCapacity_ = newCapacity; return true; } // Transfer ownership of buffer, should not use this Serializer after release std::pair JSSerializer::ReleaseBuffer() { - auto res = std::make_pair(buffer_, buffer_size_); + auto res = std::make_pair(buffer_, bufferSize_); buffer_ = nullptr; - buffer_size_ = 0; - buffer_capacity_ = 0; - object_id_ = 0; + bufferSize_ = 0; + bufferCapacity_ = 0; + objectId_ = 0; return res; } bool JSSerializer::IsSerialized(uintptr_t addr) const { - return reference_map_.find(addr) != reference_map_.end(); + return referenceMap_.find(addr) != referenceMap_.end(); } bool JSSerializer::WriteIfSerialized(uintptr_t addr) { - size_t old_size = buffer_size_; - auto iter = reference_map_.find(addr); - if (iter == reference_map_.end()) { + size_t oldSize = bufferSize_; + auto iter = referenceMap_.find(addr); + if (iter == referenceMap_.end()) { return false; } uint64_t id = iter->second; @@ -250,7 +250,7 @@ bool JSSerializer::WriteIfSerialized(uintptr_t addr) return false; } if (!WriteRawData(&id, sizeof(uint64_t))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } return true; @@ -264,11 +264,11 @@ bool JSSerializer::WriteTaggedObject(const JSHandle &value) if (serialized) { return WriteIfSerialized(addr); } - reference_map_.insert(std::pair(addr, object_id_)); - object_id_++; + referenceMap_.insert(std::pair(addr, objectId_)); + objectId_++; - TaggedObject *tagged_object = value->GetTaggedObject(); - JSType type = tagged_object->GetClass()->GetObjectType(); + TaggedObject *taggedObject = value->GetTaggedObject(); + JSType type = taggedObject->GetClass()->GetObjectType(); switch (type) { case JSType::JS_ERROR: case JSType::JS_EVAL_ERROR: @@ -320,18 +320,18 @@ bool JSSerializer::WriteTaggedObject(const JSHandle &value) bool JSSerializer::WriteJSError(const JSHandle &value) { - size_t old_size = buffer_size_; - TaggedObject *tagged_object = value->GetTaggedObject(); - JSType error_type = tagged_object->GetClass()->GetObjectType(); - if (!WriteJSErrorHeader(error_type)) { + size_t oldSize = bufferSize_; + TaggedObject *taggedObject = value->GetTaggedObject(); + JSType errorType = taggedObject->GetClass()->GetObjectType(); + if (!WriteJSErrorHeader(errorType)) { return false; } - auto global_const = thread_->GlobalConstants(); - JSHandle handle_msg = global_const->GetHandledMessageString(); - JSHandle msg = JSObject::GetProperty(thread_, value, handle_msg).GetValue(); + auto globalConst = thread_->GlobalConstants(); + JSHandle handleMsg = globalConst->GetHandledMessageString(); + JSHandle msg = JSObject::GetProperty(thread_, value, handleMsg).GetValue(); // Write error message if (!SerializeJSTaggedValue(msg)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } return true; @@ -363,22 +363,22 @@ bool JSSerializer::WriteJSErrorHeader(JSType type) bool JSSerializer::WriteJSDate(const JSHandle &value) { JSHandle date = JSHandle::Cast(value); - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::JS_DATE)) { return false; } if (!WritePlainObject(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } - double time_value = date->GetTimeValue().GetDouble(); - if (!WriteDouble(time_value)) { - buffer_size_ = old_size; + double timeValue = date->GetTimeValue().GetDouble(); + if (!WriteDouble(timeValue)) { + bufferSize_ = oldSize; return false; } - double local_offset = date->GetLocalOffset().GetDouble(); - if (!WriteDouble(local_offset)) { - buffer_size_ = old_size; + double localOffset = date->GetLocalOffset().GetDouble(); + if (!WriteDouble(localOffset)) { + bufferSize_ = oldSize; return false; } return true; @@ -387,17 +387,17 @@ bool JSSerializer::WriteJSDate(const JSHandle &value) bool JSSerializer::WriteJSArray(const JSHandle &value) { JSHandle array = JSHandle::Cast(value); - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::JS_ARRAY)) { return false; } if (!WritePlainObject(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } - uint32_t array_length = static_cast(array->GetLength().GetInt()); - if (!WriteInt(array_length)) { - buffer_size_ = old_size; + uint32_t arrayLength = static_cast(array->GetLength().GetInt()); + if (!WriteInt(arrayLength)) { + bufferSize_ = oldSize; return false; } return true; @@ -406,19 +406,19 @@ bool JSSerializer::WriteJSArray(const JSHandle &value) bool JSSerializer::WriteEcmaString(const JSHandle &value) { JSHandle string = JSHandle::Cast(value); - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::ECMASTRING)) { return false; } size_t length = string->GetLength(); if (!WriteLength(static_cast(length))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } const uint8_t *data = string->GetDataUtf8(); - const uint8_t str_end = '\0'; - if (!WriteRawData(data, length) || !WriteRawData(&str_end, sizeof(uint8_t))) { - buffer_size_ = old_size; + const uint8_t strEnd = '\0'; + if (!WriteRawData(data, length) || !WriteRawData(&strEnd, sizeof(uint8_t))) { + bufferSize_ = oldSize; return false; } return true; @@ -427,28 +427,28 @@ bool JSSerializer::WriteEcmaString(const JSHandle &value) bool JSSerializer::WriteJSMap(const JSHandle &value) { JSHandle map = JSHandle::Cast(value); - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::JS_MAP)) { return false; } if (!WritePlainObject(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } int size = map->GetSize(); if (!WriteLength(static_cast(size))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } for (int i = 0; i < size; i++) { JSHandle key(thread_, map->GetKey(i)); if (!SerializeJSTaggedValue(key)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } JSHandle val(thread_, map->GetValue(i)); if (!SerializeJSTaggedValue(val)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } } @@ -458,23 +458,23 @@ bool JSSerializer::WriteJSMap(const JSHandle &value) bool JSSerializer::WriteJSSet(const JSHandle &value) { JSHandle set = JSHandle::Cast(value); - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::JS_SET)) { return false; } if (!WritePlainObject(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } int size = set->GetSize(); if (!WriteLength(static_cast(size))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } for (int i = 0; i < size; i++) { JSHandle val(thread_, set->GetValue(i)); if (!SerializeJSTaggedValue(val)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } } @@ -483,82 +483,82 @@ bool JSSerializer::WriteJSSet(const JSHandle &value) bool JSSerializer::WriteJSRegExp(const JSHandle &value) { - JSHandle reg_exp = JSHandle::Cast(value); - size_t old_size = buffer_size_; + JSHandle regExp = JSHandle::Cast(value); + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::JS_REG_EXP)) { return false; } if (!WritePlainObject(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } - uint32_t buffer_size = static_cast(reg_exp->GetLength().GetInt()); - if (!WriteLength(buffer_size)) { - buffer_size_ = old_size; + uint32_t bufferSize = static_cast(regExp->GetLength().GetInt()); + if (!WriteLength(bufferSize)) { + bufferSize_ = oldSize; return false; } // Write Accessor(ByteCodeBuffer) which is a pointer to a Dynbuffer - JSHandle buffer_value(thread_, reg_exp->GetByteCodeBuffer()); - JSHandle np = JSHandle::Cast(buffer_value); - void *dyn_buffer = np->GetExternalPointer(); - if (!WriteRawData(dyn_buffer, buffer_size)) { - buffer_size_ = old_size; + JSHandle bufferValue(thread_, regExp->GetByteCodeBuffer()); + JSHandle np = JSHandle::Cast(bufferValue); + void *dynBuffer = np->GetExternalPointer(); + if (!WriteRawData(dynBuffer, bufferSize)) { + bufferSize_ = oldSize; return false; } // Write Accessor(OriginalSource) - JSHandle original_source(thread_, reg_exp->GetOriginalSource()); - if (!SerializeJSTaggedValue(original_source)) { - buffer_size_ = old_size; + JSHandle originalSource(thread_, regExp->GetOriginalSource()); + if (!SerializeJSTaggedValue(originalSource)) { + bufferSize_ = oldSize; return false; } // Write Accessor(OriginalFlags) - JSHandle original_flags(thread_, reg_exp->GetOriginalFlags()); - if (!SerializeJSTaggedValue(original_flags)) { - buffer_size_ = old_size; + JSHandle originalFlags(thread_, regExp->GetOriginalFlags()); + if (!SerializeJSTaggedValue(originalFlags)) { + bufferSize_ = oldSize; return false; } return true; } -bool JSSerializer::WriteJSTypedArray(const JSHandle &value, SerializationUID u_id) +bool JSSerializer::WriteJSTypedArray(const JSHandle &value, SerializationUID uId) { - JSHandle typed_array = JSHandle::Cast(value); - size_t old_size = buffer_size_; - if (!WriteType(u_id)) { + JSHandle typedArray = JSHandle::Cast(value); + size_t oldSize = bufferSize_; + if (!WriteType(uId)) { return false; } if (!WritePlainObject(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } // Write ACCESSORS(ViewedArrayBuffer) which is a pointer to an ArrayBuffer - JSHandle viewed_array_buffer(thread_, typed_array->GetViewedArrayBuffer()); - if (!WriteJSArrayBuffer(viewed_array_buffer)) { - buffer_size_ = old_size; + JSHandle viewedArrayBuffer(thread_, typedArray->GetViewedArrayBuffer()); + if (!WriteJSArrayBuffer(viewedArrayBuffer)) { + bufferSize_ = oldSize; return false; } // Write ACCESSORS(TypedArrayName) - JSHandle typed_array_name(thread_, typed_array->GetTypedArrayName()); - if (!SerializeJSTaggedValue(typed_array_name)) { - buffer_size_ = old_size; + JSHandle typedArrayName(thread_, typedArray->GetTypedArrayName()); + if (!SerializeJSTaggedValue(typedArrayName)) { + bufferSize_ = oldSize; return false; } // Write ACCESSORS(ByteLength) - JSTaggedValue byte_length = typed_array->GetByteLength(); - if (!WriteRawData(&byte_length, sizeof(JSTaggedValue))) { - buffer_size_ = old_size; + JSTaggedValue byteLength = typedArray->GetByteLength(); + if (!WriteRawData(&byteLength, sizeof(JSTaggedValue))) { + bufferSize_ = oldSize; return false; } // Write ACCESSORS(ByteOffset) - JSTaggedValue byte_offset = typed_array->GetByteOffset(); - if (!WriteRawData(&byte_offset, sizeof(JSTaggedValue))) { - buffer_size_ = old_size; + JSTaggedValue byteOffset = typedArray->GetByteOffset(); + if (!WriteRawData(&byteOffset, sizeof(JSTaggedValue))) { + bufferSize_ = oldSize; return false; } // Write ACCESSORS(ArrayLength) - JSTaggedValue array_length = typed_array->GetArrayLength(); - if (!WriteRawData(&array_length, sizeof(JSTaggedValue))) { - buffer_size_ = old_size; + JSTaggedValue arrayLength = typedArray->GetArrayLength(); + if (!WriteRawData(&arrayLength, sizeof(JSTaggedValue))) { + bufferSize_ = oldSize; return false; } return true; @@ -566,13 +566,13 @@ bool JSSerializer::WriteJSTypedArray(const JSHandle &value, Seria bool JSSerializer::WriteNativeFunctionPointer(const JSHandle &value) { - size_t old_size = buffer_size_; + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::NATIVE_FUNCTION_POINTER)) { return false; } JSTaggedValue pointer = value.GetTaggedValue(); if (!WriteRawData(&pointer, sizeof(JSTaggedValue))) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } return true; @@ -580,10 +580,10 @@ bool JSSerializer::WriteNativeFunctionPointer(const JSHandle &val bool JSSerializer::WriteJSArrayBuffer(const JSHandle &value) { - size_t old_size = buffer_size_; - JSHandle array_buffer = JSHandle::Cast(value); + size_t oldSize = bufferSize_; + JSHandle arrayBuffer = JSHandle::Cast(value); - if (array_buffer->IsDetach()) { + if (arrayBuffer->IsDetach()) { return false; } @@ -592,117 +592,117 @@ bool JSSerializer::WriteJSArrayBuffer(const JSHandle &value) } // Write Accessors(ArrayBufferByteLength) - JSTaggedValue tagged_length = array_buffer->GetArrayBufferByteLength(); - if (!WriteRawData(&tagged_length, sizeof(JSTaggedValue))) { - buffer_size_ = old_size; + JSTaggedValue taggedLength = arrayBuffer->GetArrayBufferByteLength(); + if (!WriteRawData(&taggedLength, sizeof(JSTaggedValue))) { + bufferSize_ = oldSize; return false; } // write Accessor shared which indicate the C memeory is shared - bool shared = array_buffer->GetShared().ToBoolean(); + bool shared = arrayBuffer->GetShared().ToBoolean(); if (!WriteBoolean(shared)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } if (shared) { - JSHandle np(thread_, array_buffer->GetArrayBufferData()); + JSHandle np(thread_, arrayBuffer->GetArrayBufferData()); void *buffer = np->GetExternalPointer(); - auto buffer_addr = reinterpret_cast(buffer); - if (!WriteRawData(&buffer_addr, sizeof(uint64_t))) { - buffer_size_ = old_size; + auto bufferAddr = reinterpret_cast(buffer); + if (!WriteRawData(&bufferAddr, sizeof(uint64_t))) { + bufferSize_ = oldSize; return false; } } else { - uint32_t byte_length = JSTaggedNumber(tagged_length).ToUint32(); + uint32_t byteLength = JSTaggedNumber(taggedLength).ToUint32(); // Write Accessors(ArrayBufferData) which is a pointer to a DynBuffer - JSHandle np(thread_, array_buffer->GetArrayBufferData()); + JSHandle np(thread_, arrayBuffer->GetArrayBufferData()); void *buffer = np->GetExternalPointer(); - if (!WriteRawData(buffer, byte_length)) { - buffer_size_ = old_size; + if (!WriteRawData(buffer, byteLength)) { + bufferSize_ = oldSize; return false; } } // write obj properties if (!WritePlainObject(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } return true; } -bool JSSerializer::WritePlainObject(const JSHandle &obj_value) +bool JSSerializer::WritePlainObject(const JSHandle &objValue) { - JSHandle obj = JSHandle::Cast(obj_value); - size_t old_size = buffer_size_; + JSHandle obj = JSHandle::Cast(objValue); + size_t oldSize = bufferSize_; if (!WriteType(SerializationUID::JS_PLAIN_OBJECT)) { return false; } // Get the number of elements stored in obj - uint32_t elements_length = obj->GetNumberOfElements(); - if (!WriteLength(elements_length)) { - buffer_size_ = old_size; + uint32_t elementsLength = obj->GetNumberOfElements(); + if (!WriteLength(elementsLength)) { + bufferSize_ = oldSize; return false; } - std::vector key_vector; - JSObject::GetALLElementKeysIntoVector(thread_, obj, key_vector); + std::vector keyVector; + JSObject::GetALLElementKeysIntoVector(thread_, obj, keyVector); // Write elements' description attributes and value - if (key_vector.size() != elements_length) { - buffer_size_ = old_size; + if (keyVector.size() != elementsLength) { + bufferSize_ = oldSize; return false; } - for (uint32_t i = 0; i < elements_length; i++) { - JSHandle key(thread_, key_vector[i]); + for (uint32_t i = 0; i < elementsLength; i++) { + JSHandle key(thread_, keyVector[i]); if (!SerializeJSTaggedValue(key)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } PropertyDescriptor desc(thread_); JSObject::OrdinaryGetOwnProperty(thread_, obj, key, desc); if (!WriteDesc(desc)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } JSHandle value = desc.GetValue(); if (!SerializeJSTaggedValue(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } } // Get the number of k-v form properties stored in obj - key_vector.clear(); - uint32_t properties_length = obj->GetNumberOfKeys(); - if (!WriteLength(properties_length)) { - buffer_size_ = old_size; + keyVector.clear(); + uint32_t propertiesLength = obj->GetNumberOfKeys(); + if (!WriteLength(propertiesLength)) { + bufferSize_ = oldSize; return false; } - JSObject::GetAllKeys(thread_, obj, key_vector); - if (key_vector.size() != properties_length) { - buffer_size_ = old_size; + JSObject::GetAllKeys(thread_, obj, keyVector); + if (keyVector.size() != propertiesLength) { + bufferSize_ = oldSize; return false; } // Write keys' description attributes and related values - for (uint32_t i = 0; i < properties_length; i++) { - if (key_vector.empty()) { - buffer_size_ = old_size; + for (uint32_t i = 0; i < propertiesLength; i++) { + if (keyVector.empty()) { + bufferSize_ = oldSize; return false; } - JSHandle key(thread_, key_vector[i]); + JSHandle key(thread_, keyVector[i]); if (!SerializeJSTaggedValue(key)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } PropertyDescriptor desc(thread_); JSObject::OrdinaryGetOwnProperty(thread_, obj, key, desc); if (!WriteDesc(desc)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } JSHandle value = desc.GetValue(); if (!SerializeJSTaggedValue(value)) { - buffer_size_ = old_size; + bufferSize_ = oldSize; return false; } } @@ -711,35 +711,35 @@ bool JSSerializer::WritePlainObject(const JSHandle &obj_value) bool JSSerializer::WriteDesc(const PropertyDescriptor &desc) { - size_t old_size = buffer_size_; - bool is_writable = desc.IsWritable(); - if (!WriteBoolean(is_writable)) { - buffer_size_ = old_size; + size_t oldSize = bufferSize_; + bool isWritable = desc.IsWritable(); + if (!WriteBoolean(isWritable)) { + bufferSize_ = oldSize; return false; } - bool is_enumerable = desc.IsEnumerable(); - if (!WriteBoolean(is_enumerable)) { - buffer_size_ = old_size; + bool isEnumerable = desc.IsEnumerable(); + if (!WriteBoolean(isEnumerable)) { + bufferSize_ = oldSize; return false; } - bool is_configurable = desc.IsConfigurable(); - if (!WriteBoolean(is_configurable)) { - buffer_size_ = old_size; + bool isConfigurable = desc.IsConfigurable(); + if (!WriteBoolean(isConfigurable)) { + bufferSize_ = oldSize; return false; } - bool has_writable = desc.HasWritable(); - if (!WriteBoolean(has_writable)) { - buffer_size_ = old_size; + bool hasWritable = desc.HasWritable(); + if (!WriteBoolean(hasWritable)) { + bufferSize_ = oldSize; return false; } - bool has_enumerable = desc.HasEnumerable(); - if (!WriteBoolean(has_enumerable)) { - buffer_size_ = old_size; + bool hasEnumerable = desc.HasEnumerable(); + if (!WriteBoolean(hasEnumerable)) { + bufferSize_ = oldSize; return false; } - bool has_configurable = desc.HasConfigurable(); - if (!WriteBoolean(has_configurable)) { - buffer_size_ = old_size; + bool hasConfigurable = desc.HasConfigurable(); + if (!WriteBoolean(hasConfigurable)) { + bufferSize_ = oldSize; return false; } return true; @@ -787,13 +787,13 @@ bool JSDeserializer::ReadInt(uint32_t *value) return true; } -bool JSDeserializer::ReadObjectId(uint64_t *object_id) +bool JSDeserializer::ReadObjectId(uint64_t *objectId) { size_t len = sizeof(uint64_t); if (len > static_cast(end_ - position_)) { return false; } - if (memcpy_s(object_id, len, position_, len) != EOK) { + if (memcpy_s(objectId, len, position_, len) != EOK) { UNREACHABLE(); } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -914,130 +914,130 @@ JSHandle JSDeserializer::DeserializeJSTaggedValue() JSHandle JSDeserializer::ReadJSError(SerializationUID uid) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - base::ErrorType error_type; + base::ErrorType errorType; switch (uid) { case SerializationUID::JS_ERROR: - error_type = base::ErrorType::ERROR; + errorType = base::ErrorType::ERROR; break; case SerializationUID::EVAL_ERROR: - error_type = base::ErrorType::EVAL_ERROR; + errorType = base::ErrorType::EVAL_ERROR; break; case SerializationUID::RANGE_ERROR: - error_type = base::ErrorType::RANGE_ERROR; + errorType = base::ErrorType::RANGE_ERROR; break; case SerializationUID::REFERENCE_ERROR: - error_type = base::ErrorType::REFERENCE_ERROR; + errorType = base::ErrorType::REFERENCE_ERROR; break; case SerializationUID::TYPE_ERROR: - error_type = base::ErrorType::TYPE_ERROR; + errorType = base::ErrorType::TYPE_ERROR; break; case SerializationUID::URI_ERROR: - error_type = base::ErrorType::URI_ERROR; + errorType = base::ErrorType::URI_ERROR; break; case SerializationUID::SYNTAX_ERROR: - error_type = base::ErrorType::URI_ERROR; + errorType = base::ErrorType::URI_ERROR; break; default: UNREACHABLE(); } JSHandle msg = DeserializeJSTaggedValue(); - JSHandle handle_msg(msg); - JSHandle error_tag = JSHandle::Cast(factory->NewJSError(error_type, handle_msg)); - reference_map_.insert(std::pair(object_id_++, error_tag)); - return error_tag; + JSHandle handleMsg(msg); + JSHandle errorTag = JSHandle::Cast(factory->NewJSError(errorType, handleMsg)); + referenceMap_.insert(std::pair(objectId_++, errorTag)); + return errorTag; } JSHandle JSDeserializer::ReadJSDate() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle date_function = env->GetDateFunction(); + JSHandle dateFunction = env->GetDateFunction(); JSHandle date = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(date_function), date_function)); - JSHandle date_tag = JSHandle::Cast(date); - reference_map_.insert(std::pair(object_id_++, date_tag)); - if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(date_tag)) { + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(dateFunction), dateFunction)); + JSHandle dateTag = JSHandle::Cast(date); + referenceMap_.insert(std::pair(objectId_++, dateTag)); + if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(dateTag)) { return JSHandle(); } - double time_value; - if (!JudgeType(SerializationUID::DOUBLE) || !ReadDouble(&time_value)) { + double timeValue; + if (!JudgeType(SerializationUID::DOUBLE) || !ReadDouble(&timeValue)) { return JSHandle(); } - date->SetTimeValue(thread_, JSTaggedValue(time_value)); - double local_offset; - if (!JudgeType(SerializationUID::DOUBLE) || !ReadDouble(&local_offset)) { + date->SetTimeValue(thread_, JSTaggedValue(timeValue)); + double localOffset; + if (!JudgeType(SerializationUID::DOUBLE) || !ReadDouble(&localOffset)) { return JSHandle(); } - date->SetLocalOffset(thread_, JSTaggedValue(local_offset)); - return date_tag; + date->SetLocalOffset(thread_, JSTaggedValue(localOffset)); + return dateTag; } JSHandle JSDeserializer::ReadJSArray() { - JSHandle js_array = thread_->GetEcmaVM()->GetFactory()->NewJSArray(); - JSHandle array_tag = JSHandle::Cast(js_array); - reference_map_.insert(std::pair(object_id_++, array_tag)); - if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(array_tag)) { + JSHandle jsArray = thread_->GetEcmaVM()->GetFactory()->NewJSArray(); + JSHandle arrayTag = JSHandle::Cast(jsArray); + referenceMap_.insert(std::pair(objectId_++, arrayTag)); + if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(arrayTag)) { return JSHandle(); } - uint32_t arr_length; - if (!JudgeType(SerializationUID::UINT32) || !ReadInt(&arr_length)) { + uint32_t arrLength; + if (!JudgeType(SerializationUID::UINT32) || !ReadInt(&arrLength)) { return JSHandle(); } - js_array->SetLength(thread_, JSTaggedValue(arr_length)); - return array_tag; + jsArray->SetLength(thread_, JSTaggedValue(arrLength)); + return arrayTag; } JSHandle JSDeserializer::ReadEcmaString() { - uint32_t string_length; - if (!ReadInt(&string_length)) { + uint32_t stringLength; + if (!ReadInt(&stringLength)) { return JSHandle(); } ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto *string = reinterpret_cast(GetBuffer(string_length + 1)); + auto *string = reinterpret_cast(GetBuffer(stringLength + 1)); if (string == nullptr) { return JSHandle(); } - JSHandle ecma_string = factory->NewFromUtf8(string, string_length); - auto string_tag = JSHandle(ecma_string); - reference_map_.insert(std::pair(object_id_++, string_tag)); - return string_tag; + JSHandle ecmaString = factory->NewFromUtf8(string, stringLength); + auto stringTag = JSHandle(ecmaString); + referenceMap_.insert(std::pair(objectId_++, stringTag)); + return stringTag; } JSHandle JSDeserializer::ReadPlainObject() { JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle obj_func(thread_, env->GetObjectFunction().GetObject()); - JSHandle js_object = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); - JSHandle obj_tag = JSHandle::Cast(js_object); - reference_map_.insert(std::pair(object_id_++, obj_tag)); - if (!DefinePropertiesAndElements(obj_tag)) { + JSHandle objFunc(thread_, env->GetObjectFunction().GetObject()); + JSHandle jsObject = + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); + JSHandle objTag = JSHandle::Cast(jsObject); + referenceMap_.insert(std::pair(objectId_++, objTag)); + if (!DefinePropertiesAndElements(objTag)) { return JSHandle(); } - return obj_tag; + return objTag; } JSHandle JSDeserializer::ReadJSMap() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle map_function = env->GetMapFunction(); - JSHandle js_map = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(map_function), map_function)); - JSHandle map_tag = JSHandle::Cast(js_map); - reference_map_.insert(std::pair(object_id_++, map_tag)); - if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(map_tag)) { + JSHandle mapFunction = env->GetMapFunction(); + JSHandle jsMap = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(mapFunction), mapFunction)); + JSHandle mapTag = JSHandle::Cast(jsMap); + referenceMap_.insert(std::pair(objectId_++, mapTag)); + if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(mapTag)) { return JSHandle(); } uint32_t size; if (!ReadInt(&size)) { return JSHandle(); } - JSHandle linked_map = LinkedHashMap::Create(thread_); - js_map->SetLinkedMap(thread_, linked_map); + JSHandle linkedMap = LinkedHashMap::Create(thread_); + jsMap->SetLinkedMap(thread_, linkedMap); for (uint32_t i = 0; i < size; i++) { JSHandle key = DeserializeJSTaggedValue(); if (key.IsEmpty()) { @@ -1047,65 +1047,65 @@ JSHandle JSDeserializer::ReadJSMap() if (value.IsEmpty()) { return JSHandle(); } - JSMap::Set(thread_, js_map, key, value); + JSMap::Set(thread_, jsMap, key, value); } - return map_tag; + return mapTag; } JSHandle JSDeserializer::ReadJSSet() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle set_function = env->GetSetFunction(); - JSHandle js_set = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(set_function), set_function)); - JSHandle set_tag = JSHandle::Cast(js_set); - reference_map_.insert(std::pair(object_id_++, set_tag)); - if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(set_tag)) { + JSHandle setFunction = env->GetSetFunction(); + JSHandle jsSet = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(setFunction), setFunction)); + JSHandle setTag = JSHandle::Cast(jsSet); + referenceMap_.insert(std::pair(objectId_++, setTag)); + if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(setTag)) { return JSHandle(); } uint32_t size; if (!ReadInt(&size)) { return JSHandle(); } - JSHandle linked_set = LinkedHashSet::Create(thread_); - js_set->SetLinkedSet(thread_, linked_set); + JSHandle linkedSet = LinkedHashSet::Create(thread_); + jsSet->SetLinkedSet(thread_, linkedSet); for (uint32_t i = 0; i < size; i++) { JSHandle key = DeserializeJSTaggedValue(); if (key.IsEmpty()) { return JSHandle(); } - JSSet::Add(thread_, js_set, key); + JSSet::Add(thread_, jsSet, key); } - return set_tag; + return setTag; } JSHandle JSDeserializer::ReadJSRegExp() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle regexp_function = env->GetRegExpFunction(); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(regexp_function), regexp_function); - JSHandle reg_exp = JSHandle::Cast(obj); - JSHandle regexp_tag = JSHandle::Cast(reg_exp); - reference_map_.insert(std::pair(object_id_++, regexp_tag)); - if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(regexp_tag)) { + JSHandle regexpFunction = env->GetRegExpFunction(); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(regexpFunction), regexpFunction); + JSHandle regExp = JSHandle::Cast(obj); + JSHandle regexpTag = JSHandle::Cast(regExp); + referenceMap_.insert(std::pair(objectId_++, regexpTag)); + if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(regexpTag)) { return JSHandle(); } - uint32_t buffer_size; - if (!ReadInt(&buffer_size)) { + uint32_t bufferSize; + if (!ReadInt(&bufferSize)) { return JSHandle(); } - void *buffer = GetBuffer(buffer_size); + void *buffer = GetBuffer(bufferSize); if (buffer == nullptr) { return JSHandle(); } - factory->NewJSRegExpByteCodeData(reg_exp, buffer, buffer_size); - JSHandle original_source = DeserializeJSTaggedValue(); - reg_exp->SetOriginalSource(thread_, original_source); - JSHandle original_flags = DeserializeJSTaggedValue(); - reg_exp->SetOriginalFlags(thread_, original_flags); - return regexp_tag; + factory->NewJSRegExpByteCodeData(regExp, buffer, bufferSize); + JSHandle originalSource = DeserializeJSTaggedValue(); + regExp->SetOriginalSource(thread_, originalSource); + JSHandle originalFlags = DeserializeJSTaggedValue(); + regExp->SetOriginalFlags(thread_, originalFlags); + return regexpTag; } JSHandle JSDeserializer::ReadJSTypedArray(SerializationUID uid) @@ -1114,7 +1114,7 @@ JSHandle JSDeserializer::ReadJSTypedArray(SerializationUID uid) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle target; JSHandle obj; - JSHandle obj_tag; + JSHandle objTag; switch (uid) { case SerializationUID::JS_INT8_ARRAY: { target = env->GetInt8ArrayFunction(); @@ -1155,45 +1155,45 @@ JSHandle JSDeserializer::ReadJSTypedArray(SerializationUID uid) default: UNREACHABLE(); } - JSHandle typed_array = + JSHandle typedArray = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(target), target)); - obj = JSHandle::Cast(typed_array); - obj_tag = JSHandle::Cast(obj); - reference_map_.insert(std::pair(object_id_++, obj_tag)); - if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(obj_tag)) { + obj = JSHandle::Cast(typedArray); + objTag = JSHandle::Cast(obj); + referenceMap_.insert(std::pair(objectId_++, objTag)); + if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(objTag)) { return JSHandle(); } - JSHandle viewed_array_buffer = DeserializeJSTaggedValue(); - if (viewed_array_buffer.IsEmpty()) { + JSHandle viewedArrayBuffer = DeserializeJSTaggedValue(); + if (viewedArrayBuffer.IsEmpty()) { return JSHandle(); } - typed_array->SetViewedArrayBuffer(thread_, viewed_array_buffer); + typedArray->SetViewedArrayBuffer(thread_, viewedArrayBuffer); - JSHandle typed_array_name = DeserializeJSTaggedValue(); - if (typed_array_name.IsEmpty()) { + JSHandle typedArrayName = DeserializeJSTaggedValue(); + if (typedArrayName.IsEmpty()) { return JSHandle(); } - typed_array->SetTypedArrayName(thread_, typed_array_name); + typedArray->SetTypedArrayName(thread_, typedArrayName); - JSTaggedValue byte_length; - if (!ReadJSTaggedValue(&byte_length) || !byte_length.IsNumber()) { + JSTaggedValue byteLength; + if (!ReadJSTaggedValue(&byteLength) || !byteLength.IsNumber()) { return JSHandle(); } - typed_array->SetByteLength(thread_, byte_length); + typedArray->SetByteLength(thread_, byteLength); - JSTaggedValue byte_offset; - if (!ReadJSTaggedValue(&byte_offset) || !byte_offset.IsNumber()) { + JSTaggedValue byteOffset; + if (!ReadJSTaggedValue(&byteOffset) || !byteOffset.IsNumber()) { return JSHandle(); } - typed_array->SetByteOffset(thread_, byte_offset); + typedArray->SetByteOffset(thread_, byteOffset); - JSTaggedValue array_length; - if (!ReadJSTaggedValue(&array_length) || !byte_offset.IsNumber()) { + JSTaggedValue arrayLength; + if (!ReadJSTaggedValue(&arrayLength) || !byteOffset.IsNumber()) { return JSHandle(); } - typed_array->SetArrayLength(thread_, array_length); - return obj_tag; + typedArray->SetArrayLength(thread_, arrayLength); + return objTag; } JSHandle JSDeserializer::ReadNativeFunctionPointer() @@ -1209,8 +1209,8 @@ JSHandle JSDeserializer::ReadJSArrayBuffer() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // read access length - JSTaggedValue tagged_length; - if (!ReadJSTaggedValue(&tagged_length)) { + JSTaggedValue taggedLength; + if (!ReadJSTaggedValue(&taggedLength)) { return JSHandle(); } // read access shared @@ -1219,34 +1219,34 @@ JSHandle JSDeserializer::ReadJSArrayBuffer() return JSHandle(); } // create jsarraybuffer - JSHandle array_buffer_tag; - uint32_t byte_length = JSTaggedNumber(tagged_length).ToUint32(); + JSHandle arrayBufferTag; + uint32_t byteLength = JSTaggedNumber(taggedLength).ToUint32(); if (shared) { - auto *buffer_addr = static_cast(GetBuffer(sizeof(uint64_t))); - void *buffer_data = ToVoidPtr(*buffer_addr); - JSHandle array_buffer = factory->NewJSArrayBuffer(buffer_data, byte_length, nullptr, nullptr); - array_buffer_tag = JSHandle::Cast(array_buffer); - reference_map_.insert(std::pair(object_id_++, array_buffer_tag)); + auto *bufferAddr = static_cast(GetBuffer(sizeof(uint64_t))); + void *bufferData = ToVoidPtr(*bufferAddr); + JSHandle arrayBuffer = factory->NewJSArrayBuffer(bufferData, byteLength, nullptr, nullptr); + arrayBufferTag = JSHandle::Cast(arrayBuffer); + referenceMap_.insert(std::pair(objectId_++, arrayBufferTag)); } else { - void *from_buffer = GetBuffer(byte_length); - if (from_buffer == nullptr) { - return array_buffer_tag; + void *fromBuffer = GetBuffer(byteLength); + if (fromBuffer == nullptr) { + return arrayBufferTag; } - JSHandle array_buffer = factory->NewJSArrayBuffer(byte_length); - array_buffer_tag = JSHandle::Cast(array_buffer); - reference_map_.insert(std::pair(object_id_++, array_buffer_tag)); - JSHandle np(thread_, array_buffer->GetArrayBufferData()); - void *to_buffer = np->GetExternalPointer(); - if (memcpy_s(to_buffer, byte_length, from_buffer, byte_length) != EOK) { + JSHandle arrayBuffer = factory->NewJSArrayBuffer(byteLength); + arrayBufferTag = JSHandle::Cast(arrayBuffer); + referenceMap_.insert(std::pair(objectId_++, arrayBufferTag)); + JSHandle np(thread_, arrayBuffer->GetArrayBufferData()); + void *toBuffer = np->GetExternalPointer(); + if (memcpy_s(toBuffer, byteLength, fromBuffer, byteLength) != EOK) { UNREACHABLE(); } } // read jsarraybuffer properties - if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(array_buffer_tag)) { + if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(arrayBufferTag)) { return JSHandle(); } - return array_buffer_tag; + return arrayBufferTag; } bool JSDeserializer::ReadJSTaggedValue(JSTaggedValue *value) @@ -1263,44 +1263,44 @@ bool JSDeserializer::ReadJSTaggedValue(JSTaggedValue *value) return true; } -void *JSDeserializer::GetBuffer(uint32_t buffer_size) +void *JSDeserializer::GetBuffer(uint32_t bufferSize) { const uint8_t *buffer = nullptr; - if (buffer_size > static_cast(end_ - position_)) { + if (bufferSize > static_cast(end_ - position_)) { return nullptr; } buffer = position_; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - position_ += buffer_size; - auto *ret_buffer = const_cast(buffer); - return static_cast(ret_buffer); + position_ += bufferSize; + auto *retBuffer = const_cast(buffer); + return static_cast(retBuffer); } JSHandle JSDeserializer::ReadReference() { - uint64_t obj_id; - if (!ReadObjectId(&obj_id)) { + uint64_t objId; + if (!ReadObjectId(&objId)) { return JSHandle(); } - auto obj_iter = reference_map_.find(obj_id); - if (obj_iter == reference_map_.end()) { + auto objIter = referenceMap_.find(objId); + if (objIter == referenceMap_.end()) { return JSHandle(); } - return obj_iter->second; + return objIter->second; } -bool JSDeserializer::JudgeType(SerializationUID target_uid) +bool JSDeserializer::JudgeType(SerializationUID targetUid) { - return ReadType() != target_uid; + return ReadType() != targetUid; } bool JSDeserializer::DefinePropertiesAndElements(const JSHandle &obj) { - uint32_t element_length; - if (!ReadInt(&element_length)) { + uint32_t elementLength; + if (!ReadInt(&elementLength)) { return false; } - for (uint32_t i = 0; i < element_length; i++) { + for (uint32_t i = 0; i < elementLength; i++) { JSHandle key = DeserializeJSTaggedValue(); if (key.IsEmpty()) { return false; @@ -1319,11 +1319,11 @@ bool JSDeserializer::DefinePropertiesAndElements(const JSHandle & } } - uint32_t property_length; - if (!ReadInt(&property_length)) { + uint32_t propertyLength; + if (!ReadInt(&propertyLength)) { return false; } - for (uint32_t i = 0; i < property_length; i++) { + for (uint32_t i = 0; i < propertyLength; i++) { JSHandle key = DeserializeJSTaggedValue(); if (key.IsEmpty()) { return false; @@ -1346,38 +1346,38 @@ bool JSDeserializer::DefinePropertiesAndElements(const JSHandle & bool JSDeserializer::ReadDesc(PropertyDescriptor *desc) { - bool is_writable = false; - if (!ReadBoolean(&is_writable)) { + bool isWritable = false; + if (!ReadBoolean(&isWritable)) { return false; } - bool is_enumerable = false; - if (!ReadBoolean(&is_enumerable)) { + bool isEnumerable = false; + if (!ReadBoolean(&isEnumerable)) { return false; } - bool is_configurable = false; - if (!ReadBoolean(&is_configurable)) { + bool isConfigurable = false; + if (!ReadBoolean(&isConfigurable)) { return false; } - bool has_writable = false; - if (!ReadBoolean(&has_writable)) { + bool hasWritable = false; + if (!ReadBoolean(&hasWritable)) { return false; } - bool has_enumerable = false; - if (!ReadBoolean(&has_enumerable)) { + bool hasEnumerable = false; + if (!ReadBoolean(&hasEnumerable)) { return false; } - bool has_configurable = false; - if (!ReadBoolean(&has_configurable)) { + bool hasConfigurable = false; + if (!ReadBoolean(&hasConfigurable)) { return false; } - if (has_writable) { - desc->SetWritable(is_writable); + if (hasWritable) { + desc->SetWritable(isWritable); } - if (has_enumerable) { - desc->SetEnumerable(is_enumerable); + if (hasEnumerable) { + desc->SetEnumerable(isEnumerable); } - if (has_configurable) { - desc->SetConfigurable(is_configurable); + if (hasConfigurable) { + desc->SetConfigurable(isConfigurable); } return true; } @@ -1407,15 +1407,15 @@ bool Serializer::WriteValue(JSThread *thread, const JSHandle &val if (!PrepareTransfer(thread, transfer)) { return false; } - if (!value_serializer_.SerializeJSTaggedValue(value)) { + if (!valueSerializer_.SerializeJSTaggedValue(value)) { return false; } if (!FinalizeTransfer(thread, transfer)) { return false; } - std::pair pair = value_serializer_.ReleaseBuffer(); + std::pair pair = valueSerializer_.ReleaseBuffer(); data_->value_.reset(pair.first); - data_->data_size_ = pair.second; + data_->dataSize_ = pair.second; return true; } @@ -1441,7 +1441,7 @@ bool Serializer::PrepareTransfer(JSThread *thread, const JSHandle if (!element->IsArrayBuffer()) { return false; } - array_buffer_idxs_.emplace_back(k); + arrayBufferIdxs_.emplace_back(k); } k++; } @@ -1450,7 +1450,7 @@ bool Serializer::PrepareTransfer(JSThread *thread, const JSHandle bool Serializer::FinalizeTransfer(JSThread *thread, const JSHandle &transfer) { - for (int idx : array_buffer_idxs_) { + for (int idx : arrayBufferIdxs_) { JSHandle element = JSArray::FastGetPropertyByValue(thread, transfer, idx); JSArrayBuffer::Cast(element->GetHeapObject())->Detach(thread); } @@ -1459,6 +1459,6 @@ bool Serializer::FinalizeTransfer(JSThread *thread, const JSHandle Deserializer::ReadValue() { - return value_deserializer_.DeserializeJSTaggedValue(); + return valueDeserializer_.DeserializeJSTaggedValue(); } } // namespace panda::ecmascript diff --git a/runtime/js_serializer.h b/runtime/js_serializer.h index 8de592caf4e8996209d8743d31b578e2076138ae..bd25c45e4bb0fb598f6ebb4561694c78de3be014 100644 --- a/runtime/js_serializer.h +++ b/runtime/js_serializer.h @@ -98,9 +98,9 @@ private: bool WriteInt(uint32_t value); bool WriteDouble(double value); bool WriteRawData(const void *data, size_t length); - bool WriteType(SerializationUID u_id); + bool WriteType(SerializationUID uId); bool AllocateBuffer(size_t bytes); - bool ExpandBuffer(size_t requested_size); + bool ExpandBuffer(size_t requestedSize); bool WriteBoolean(bool value); bool WriteJSError(const JSHandle &value); bool WriteJSErrorHeader(JSType type); @@ -110,7 +110,7 @@ private: bool WriteJSSet(const JSHandle &value); bool WriteJSRegExp(const JSHandle &value); bool WriteEcmaString(const JSHandle &value); - bool WriteJSTypedArray(const JSHandle &value, SerializationUID u_id); + bool WriteJSTypedArray(const JSHandle &value, SerializationUID uId); bool WritePlainObject(const JSHandle &value); bool WriteLength(uint32_t length); bool WriteNativeFunctionPointer(const JSHandle &value); @@ -124,13 +124,13 @@ private: JSThread *thread_; uint8_t *buffer_ = nullptr; - uint64_t size_limit_ = 0; - size_t buffer_size_ = 0; - size_t buffer_capacity_ = 0; + uint64_t sizeLimit_ = 0; + size_t bufferSize_ = 0; + size_t bufferCapacity_ = 0; // The Reference map is used for check whether a tagged object has been serialized // Reference map works only if no gc happens during serialization - std::map reference_map_; - uint64_t object_id_ = 0; + std::map referenceMap_; + uint64_t objectId_ = 0; }; class JSDeserializer { @@ -148,7 +148,7 @@ public: private: bool ReadInt(int32_t *value); bool ReadInt(uint32_t *value); - bool ReadObjectId(uint64_t *object_id); + bool ReadObjectId(uint64_t *objectId); bool ReadDouble(double *value); SerializationUID ReadType(); JSHandle ReadJSError(SerializationUID uid); @@ -163,8 +163,8 @@ private: JSHandle ReadNativeFunctionPointer(); JSHandle ReadJSArrayBuffer(); JSHandle ReadReference(); - bool JudgeType(SerializationUID target_uid); - void *GetBuffer(uint32_t buffer_size); + bool JudgeType(SerializationUID targetUid); + void *GetBuffer(uint32_t bufferSize); bool ReadJSTaggedValue(JSTaggedValue *value); bool DefinePropertiesAndElements(const JSHandle &obj); bool ReadDesc(PropertyDescriptor *desc); @@ -177,8 +177,8 @@ private: uint8_t *begin_ = nullptr; const uint8_t *position_ = nullptr; const uint8_t *const end_ = nullptr; - uint64_t object_id_ = 0; - std::map> reference_map_; + uint64_t objectId_ = 0; + std::map> referenceMap_; }; class SerializationData { @@ -192,7 +192,7 @@ public: } size_t GetSize() const { - return data_size_; + return dataSize_; } NO_MOVE_SEMANTIC(SerializationData); @@ -206,7 +206,7 @@ private: free(ptr); } }; - size_t data_size_ {0}; + size_t dataSize_ {0}; std::unique_ptr value_; private: @@ -215,7 +215,7 @@ private: class Serializer { public: - explicit Serializer(JSThread *thread) : value_serializer_(thread) {} + explicit Serializer(JSThread *thread) : valueSerializer_(thread) {} ~Serializer() = default; bool WriteValue(JSThread *thread, const JSHandle &value, const JSHandle &transfer); @@ -228,15 +228,15 @@ private: bool PrepareTransfer(JSThread *thread, const JSHandle &transfer); bool FinalizeTransfer(JSThread *thread, const JSHandle &transfer); - ecmascript::JSSerializer value_serializer_; + ecmascript::JSSerializer valueSerializer_; std::unique_ptr data_; - PandaVector array_buffer_idxs_; + PandaVector arrayBufferIdxs_; }; class Deserializer { public: explicit Deserializer(JSThread *thread, SerializationData *data) - : value_deserializer_(thread, data->GetData(), data->GetSize()) + : valueDeserializer_(thread, data->GetData(), data->GetSize()) { } ~Deserializer() = default; @@ -247,7 +247,7 @@ public: NO_COPY_SEMANTIC(Deserializer); private: - ecmascript::JSDeserializer value_deserializer_; + ecmascript::JSDeserializer valueDeserializer_; }; } // namespace panda::ecmascript diff --git a/runtime/js_set.cpp b/runtime/js_set.cpp index 492a791f49a5643d18ba867f1aab9027e6774c5b..a6b45f29d9797b1a6510b89560fba7a760e99b9c 100644 --- a/runtime/js_set.cpp +++ b/runtime/js_set.cpp @@ -26,33 +26,33 @@ void JSSet::Add(JSThread *thread, const JSHandle &set, const JSHandle set_handle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); - JSHandle new_set = LinkedHashSet::Add(thread, set_handle, value); - set->SetLinkedSet(thread, new_set); + JSHandle newSet = LinkedHashSet::Add(thread, setHandle, value); + set->SetLinkedSet(thread, newSet); } bool JSSet::Delete(const JSThread *thread, const JSHandle &set, const JSHandle &value) { - JSHandle set_handle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); if (!LinkedHashSet::IsKey(value.GetTaggedValue())) { return false; } int hash = LinkedHash::Hash(value.GetTaggedValue()); - int entry = set_handle->FindElement(value.GetTaggedValue(), hash); + int entry = setHandle->FindElement(value.GetTaggedValue(), hash); if (entry == -1) { return false; } - set_handle->RemoveEntry(thread, entry); - JSHandle new_set = LinkedHashSet::Shrink(thread, set_handle); - set->SetLinkedSet(thread, new_set); + setHandle->RemoveEntry(thread, entry); + JSHandle newSet = LinkedHashSet::Shrink(thread, setHandle); + set->SetLinkedSet(thread, newSet); return true; } void JSSet::Clear(const JSThread *thread, const JSHandle &set) { - LinkedHashSet *linked_set = LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject()); - linked_set->Clear(thread); + LinkedHashSet *linkedSet = LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject()); + linkedSet->Clear(thread); } bool JSSet::Has(JSTaggedValue value, int hash) const diff --git a/runtime/js_set_iterator.cpp b/runtime/js_set_iterator.cpp index 3bdf98ce3197247fdbd86f9d18540425bc423bae..1a7f78498bfbe5981c76e8b2ce7b22c2b1e5d3dc 100644 --- a/runtime/js_set_iterator.cpp +++ b/runtime/js_set_iterator.cpp @@ -26,7 +26,7 @@ JSTaggedValue JSSetIterator::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1.If Type(O) is not Object, throw a TypeError exception. JSHandle input(builtins_common::GetThis(argv)); @@ -37,26 +37,26 @@ JSTaggedValue JSSetIterator::Next(EcmaRuntimeCallInfo *argv) } JSHandle iter(input); iter->Update(thread); - JSHandle undefined_handle(thread, JSTaggedValue::Undefined()); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); // 4.Let s be O.[[IteratedSet]]. - JSHandle iterated_set(thread, iter->GetIteratedSet()); + JSHandle iteratedSet(thread, iter->GetIteratedSet()); // 5.Let index be O.[[SetNextIndex]]. int index = iter->GetNextIndex().GetInt(); - IterationKind item_kind = IterationKind(iter->GetIterationKind().GetInt()); + IterationKind itemKind = IterationKind(iter->GetIterationKind().GetInt()); // 7.If s is undefined, return CreateIterResultObject(undefined, true). - if (iterated_set->IsUndefined()) { - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + if (iteratedSet->IsUndefined()) { + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } - JSHandle set(iterated_set); - int total_elements = set->NumberOfElements() + set->NumberOfDeletedElements(); + JSHandle set(iteratedSet); + int totalElements = set->NumberOfElements() + set->NumberOfDeletedElements(); - while (index < total_elements) { + while (index < totalElements) { if (!set->GetKey(index).IsHole()) { iter->SetNextIndex(thread, JSTaggedValue(index + 1)); JSHandle key(thread, set->GetKey(index)); // If itemKind is value - if (item_kind == IterationKind::VALUE || item_kind == IterationKind::KEY) { + if (itemKind == IterationKind::VALUE || itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); } // If itemKind is key+value, then @@ -64,32 +64,32 @@ JSTaggedValue JSSetIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle array(factory->NewTaggedArray(2)); // 2: key and value pair array->Set(thread, 0, key); array->Set(thread, 1, key); - JSHandle key_and_value(JSArray::CreateArrayFromList(thread, array)); - return JSIterator::CreateIterResultObject(thread, key_and_value, false).GetTaggedValue(); + JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); + return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue(); } index++; } // 13.Set O.[[IteratedSet]] to undefined. iter->SetIteratedSet(thread, JSTaggedValue::Undefined()); - return JSIterator::CreateIterResultObject(thread, undefined_handle, true).GetTaggedValue(); + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } void JSSetIterator::Update(const JSThread *thread) { - JSTaggedValue iterated_set = GetIteratedSet(); - if (iterated_set.IsUndefined()) { + JSTaggedValue iteratedSet = GetIteratedSet(); + if (iteratedSet.IsUndefined()) { return; } - LinkedHashSet *set = LinkedHashSet::Cast(iterated_set.GetTaggedObject()); + LinkedHashSet *set = LinkedHashSet::Cast(iteratedSet.GetTaggedObject()); if (set->GetNextTable().IsHole()) { return; } int index = GetNextIndex().GetInt(); - JSTaggedValue next_table = set->GetNextTable(); - while (!next_table.IsHole()) { + JSTaggedValue nextTable = set->GetNextTable(); + while (!nextTable.IsHole()) { index -= set->GetDeletedElementsAt(index); - set = LinkedHashSet::Cast(next_table.GetTaggedObject()); - next_table = set->GetNextTable(); + set = LinkedHashSet::Cast(nextTable.GetTaggedObject()); + nextTable = set->GetNextTable(); } SetIteratedSet(thread, JSTaggedValue(set)); SetNextIndex(thread, JSTaggedValue(index)); @@ -100,8 +100,8 @@ JSHandle JSSetIterator::CreateSetIterator(JSThread *thread, const { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!obj->IsJSSet()) { - JSHandle undefined_handle(thread, JSTaggedValue::Undefined()); - THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", undefined_handle); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", undefinedHandle); } JSHandle iter(factory->NewJSSetIterator(JSHandle(obj), kind)); return iter; diff --git a/runtime/js_stable_array.cpp b/runtime/js_stable_array.cpp index 6c5d6800e83863c83812334c6dc6e3accd834134..027d536ca04263635e5b3cbb197b75671ab41df6 100644 --- a/runtime/js_stable_array.cpp +++ b/runtime/js_stable_array.cpp @@ -29,21 +29,21 @@ JSTaggedValue JSStableArray::Push(JSHandle receiver, EcmaRuntimeCallInf { JSThread *thread = argv->GetThread(); uint32_t argc = argv->GetArgsNumber(); - uint32_t old_length = receiver->GetArrayLength(); - uint32_t new_length = argc + old_length; + uint32_t oldLength = receiver->GetArrayLength(); + uint32_t newLength = argc + oldLength; TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); - if (new_length > elements->GetLength()) { - elements = *JSObject::GrowElementsCapacity(thread, JSHandle::Cast(receiver), new_length); + if (newLength > elements->GetLength()) { + elements = *JSObject::GrowElementsCapacity(thread, JSHandle::Cast(receiver), newLength); } for (uint32_t k = 0; k < argc; k++) { JSHandle value = argv->GetCallArg(k); - elements->Set(thread, old_length + k, value.GetTaggedValue()); + elements->Set(thread, oldLength + k, value.GetTaggedValue()); } - receiver->SetArrayLength(thread, new_length); + receiver->SetArrayLength(thread, newLength); - return JSTaggedValue(new_length); + return JSTaggedValue(newLength); } JSTaggedValue JSStableArray::Pop(JSHandle receiver, EcmaRuntimeCallInfo *argv) @@ -68,94 +68,93 @@ JSTaggedValue JSStableArray::Pop(JSHandle receiver, EcmaRuntimeCallInfo } JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntimeCallInfo *argv, double start, - double insert_count, double actual_delete_count) + double insertCount, double actualDeleteCount) { JSThread *thread = argv->GetThread(); uint32_t len = receiver->GetArrayLength(); uint32_t argc = argv->GetArgsNumber(); - JSHandle this_obj_handle(receiver); - JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(actual_delete_count)); + JSHandle thisObjHandle(receiver); + JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(actualDeleteCount)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle new_array_handle(thread, new_array); + JSHandle newArrayHandle(thread, newArray); - JSHandle this_obj_val(this_obj_handle); - JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); - TaggedArray *src_elements = TaggedArray::Cast(this_obj_handle->GetElements().GetTaggedObject()); - JSHandle src_elements_handle(thread, src_elements); - if (new_array.IsStableJSArray(thread)) { - TaggedArray *dest_elements = TaggedArray::Cast(new_array_handle->GetElements().GetTaggedObject()); - if (actual_delete_count > dest_elements->GetLength()) { - dest_elements = *JSObject::GrowElementsCapacity(thread, new_array_handle, actual_delete_count); + JSHandle thisObjVal(thisObjHandle); + JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + JSHandle srcElementsHandle(thread, srcElements); + if (newArray.IsStableJSArray(thread)) { + TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject()); + if (actualDeleteCount > destElements->GetLength()) { + destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, actualDeleteCount); } - for (uint32_t idx = 0; idx < actual_delete_count; idx++) { - dest_elements->Set(thread, idx, src_elements_handle->Get(start + idx)); + for (uint32_t idx = 0; idx < actualDeleteCount; idx++) { + destElements->Set(thread, idx, srcElementsHandle->Get(start + idx)); } - JSHandle::Cast(new_array_handle)->SetArrayLength(thread, actual_delete_count); + JSHandle::Cast(newArrayHandle)->SetArrayLength(thread, actualDeleteCount); } else { - JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); - JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); double k = 0; - while (k < actual_delete_count) { + while (k < actualDeleteCount) { double from = start + k; - from_key.Update(JSTaggedValue(from)); - bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); + fromKey.Update(JSTaggedValue(from)); + bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); + JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - to_key.Update(JSTaggedValue(k)); - if (new_array_handle->IsJSProxy()) { - to_key.Update(JSTaggedValue::ToString(thread, to_key).GetTaggedValue()); + toKey.Update(JSTaggedValue(k)); + if (newArrayHandle->IsJSProxy()) { + toKey.Update(JSTaggedValue::ToString(thread, toKey).GetTaggedValue()); } - JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_key, from_value); + JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } - JSHandle delete_count(thread, JSTaggedValue(actual_delete_count)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, delete_count, - true); + JSHandle deleteCount(thread, JSTaggedValue(actualDeleteCount)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, deleteCount, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - uint32_t old_capacity = src_elements_handle->GetLength(); - uint32_t new_capacity = len - actual_delete_count + insert_count; - if (insert_count < actual_delete_count) { - for (uint32_t idx = start; idx < len - actual_delete_count; idx++) { - auto element = src_elements_handle->Get(idx + actual_delete_count); + uint32_t oldCapacity = srcElementsHandle->GetLength(); + uint32_t newCapacity = len - actualDeleteCount + insertCount; + if (insertCount < actualDeleteCount) { + for (uint32_t idx = start; idx < len - actualDeleteCount; idx++) { + auto element = srcElementsHandle->Get(idx + actualDeleteCount); element = element.IsHole() ? JSTaggedValue::Undefined() : element; - src_elements_handle->Set(thread, idx + insert_count, element); + srcElementsHandle->Set(thread, idx + insertCount, element); } - if (TaggedArray::ShouldTrim(thread, old_capacity, new_capacity)) { - src_elements_handle->Trim(thread, new_capacity); + if (TaggedArray::ShouldTrim(thread, oldCapacity, newCapacity)) { + srcElementsHandle->Trim(thread, newCapacity); } else { - for (uint32_t idx = new_capacity; idx < len; idx++) { - src_elements_handle->Set(thread, idx, JSTaggedValue::Hole()); + for (uint32_t idx = newCapacity; idx < len; idx++) { + srcElementsHandle->Set(thread, idx, JSTaggedValue::Hole()); } } } else { - if (new_capacity > old_capacity) { - src_elements_handle = JSObject::GrowElementsCapacity(thread, this_obj_handle, new_capacity); + if (newCapacity > oldCapacity) { + srcElementsHandle = JSObject::GrowElementsCapacity(thread, thisObjHandle, newCapacity); } - for (uint32_t idx = len - actual_delete_count; idx > start; idx--) { - auto element = src_elements_handle->Get(idx + actual_delete_count - 1); + for (uint32_t idx = len - actualDeleteCount; idx > start; idx--) { + auto element = srcElementsHandle->Get(idx + actualDeleteCount - 1); element = element.IsHole() ? JSTaggedValue::Undefined() : element; - src_elements_handle->Set(thread, idx + insert_count - 1, element); + srcElementsHandle->Set(thread, idx + insertCount - 1, element); } } for (uint32_t i = 2, idx = start; i < argc; i++, idx++) { - src_elements_handle->Set(thread, idx, argv->GetCallArg(i)); + srcElementsHandle->Set(thread, idx, argv->GetCallArg(i)); } - JSHandle new_len_handle(thread, JSTaggedValue(new_capacity)); - JSTaggedValue::SetProperty(thread, this_obj_val, length_key, new_len_handle, true); + JSHandle newLenHandle(thread, JSTaggedValue(newCapacity)); + JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return new_array_handle.GetTaggedValue(); + return newArrayHandle.GetTaggedValue(); } JSTaggedValue JSStableArray::Shift(JSHandle receiver, EcmaRuntimeCallInfo *argv) @@ -169,11 +168,11 @@ JSTaggedValue JSStableArray::Shift(JSHandle receiver, EcmaRuntimeCallIn TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); auto result = elements->Get(0); for (uint32_t k = 1; k < length; k++) { - auto k_value = elements->Get(k); - if (k_value.IsHole()) { + auto kValue = elements->Get(k); + if (kValue.IsHole()) { elements->Set(thread, k - 1, JSTaggedValue::Undefined()); } else { - elements->Set(thread, k - 1, k_value); + elements->Set(thread, k - 1, kValue); } } uint32_t capacity = elements->GetLength(); @@ -191,74 +190,74 @@ JSTaggedValue JSStableArray::Join(JSHandle receiver, EcmaRuntimeCallInf { JSThread *thread = argv->GetThread(); uint32_t length = receiver->GetArrayLength(); - JSHandle sep_handle = builtins_common::GetCallArg(argv, 0); + JSHandle sepHandle = builtins_common::GetCallArg(argv, 0); int sep = ','; - uint32_t sep_length = 1; - JSHandle sep_string_handle; - if (!sep_handle->IsUndefined()) { - if (sep_handle->IsString()) { - sep_string_handle = JSHandle::Cast(sep_handle); + uint32_t sepLength = 1; + JSHandle sepStringHandle; + if (!sepHandle->IsUndefined()) { + if (sepHandle->IsString()) { + sepStringHandle = JSHandle::Cast(sepHandle); } else { - sep_string_handle = JSTaggedValue::ToString(thread, sep_handle); + sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (sep_string_handle->IsUtf8() && sep_string_handle->GetLength() == 1) { + if (sepStringHandle->IsUtf8() && sepStringHandle->GetLength() == 1) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sep = sep_string_handle->GetDataUtf8()[0]; - } else if (sep_string_handle->GetLength() == 0) { + sep = sepStringHandle->GetDataUtf8()[0]; + } else if (sepStringHandle->GetLength() == 0) { sep = JSStableArray::SeparatorFlag::MINUS_TWO; - sep_length = 0; + sepLength = 0; } else { sep = JSStableArray::SeparatorFlag::MINUS_ONE; - sep_length = sep_string_handle->GetLength(); + sepLength = sepStringHandle->GetLength(); } } if (length == 0) { - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - return global_const->GetEmptyString(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + return globalConst->GetEmptyString(); } TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); - size_t allocate_length = 0; - bool is_one_byte = (sep != JSStableArray::SeparatorFlag::MINUS_ONE) || sep_string_handle->IsUtf8(); + size_t allocateLength = 0; + bool isOneByte = (sep != JSStableArray::SeparatorFlag::MINUS_ONE) || sepStringHandle->IsUtf8(); PandaVector> vec; - JSMutableHandle element_handle(thread, JSTaggedValue::Undefined()); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); + JSMutableHandle elementHandle(thread, JSTaggedValue::Undefined()); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); for (uint32_t k = 0; k < length; k++) { JSTaggedValue element = elements->Get(k); if (!element.IsUndefinedOrNull() && !element.IsHole()) { if (!element.IsString()) { - element_handle.Update(element); - JSHandle str_element = JSTaggedValue::ToString(thread, element_handle); + elementHandle.Update(element); + JSHandle strElement = JSTaggedValue::ToString(thread, elementHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - element = str_element.GetTaggedValue(); + element = strElement.GetTaggedValue(); elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); } - auto next_str = EcmaString::Cast(element.GetTaggedObject()); - JSHandle next_str_handle(thread, next_str); - vec.push_back(next_str_handle); - is_one_byte = next_str->IsUtf8() ? is_one_byte : false; - allocate_length += next_str->GetLength(); + auto nextStr = EcmaString::Cast(element.GetTaggedObject()); + JSHandle nextStrHandle(thread, nextStr); + vec.push_back(nextStrHandle); + isOneByte = nextStr->IsUtf8() ? isOneByte : false; + allocateLength += nextStr->GetLength(); } else { - vec.push_back(JSHandle(global_const->GetHandledEmptyString())); + vec.push_back(JSHandle(globalConst->GetHandledEmptyString())); } } - allocate_length += sep_length * (length - 1); - auto new_string = EcmaString::AllocStringObject(allocate_length, is_one_byte, thread->GetEcmaVM()); + allocateLength += sepLength * (length - 1); + auto newString = EcmaString::AllocStringObject(allocateLength, isOneByte, thread->GetEcmaVM()); int current = 0; for (uint32_t k = 0; k < length; k++) { if (k > 0) { if (sep >= 0) { - new_string->WriteData(static_cast(sep), current); + newString->WriteData(static_cast(sep), current); } else if (sep != JSStableArray::SeparatorFlag::MINUS_TWO) { - new_string->WriteData(*sep_string_handle, current, allocate_length - current, sep_length); + newString->WriteData(*sepStringHandle, current, allocateLength - current, sepLength); } - current += sep_length; + current += sepLength; } - JSHandle next_str = vec[k]; - int next_length = next_str->GetLength(); - new_string->WriteData(*next_str, current, allocate_length - current, next_length); - current += next_length; + JSHandle nextStr = vec[k]; + int nextLength = nextStr->GetLength(); + newString->WriteData(*nextStr, current, allocateLength - current, nextLength); + current += nextLength; } - return JSTaggedValue(new_string); + return JSTaggedValue(newString); } } // namespace panda::ecmascript diff --git a/runtime/js_stable_array.h b/runtime/js_stable_array.h index c2c7b3f1651323c5e1c015407cd3553ead68f1d1..353419a0ec1919ab7598253798c4a9eec7082a0e 100644 --- a/runtime/js_stable_array.h +++ b/runtime/js_stable_array.h @@ -26,8 +26,8 @@ public: enum SeparatorFlag : int { MINUS_ONE = -1, MINUS_TWO = -2 }; static JSTaggedValue Push(JSHandle receiver, EcmaRuntimeCallInfo *argv); static JSTaggedValue Pop(JSHandle receiver, EcmaRuntimeCallInfo *argv); - static JSTaggedValue Splice(JSHandle receiver, EcmaRuntimeCallInfo *argv, double start, - double insert_count, double actual_delete_count); + static JSTaggedValue Splice(JSHandle receiver, EcmaRuntimeCallInfo *argv, double start, double insertCount, + double actualDeleteCount); static JSTaggedValue Shift(JSHandle receiver, EcmaRuntimeCallInfo *argv); static JSTaggedValue Join(JSHandle receiver, EcmaRuntimeCallInfo *argv); }; diff --git a/runtime/js_string_iterator.cpp b/runtime/js_string_iterator.cpp index 8253e2be38a3bb0973c5c0db676246292fd65794..ec015d2d6ac1fe65eef90290de079b094505f888 100644 --- a/runtime/js_string_iterator.cpp +++ b/runtime/js_string_iterator.cpp @@ -28,10 +28,10 @@ JSHandle JSStringIterator::CreateStringIterator(const JSThread // 1. Assert: Type(string) is String. // 2. Let iterator be ObjectCreate(%StringIteratorPrototype%, [[IteratedString]], [[StringIteratorNextIndex]] ?.) JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle str_iter_ctor = env->GetStringIteratorFunction(); + JSHandle strIterCtor = env->GetStringIteratorFunction(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle iterator = JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle(str_iter_ctor), str_iter_ctor)); + factory->NewJSObjectByConstructor(JSHandle(strIterCtor), strIterCtor)); // 3. Set iterator’s [[IteratedString]] internal slot to string. // 4. Set iterator’s [[StringIteratorNextIndex]] internal slot to 0. iterator->SetIteratedString(thread, string); diff --git a/runtime/js_symbol.h b/runtime/js_symbol.h index 91244f784ca02c9c97a0169d1c7e50e5eefb9c61..444ef7d7a7947364d1e711b1f38bbdf4dfb870e3 100644 --- a/runtime/js_symbol.h +++ b/runtime/js_symbol.h @@ -51,8 +51,8 @@ public: static inline uint32_t ComputeHash() { - uint32_t hash_seed = LINEAR_SEED + std::time(nullptr); - uint32_t hash = hash_seed * LINEAR_X + LINEAR_Y; + uint32_t hashSeed = LINEAR_SEED + std::time(nullptr); + uint32_t hash = hashSeed * LINEAR_X + LINEAR_Y; return hash; } @@ -150,9 +150,9 @@ public: if (src.GetFlags() != dst.GetFlags()) { return false; } - EcmaString *src_string = EcmaString::Cast(src.GetDescription().GetTaggedObject()); - EcmaString *dst_string = EcmaString::Cast(dst.GetDescription().GetTaggedObject()); - return EcmaString::StringsAreEqual(src_string, dst_string); + EcmaString *srcString = EcmaString::Cast(src.GetDescription().GetTaggedObject()); + EcmaString *dstString = EcmaString::Cast(dst.GetDescription().GetTaggedObject()); + return EcmaString::StringsAreEqual(srcString, dstString); } public: diff --git a/runtime/js_tagged_number.h b/runtime/js_tagged_number.h index cbf56bd0f9299508f001a0e34fc8d5290c078371..11671d1ec3ec06b1e34b88d902f4db19bed3ff77 100644 --- a/runtime/js_tagged_number.h +++ b/runtime/js_tagged_number.h @@ -104,9 +104,9 @@ public: JSTaggedNumber operator*(JSTaggedNumber number) const { if (IsInt() && number.IsInt()) { - int64_t int_a = GetInt(); - int64_t int_b = number.GetInt(); - int64_t res = int_a * int_b; + int64_t intA = GetInt(); + int64_t intB = number.GetInt(); + int64_t res = intA * intB; if (res > INT32_MAX || res < INT32_MIN) { return JSTaggedNumber(static_cast(res)); } @@ -147,14 +147,14 @@ public: /* static */ inline static bool SameValue(JSTaggedNumber x, JSTaggedNumber y) { - double x_value = x.GetNumber(); - double y_value = y.GetNumber(); + double xValue = x.GetNumber(); + double yValue = y.GetNumber(); // SameNumberValue(NaN, NaN) is true. - if (x_value != y_value) { - return std::isnan(x_value) && std::isnan(y_value); + if (xValue != yValue) { + return std::isnan(xValue) && std::isnan(yValue); } // SameNumberValue(0.0, -0.0) is false. - return (std::signbit(x_value) == std::signbit(y_value)); + return (std::signbit(xValue) == std::signbit(yValue)); } inline static JSTaggedNumber FromIntOrDouble(JSThread *thread, JSTaggedValue tagged) diff --git a/runtime/js_tagged_value-inl.h b/runtime/js_tagged_value-inl.h index a88db2b790439cec0684b12d28010f8aa697b444..96089645b7f26ee6150dcb9b3e2fa351fa060fc8 100644 --- a/runtime/js_tagged_value-inl.h +++ b/runtime/js_tagged_value-inl.h @@ -90,14 +90,14 @@ inline JSHandle JSTaggedValue::ToNumeric(JSThread *thread, JSHand { // 1. Let primValue be ? ToPrimitive(value, number) - JSHandle prim_value(thread, ToPrimitive(thread, tagged, PREFER_NUMBER)); + JSHandle primValue(thread, ToPrimitive(thread, tagged, PREFER_NUMBER)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // 2. If Type(primValue) is BigInt, return primValue. - if (prim_value->IsBigInt()) { - return prim_value; + if (primValue->IsBigInt()) { + return primValue; } // 3. Return ? ToNumber(primValue). - JSTaggedNumber number = ToNumber(thread, prim_value); + JSTaggedNumber number = ToNumber(thread, primValue); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); JSHandle value(thread, number); return value; @@ -128,28 +128,28 @@ inline JSTaggedNumber JSTaggedValue::ToNumber(JSThread *thread, const JSHandleIsString()) { Span str; - auto str_obj = static_cast(tagged->GetTaggedObject()); - size_t str_len = str_obj->GetLength(); - if (str_len == 0) { + auto strObj = static_cast(tagged->GetTaggedObject()); + size_t strLen = strObj->GetLength(); + if (strLen == 0) { return JSTaggedNumber(0); } [[maybe_unused]] PandaVector buf; // Span will use buf.data(), shouldn't define inside 'if' - if (UNLIKELY(str_obj->IsUtf16())) { - size_t len = utf::Utf16ToUtf8Size(str_obj->GetDataUtf16(), str_len) - 1; + if (UNLIKELY(strObj->IsUtf16())) { + size_t len = utf::Utf16ToUtf8Size(strObj->GetDataUtf16(), strLen) - 1; buf.reserve(len); - len = utf::ConvertRegionUtf16ToUtf8(str_obj->GetDataUtf16(), buf.data(), str_len, len, 0); + len = utf::ConvertRegionUtf16ToUtf8(strObj->GetDataUtf16(), buf.data(), strLen, len, 0); str = Span(buf.data(), len); } else { - str = Span(str_obj->GetDataUtf8(), str_len); + str = Span(strObj->GetDataUtf8(), strLen); } double d = base::NumberHelper::StringToDouble(str.begin(), str.end(), 0, base::ALLOW_BINARY + base::ALLOW_OCTAL + base::ALLOW_HEX); return JSTaggedNumber(d); } if (tagged->IsECMAObject()) { - JSHandle prim_value(thread, ToPrimitive(thread, tagged, PREFER_NUMBER)); + JSHandle primValue(thread, ToPrimitive(thread, tagged, PREFER_NUMBER)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedNumber::Exception()); - return ToNumber(thread, prim_value); + return ToNumber(thread, primValue); } if (tagged->IsSymbol()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Symbol value to a number", JSTaggedNumber::Exception()); @@ -163,9 +163,9 @@ inline JSTaggedNumber JSTaggedValue::ToNumber(JSThread *thread, const JSHandle &tagged) { - JSHandle prim_value(thread, ToPrimitive(thread, tagged)); + JSHandle primValue(thread, ToPrimitive(thread, tagged)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - switch (prim_value->GetRawData()) { + switch (primValue->GetRawData()) { case JSTaggedValue::VALUE_UNDEFINED: case JSTaggedValue::VALUE_NULL: { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a undefine or null value to a BigInt", @@ -182,11 +182,11 @@ inline JSTaggedValue JSTaggedValue::ToBigInt(JSThread *thread, const JSHandleIsNumber()) { + if (primValue->IsNumber()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Number value to a BigInt", JSTaggedNumber::Exception()); } - if (prim_value->IsString()) { - JSHandle value(thread, base::NumberHelper::StringToBigInt(thread, prim_value)); + if (primValue->IsString()) { + JSHandle value(thread, base::NumberHelper::StringToBigInt(thread, primValue)); if (value->IsBigInt()) { return value.GetTaggedValue(); } @@ -195,11 +195,11 @@ inline JSTaggedValue JSTaggedValue::ToBigInt(JSThread *thread, const JSHandleIsSymbol()) { + if (primValue->IsSymbol()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Symbol value to a BigInt", JSTaggedNumber::Exception()); } - if (prim_value->IsBigInt()) { - return prim_value.GetTaggedValue(); + if (primValue->IsBigInt()) { + return primValue.GetTaggedValue(); } THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Unknown value to a BigInt", JSTaggedNumber::Exception()); } @@ -211,15 +211,15 @@ inline JSTaggedValue JSTaggedValue::ToBigInt64(JSThread *thread, const JSHandle< JSHandle exponent = BigInt::Int32ToBigInt(thread, 64); // NOLINT: 64 : bits JSHandle exponentone = BigInt::Int32ToBigInt(thread, 63); // NOLINT: 63 : bits JSHandle base = BigInt::Int32ToBigInt(thread, 2); // 2 : base value - JSHandle t_val = BigInt::Exponentiate(thread, base, exponent); + JSHandle tVal = BigInt::Exponentiate(thread, base, exponent); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle int64bit_val = BigInt::FloorMod(thread, value, t_val); - JSHandle res_value = BigInt::Exponentiate(thread, base, exponentone); + JSHandle int64bitVal = BigInt::FloorMod(thread, value, tVal); + JSHandle resValue = BigInt::Exponentiate(thread, base, exponentone); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!BigInt::LessThan(thread, int64bit_val.GetTaggedValue(), res_value.GetTaggedValue())) { - return BigInt::Subtract(thread, int64bit_val, t_val).GetTaggedValue(); + if (!BigInt::LessThan(thread, int64bitVal.GetTaggedValue(), resValue.GetTaggedValue())) { + return BigInt::Subtract(thread, int64bitVal, tVal).GetTaggedValue(); } - return int64bit_val.GetTaggedValue(); + return int64bitVal.GetTaggedValue(); } inline JSTaggedValue JSTaggedValue::ToBigUint64(JSThread *thread, const JSHandle &tagged) @@ -228,9 +228,9 @@ inline JSTaggedValue JSTaggedValue::ToBigUint64(JSThread *thread, const JSHandle RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle exponent = BigInt::Int32ToBigInt(thread, 64); // NOLINT: 64 : exponet value JSHandle base = BigInt::Int32ToBigInt(thread, 2); // 2 : base value - JSHandle t_val = BigInt::Exponentiate(thread, base, exponent); + JSHandle tVal = BigInt::Exponentiate(thread, base, exponent); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return BigInt::FloorMod(thread, value, t_val).GetTaggedValue(); + return BigInt::FloorMod(thread, value, tVal).GetTaggedValue(); } inline JSTaggedNumber JSTaggedValue::ToInteger(JSThread *thread, const JSHandle &tagged) @@ -371,9 +371,9 @@ inline bool JSTaggedValue::SameValue(const JSTaggedValue &x, const JSTaggedValue return false; } -inline bool JSTaggedValue::SameValue(const JSHandle &x_handle, const JSHandle &y_handle) +inline bool JSTaggedValue::SameValue(const JSHandle &xHandle, const JSHandle &yHandle) { - return SameValue(x_handle.GetTaggedValue(), y_handle.GetTaggedValue()); + return SameValue(xHandle.GetTaggedValue(), yHandle.GetTaggedValue()); } inline bool JSTaggedValue::SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y) @@ -383,10 +383,10 @@ inline bool JSTaggedValue::SameValueZero(const JSTaggedValue &x, const JSTaggedV } if (x.IsNumber() && y.IsNumber()) { - double x_value = x.ExtractNumber(); - double y_value = y.ExtractNumber(); + double xValue = x.ExtractNumber(); + double yValue = y.ExtractNumber(); // Compare xValue with yValue to deal with -0.0 - return (x_value == y_value) || (std::isnan(x_value) && std::isnan(y_value)); + return (xValue == yValue) || (std::isnan(xValue) && std::isnan(yValue)); } if (x.IsString() && y.IsString()) { @@ -398,14 +398,14 @@ inline bool JSTaggedValue::SameValueZero(const JSTaggedValue &x, const JSTaggedV inline bool JSTaggedValue::SameValueNumberic(const JSTaggedValue &x, const JSTaggedValue &y) { - double x_value = x.ExtractNumber(); - double y_value = y.ExtractNumber(); + double xValue = x.ExtractNumber(); + double yValue = y.ExtractNumber(); // SameNumberValue(NaN, NaN) is true. - if (x_value != y_value) { - return std::isnan(x_value) && std::isnan(y_value); + if (xValue != yValue) { + return std::isnan(xValue) && std::isnan(yValue); } // SameNumberValue(0.0, -0.0) is false. - return (std::signbit(x_value) == std::signbit(y_value)); + return (std::signbit(xValue) == std::signbit(yValue)); } inline bool JSTaggedValue::Less(JSThread *thread, const JSHandle &x, const JSHandle &y) @@ -659,12 +659,12 @@ inline bool JSTaggedValue::IsArray(JSThread *thread) const if (!IsHeapObject()) { return false; } - JSHClass *js_hclass = GetTaggedObject()->GetClass(); - if (js_hclass->IsJSArray()) { + JSHClass *jsHclass = GetTaggedObject()->GetClass(); + if (jsHclass->IsJSArray()) { return true; } - if (js_hclass->IsJSProxy()) { + if (jsHclass->IsJSProxy()) { return JSProxy::Cast(GetTaggedObject())->IsArray(thread); } return false; @@ -1027,21 +1027,21 @@ inline double JSTaggedValue::ExtractNumber() const inline bool JSTaggedValue::ToArrayLength(JSThread *thread, const JSHandle &tagged, uint32_t *output) { // 3. Let newLen be ToUint32(Desc.[[Value]]). - uint32_t new_len = ToUint32(thread, tagged); + uint32_t newLen = ToUint32(thread, tagged); // 4. ReturnIfAbrupt(newLen). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 5. Let numberLen be ToNumber(Desc.[[Value]]). - JSTaggedNumber number_len = ToNumber(thread, tagged); + JSTaggedNumber numberLen = ToNumber(thread, tagged); // 6. ReturnIfAbrupt(newLen). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 7. If newLen != numberLen, throw a RangeError exception. - if (JSTaggedNumber(new_len) != number_len) { + if (JSTaggedNumber(newLen) != numberLen) { THROW_RANGE_ERROR_AND_RETURN(thread, "Not a valid array length", false); } - *output = new_len; + *output = newLen; return true; } @@ -1083,16 +1083,16 @@ inline bool JSTaggedValue::StringToElementIndex(JSTaggedValue key, uint32_t *out { ASSERT(key.IsString()); - auto str_obj = static_cast(key.GetTaggedObject()); - uint32_t len = str_obj->GetLength(); + auto strObj = static_cast(key.GetTaggedObject()); + uint32_t len = strObj->GetLength(); if (len == 0 || len > MAX_INDEX_LEN) { return false; } uint32_t c; - if (str_obj->IsUtf16()) { - c = str_obj->GetDataUtf16()[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + if (strObj->IsUtf16()) { + c = strObj->GetDataUtf16()[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } else { - c = str_obj->GetDataUtf8()[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + c = strObj->GetDataUtf8()[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } uint64_t n = 0; if (c >= '0' && c <= '9') { @@ -1106,10 +1106,10 @@ inline bool JSTaggedValue::StringToElementIndex(JSTaggedValue key, uint32_t *out n = c - '0'; for (uint32_t i = 1; i < len; i++) { - if (str_obj->IsUtf16()) { - c = str_obj->GetDataUtf16()[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + if (strObj->IsUtf16()) { + c = strObj->GetDataUtf16()[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } else { - c = str_obj->GetDataUtf8()[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + c = strObj->GetDataUtf8()[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } if (c < '0' || c > '9') { return false; diff --git a/runtime/js_tagged_value.cpp b/runtime/js_tagged_value.cpp index 2e3490ce97c144559ae1d4ff457b4b896e32e7a4..e4006d11517d5b16ce491055529014c2caa7d551 100644 --- a/runtime/js_tagged_value.cpp +++ b/runtime/js_tagged_value.cpp @@ -68,14 +68,14 @@ bool JSTaggedValue::IsInteger() const return true; } - double this_value = GetDouble(); + double thisValue = GetDouble(); // If argument is NaN, +∞, or -∞, return false. - if (!std::isfinite(this_value)) { + if (!std::isfinite(thisValue)) { return false; } // If floor(abs(argument)) ≠ abs(argument), return false. - if (std::floor(std::abs(this_value)) != std::abs(this_value)) { + if (std::floor(std::abs(thisValue)) != std::abs(thisValue)) { return false; } @@ -88,13 +88,13 @@ bool JSTaggedValue::WithinInt32() const return false; } - double double_value = GetNumber(); - if (bit_cast(double_value) == bit_cast(-0.0)) { + double doubleValue = GetNumber(); + if (bit_cast(doubleValue) == bit_cast(-0.0)) { return false; } - int32_t intvalue = base::NumberHelper::DoubleToInt(double_value, base::INT32_BITS); - return double_value == static_cast(intvalue); + int32_t intvalue = base::NumberHelper::DoubleToInt(doubleValue, base::INT32_BITS); + return doubleValue == static_cast(intvalue); } bool JSTaggedValue::IsZero() const @@ -116,22 +116,22 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle &x, co return StrictNumberEquals(x->ExtractNumber(), y->ExtractNumber()); } if (y->IsString()) { - JSTaggedNumber y_number = ToNumber(thread, y); + JSTaggedNumber yNumber = ToNumber(thread, y); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return StrictNumberEquals(x->ExtractNumber(), y_number.GetNumber()); + return StrictNumberEquals(x->ExtractNumber(), yNumber.GetNumber()); } if (y->IsBigInt()) { return Equal(thread, y, x); } if (y->IsBoolean()) { - JSTaggedNumber y_number = ToNumber(thread, y); + JSTaggedNumber yNumber = ToNumber(thread, y); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return StrictNumberEquals(x->ExtractNumber(), y_number.GetNumber()); + return StrictNumberEquals(x->ExtractNumber(), yNumber.GetNumber()); } if (y->IsHeapObject() && !y->IsSymbol()) { - JSHandle y_primitive(thread, ToPrimitive(thread, y)); + JSHandle yPrimitive(thread, ToPrimitive(thread, y)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return Equal(thread, x, y_primitive); + return Equal(thread, x, yPrimitive); } return false; } @@ -142,32 +142,32 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle &x, co static_cast(y->GetTaggedObject())); } if (y->IsNumber()) { - JSTaggedNumber x_number = ToNumber(thread, x); + JSTaggedNumber xNumber = ToNumber(thread, x); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return StrictNumberEquals(x_number.GetNumber(), y->ExtractNumber()); + return StrictNumberEquals(xNumber.GetNumber(), y->ExtractNumber()); } if (y->IsBigInt()) { return Equal(thread, y, x); } if (y->IsBoolean()) { - JSTaggedNumber x_number = ToNumber(thread, x); + JSTaggedNumber xNumber = ToNumber(thread, x); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - JSTaggedNumber y_number = ToNumber(thread, y); + JSTaggedNumber yNumber = ToNumber(thread, y); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return StrictNumberEquals(x_number.GetNumber(), y_number.GetNumber()); + return StrictNumberEquals(xNumber.GetNumber(), yNumber.GetNumber()); } if (y->IsHeapObject() && !y->IsSymbol()) { - JSHandle y_primitive(thread, ToPrimitive(thread, y)); + JSHandle yPrimitive(thread, ToPrimitive(thread, y)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return Equal(thread, x, y_primitive); + return Equal(thread, x, yPrimitive); } return false; } if (x->IsBoolean()) { - JSTaggedNumber x_number = ToNumber(thread, x); + JSTaggedNumber xNumber = ToNumber(thread, x); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return Equal(thread, JSHandle(thread, x_number), y); + return Equal(thread, JSHandle(thread, xNumber), y); } if (x->IsSymbol()) { @@ -178,9 +178,9 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle &x, co return Equal(thread, y, x); } if (y->IsHeapObject() && y->IsECMAObject()) { - JSHandle y_primitive(thread, ToPrimitive(thread, y)); + JSHandle yPrimitive(thread, ToPrimitive(thread, y)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return Equal(thread, x, y_primitive); + return Equal(thread, x, yPrimitive); } return false; } @@ -190,25 +190,25 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle &x, co return BigInt::Equal(thread, x.GetTaggedValue(), y.GetTaggedValue()); } if (y->IsString()) { - JSHandle y_number(thread, base::NumberHelper::StringToBigInt(thread, y)); - if (!y_number->IsBigInt()) { + JSHandle yNumber(thread, base::NumberHelper::StringToBigInt(thread, y)); + if (!yNumber->IsBigInt()) { return false; } - return BigInt::Equal(thread, x.GetTaggedValue(), y_number.GetTaggedValue()); + return BigInt::Equal(thread, x.GetTaggedValue(), yNumber.GetTaggedValue()); } if (y->IsBoolean()) { - JSHandle y_number(thread, ToBigInt(thread, y)); + JSHandle yNumber(thread, ToBigInt(thread, y)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return BigInt::Equal(thread, x.GetTaggedValue(), y_number.GetTaggedValue()); + return BigInt::Equal(thread, x.GetTaggedValue(), yNumber.GetTaggedValue()); } if (y->IsNumber()) { JSHandle bigint = JSHandle::Cast(x); return BigInt::CompareWithNumber(bigint, y) == ComparisonResult::EQUAL; } if (y->IsHeapObject() && !y->IsSymbol()) { - JSHandle y_primitive(thread, ToPrimitive(thread, y)); + JSHandle yPrimitive(thread, ToPrimitive(thread, y)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return Equal(thread, x, y_primitive); + return Equal(thread, x, yPrimitive); } return false; } @@ -216,16 +216,16 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle &x, co if (x->IsHeapObject()) { if (y->IsHeapObject()) { // if same type, must call Type::StrictEqual() - JSType x_type = x.GetTaggedValue().GetTaggedObject()->GetClass()->GetObjectType(); - JSType y_type = y.GetTaggedValue().GetTaggedObject()->GetClass()->GetObjectType(); - if (x_type == y_type) { + JSType xType = x.GetTaggedValue().GetTaggedObject()->GetClass()->GetObjectType(); + JSType yType = y.GetTaggedValue().GetTaggedObject()->GetClass()->GetObjectType(); + if (xType == yType) { return StrictEqual(thread, x, y); } } if (y->IsNumber() || y->IsStringOrSymbol() || y->IsBoolean() || y->IsBigInt()) { - JSHandle x_primitive(thread, ToPrimitive(thread, x)); + JSHandle xPrimitive(thread, ToPrimitive(thread, x)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return Equal(thread, x_primitive, y); + return Equal(thread, xPrimitive, y); } return false; } @@ -252,15 +252,15 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle &x, co ComparisonResult JSTaggedValue::Compare(JSThread *thread, const JSHandle &x, const JSHandle &y) { - JSHandle prim_x(thread, ToPrimitive(thread, x)); + JSHandle primX(thread, ToPrimitive(thread, x)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); - JSHandle prim_y(thread, ToPrimitive(thread, y)); + JSHandle primY(thread, ToPrimitive(thread, y)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); - if (prim_x->IsString() && prim_y->IsString()) { - auto x_string = static_cast(prim_x->GetTaggedObject()); - auto y_string = static_cast(prim_y->GetTaggedObject()); - int result = x_string->Compare(y_string); + if (primX->IsString() && primY->IsString()) { + auto xString = static_cast(primX->GetTaggedObject()); + auto yString = static_cast(primY->GetTaggedObject()); + int result = xString->Compare(yString); if (result < 0) { return ComparisonResult::LESS; } @@ -270,25 +270,25 @@ ComparisonResult JSTaggedValue::Compare(JSThread *thread, const JSHandleIsBigInt()) { - if (prim_y->IsNumber()) { - JSHandle bigint = JSHandle::Cast(prim_x); - return BigInt::CompareWithNumber(bigint, prim_y); + if (primX->IsBigInt()) { + if (primY->IsNumber()) { + JSHandle bigint = JSHandle::Cast(primX); + return BigInt::CompareWithNumber(bigint, primY); } - if (prim_y->IsString()) { - JSHandle big_y(thread, base::NumberHelper::StringToBigInt(thread, prim_y)); - if (!big_y->IsBigInt()) { + if (primY->IsString()) { + JSHandle bigY(thread, base::NumberHelper::StringToBigInt(thread, primY)); + if (!bigY->IsBigInt()) { return ComparisonResult::UNDEFINED; } - return BigInt::Compare(thread, prim_x.GetTaggedValue(), big_y.GetTaggedValue()); + return BigInt::Compare(thread, primX.GetTaggedValue(), bigY.GetTaggedValue()); } - JSHandle big_y(thread, ToBigInt(thread, prim_y)); + JSHandle bigY(thread, ToBigInt(thread, primY)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); - return BigInt::Compare(thread, prim_x.GetTaggedValue(), big_y.GetTaggedValue()); + return BigInt::Compare(thread, primX.GetTaggedValue(), bigY.GetTaggedValue()); } - if (prim_y->IsBigInt()) { - ComparisonResult res = Compare(thread, prim_y, prim_x); + if (primY->IsBigInt()) { + ComparisonResult res = Compare(thread, primY, primX); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); if (res == ComparisonResult::GREAT) { return ComparisonResult::LESS; @@ -299,11 +299,11 @@ ComparisonResult JSTaggedValue::Compare(JSThread *thread, const JSHandleIsECMAObject()) { EcmaVM *vm = thread->GetEcmaVM(); - JSHandle key_string = vm->GetGlobalEnv()->GetToPrimitiveSymbol(); + JSHandle keyString = vm->GetGlobalEnv()->GetToPrimitiveSymbol(); - JSHandle exotic_toprim = JSObject::GetMethod(thread, tagged, key_string); + JSHandle exoticToprim = JSObject::GetMethod(thread, tagged, keyString); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - if (!exotic_toprim->IsUndefined()) { + if (!exoticToprim->IsUndefined()) { JSTaggedValue value = GetTypeString(thread, type).GetTaggedValue(); - auto info = NewRuntimeCallInfo(thread, exotic_toprim, tagged, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread, exoticToprim, tagged, JSTaggedValue::Undefined(), 1); info->SetCallArgs(value); - JSTaggedValue value_result = JSFunction::Call(info.Get()); + JSTaggedValue valueResult = JSFunction::Call(info.Get()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - if (!value_result.IsECMAObject()) { - return value_result; + if (!valueResult.IsECMAObject()) { + return valueResult; } THROW_TYPE_ERROR_AND_RETURN(thread, "", JSTaggedValue::Exception()); } else { @@ -357,21 +357,21 @@ JSTaggedValue JSTaggedValue::OrdinaryToPrimitive(JSThread *thread, const JSHandl { static_assert(PREFER_NUMBER == 0 && PREFER_STRING == 1); ASSERT(tagged->IsECMAObject()); - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); for (uint8_t i = 0; i < 2; i++) { // 2: 2 means value has 2 target types, string or value. - JSHandle key_string; + JSHandle keyString; if ((type ^ i) != 0) { - key_string = global_const->GetHandledToStringString(); + keyString = globalConst->GetHandledToStringString(); } else { - key_string = global_const->GetHandledValueOfString(); + keyString = globalConst->GetHandledValueOfString(); } - JSHandle entryfunc = GetProperty(thread, tagged, key_string).GetValue(); + JSHandle entryfunc = GetProperty(thread, tagged, keyString).GetValue(); if (entryfunc->IsCallable()) { auto info = NewRuntimeCallInfo(thread, entryfunc, tagged, JSTaggedValue::Undefined(), 0); - JSTaggedValue value_result = JSFunction::Call(info.Get()); + JSTaggedValue valueResult = JSFunction::Call(info.Get()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - if (!value_result.IsECMAObject()) { - return value_result; + if (!valueResult.IsECMAObject()) { + return valueResult; } } } @@ -383,23 +383,23 @@ JSHandle JSTaggedValue::ToString(JSThread *thread, const JSHandleIsString()) { return JSHandle(tagged); } - auto global_const = thread->GlobalConstants(); + auto globalConst = thread->GlobalConstants(); if (tagged->IsSpecial()) { switch (tagged->GetRawData()) { case VALUE_UNDEFINED: { - return JSHandle(global_const->GetHandledUndefinedString()); + return JSHandle(globalConst->GetHandledUndefinedString()); } case VALUE_NULL: { - return JSHandle(global_const->GetHandledNullString()); + return JSHandle(globalConst->GetHandledNullString()); } case VALUE_TRUE: { - return JSHandle(global_const->GetHandledTrueString()); + return JSHandle(globalConst->GetHandledTrueString()); } case VALUE_FALSE: { - return JSHandle(global_const->GetHandledFalseString()); + return JSHandle(globalConst->GetHandledFalseString()); } case VALUE_HOLE: { - return JSHandle(global_const->GetHandledEmptyString()); + return JSHandle(globalConst->GetHandledEmptyString()); } default: break; @@ -411,18 +411,18 @@ JSHandle JSTaggedValue::ToString(JSThread *thread, const JSHandleIsBigInt()) { - JSHandle tagged_value(tagged); - return BigInt::ToString(thread, tagged_value); + JSHandle taggedValue(tagged); + return BigInt::ToString(thread, taggedValue); } - auto empty_str = global_const->GetHandledEmptyString(); + auto emptyStr = globalConst->GetHandledEmptyString(); if (tagged->IsECMAObject()) { - JSHandle prim_value(thread, ToPrimitive(thread, tagged, PREFER_STRING)); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(empty_str)); - return ToString(thread, prim_value); + JSHandle primValue(thread, ToPrimitive(thread, tagged, PREFER_STRING)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(emptyStr)); + return ToString(thread, primValue); } // Already Include Symbol - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a illegal value to a String", JSHandle(empty_str)); + THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a illegal value to a String", JSHandle(emptyStr)); } JSTaggedValue JSTaggedValue::CanonicalNumericIndexString(JSThread *thread, const JSHandle &tagged) @@ -513,8 +513,8 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandleIsJSProxy()) { - JSHandle key_handle(thread, JSTaggedValue(key)); - return JSProxy::GetProperty(thread, JSHandle(obj), key_handle); + JSHandle keyHandle(thread, JSTaggedValue(key)); + return JSProxy::GetProperty(thread, JSHandle(obj), keyHandle); } if (obj->IsTypedArray()) { @@ -545,8 +545,7 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandle &obj, - const JSHandle &key, const JSHandle &value, - bool may_throw) + const JSHandle &key, const JSHandle &value, bool mayThrow) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Obj is not a Valid object", false); @@ -557,11 +556,11 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle // 4. Let success be O.[[Set]](P, V, O). bool success = false; if (obj->IsJSProxy()) { - success = JSProxy::SetProperty(thread, JSHandle(obj), key, value, may_throw); + success = JSProxy::SetProperty(thread, JSHandle(obj), key, value, mayThrow); } else if (obj->IsTypedArray()) { - success = JSTypedArray::SetProperty(thread, obj, JSTypedArray::ToPropKey(thread, key), value, may_throw); + success = JSTypedArray::SetProperty(thread, obj, JSTypedArray::ToPropKey(thread, key), value, mayThrow); } else { - success = JSObject::SetProperty(thread, obj, key, value, may_throw); + success = JSObject::SetProperty(thread, obj, key, value, mayThrow); } // 5. ReturnIfAbrupt(success). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, success); @@ -571,7 +570,7 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle } bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle &obj, uint32_t key, - const JSHandle &value, bool may_throw) + const JSHandle &value, bool mayThrow) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Obj is not a Valid object", false); @@ -580,14 +579,14 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle // 4. Let success be O.[[Set]](P, V, O). bool success = false; if (obj->IsJSProxy()) { - JSHandle key_handle(thread, JSTaggedValue(key)); - success = JSProxy::SetProperty(thread, JSHandle(obj), key_handle, value, may_throw); + JSHandle keyHandle(thread, JSTaggedValue(key)); + success = JSProxy::SetProperty(thread, JSHandle(obj), keyHandle, value, mayThrow); } else if (obj->IsTypedArray()) { - JSHandle key_handle(thread, JSTaggedValue(key)); + JSHandle keyHandle(thread, JSTaggedValue(key)); success = JSTypedArray::SetProperty( - thread, obj, JSHandle(JSTaggedValue::ToString(thread, key_handle)), value, may_throw); + thread, obj, JSHandle(JSTaggedValue::ToString(thread, keyHandle)), value, mayThrow); } else { - success = JSObject::SetProperty(thread, obj, key, value, may_throw); + success = JSObject::SetProperty(thread, obj, key, value, mayThrow); } // 5. ReturnIfAbrupt(success). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, success); @@ -598,7 +597,7 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, - const JSHandle &receiver, bool may_throw) + const JSHandle &receiver, bool mayThrow) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Obj is not a Valid object", false); @@ -609,12 +608,12 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle // 4. Let success be O.[[Set]](P, V, O). bool success = false; if (obj->IsJSProxy()) { - success = JSProxy::SetProperty(thread, JSHandle(obj), key, value, receiver, may_throw); + success = JSProxy::SetProperty(thread, JSHandle(obj), key, value, receiver, mayThrow); } else if (obj->IsTypedArray()) { success = - JSTypedArray::SetProperty(thread, obj, JSTypedArray::ToPropKey(thread, key), value, receiver, may_throw); + JSTypedArray::SetProperty(thread, obj, JSTypedArray::ToPropKey(thread, key), value, receiver, mayThrow); } else { - success = JSObject::SetProperty(thread, obj, key, value, receiver, may_throw); + success = JSObject::SetProperty(thread, obj, key, value, receiver, mayThrow); } // 5. ReturnIfAbrupt(success). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, success); @@ -767,12 +766,12 @@ bool JSTaggedValue::HasProperty(JSThread *thread, const JSHandle bool JSTaggedValue::HasProperty(JSThread *thread, const JSHandle &obj, uint32_t key) { if (obj->IsJSProxy()) { - JSHandle key_handle(thread, JSTaggedValue(key)); - return JSProxy::HasProperty(thread, JSHandle(obj), key_handle); + JSHandle keyHandle(thread, JSTaggedValue(key)); + return JSProxy::HasProperty(thread, JSHandle(obj), keyHandle); } if (obj->IsTypedArray()) { - JSHandle key_handle(thread, JSTaggedValue(key)); - return JSTypedArray::HasProperty(thread, obj, JSHandle(ToString(thread, key_handle))); + JSHandle keyHandle(thread, JSTaggedValue(key)); + return JSTypedArray::HasProperty(thread, obj, JSHandle(ToString(thread, keyHandle))); } if (obj->IsSpecialContainer()) { return HasContainerProperty(thread, obj, JSHandle(thread, JSTaggedValue(key))); @@ -803,14 +802,14 @@ JSTaggedNumber JSTaggedValue::ToIndex(JSThread *thread, const JSHandleIsUndefined()) { return JSTaggedNumber(0); } - JSTaggedNumber integer_index = ToInteger(thread, tagged); + JSTaggedNumber integerIndex = ToInteger(thread, tagged); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedNumber::Exception()); - if (integer_index.GetNumber() < 0) { + if (integerIndex.GetNumber() < 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "integerIndex < 0", JSTaggedNumber::Exception()); } JSTaggedNumber index = ToLength(thread, tagged); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedNumber::Exception()); - if (!SameValue(integer_index, index)) { + if (!SameValue(integerIndex, index)) { THROW_RANGE_ERROR_AND_RETURN(thread, "integerIndex != index", JSTaggedNumber::Exception()); } return index; @@ -858,8 +857,8 @@ bool JSTaggedValue::HasContainerProperty([[maybe_unused]] JSThread *thread, cons const JSHandle &key) { auto *hclass = obj->GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - switch (js_type) { + JSType jsType = hclass->GetObjectType(); + switch (jsType) { case JSType::JS_ARRAY_LIST: { return JSHandle::Cast(obj)->Has(key.GetTaggedValue()); } @@ -875,8 +874,8 @@ bool JSTaggedValue::HasContainerProperty([[maybe_unused]] JSThread *thread, cons JSHandle JSTaggedValue::GetOwnContainerPropertyKeys(JSThread *thread, const JSHandle &obj) { auto *hclass = obj->GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - switch (js_type) { + JSType jsType = hclass->GetObjectType(); + switch (jsType) { case JSType::JS_ARRAY_LIST: { return JSArrayList::OwnKeys(thread, JSHandle::Cast(obj)); } @@ -893,8 +892,8 @@ bool JSTaggedValue::GetContainerProperty(JSThread *thread, const JSHandle &key, PropertyDescriptor &desc) { auto *hclass = obj->GetTaggedObject()->GetClass(); - JSType js_type = hclass->GetObjectType(); - switch (js_type) { + JSType jsType = hclass->GetObjectType(); + switch (jsType) { case JSType::JS_ARRAY_LIST: { return JSArrayList::GetOwnProperty(thread, JSHandle::Cast(obj), key, desc); } diff --git a/runtime/js_tagged_value.h b/runtime/js_tagged_value.h index 768240e9f114b5bed790f30af7b3860a2e6c9df3..77cce1818a64e06248733480b8ec20ba927c8974 100644 --- a/runtime/js_tagged_value.h +++ b/runtime/js_tagged_value.h @@ -171,7 +171,7 @@ public: static bool IsPropertyKey(const JSHandle &key); static JSHandle RequireObjectCoercible(JSThread *thread, const JSHandle &tagged); static bool SameValue(const JSTaggedValue &x, const JSTaggedValue &y); - static bool SameValue(const JSHandle &x_handle, const JSHandle &y_handle); + static bool SameValue(const JSHandle &xHandle, const JSHandle &yHandle); static bool SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y); static bool Less(JSThread *thread, const JSHandle &x, const JSHandle &y); static bool Equal(JSThread *thread, const JSHandle &x, const JSHandle &y); @@ -189,14 +189,14 @@ public: static OperationResult GetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &receiver); static bool SetProperty(JSThread *thread, const JSHandle &obj, uint32_t key, - const JSHandle &value, bool may_throw = false); + const JSHandle &value, bool mayThrow = false); static bool SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, - const JSHandle &value, bool may_throw = false); + const JSHandle &value, bool mayThrow = false); static bool SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, const JSHandle &receiver, - bool may_throw = false); + bool mayThrow = false); static bool DeleteProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key); static bool DeletePropertyOrThrow(JSThread *thread, const JSHandle &obj, @@ -346,7 +346,7 @@ public: void Dump(JSThread *thread, std::ostream &os) const DUMP_API_ATTR; void D() const DUMP_API_ATTR; void DumpForSnapshot(JSThread *thread, std::vector> &vec, - bool is_vm_mode = true) const; + bool isVmMode = true) const; static void DV(JSTaggedType val) DUMP_API_ATTR; private: diff --git a/runtime/js_thread.cpp b/runtime/js_thread.cpp index 9025e7bc426fb86ead9afd6de59385003a12c369..c1603358003cd67daaa1fa18e2cac42d58069afd 100644 --- a/runtime/js_thread.cpp +++ b/runtime/js_thread.cpp @@ -26,12 +26,12 @@ namespace panda::ecmascript { // static JSThread *JSThread::Create(Runtime *runtime, PandaVM *vm) { - auto js_thread = new JSThread(runtime, vm); - js_thread->InitBuffers(); - JSThread::SetCurrent(js_thread); - js_thread->NativeCodeBegin(); - js_thread->InitForStackOverflowCheck(STACK_OVERFLOW_RESERVED_SIZE, STACK_OVERFLOW_PROTECTED_SIZE); - return js_thread; + auto jsThread = new JSThread(runtime, vm); + jsThread->InitBuffers(); + JSThread::SetCurrent(jsThread); + jsThread->NativeCodeBegin(); + jsThread->InitForStackOverflowCheck(STACK_OVERFLOW_RESERVED_SIZE, STACK_OVERFLOW_PROTECTED_SIZE); + return jsThread; } JSThread::JSThread(Runtime *runtime, PandaVM *vm) @@ -39,29 +39,29 @@ JSThread::JSThread(Runtime *runtime, PandaVM *vm) panda_file::SourceLang::ECMASCRIPT) { SetLanguageContext(runtime->GetLanguageContext(panda_file::SourceLang::ECMASCRIPT)); - global_storage_ = runtime->GetInternalAllocator()->New(); - internal_call_params_ = new InternalCallParams(); - properties_cache_ = new PropertiesCache(); + globalStorage_ = runtime->GetInternalAllocator()->New(); + internalCallParams_ = new InternalCallParams(); + propertiesCache_ = new PropertiesCache(); } JSThread::~JSThread() { - for (auto n : handle_storage_nodes_) { + for (auto n : handleStorageNodes_) { delete n; } - handle_storage_nodes_.clear(); - current_handle_storage_index_ = -1; - handle_scope_count_ = 0; - handle_scope_storage_next_ = handle_scope_storage_end_ = nullptr; - Runtime::GetCurrent()->GetInternalAllocator()->Delete(global_storage_); - - if (internal_call_params_ != nullptr) { - delete internal_call_params_; - internal_call_params_ = nullptr; + handleStorageNodes_.clear(); + currentHandleStorageIndex_ = -1; + handleScopeCount_ = 0; + handleScopeStorageNext_ = handleScopeStorageEnd_ = nullptr; + Runtime::GetCurrent()->GetInternalAllocator()->Delete(globalStorage_); + + if (internalCallParams_ != nullptr) { + delete internalCallParams_; + internalCallParams_ = nullptr; } - if (properties_cache_ != nullptr) { - delete properties_cache_; - properties_cache_ = nullptr; + if (propertiesCache_ != nullptr) { + delete propertiesCache_; + propertiesCache_ = nullptr; } } @@ -96,21 +96,21 @@ void JSThread::Iterate(const RootVisitor &v0, const RootRangeVisitor &v1) }); } IterateEcmascriptEnvironment(v0, v1); - v0(Root::ROOT_VM, ObjectSlot(ToUintPtr(&invocation_lexical_env_))); + v0(Root::ROOT_VM, ObjectSlot(ToUintPtr(&invocationLexicalEnv_))); // visit internal call params; - internal_call_params_->Iterate(v1); + internalCallParams_->Iterate(v1); // visit tagged handle storage roots - if (current_handle_storage_index_ != -1) { - int32_t nid = current_handle_storage_index_; + if (currentHandleStorageIndex_ != -1) { + int32_t nid = currentHandleStorageIndex_; for (int32_t i = 0; i <= nid; ++i) { - auto node = handle_storage_nodes_.at(i); + auto node = handleStorageNodes_.at(i); auto start = node->data(); - auto end = (i != nid) ? &(node->data()[NODE_BLOCK_SIZE]) : handle_scope_storage_next_; + auto end = (i != nid) ? &(node->data()[NODE_BLOCK_SIZE]) : handleScopeStorageNext_; v1(ecmascript::Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(start)), ObjectSlot(ToUintPtr(end))); } } - global_storage_->IterateUsageGlobal([v0](EcmaGlobalStorage::Node *node) { + globalStorage_->IterateUsageGlobal([v0](EcmaGlobalStorage::Node *node) { JSTaggedValue value(node->GetObject()); if (value.IsHeapObject()) { v0(ecmascript::Root::ROOT_HANDLE, ecmascript::ObjectSlot(node->GetObjectAddress())); @@ -126,15 +126,15 @@ void JSThread::IterateEcmascriptEnvironment(const RootVisitor &v0, const RootRan auto adapter = [&v1]([[maybe_unused]] ObjectHeader *obj, ObjectSlot start, ObjectSlot end) { v1(Root::ROOT_VM, start, end); }; - auto visit_env = [&v0, &adapter](EcmascriptEnvironment *env) { + auto visitEnv = [&v0, &adapter](EcmascriptEnvironment *env) { v0(Root::ROOT_VM, ObjectSlot(ToUintPtr(env) + EcmascriptEnvironment::GetConstantPoolOffset())); v0(Root::ROOT_VM, ObjectSlot(ToUintPtr(env) + EcmascriptEnvironment::GetLexicalEnvOffset())); v0(Root::ROOT_VM, ObjectSlot(ToUintPtr(env) + EcmascriptEnvironment::GetThisFuncOffset())); - JSTaggedValue lex_env(env->GetLexicalEnv()); - while (!lex_env.IsJSGlobalEnv()) { - LexicalEnv::Cast(lex_env.GetHeapObject())->VisitRangeSlot(adapter); - lex_env = LexicalEnv::Cast(lex_env.GetHeapObject())->GetParentEnv(); + JSTaggedValue lexEnv(env->GetLexicalEnv()); + while (!lexEnv.IsJSGlobalEnv()) { + LexicalEnv::Cast(lexEnv.GetHeapObject())->VisitRangeSlot(adapter); + lexEnv = LexicalEnv::Cast(lexEnv.GetHeapObject())->GetParentEnv(); } }; @@ -142,43 +142,43 @@ void JSThread::IterateEcmascriptEnvironment(const RootVisitor &v0, const RootRan if (!stack.IsCFrame()) { auto iframe = stack.GetIFrame(); if (iframe->GetExt() != reinterpret_cast(iframe)) { - visit_env(JSFrame::GetJSEnv(iframe)); + visitEnv(JSFrame::GetJSEnv(iframe)); } } } - if (properties_cache_ != nullptr) { - properties_cache_->Clear(); + if (propertiesCache_ != nullptr) { + propertiesCache_->Clear(); } // visit global Constant - global_const_.VisitRangeSlot(v1); + globalConst_.VisitRangeSlot(v1); } uintptr_t *JSThread::ExpandHandleStorage() { uintptr_t *result = nullptr; - int32_t last_index = handle_storage_nodes_.size() - 1; - if (current_handle_storage_index_ == last_index) { + int32_t lastIndex = handleStorageNodes_.size() - 1; + if (currentHandleStorageIndex_ == lastIndex) { auto n = new std::array(); - handle_storage_nodes_.push_back(n); - current_handle_storage_index_++; + handleStorageNodes_.push_back(n); + currentHandleStorageIndex_++; result = reinterpret_cast(&n->data()[0]); - handle_scope_storage_end_ = &n->data()[NODE_BLOCK_SIZE]; + handleScopeStorageEnd_ = &n->data()[NODE_BLOCK_SIZE]; } else { - current_handle_storage_index_++; - auto last_node = handle_storage_nodes_[current_handle_storage_index_]; - result = reinterpret_cast(&last_node->data()[0]); - handle_scope_storage_end_ = &last_node->data()[NODE_BLOCK_SIZE]; + currentHandleStorageIndex_++; + auto lastNode = handleStorageNodes_[currentHandleStorageIndex_]; + result = reinterpret_cast(&lastNode->data()[0]); + handleScopeStorageEnd_ = &lastNode->data()[NODE_BLOCK_SIZE]; } return result; } -void JSThread::ShrinkHandleStorage(int prev_index) +void JSThread::ShrinkHandleStorage(int prevIndex) { - current_handle_storage_index_ = prev_index; - int32_t last_index = handle_storage_nodes_.size() - 1; + currentHandleStorageIndex_ = prevIndex; + int32_t lastIndex = handleStorageNodes_.size() - 1; #if ECMASCRIPT_ENABLE_ZAP_MEM uintptr_t size = ToUintPtr(handle_scope_storage_end_) - ToUintPtr(handle_scope_storage_next_); memset_s(handle_scope_storage_next_, size, 0, size); @@ -188,11 +188,11 @@ void JSThread::ShrinkHandleStorage(int prev_index) } #endif - if (last_index > MIN_HANDLE_STORAGE_SIZE && current_handle_storage_index_ < MIN_HANDLE_STORAGE_SIZE) { - for (int i = MIN_HANDLE_STORAGE_SIZE; i < last_index; i++) { - auto node = handle_storage_nodes_.back(); + if (lastIndex > MIN_HANDLE_STORAGE_SIZE && currentHandleStorageIndex_ < MIN_HANDLE_STORAGE_SIZE) { + for (int i = MIN_HANDLE_STORAGE_SIZE; i < lastIndex; i++) { + auto node = handleStorageNodes_.back(); delete node; - handle_storage_nodes_.pop_back(); + handleStorageNodes_.pop_back(); } } } @@ -202,19 +202,19 @@ void JSThread::NotifyStableArrayElementsGuardians(JSHandle receiver) if (!receiver->GetJSHClass()->IsPrototype()) { return; } - if (!stable_array_elements_guardians_) { + if (!stableArrayElementsGuardians_) { return; } auto env = GetEcmaVM()->GetGlobalEnv(); if (receiver.GetTaggedValue() == env->GetObjectFunctionPrototype().GetTaggedValue() || receiver.GetTaggedValue() == env->GetArrayPrototype().GetTaggedValue()) { - stable_array_elements_guardians_ = false; + stableArrayElementsGuardians_ = false; } } void JSThread::ResetGuardians() { - stable_array_elements_guardians_ = true; + stableArrayElementsGuardians_ = true; } void JSThread::DisableStackOverflowCheck() diff --git a/runtime/js_thread.h b/runtime/js_thread.h index fb844c5e06235622c84e6067296599eede3c77e1..26bd9104f309d0d8adc93134c5f152c14abb0b41 100644 --- a/runtime/js_thread.h +++ b/runtime/js_thread.h @@ -50,10 +50,10 @@ public: */ static JSThread *GetCurrentRaw() { - ManagedThread *managed_thread = ManagedThread::GetCurrent(); - ASSERT(managed_thread != nullptr); - ASSERT(managed_thread->GetThreadLang() == panda::panda_file::SourceLang::ECMASCRIPT); - return JSThread::Cast(managed_thread); + ManagedThread *managedThread = ManagedThread::GetCurrent(); + ASSERT(managedThread != nullptr); + ASSERT(managedThread->GetThreadLang() == panda::panda_file::SourceLang::ECMASCRIPT); + return JSThread::Cast(managedThread); } /** @@ -62,9 +62,9 @@ public: */ static JSThread *GetCurrent() { - ManagedThread *managed_thread = ManagedThread::GetCurrent(); - if (managed_thread != nullptr && managed_thread->GetThreadLang() == panda::panda_file::SourceLang::ECMASCRIPT) { - return JSThread::Cast(managed_thread); + ManagedThread *managedThread = ManagedThread::GetCurrent(); + if (managedThread != nullptr && managedThread->GetThreadLang() == panda::panda_file::SourceLang::ECMASCRIPT) { + return JSThread::Cast(managedThread); } return nullptr; } @@ -79,52 +79,52 @@ public: int GetNestedLevel() const { - return nested_level_; + return nestedLevel_; } void SetNestedLevel(int level) { - nested_level_ = level; + nestedLevel_ = level; } void Iterate(const RootVisitor &v0, const RootRangeVisitor &v1); PANDA_PUBLIC_API uintptr_t *ExpandHandleStorage(); - PANDA_PUBLIC_API void ShrinkHandleStorage(int prev_index); + PANDA_PUBLIC_API void ShrinkHandleStorage(int prevIndex); JSTaggedType *GetHandleScopeStorageNext() const { - return handle_scope_storage_next_; + return handleScopeStorageNext_; } void SetHandleScopeStorageNext(JSTaggedType *value) { - handle_scope_storage_next_ = value; + handleScopeStorageNext_ = value; } JSTaggedType *GetHandleScopeStorageEnd() const { - return handle_scope_storage_end_; + return handleScopeStorageEnd_; } void SetHandleScopeStorageEnd(JSTaggedType *value) { - handle_scope_storage_end_ = value; + handleScopeStorageEnd_ = value; } int GetCurrentHandleStorageIndex() { - return current_handle_storage_index_; + return currentHandleStorageIndex_; } void HandleScopeCountAdd() { - handle_scope_count_++; + handleScopeCount_++; } void HandleScopeCountDec() { - handle_scope_count_--; + handleScopeCount_--; } void SetException(JSTaggedValue exception); @@ -143,47 +143,47 @@ public: EcmaGlobalStorage *GetEcmaGlobalStorage() const { - return global_storage_; + return globalStorage_; } const GlobalEnvConstants *GlobalConstants() const { - return &global_const_; + return &globalConst_; } JSTaggedValue GetFunctionalObject() const { - return functional_object_; + return functionalObject_; } - void SetFunctionalObject(JSTaggedValue functional_object) + void SetFunctionalObject(JSTaggedValue functionalObject) { - functional_object_ = functional_object; + functionalObject_ = functionalObject; } JSTaggedValue GetInvocationLexicalEnv() const { // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - return invocation_lexical_env_; // GC root + return invocationLexicalEnv_; // GC root } - void SetInvocationLexicalEnv(JSTaggedValue invocation_lexical_env) + void SetInvocationLexicalEnv(JSTaggedValue invocationLexicalEnv) { - invocation_lexical_env_ = invocation_lexical_env; + invocationLexicalEnv_ = invocationLexicalEnv; } void NotifyStableArrayElementsGuardians(JSHandle receiver); bool IsStableArrayElementsGuardiansInvalid() const { - return !stable_array_elements_guardians_; + return !stableArrayElementsGuardians_; } void ResetGuardians(); InternalCallParams *GetInternalCallParams() const { - return internal_call_params_; + return internalCallParams_; } ThreadId GetThreadId() const @@ -198,37 +198,37 @@ public: PropertiesCache *GetPropertiesCache() const { - return properties_cache_; + return propertiesCache_; } static constexpr uint32_t GetPropertiesCacheOffset() { - return MEMBER_OFFSET(JSThread, properties_cache_); + return MEMBER_OFFSET(JSThread, propertiesCache_); } static constexpr uint32_t GetGlobalConstantsOffset() { - return MEMBER_OFFSET(JSThread, global_const_); + return MEMBER_OFFSET(JSThread, globalConst_); } static constexpr uint32_t GetGlobalStorageOffset() { - return MEMBER_OFFSET(JSThread, global_storage_); + return MEMBER_OFFSET(JSThread, globalStorage_); } static constexpr uint32_t GetGlobalObjectOffset() { - return MEMBER_OFFSET(JSThread, global_obj_); + return MEMBER_OFFSET(JSThread, globalObj_); } - void SetGlobalObject(JSTaggedValue global_obj) + void SetGlobalObject(JSTaggedValue globalObj) { - global_obj_ = global_obj; + globalObj_ = globalObj; } JSTaggedValue GetGlobalObject() const { - return global_obj_; + return globalObj_; } void DisableStackOverflowCheck() override; @@ -253,29 +253,29 @@ private: static constexpr int32_t MIN_HANDLE_STORAGE_SIZE = 2; // MM: handles, global-handles - int nested_level_ = 0; - JSTaggedType *handle_scope_storage_next_ {nullptr}; - JSTaggedType *handle_scope_storage_end_ {nullptr}; - PandaVector *> handle_storage_nodes_ {}; - int32_t current_handle_storage_index_ {-1}; - int32_t handle_scope_count_ {0}; - JSSpanHandle *span_handle_ {nullptr}; - ScopedCallInfo *scoped_call_info_ {nullptr}; + int nestedLevel_ = 0; + JSTaggedType *handleScopeStorageNext_ {nullptr}; + JSTaggedType *handleScopeStorageEnd_ {nullptr}; + PandaVector *> handleStorageNodes_ {}; + int32_t currentHandleStorageIndex_ {-1}; + int32_t handleScopeCount_ {0}; + JSSpanHandle *spanHandle_ {nullptr}; + ScopedCallInfo *scopedCallInfo_ {nullptr}; // Run-time state - bool stable_array_elements_guardians_ {true}; - InternalCallParams *internal_call_params_ {nullptr}; + bool stableArrayElementsGuardians_ {true}; + InternalCallParams *internalCallParams_ {nullptr}; // GLUE members start, very careful to modify here - GlobalEnvConstants global_const_; // Place-Holder - PropertiesCache *properties_cache_ {nullptr}; - EcmaGlobalStorage *global_storage_ {nullptr}; + GlobalEnvConstants globalConst_; // Place-Holder + PropertiesCache *propertiesCache_ {nullptr}; + EcmaGlobalStorage *globalStorage_ {nullptr}; - JSTaggedValue global_obj_ {JSTaggedValue::Hole()}; + JSTaggedValue globalObj_ {JSTaggedValue::Hole()}; // Uses to forward a0 argument (functional object) to InvokeHelper - JSTaggedValue functional_object_; - JSTaggedValue invocation_lexical_env_; + JSTaggedValue functionalObject_; + JSTaggedValue invocationLexicalEnv_; friend class EcmaHandleScope; friend class JSSpanHandle; diff --git a/runtime/js_typed_array.cpp b/runtime/js_typed_array.cpp index ffbcd1aa86f3b14adc12930d66605482075efd9e..1eec8076b72a6255f18c370a2d163d57b1ea0e07 100644 --- a/runtime/js_typed_array.cpp +++ b/runtime/js_typed_array.cpp @@ -45,11 +45,11 @@ bool JSTypedArray::GetOwnProperty(JSThread *thread, const JSHandleIsString()) { - JSTaggedValue numeric_index = JSTaggedValue::CanonicalNumericIndexString(thread, key); + JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(thread, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!numeric_index.IsUndefined()) { + if (!numericIndex.IsUndefined()) { JSHandle value = - JSTypedArray::IntegerIndexedElementGet(thread, typedarray, numeric_index).GetValue(); + JSTypedArray::IntegerIndexedElementGet(thread, typedarray, numericIndex).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (value->IsUndefined()) { return false; @@ -83,40 +83,40 @@ bool JSTypedArray::HasProperty(JSThread *thread, const JSHandle & // v. If numericIndex < 0, return false. // vi. If numericIndex ≥ the value of O’s [[ArrayLength]] internal slot, return false. // vii. Return true. - JSHandle typedarray_obj(typedarray); + JSHandle typedarrayObj(typedarray); if (key->IsString()) { - JSTaggedValue numeric_index = JSTaggedValue::CanonicalNumericIndexString(thread, key); + JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(thread, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!numeric_index.IsUndefined()) { - JSTaggedValue buffer = JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer(); + if (!numericIndex.IsUndefined()) { + JSTaggedValue buffer = JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer(); if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); } - if (!numeric_index.IsInteger()) { + if (!numericIndex.IsInteger()) { return false; } - JSHandle numeric_index_handle(thread, numeric_index); - JSTaggedNumber numeric_index_number = JSTaggedValue::ToNumber(thread, numeric_index_handle); - double t_neg_zero = -0.0; - auto e_zero = JSTaggedNumber(t_neg_zero); - if (JSTaggedNumber::SameValue(numeric_index_number, e_zero)) { + JSHandle numericIndexHandle(thread, numericIndex); + JSTaggedNumber numericIndexNumber = JSTaggedValue::ToNumber(thread, numericIndexHandle); + double tNegZero = -0.0; + auto eZero = JSTaggedNumber(tNegZero); + if (JSTaggedNumber::SameValue(numericIndexNumber, eZero)) { return false; } - if (JSTaggedValue::Less(thread, numeric_index_handle, thread->GlobalConstants()->GetHandledZero())) { + if (JSTaggedValue::Less(thread, numericIndexHandle, thread->GlobalConstants()->GetHandledZero())) { return false; } - int32_t arr_len = TypedArrayHelper::GetArrayLength(thread, typedarray_obj); - JSHandle arr_len_handle(thread, JSTaggedValue(arr_len)); - return JSTaggedValue::Less(thread, numeric_index_handle, arr_len_handle); + int32_t arrLen = TypedArrayHelper::GetArrayLength(thread, typedarrayObj); + JSHandle arrLenHandle(thread, JSTaggedValue(arrLen)); + return JSTaggedValue::Less(thread, numericIndexHandle, arrLenHandle); } } // 4. Return OrdinaryHasProperty(O, P). PropertyDescriptor desc(thread); - if (JSObject::OrdinaryGetOwnProperty(thread, typedarray_obj, key, desc)) { + if (JSObject::OrdinaryGetOwnProperty(thread, typedarrayObj, key, desc)) { return true; } - JSTaggedValue parent = typedarray_obj->GetPrototype(thread); + JSTaggedValue parent = typedarrayObj->GetPrototype(thread); if (!parent.IsNull()) { return JSTaggedValue::HasProperty(thread, JSHandle(thread, parent), key); } @@ -134,11 +134,11 @@ bool JSTypedArray::DefineOwnProperty(JSThread *thread, const JSHandle typedarray_obj(typedarray); + JSHandle typedarrayObj(typedarray); if (key->IsString()) { - JSTaggedValue numeric_index = JSTaggedValue::CanonicalNumericIndexString(thread, key); + JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(thread, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!numeric_index.IsUndefined()) { + if (!numericIndex.IsUndefined()) { // i. If IsInteger(numericIndex) is false, return false // ii. Let intIndex be numericIndex. // iii. If intIndex = −0, return false. @@ -153,22 +153,22 @@ bool JSTypedArray::DefineOwnProperty(JSThread *thread, const JSHandle numeric_index_handle(thread, numeric_index); - JSTaggedNumber numeric_index_number = JSTaggedValue::ToNumber(thread, numeric_index_handle); - double t_neg_zero = -0.0; - auto e_zero = JSTaggedNumber(t_neg_zero); - if (JSTaggedNumber::SameValue(numeric_index_number, e_zero)) { + JSHandle numericIndexHandle(thread, numericIndex); + JSTaggedNumber numericIndexNumber = JSTaggedValue::ToNumber(thread, numericIndexHandle); + double tNegZero = -0.0; + auto eZero = JSTaggedNumber(tNegZero); + if (JSTaggedNumber::SameValue(numericIndexNumber, eZero)) { return false; } - if (JSTaggedValue::Less(thread, numeric_index_handle, thread->GlobalConstants()->GetHandledZero())) { + if (JSTaggedValue::Less(thread, numericIndexHandle, thread->GlobalConstants()->GetHandledZero())) { return false; } - int32_t arr_len = TypedArrayHelper::GetArrayLength(thread, typedarray_obj); - JSHandle arr_len_handle(thread, JSTaggedValue(arr_len)); - if (!JSTaggedValue::Less(thread, numeric_index_handle, arr_len_handle)) { + int32_t arrLen = TypedArrayHelper::GetArrayLength(thread, typedarrayObj); + JSHandle arrLenHandle(thread, JSTaggedValue(arrLen)); + if (!JSTaggedValue::Less(thread, numericIndexHandle, arrLenHandle)) { return false; } if (desc.IsAccessorDescriptor()) { @@ -188,13 +188,13 @@ bool JSTypedArray::DefineOwnProperty(JSThread *thread, const JSHandle &typedarray, const JSHandle &key, const JSHandle &value, - const JSHandle &receiver, bool may_throw) + const JSHandle &receiver, bool mayThrow) { // 1. Assert : IsPropertyKey(P) is true. ASSERT(JSTaggedValue::IsPropertyKey(key)); @@ -235,15 +235,15 @@ bool JSTypedArray::SetProperty(JSThread *thread, const JSHandle & // b. Assert: numericIndex is not an abrupt completion. // c. If numericIndex is not undefined, then // i. Return IntegerIndexedElementSet (O, numericIndex, V). - JSTaggedValue numeric_index = JSTaggedValue::CanonicalNumericIndexString(thread, key); + JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(thread, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - if (!numeric_index.IsUndefined()) { - return JSTypedArray::IntegerIndexedElementSet(thread, typedarray, numeric_index, value); + if (!numericIndex.IsUndefined()) { + return JSTypedArray::IntegerIndexedElementSet(thread, typedarray, numericIndex, value); } } // 3. Return the result of calling the default ordinary object [[Set]] internal method (9.1.8) on O passing // P, V, and Receiver as arguments. - return JSObject::SetProperty(thread, typedarray, key, value, receiver, may_throw); + return JSObject::SetProperty(thread, typedarray, key, value, receiver, mayThrow); } // 9.4.5.6 [[OwnPropertyKeys]] ( ) @@ -254,47 +254,47 @@ JSHandle JSTypedArray::OwnPropertyKeys(JSThread *thread, const JSHa // 2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and // [[TypedArrayName]] internal slots. // 3. Let len be the value of O’s [[ArrayLength]] internal slot. - JSHandle array_obj(typedarray); - JSHandle obj_keys = JSObject::GetOwnPropertyKeys(thread, array_obj); - uint32_t obj_keys_len = obj_keys->GetLength(); - uint32_t buffer_keys_len = TypedArrayHelper::GetArrayLength(thread, array_obj); - uint32_t length = obj_keys_len + buffer_keys_len; - JSHandle name_list = factory->NewTaggedArray(length); + JSHandle arrayObj(typedarray); + JSHandle objKeys = JSObject::GetOwnPropertyKeys(thread, arrayObj); + uint32_t objKeysLen = objKeys->GetLength(); + uint32_t bufferKeysLen = TypedArrayHelper::GetArrayLength(thread, arrayObj); + uint32_t length = objKeysLen + bufferKeysLen; + JSHandle nameList = factory->NewTaggedArray(length); // 4. For each integer i starting with 0 such that i < len, in ascending order, // a. Add ToString(i) as the last element of keys. - uint32_t copy_length = 0; - JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); - for (uint32_t k = 0; k < buffer_keys_len; k++) { - t_key.Update(JSTaggedValue(k)); - JSHandle s_key(JSTaggedValue::ToString(thread, t_key)); - name_list->Set(thread, copy_length, s_key.GetTaggedValue()); - copy_length++; + uint32_t copyLength = 0; + JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + for (uint32_t k = 0; k < bufferKeysLen; k++) { + tKey.Update(JSTaggedValue(k)); + JSHandle sKey(JSTaggedValue::ToString(thread, tKey)); + nameList->Set(thread, copyLength, sKey.GetTaggedValue()); + copyLength++; } // 5. For each own property key P of O such that Type(P) is String and P is not an integer index, in // property creation order // a. Add P as the last element of keys. - for (uint32_t i = 0; i < obj_keys_len; i++) { - JSTaggedValue key = obj_keys->Get(i); + for (uint32_t i = 0; i < objKeysLen; i++) { + JSTaggedValue key = objKeys->Get(i); if (JSTaggedValue(key).IsString()) { - name_list->Set(thread, copy_length, key); - copy_length++; + nameList->Set(thread, copyLength, key); + copyLength++; } } // 6. For each own property key P of O such that Type(P) is Symbol, in property creation order // a. Add P as the last element of keys. - for (uint32_t i = 0; i < obj_keys_len; i++) { - JSTaggedValue key = obj_keys->Get(i); + for (uint32_t i = 0; i < objKeysLen; i++) { + JSTaggedValue key = objKeys->Get(i); if (JSTaggedValue(key).IsSymbol()) { - name_list->Set(thread, copy_length, key); - copy_length++; + nameList->Set(thread, copyLength, key); + copyLength++; } } // 7. Return keys. - return factory->CopyArray(name_list, length, copy_length); + return factory->CopyArray(nameList, length, copyLength); } // 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) @@ -309,11 +309,11 @@ OperationResult JSTypedArray::IntegerIndexedElementGet(JSThread *thread, const J // [[TypedArrayName]] internal slots. ASSERT(typedarray->IsTypedArray()); // 3. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSHandle typedarray_obj(typedarray); + JSHandle typedarrayObj(typedarray); { // 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 = JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer(); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", @@ -328,52 +328,52 @@ OperationResult JSTypedArray::IntegerIndexedElementGet(JSThread *thread, const J // 6. If index = −0, return undefined. // 7. Let length be the value of O’s [[ArrayLength]] internal slot. // 8. If index < 0 or index ≥ length, return undefined. - JSHandle index_handle(thread, index); - JSTaggedNumber index_number = JSTaggedValue::ToNumber(thread, index_handle); - double t_neg_zero = -0.0; - auto e_zero = JSTaggedNumber(t_neg_zero); - if (JSTaggedNumber::SameValue(index_number, e_zero)) { + JSHandle indexHandle(thread, index); + JSTaggedNumber indexNumber = JSTaggedValue::ToNumber(thread, indexHandle); + double tNegZero = -0.0; + auto eZero = JSTaggedNumber(tNegZero); + if (JSTaggedNumber::SameValue(indexNumber, eZero)) { return OperationResult(thread, JSTaggedValue::Undefined(), PropertyMetaData(true)); } - int32_t arr_len = TypedArrayHelper::GetArrayLength(thread, typedarray_obj); - JSHandle arr_len_handle(thread, JSTaggedValue(arr_len)); - if (JSTaggedValue::Less(thread, index_handle, thread->GlobalConstants()->GetHandledZero()) || - !JSTaggedValue::Less(thread, index_handle, arr_len_handle)) { + int32_t arrLen = TypedArrayHelper::GetArrayLength(thread, typedarrayObj); + JSHandle arrLenHandle(thread, JSTaggedValue(arrLen)); + if (JSTaggedValue::Less(thread, indexHandle, thread->GlobalConstants()->GetHandledZero()) || + !JSTaggedValue::Less(thread, indexHandle, arrLenHandle)) { return OperationResult(thread, JSTaggedValue::Undefined(), PropertyMetaData(true)); } // 9. Let offset be the value of O’s [[ByteOffset]] internal slot. - int32_t offset = TypedArrayHelper::GetByteOffset(thread, typedarray_obj); + int32_t offset = TypedArrayHelper::GetByteOffset(thread, typedarrayObj); // 10. Let arrayTypeName be the String value of O’s [[TypedArrayName]] internal slot. // 11. Let elementSize be the Number value of the Element Size value specified in Table 49 for // arrayTypeName. - int32_t element_size = TypedArrayHelper::GetElementSize(typedarray_obj); + int32_t elementSize = TypedArrayHelper::GetElementSize(typedarrayObj); // 12. Let indexedPosition = (index × elementSize) + offset. - int32_t k = JSTaggedValue::ToInteger(thread, index_handle).ToInt32(); - int32_t byte_index = k * element_size + offset; + int32_t k = JSTaggedValue::ToInteger(thread, indexHandle).ToInt32(); + int32_t byteIndex = k * elementSize + offset; // 13. Let elementType be the String value of the Element Type value in Table 49 for arrayTypeName. - DataViewType element_type = TypedArrayHelper::GetType(typedarray_obj); + DataViewType elementType = TypedArrayHelper::GetType(typedarrayObj); // 14. Return GetValueFromBuffer(buffer, indexedPosition, elementType). JSTaggedValue result; { // We use buffer without handle and GC can move it. So we have to get buffer each time. // To make developer get buffer each time use scope and don't populate buffer into function's scope. - JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); - result = builtins::array_buffer::GetValueFromBuffer(thread, buffer, byte_index, element_type, true); + JSHandle buffer(thread, JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer()); + result = builtins::array_buffer::GetValueFromBuffer(thread, buffer, byteIndex, elementType, true); } return OperationResult(thread, result, PropertyMetaData(true)); } // static -bool JSTypedArray::FastCopyElementToArray(JSThread *thread, const JSHandle &typed_array, +bool JSTypedArray::FastCopyElementToArray(JSThread *thread, const JSHandle &typedArray, JSHandle &array) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); // 2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and // [[TypedArrayName]] internal slots. - ASSERT(typed_array->IsTypedArray()); + ASSERT(typedArray->IsTypedArray()); // 3. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSHandle typedarray_obj(typed_array); - JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); + JSHandle typedarrayObj(typedArray); + JSHandle buffer(thread, JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer()); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::IsDetachedBuffer(buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); @@ -381,23 +381,22 @@ bool JSTypedArray::FastCopyElementToArray(JSThread *thread, const JSHandleSet(thread, index, result); } return true; @@ -411,11 +410,11 @@ OperationResult JSTypedArray::FastElementGet(JSThread *thread, const JSHandleIsTypedArray()); // 3. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSHandle typedarray_obj(typedarray); + JSHandle typedarrayObj(typedarray); { // 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 = JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer(); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", @@ -425,25 +424,24 @@ OperationResult JSTypedArray::FastElementGet(JSThread *thread, const JSHandle= static_cast(arr_len)) { + int32_t arrLen = TypedArrayHelper::GetArrayLength(thread, typedarrayObj); + if (arrLen < 0 || index >= static_cast(arrLen)) { return OperationResult(thread, JSTaggedValue::Undefined(), PropertyMetaData(true)); } // 9. Let offset be the value of O’s [[ByteOffset]] internal slot. - int32_t offset = TypedArrayHelper::GetByteOffset(thread, typedarray_obj); + int32_t offset = TypedArrayHelper::GetByteOffset(thread, typedarrayObj); // 11. Let elementSize be the Number value of the Element Size value specified in Table 49 for arrayTypeName. - int32_t element_size = TypedArrayHelper::GetElementSize(typedarray_obj); + int32_t elementSize = TypedArrayHelper::GetElementSize(typedarrayObj); // 12. Let indexedPosition = (index × elementSize) + offset. - int32_t byte_index = index * element_size + offset; + int32_t byteIndex = index * elementSize + offset; // 13. Let elementType be the String value of the Element Type value in Table 49 for arrayTypeName. - DataViewType element_type = TypedArrayHelper::GetType(typedarray_obj); + DataViewType elementType = TypedArrayHelper::GetType(typedarrayObj); // 14. Return GetValueFromBuffer(buffer, indexedPosition, elementType). { // We use buffer without handle and GC can move it. So we have to get buffer each time. // To make developer get buffer each time use scope and don't populate buffer into function's scope. - JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); - JSTaggedValue result = - builtins::array_buffer::GetValueFromBuffer(thread, buffer, byte_index, element_type, true); + JSHandle buffer(thread, JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer()); + JSTaggedValue result = builtins::array_buffer::GetValueFromBuffer(thread, buffer, byteIndex, elementType, true); return OperationResult(thread, result, PropertyMetaData(true)); } } @@ -452,29 +450,29 @@ OperationResult JSTypedArray::FastElementGet(JSThread *thread, const JSHandle &typedarray, JSTaggedValue index, const JSHandle &value) { - JSHandle index_handle(thread, index); + JSHandle indexHandle(thread, index); // 1. Assert: Type(index) is Number. ASSERT(index.IsNumber()); // 2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and // [[TypedArrayName]] internal slots. ASSERT(typedarray->IsTypedArray()); // 3. If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). - JSHandle num_value_handle; - ContentType content_type = JSHandle::Cast(typedarray)->GetContentType(); - if (content_type == ContentType::BIG_INT) { - num_value_handle = JSHandle(thread, JSTaggedValue::ToBigInt(thread, value)); + JSHandle numValueHandle; + ContentType contentType = JSHandle::Cast(typedarray)->GetContentType(); + if (contentType == ContentType::BIG_INT) { + numValueHandle = JSHandle(thread, JSTaggedValue::ToBigInt(thread, value)); } else { - num_value_handle = JSHandle(thread, JSTaggedValue::ToNumber(thread, value)); + numValueHandle = JSHandle(thread, JSTaggedValue::ToNumber(thread, value)); } // 4. ReturnIfAbrupt(numValue). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSHandle typedarray_obj(typedarray); + JSHandle typedarrayObj(typedarray); { // 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 = JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer(); // 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); @@ -488,36 +486,36 @@ bool JSTypedArray::IntegerIndexedElementSet(JSThread *thread, const JSHandle arr_len_handle(thread, JSTaggedValue(arr_len)); - if (JSTaggedValue::Less(thread, index_handle, thread->GlobalConstants()->GetHandledZero()) || - !JSTaggedValue::Less(thread, index_handle, arr_len_handle)) { + int32_t arrLen = TypedArrayHelper::GetArrayLength(thread, typedarrayObj); + JSHandle arrLenHandle(thread, JSTaggedValue(arrLen)); + if (JSTaggedValue::Less(thread, indexHandle, thread->GlobalConstants()->GetHandledZero()) || + !JSTaggedValue::Less(thread, indexHandle, arrLenHandle)) { return false; } // 11. Let offset be the value of O’s [[ByteOffset]] internal slot. - int32_t offset = TypedArrayHelper::GetByteOffset(thread, typedarray_obj); + int32_t offset = TypedArrayHelper::GetByteOffset(thread, typedarrayObj); // 12. Let arrayTypeName be the String value of O’s [[TypedArrayName]] internal slot. // 13. Let elementSize be the Number value of the Element Size value specified in Table 49 for // arrayTypeName. - int32_t element_size = TypedArrayHelper::GetElementSize(typedarray_obj); + int32_t elementSize = TypedArrayHelper::GetElementSize(typedarrayObj); // 14. Let indexedPosition = (index × elementSize) + offset. - int32_t k = JSTaggedValue::ToInteger(thread, index_handle).ToInt32(); - int32_t byte_index = k * element_size + offset; + int32_t k = JSTaggedValue::ToInteger(thread, indexHandle).ToInt32(); + int32_t byteIndex = k * elementSize + offset; // 15. Let elementType be the String value of the Element Type value in Table 49 for arrayTypeName. - DataViewType element_type = TypedArrayHelper::GetType(typedarray_obj); + DataViewType elementType = TypedArrayHelper::GetType(typedarrayObj); // 16. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). { // We use buffer without handle and GC can move it. So we have to get buffer each time. // To make developer get buffer each time use scope and don't populate buffer into function's scope. - JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); - builtins::array_buffer::SetValueInBuffer(thread, buffer, byte_index, element_type, num_value_handle, true); + JSHandle buffer(thread, JSTypedArray::Cast(*typedarrayObj)->GetViewedArrayBuffer()); + builtins::array_buffer::SetValueInBuffer(thread, buffer, byteIndex, elementType, numValueHandle, true); } // 17. Return true. return true; diff --git a/runtime/js_typed_array.h b/runtime/js_typed_array.h index af042e9c7b1e10d35194665f7f987b812a826141..c97c91896606b84df21395f20c3a9031537a201e 100644 --- a/runtime/js_typed_array.h +++ b/runtime/js_typed_array.h @@ -63,13 +63,13 @@ public: // 9.4.5.5 [[Set]] ( P, V, Receiver ) static inline bool SetProperty(JSThread *thread, const JSHandle &typedarray, const JSHandle &key, const JSHandle &value, - bool may_throw = false) + bool mayThrow = false) { - return SetProperty(thread, typedarray, key, value, typedarray, may_throw); + return SetProperty(thread, typedarray, key, value, typedarray, mayThrow); } static bool SetProperty(JSThread *thread, const JSHandle &typedarray, const JSHandle &key, const JSHandle &value, - const JSHandle &receiver, bool may_throw = false); + const JSHandle &receiver, bool mayThrow = false); // 9.4.5.6 [[OwnPropertyKeys]] ( ) static JSHandle OwnPropertyKeys(JSThread *thread, const JSHandle &typedarray); // 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) @@ -77,7 +77,7 @@ public: static OperationResult IntegerIndexedElementGet(JSThread *thread, const JSHandle &typedarray, JSTaggedValue index); static OperationResult FastElementGet(JSThread *thread, const JSHandle &typedarray, uint32_t index); - static bool FastCopyElementToArray(JSThread *thread, const JSHandle &typed_array, + static bool FastCopyElementToArray(JSThread *thread, const JSHandle &typedArray, JSHandle &array); // 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) static bool IntegerIndexedElementSet(JSThread *thread, const JSHandle &typedarray, diff --git a/runtime/js_weak_container.cpp b/runtime/js_weak_container.cpp index c574465ad296119f780c9e61cb533d360470764e..51c1cb90e108e38c1267ec4e5302c43b1548db8f 100644 --- a/runtime/js_weak_container.cpp +++ b/runtime/js_weak_container.cpp @@ -24,31 +24,31 @@ namespace panda::ecmascript { void JSWeakMap::Set(JSThread *thread, const JSHandle &map, const JSHandle &key, const JSHandle &value) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); if (!LinkedHashMap::IsKey(JSTaggedValue(key.GetTaggedValue()))) { THROW_TYPE_ERROR(thread, "the value must be Key of JSMap"); } - JSHandle map_handle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); - auto result = LinkedHashMap::Set(thread, map_handle, key, value); + auto result = LinkedHashMap::Set(thread, mapHandle, key, value); map->SetLinkedMap(thread, result); } bool JSWeakMap::Delete(JSThread *thread, const JSHandle &map, const JSHandle &key) { - JSHandle map_handle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); if (!LinkedHashSet::IsKey(key.GetTaggedValue())) { return false; } int hash = LinkedHash::Hash(key.GetTaggedValue()); - int entry = map_handle->FindElement(key.GetTaggedValue(), hash); + int entry = mapHandle->FindElement(key.GetTaggedValue(), hash); if (entry == -1) { return false; } - map_handle->RemoveEntry(thread, entry); + mapHandle->RemoveEntry(thread, entry); - JSHandle new_map = LinkedHashMap::Shrink(thread, map_handle); - map->SetLinkedMap(thread, new_map); + JSHandle newMap = LinkedHashMap::Shrink(thread, mapHandle); + map->SetLinkedMap(thread, newMap); return true; } @@ -67,28 +67,28 @@ int JSWeakMap::GetSize() const return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->NumberOfElements(); } -void JSWeakSet::Add(JSThread *thread, const JSHandle &weak_set, const JSHandle &value) +void JSWeakSet::Add(JSThread *thread, const JSHandle &weakSet, const JSHandle &value) { if (!LinkedHashSet::IsKey(value.GetTaggedValue())) { THROW_TYPE_ERROR(thread, "the value must be Key of JSWeakSet"); } - JSHandle weak_set_handle(thread, LinkedHashSet::Cast(weak_set->GetLinkedSet().GetTaggedObject())); + JSHandle weakSetHandle(thread, LinkedHashSet::Cast(weakSet->GetLinkedSet().GetTaggedObject())); - auto result = LinkedHashSet::Add(thread, weak_set_handle, value); - weak_set->SetLinkedSet(thread, result); + auto result = LinkedHashSet::Add(thread, weakSetHandle, value); + weakSet->SetLinkedSet(thread, result); } -bool JSWeakSet::Delete(JSThread *thread, const JSHandle &weak_set, const JSHandle &value) +bool JSWeakSet::Delete(JSThread *thread, const JSHandle &weakSet, const JSHandle &value) { - JSHandle weak_set_handle(thread, LinkedHashSet::Cast(weak_set->GetLinkedSet().GetTaggedObject())); + JSHandle weakSetHandle(thread, LinkedHashSet::Cast(weakSet->GetLinkedSet().GetTaggedObject())); int hash = LinkedHash::Hash(value.GetTaggedValue()); - int entry = weak_set_handle->FindElement(value.GetTaggedValue(), hash); + int entry = weakSetHandle->FindElement(value.GetTaggedValue(), hash); if (entry == -1) { return false; } - weak_set_handle->RemoveEntry(thread, entry); - JSHandle new_set = LinkedHashSet::Shrink(thread, weak_set_handle); - weak_set->SetLinkedSet(thread, new_set); + weakSetHandle->RemoveEntry(thread, entry); + JSHandle newSet = LinkedHashSet::Shrink(thread, weakSetHandle); + weakSet->SetLinkedSet(thread, newSet); return true; } diff --git a/runtime/layout_info-inl.h b/runtime/layout_info-inl.h index 36907cc87799c63d8d408aa30f1898c7443246e7..36b161353bed7b956b6a18c77293551614f1d9eb 100644 --- a/runtime/layout_info-inl.h +++ b/runtime/layout_info-inl.h @@ -49,35 +49,35 @@ inline uint32_t LayoutInfo::GetAttrIndex(int32_t index) const inline void LayoutInfo::SetPropertyInit(const JSThread *thread, int32_t index, const JSTaggedValue &key, const PropertyAttributes &attr) { - uint32_t fixed_idx = GetKeyIndex(index); - TaggedArray::Set(thread, fixed_idx, key); - TaggedArray::Set(thread, fixed_idx + 1, attr.GetNormalTagged()); + uint32_t fixedIdx = GetKeyIndex(index); + TaggedArray::Set(thread, fixedIdx, key); + TaggedArray::Set(thread, fixedIdx + 1, attr.GetNormalTagged()); } inline void LayoutInfo::SetNormalAttr(const JSThread *thread, int32_t index, const PropertyAttributes &attr) { - uint32_t fixed_idx = GetAttrIndex(index); - PropertyAttributes old_attr(TaggedArray::Get(fixed_idx)); - old_attr.SetNormalAttr(attr.GetNormalAttr()); - TaggedArray::Set(thread, fixed_idx, old_attr.GetTaggedValue()); + uint32_t fixedIdx = GetAttrIndex(index); + PropertyAttributes oldAttr(TaggedArray::Get(fixedIdx)); + oldAttr.SetNormalAttr(attr.GetNormalAttr()); + TaggedArray::Set(thread, fixedIdx, oldAttr.GetTaggedValue()); } inline JSTaggedValue LayoutInfo::GetKey(int32_t index) const { - uint32_t fixed_idx = GetKeyIndex(index); - return TaggedArray::Get(fixed_idx); + uint32_t fixedIdx = GetKeyIndex(index); + return TaggedArray::Get(fixedIdx); } inline PropertyAttributes LayoutInfo::GetAttr(int32_t index) const { - uint32_t fixed_idx = GetAttrIndex(index); - return PropertyAttributes(TaggedArray::Get(fixed_idx)); + uint32_t fixedIdx = GetAttrIndex(index); + return PropertyAttributes(TaggedArray::Get(fixedIdx)); } inline JSTaggedValue LayoutInfo::GetSortedKey(int32_t index) const { - uint32_t fixed_idx = GetSortedIndex(index); - return GetKey(fixed_idx); + uint32_t fixedIdx = GetSortedIndex(index); + return GetKey(fixedIdx); } inline uint32_t LayoutInfo::GetSortedIndex(int32_t index) const @@ -85,22 +85,22 @@ inline uint32_t LayoutInfo::GetSortedIndex(int32_t index) const return GetAttr(index).GetSortedIndex(); } -inline void LayoutInfo::SetSortedIndex(const JSThread *thread, int32_t index, int32_t sorted_index) +inline void LayoutInfo::SetSortedIndex(const JSThread *thread, int32_t index, int32_t sortedIndex) { - uint32_t fixed_idx = GetAttrIndex(index); - PropertyAttributes attr(TaggedArray::Get(fixed_idx)); - attr.SetSortedIndex(sorted_index); - TaggedArray::Set(thread, fixed_idx, attr.GetTaggedValue()); + uint32_t fixedIdx = GetAttrIndex(index); + PropertyAttributes attr(TaggedArray::Get(fixedIdx)); + attr.SetSortedIndex(sortedIndex); + TaggedArray::Set(thread, fixedIdx, attr.GetTaggedValue()); } inline int32_t LayoutInfo::FindElementWithCache(JSThread *thread, JSHClass *cls, JSTaggedValue key, - int32_t properties_number) + int32_t propertiesNumber) { - ASSERT(NumberOfElements() >= properties_number); - const int32_t max_elements_liner_search = 9; // 9: Builtins Object properties number is nine; - if (properties_number <= max_elements_liner_search) { - Span sp(GetProperties(), properties_number); - for (int32_t i = 0; i < properties_number; i++) { + ASSERT(NumberOfElements() >= propertiesNumber); + const int32_t maxElementsLinerSearch = 9; // 9: Builtins Object properties number is nine; + if (propertiesNumber <= maxElementsLinerSearch) { + Span sp(GetProperties(), propertiesNumber); + for (int32_t i = 0; i < propertiesNumber; i++) { if (sp[i].key == key) { return i; } @@ -111,55 +111,55 @@ inline int32_t LayoutInfo::FindElementWithCache(JSThread *thread, JSHClass *cls, PropertiesCache *cache = thread->GetPropertiesCache(); int32_t index = cache->Get(cls, key); if (index == PropertiesCache::NOT_FOUND) { - index = BinarySearch(key, properties_number); + index = BinarySearch(key, propertiesNumber); cache->Set(cls, key, index); } return index; } -inline int32_t LayoutInfo::BinarySearch(JSTaggedValue key, int32_t properties_number) +inline int32_t LayoutInfo::BinarySearch(JSTaggedValue key, int32_t propertiesNumber) { - ASSERT(NumberOfElements() >= properties_number); + ASSERT(NumberOfElements() >= propertiesNumber); int32_t low = 0; int32_t elements = NumberOfElements(); int32_t high = elements - 1; - uint32_t key_hash = key.GetKeyHashCode(); + uint32_t keyHash = key.GetKeyHashCode(); ASSERT(low <= high); while (low <= high) { int32_t mid = low + (high - low) / 2; // 2: half - JSTaggedValue mid_key = GetSortedKey(mid); - uint32_t mid_hash = mid_key.GetKeyHashCode(); - if (mid_hash > key_hash) { + JSTaggedValue midKey = GetSortedKey(mid); + uint32_t midHash = midKey.GetKeyHashCode(); + if (midHash > keyHash) { high = mid - 1; - } else if (mid_hash < key_hash) { + } else if (midHash < keyHash) { low = mid + 1; } else { - int32_t sort_index = GetSortedIndex(mid); - JSTaggedValue current_key = GetKey(sort_index); - if (current_key == key) { - return sort_index < properties_number ? sort_index : -1; + int32_t sortIndex = GetSortedIndex(mid); + JSTaggedValue currentKey = GetKey(sortIndex); + if (currentKey == key) { + return sortIndex < propertiesNumber ? sortIndex : -1; } - int32_t mid_left = mid; - int32_t mid_right = mid; - while (mid_left - 1 >= 0) { - sort_index = GetSortedIndex(--mid_left); - current_key = GetKey(sort_index); - if (current_key.GetKeyHashCode() == key_hash) { - if (current_key == key) { - return sort_index < properties_number ? sort_index : -1; + int32_t midLeft = mid; + int32_t midRight = mid; + while (midLeft - 1 >= 0) { + sortIndex = GetSortedIndex(--midLeft); + currentKey = GetKey(sortIndex); + if (currentKey.GetKeyHashCode() == keyHash) { + if (currentKey == key) { + return sortIndex < propertiesNumber ? sortIndex : -1; } } else { break; } } - while (mid_right + 1 < elements) { - sort_index = GetSortedIndex(++mid_right); - current_key = GetKey(sort_index); - if (current_key.GetKeyHashCode() == key_hash) { - if (current_key == key) { - return sort_index < properties_number ? sort_index : -1; + while (midRight + 1 < elements) { + sortIndex = GetSortedIndex(++midRight); + currentKey = GetKey(sortIndex); + if (currentKey.GetKeyHashCode() == keyHash) { + if (currentKey == key) { + return sortIndex < propertiesNumber ? sortIndex : -1; } } else { break; diff --git a/runtime/layout_info.cpp b/runtime/layout_info.cpp index 83eeb32242dc2b060b3346a1fddb1951205ef4a8..2294d36e567b64d4d904b9a5c9fe5a611571b08f 100644 --- a/runtime/layout_info.cpp +++ b/runtime/layout_info.cpp @@ -28,84 +28,84 @@ void LayoutInfo::AddKey(const JSThread *thread, [[maybe_unused]] int index, cons SetNumberOfElements(thread, number + 1); SetPropertyInit(thread, number, key, attr); - uint32_t key_hash = key.GetKeyHashCode(); - int insert_index = number; - for (; insert_index > 0; --insert_index) { - JSTaggedValue prev_key = GetSortedKey(insert_index - 1); - if (prev_key.GetKeyHashCode() <= key_hash) { + uint32_t keyHash = key.GetKeyHashCode(); + int insertIndex = number; + for (; insertIndex > 0; --insertIndex) { + JSTaggedValue prevKey = GetSortedKey(insertIndex - 1); + if (prevKey.GetKeyHashCode() <= keyHash) { break; } - SetSortedIndex(thread, insert_index, GetSortedIndex(insert_index - 1)); + SetSortedIndex(thread, insertIndex, GetSortedIndex(insertIndex - 1)); } - SetSortedIndex(thread, insert_index, number); + SetSortedIndex(thread, insertIndex, number); } -void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *key_array) +void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray) { ASSERT(end <= NumberOfElements()); - ASSERT_PRINT(offset + end <= static_cast(key_array->GetLength()), + ASSERT_PRINT(offset + end <= static_cast(keyArray->GetLength()), "key_array capacity is not enough for dictionary"); - int enum_keys = 0; + int enumKeys = 0; for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsString()) { - key_array->Set(thread, enum_keys + offset, key); - enum_keys++; + keyArray->Set(thread, enumKeys + offset, key); + enumKeys++; } } - if (enum_keys < end) { + if (enumKeys < end) { for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsSymbol()) { - key_array->Set(thread, enum_keys + offset, key); - enum_keys++; + keyArray->Set(thread, enumKeys + offset, key); + enumKeys++; } } } } -void LayoutInfo::GetAllKeys([[maybe_unused]] const JSThread *thread, int end, std::vector &key_vector) +void LayoutInfo::GetAllKeys([[maybe_unused]] const JSThread *thread, int end, std::vector &keyVector) { ASSERT(end <= NumberOfElements()); for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsString()) { - key_vector.emplace_back(key); + keyVector.emplace_back(key); } } } -void LayoutInfo::GetAllEnumKeys(const JSThread *thread, int end, int offset, TaggedArray *key_array, uint32_t *keys) +void LayoutInfo::GetAllEnumKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, uint32_t *keys) { ASSERT(end <= NumberOfElements()); - ASSERT_PRINT(offset + end <= static_cast(key_array->GetLength()), + ASSERT_PRINT(offset + end <= static_cast(keyArray->GetLength()), "key_array capacity is not enough for dictionary"); - int enum_keys = 0; + int enumKeys = 0; for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsString() && GetAttr(i).IsEnumerable()) { - key_array->Set(thread, enum_keys + offset, key); - enum_keys++; + keyArray->Set(thread, enumKeys + offset, key); + enumKeys++; } } - *keys += enum_keys; + *keys += enumKeys; } -void LayoutInfo::GetAllNames(const JSThread *thread, int end, const JSHandle &key_array, uint32_t *length) +void LayoutInfo::GetAllNames(const JSThread *thread, int end, const JSHandle &keyArray, uint32_t *length) { - int array_index = 0; + int arrayIndex = 0; for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsString()) { PropertyAttributes attr = GetAttr(i); if (attr.IsEnumerable()) { - key_array->Set(thread, array_index++, key); + keyArray->Set(thread, arrayIndex++, key); } } } - *length += array_index; + *length += arrayIndex; } } // namespace panda::ecmascript diff --git a/runtime/layout_info.h b/runtime/layout_info.h index 1f0148dfcb0bcb4fbc9c58e6186a7726a49fa34b..7a34a532c902018782c3be7b17ccab0d97c5d4ee 100644 --- a/runtime/layout_info.h +++ b/runtime/layout_info.h @@ -62,7 +62,7 @@ public: PropertyAttributes GetAttr(int32_t index) const; JSTaggedValue GetSortedKey(int32_t index) const; uint32_t GetSortedIndex(int32_t index) const; - void SetSortedIndex(const JSThread *thread, int32_t index, int32_t sorted_index); + void SetSortedIndex(const JSThread *thread, int32_t index, int32_t sortedIndex); void AddKey(const JSThread *thread, int32_t index, const JSTaggedValue &key, const PropertyAttributes &attr); inline uint32_t GetLength() const @@ -75,15 +75,15 @@ public: return reinterpret_cast(reinterpret_cast(this) + GetPropertiesOffset()); } - static inline uint32_t ComputeArrayLength(uint32_t properties_number) + static inline uint32_t ComputeArrayLength(uint32_t propertiesNumber) { - return (properties_number << 1U) + ELEMENTS_START_INDEX; + return (propertiesNumber << 1U) + ELEMENTS_START_INDEX; } - static inline uint32_t ComputeGrowCapacity(uint32_t old_capacity) + static inline uint32_t ComputeGrowCapacity(uint32_t oldCapacity) { - uint32_t new_capacity = old_capacity + MIN_PROPERTIES_LENGTH; - return new_capacity > MAX_PROPERTIES_LENGTH ? MAX_PROPERTIES_LENGTH : new_capacity; + uint32_t newCapacity = oldCapacity + MIN_PROPERTIES_LENGTH; + return newCapacity > MAX_PROPERTIES_LENGTH ? MAX_PROPERTIES_LENGTH : newCapacity; } static inline constexpr uint32_t GetPropertiesOffset() @@ -91,13 +91,13 @@ public: return TaggedArray::DATA_OFFSET + ELEMENTS_START_INDEX * JSTaggedValue::TaggedTypeSize(); } - int32_t FindElementWithCache(JSThread *thread, JSHClass *cls, JSTaggedValue key, int32_t properties_number); - int32_t FindElement(JSTaggedValue key, int32_t properties_number); - int32_t BinarySearch(JSTaggedValue key, int32_t properties_number); - void GetAllKeys(const JSThread *thread, int32_t end, int32_t offset, TaggedArray *key_array); - void GetAllKeys(const JSThread *thread, int32_t end, std::vector &key_vector); - void GetAllEnumKeys(const JSThread *thread, int32_t end, int32_t offset, TaggedArray *key_array, uint32_t *keys); - void GetAllNames(const JSThread *thread, int32_t end, const JSHandle &key_array, uint32_t *length); + int32_t FindElementWithCache(JSThread *thread, JSHClass *cls, JSTaggedValue key, int32_t propertiesNumber); + int32_t FindElement(JSTaggedValue key, int32_t propertiesNumber); + int32_t BinarySearch(JSTaggedValue key, int32_t propertiesNumber); + void GetAllKeys(const JSThread *thread, int32_t end, int32_t offset, TaggedArray *keyArray); + void GetAllKeys(const JSThread *thread, int32_t end, std::vector &keyVector); + void GetAllEnumKeys(const JSThread *thread, int32_t end, int32_t offset, TaggedArray *keyArray, uint32_t *keys); + void GetAllNames(const JSThread *thread, int32_t end, const JSHandle &keyArray, uint32_t *length); DECL_DUMP() }; diff --git a/runtime/lexical_env.h b/runtime/lexical_env.h index f676cba3d274d43085aef4de49945c63ab85a3b2..cecdf9b89ea4ff9814434f4a5307d41b9600398b 100644 --- a/runtime/lexical_env.h +++ b/runtime/lexical_env.h @@ -36,9 +36,9 @@ public: return static_cast(JSTaggedValue(object).GetHeapObject()); } - static size_t ComputeSize(uint32_t num_slots) + static size_t ComputeSize(uint32_t numSlots) { - return TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), num_slots + RESERVED_ENV_LENGTH); + return TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), numSlots + RESERVED_ENV_LENGTH); } void SetParentEnv(JSThread *thread, JSTaggedValue value) diff --git a/runtime/linked_hash_table-inl.h b/runtime/linked_hash_table-inl.h index 6b1edf0392cffb564e68407fb2572bebd6107cd1..cb68f709a96413c5dccc084595782f1c0edda1f1 100644 --- a/runtime/linked_hash_table-inl.h +++ b/runtime/linked_hash_table-inl.h @@ -72,9 +72,9 @@ void LinkedHashTable::SetCapacity(const JSThread *thread, i } template -void LinkedHashTable::SetNextTable(const JSThread *thread, JSTaggedValue next_table) +void LinkedHashTable::SetNextTable(const JSThread *thread, JSTaggedValue nextTable) { - Set(thread, NEXT_TABLE_INDEX, next_table); + Set(thread, NEXT_TABLE_INDEX, nextTable); } template @@ -101,12 +101,12 @@ template int LinkedHashTable::GetDeletedElementsAt(int entry) const { ASSERT_PRINT(!GetNextTable().IsUndefined(), "function only execute after rehash"); - int current_entry = entry - 1; - while (current_entry >= 0) { - if (GetKey(current_entry).IsHole()) { - return GetDeletedNum(current_entry); + int currentEntry = entry - 1; + while (currentEntry >= 0) { + if (GetKey(currentEntry).IsHole()) { + return GetDeletedNum(currentEntry); } - current_entry--; + currentEntry--; } return 0; } @@ -165,19 +165,19 @@ JSTaggedValue LinkedHashTable::GetNextEntry(int entry) cons } template -void LinkedHashTable::SetNextEntry(const JSThread *thread, int entry, JSTaggedValue next_entry) +void LinkedHashTable::SetNextEntry(const JSThread *thread, int entry, JSTaggedValue nextEntry) { int index = EntryToIndex(entry) + HashObject::ENTRY_SIZE; - SetElement(thread, index, next_entry); + SetElement(thread, index, nextEntry); } template void LinkedHashTable::InsertNewEntry(const JSThread *thread, int bucket, int entry) { - int bucket_index = BucketToIndex(bucket); - JSTaggedValue previous_entry = GetElement(bucket_index); - SetNextEntry(thread, entry, previous_entry); - SetElement(thread, bucket_index, JSTaggedValue(entry)); + int bucketIndex = BucketToIndex(bucket); + JSTaggedValue previousEntry = GetElement(bucketIndex); + SetNextEntry(thread, entry, previousEntry); + SetElement(thread, bucketIndex, JSTaggedValue(entry)); } template @@ -202,18 +202,18 @@ int LinkedHashTable::FindElement(JSTaggedValue key, int has } // namespace panda::ecmascript template -bool LinkedHashTable::HasSufficientCapacity(int num_of_add_elements) const +bool LinkedHashTable::HasSufficientCapacity(int numOfAddElements) const { - int number_of_elements = NumberOfElements(); - int num_of_del_elements = NumberOfDeletedElements(); + int numberOfElements = NumberOfElements(); + int numOfDelElements = NumberOfDeletedElements(); int capacity = Capacity(); - int nof = number_of_elements + num_of_add_elements; + int nof = numberOfElements + numOfAddElements; // Return true if: // 50% is still free after adding numOfAddElements elements and // at most 50% of the free elements are deleted elements. - if ((nof < capacity) && ((num_of_del_elements <= (capacity - nof) / 2))) { // 2: half - int needed_free = nof / 2; // 2: half - if (nof + needed_free <= capacity) { + if ((nof < capacity) && ((numOfDelElements <= (capacity - nof) / 2))) { // 2: half + int neededFree = nof / 2; // 2: half + if (nof + neededFree <= capacity) { return true; } } @@ -221,12 +221,12 @@ bool LinkedHashTable::HasSufficientCapacity(int num_of_add_ } template -int LinkedHashTable::ComputeCapacity(uint32_t at_least_space_for) +int LinkedHashTable::ComputeCapacity(uint32_t atLeastSpaceFor) { // Add 50% slack to make slot collisions sufficiently unlikely. // See matching computation in HashTable::HasSufficientCapacity(). - uint32_t raw_cap = at_least_space_for + (at_least_space_for >> 1UL); - int capacity = static_cast(helpers::math::GetPowerOfTwoValue32(raw_cap)); + uint32_t rawCap = atLeastSpaceFor + (atLeastSpaceFor >> 1UL); + int capacity = static_cast(helpers::math::GetPowerOfTwoValue32(rawCap)); return (capacity > MIN_CAPACITY) ? capacity : MIN_CAPACITY; } @@ -243,21 +243,21 @@ void LinkedHashTable::RemoveEntry(const JSThread *thread, i } template -int LinkedHashTable::ComputeCapacityWithShrink(int current_capacity, int at_least_space_for) +int LinkedHashTable::ComputeCapacityWithShrink(int currentCapacity, int atLeastSpaceFor) { // Shrink to fit the number of elements if only a quarter of the // capacity is filled with elements. - if (at_least_space_for > (current_capacity / 4)) { // 4: quarter - return current_capacity; + if (atLeastSpaceFor > (currentCapacity / 4)) { // 4: quarter + return currentCapacity; } // Recalculate the smaller capacity actually needed. - int new_capacity = ComputeCapacity(at_least_space_for); - ASSERT_PRINT(new_capacity > at_least_space_for, "new capacity must greater than atLeastSpaceFor"); + int newCapacity = ComputeCapacity(atLeastSpaceFor); + ASSERT_PRINT(newCapacity > atLeastSpaceFor, "new capacity must greater than atLeastSpaceFor"); // Don't go lower than room for MIN_SHRINK_CAPACITY elements. - if (new_capacity < Derived::MIN_SHRINK_CAPACITY) { - return current_capacity; + if (newCapacity < Derived::MIN_SHRINK_CAPACITY) { + return currentCapacity; } - return new_capacity; + return newCapacity; } bool LinkedHashMapObject::IsMatch(JSTaggedValue key, JSTaggedValue other) diff --git a/runtime/linked_hash_table.cpp b/runtime/linked_hash_table.cpp index 6658faaeb78a1928e1923b3f68550ac75a5e4135..8135740a6d709d33c3f25f69c01b9f213cb1d69b 100644 --- a/runtime/linked_hash_table.cpp +++ b/runtime/linked_hash_table.cpp @@ -21,16 +21,16 @@ namespace panda::ecmascript { template -JSHandle LinkedHashTable::Create(const JSThread *thread, JSType table_type, bool is_weak, - int number_of_elements) +JSHandle LinkedHashTable::Create(const JSThread *thread, JSType tableType, bool isWeak, + int numberOfElements) { - ASSERT_PRINT(number_of_elements > 0, "size must be a non-negative integer"); + ASSERT_PRINT(numberOfElements > 0, "size must be a non-negative integer"); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - auto capacity = static_cast(number_of_elements); + auto capacity = static_cast(numberOfElements); ASSERT_PRINT(helpers::math::IsPowerOfTwo(capacity), "capacity must be pow of '2'"); - int length = ELEMENTS_START_INDEX + number_of_elements + number_of_elements * (HashObject::ENTRY_SIZE + 1); + int length = ELEMENTS_START_INDEX + numberOfElements + numberOfElements * (HashObject::ENTRY_SIZE + 1); - auto table = JSHandle(factory->NewLinkedHashTable(length, table_type, is_weak)); + auto table = JSHandle(factory->NewLinkedHashTable(length, tableType, isWeak)); table->SetNumberOfElements(thread, 0); table->SetNumberOfDeletedElements(thread, 0); table->SetCapacity(thread, capacity); @@ -50,37 +50,37 @@ JSHandle LinkedHashTable::Insert(const JSThread *t return table; } - JSHandle new_table = GrowCapacity(thread, table); + JSHandle newTable = GrowCapacity(thread, table); - int bucket = new_table->HashToBucket(hash); - entry = new_table->NumberOfElements() + new_table->NumberOfDeletedElements(); - new_table->InsertNewEntry(thread, bucket, entry); - new_table->SetKey(thread, entry, key.GetTaggedValue()); + int bucket = newTable->HashToBucket(hash); + entry = newTable->NumberOfElements() + newTable->NumberOfDeletedElements(); + newTable->InsertNewEntry(thread, bucket, entry); + newTable->SetKey(thread, entry, key.GetTaggedValue()); // The ENTRY_VALUE_INDEX of LinkedHashSet is 0. SetValue will cause the overwitten key. if (std::is_same_v) { - new_table->SetValue(thread, entry, value.GetTaggedValue()); + newTable->SetValue(thread, entry, value.GetTaggedValue()); } - new_table->SetNumberOfElements(thread, new_table->NumberOfElements() + 1); + newTable->SetNumberOfElements(thread, newTable->NumberOfElements() + 1); - return new_table; + return newTable; } template -void LinkedHashTable::Rehash(const JSThread *thread, const JSHandle &new_table) +void LinkedHashTable::Rehash(const JSThread *thread, const JSHandle &newTable) { - ASSERT_PRINT(*new_table != nullptr && new_table->Capacity() > NumberOfElements(), "can not rehash to new table"); + ASSERT_PRINT(*newTable != nullptr && newTable->Capacity() > NumberOfElements(), "can not rehash to new table"); // Rehash elements to new table - int number_of_all_elements = NumberOfElements() + NumberOfDeletedElements(); - int des_entry = 0; - int current_deleted_elements = 0; - SetNextTable(thread, new_table.GetTaggedValue()); - for (int i = 0; i < number_of_all_elements; i++) { - int from_index = EntryToIndex(i); - JSTaggedValue key = GetElement(from_index); + int numberOfAllElements = NumberOfElements() + NumberOfDeletedElements(); + int desEntry = 0; + int currentDeletedElements = 0; + SetNextTable(thread, newTable.GetTaggedValue()); + for (int i = 0; i < numberOfAllElements; i++) { + int fromIndex = EntryToIndex(i); + JSTaggedValue key = GetElement(fromIndex); if (key.IsHole()) { // store num_of_deleted_element before entry i; it will be used when iterator update. - current_deleted_elements++; - SetDeletedNum(thread, i, JSTaggedValue(current_deleted_elements)); + currentDeletedElements++; + SetDeletedNum(thread, i, JSTaggedValue(currentDeletedElements)); continue; } @@ -89,32 +89,32 @@ void LinkedHashTable::Rehash(const JSThread *thread, const key.RemoveWeakTag(); } - int bucket = new_table->HashToBucket(LinkedHash::Hash(key)); - new_table->InsertNewEntry(thread, bucket, des_entry); - int des_index = new_table->EntryToIndex(des_entry); + int bucket = newTable->HashToBucket(LinkedHash::Hash(key)); + newTable->InsertNewEntry(thread, bucket, desEntry); + int desIndex = newTable->EntryToIndex(desEntry); for (int j = 0; j < HashObject::ENTRY_SIZE; j++) { - new_table->SetElement(thread, des_index + j, GetElement(from_index + j)); + newTable->SetElement(thread, desIndex + j, GetElement(fromIndex + j)); } - des_entry++; + desEntry++; } - new_table->SetNumberOfElements(thread, NumberOfElements()); - new_table->SetNumberOfDeletedElements(thread, 0); + newTable->SetNumberOfElements(thread, NumberOfElements()); + newTable->SetNumberOfDeletedElements(thread, 0); } template JSHandle LinkedHashTable::GrowCapacity(const JSThread *thread, const JSHandle &table, - int number_of_added_elements) + int numberOfAddedElements) { - if (table->HasSufficientCapacity(number_of_added_elements)) { + if (table->HasSufficientCapacity(numberOfAddedElements)) { return table; } - int new_capacity = ComputeCapacity(table->NumberOfElements() + number_of_added_elements); - auto table_class = table->GetClass(); - JSHandle new_table = - Create(thread, table_class->GetObjectType(), table_class->IsWeakContainer(), new_capacity); - table->Rehash(thread, new_table); - return new_table; + int newCapacity = ComputeCapacity(table->NumberOfElements() + numberOfAddedElements); + auto tableClass = table->GetClass(); + JSHandle newTable = + Create(thread, tableClass->GetObjectType(), tableClass->IsWeakContainer(), newCapacity); + table->Rehash(thread, newTable); + return newTable; } template @@ -134,30 +134,30 @@ JSHandle LinkedHashTable::Remove(const JSThread *t template JSHandle LinkedHashTable::Shrink(const JSThread *thread, const JSHandle &table, - int additional_capacity) + int additionalCapacity) { - int new_capacity = ComputeCapacityWithShrink(table->Capacity(), table->NumberOfElements() + additional_capacity); - if (new_capacity == table->Capacity()) { + int newCapacity = ComputeCapacityWithShrink(table->Capacity(), table->NumberOfElements() + additionalCapacity); + if (newCapacity == table->Capacity()) { return table; } - auto table_class = table->GetClass(); - JSHandle new_table = - Create(thread, table_class->GetObjectType(), table_class->IsWeakContainer(), new_capacity); - if (new_table.IsEmpty()) { + auto tableClass = table->GetClass(); + JSHandle newTable = + Create(thread, tableClass->GetObjectType(), tableClass->IsWeakContainer(), newCapacity); + if (newTable.IsEmpty()) { // No enough memory. Use the origin table. return table; } - table->Rehash(thread, new_table); - return new_table; + table->Rehash(thread, newTable); + return newTable; } // LinkedHashMap -JSHandle LinkedHashMap::Create(const JSThread *thread, bool is_weak, int number_of_elements) +JSHandle LinkedHashMap::Create(const JSThread *thread, bool isWeak, int numberOfElements) { - return LinkedHashTable::Create(thread, JSType::LINKED_HASH_MAP, is_weak, - number_of_elements); + return LinkedHashTable::Create(thread, JSType::LINKED_HASH_MAP, isWeak, + numberOfElements); } JSHandle LinkedHashMap::Delete(const JSThread *thread, const JSHandle &obj, @@ -191,26 +191,26 @@ bool LinkedHashMap::Has(JSTaggedValue key, int hash) const void LinkedHashMap::Clear(const JSThread *thread) { - int number_of_elements = NumberOfElements() + NumberOfDeletedElements(); - for (int entry = 0; entry < number_of_elements; entry++) { + int numberOfElements = NumberOfElements() + NumberOfDeletedElements(); + for (int entry = 0; entry < numberOfElements; entry++) { SetKey(thread, entry, JSTaggedValue::Hole()); SetValue(thread, entry, JSTaggedValue::Hole()); } SetNumberOfElements(thread, 0); - SetNumberOfDeletedElements(thread, number_of_elements); + SetNumberOfDeletedElements(thread, numberOfElements); } JSHandle LinkedHashMap::Shrink(const JSThread *thread, const JSHandle &table, - int additional_capacity) + int additionalCapacity) { - return LinkedHashTable::Shrink(thread, table, additional_capacity); + return LinkedHashTable::Shrink(thread, table, additionalCapacity); } // LinkedHashSet -JSHandle LinkedHashSet::Create(const JSThread *thread, bool is_weak, int number_of_elements) +JSHandle LinkedHashSet::Create(const JSThread *thread, bool isWeak, int numberOfElements) { - return LinkedHashTable::Create(thread, JSType::LINKED_HASH_SET, is_weak, - number_of_elements); + return LinkedHashTable::Create(thread, JSType::LINKED_HASH_SET, isWeak, + numberOfElements); } JSHandle LinkedHashSet::Delete(const JSThread *thread, const JSHandle &obj, @@ -234,18 +234,18 @@ bool LinkedHashSet::Has(JSTaggedValue key, int hash) const void LinkedHashSet::Clear(const JSThread *thread) { - int number_of_elements = NumberOfElements() + NumberOfDeletedElements(); - for (int entry = 0; entry < number_of_elements; entry++) { + int numberOfElements = NumberOfElements() + NumberOfDeletedElements(); + for (int entry = 0; entry < numberOfElements; entry++) { SetKey(thread, entry, JSTaggedValue::Hole()); } SetNumberOfElements(thread, 0); - SetNumberOfDeletedElements(thread, number_of_elements); + SetNumberOfDeletedElements(thread, numberOfElements); } JSHandle LinkedHashSet::Shrink(const JSThread *thread, const JSHandle &table, - int additional_capacity) + int additionalCapacity) { - return LinkedHashTable::Shrink(thread, table, additional_capacity); + return LinkedHashTable::Shrink(thread, table, additionalCapacity); } int LinkedHash::Hash(JSTaggedValue key) @@ -254,25 +254,25 @@ int LinkedHash::Hash(JSTaggedValue key) key = JSTaggedValue(0); } if (key.IsSymbol()) { - auto symbol_string = JSSymbol::Cast(key.GetHeapObject()); - return static_cast(symbol_string->GetHashField()).GetInt(); + auto symbolString = JSSymbol::Cast(key.GetHeapObject()); + return static_cast(symbolString->GetHashField()).GetInt(); } if (key.IsString()) { - auto key_string = reinterpret_cast(key.GetHeapObject()); - return key_string->GetHashcode(); + auto keyString = reinterpret_cast(key.GetHeapObject()); + return keyString->GetHashcode(); } if (key.IsECMAObject()) { int32_t hash = ECMAObject::Cast(key.GetHeapObject())->GetHash(); if (hash == 0) { - uint64_t key_value = key.GetRawData(); - hash = GetHash32(reinterpret_cast(&key_value), sizeof(key_value) / sizeof(uint8_t)); + uint64_t keyValue = key.GetRawData(); + hash = GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); ECMAObject::Cast(key.GetHeapObject())->SetHash(hash); } return hash; } // Int, Double, Special and HeapObject(except symbol and string) - uint64_t key_value = key.GetRawData(); - return GetHash32(reinterpret_cast(&key_value), sizeof(key_value) / sizeof(uint8_t)); + uint64_t keyValue = key.GetRawData(); + return GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); } } // namespace panda::ecmascript diff --git a/runtime/linked_hash_table.h b/runtime/linked_hash_table.h index be67af0e416d4ceea1df6cbaa243309977808a46..db788841b4f3129642264de193de789d884df4e4 100644 --- a/runtime/linked_hash_table.h +++ b/runtime/linked_hash_table.h @@ -42,31 +42,30 @@ public: // Don't shrink a HashTable below this capacity. static const int MIN_SHRINK_CAPACITY = 16; - static JSHandle Create(const JSThread *thread, JSType table_type, bool is_weak, int number_of_elements); + static JSHandle Create(const JSThread *thread, JSType tableType, bool isWeak, int numberOfElements); static JSHandle Insert(const JSThread *thread, const JSHandle &table, const JSHandle &key, const JSHandle &value); static JSHandle GrowCapacity(const JSThread *thread, const JSHandle &table, - int number_of_added_elements = 1); + int numberOfAddedElements = 1); static JSHandle Remove(const JSThread *thread, const JSHandle &table, const JSHandle &key); - static JSHandle Shrink(const JSThread *thread, const JSHandle &table, - int additional_capacity = 0); + static JSHandle Shrink(const JSThread *thread, const JSHandle &table, int additionalCapacity = 0); - void Rehash(const JSThread *thread, const JSHandle &new_table); + void Rehash(const JSThread *thread, const JSHandle &newTable); - inline bool HasSufficientCapacity(int num_of_add_elements) const; + inline bool HasSufficientCapacity(int numOfAddElements) const; inline int FindElement(JSTaggedValue key, int hash) const; inline void RemoveEntry(const JSThread *thread, int entry); - inline static int ComputeCapacity(uint32_t at_least_space_for); + inline static int ComputeCapacity(uint32_t atLeastSpaceFor); - inline static int ComputeCapacityWithShrink(int current_capacity, int at_least_space_for); + inline static int ComputeCapacityWithShrink(int currentCapacity, int atLeastSpaceFor); inline int NumberOfElements() const; @@ -91,7 +90,7 @@ public: inline JSTaggedValue GetNextTable() const; - inline void SetNextTable(const JSThread *thread, JSTaggedValue next_table); + inline void SetNextTable(const JSThread *thread, JSTaggedValue nextTable); inline int GetDeletedElementsAt(int entry) const; @@ -106,7 +105,7 @@ protected: inline JSTaggedValue GetNextEntry(int entry) const; - inline void SetNextEntry(const JSThread *thread, int entry, JSTaggedValue next_entry); + inline void SetNextEntry(const JSThread *thread, int entry, JSTaggedValue nextEntry); inline uint32_t HashToBucket(uint32_t hash) const; @@ -148,13 +147,13 @@ public: return static_cast(obj); } - static JSHandle Create(const JSThread *thread, int number_of_elements) + static JSHandle Create(const JSThread *thread, int numberOfElements) { - return Create(thread, false, number_of_elements); + return Create(thread, false, numberOfElements); } - static JSHandle Create(const JSThread *thread, bool is_weak = false, - int number_of_elements = MIN_CAPACITY); + static JSHandle Create(const JSThread *thread, bool isWeak = false, + int numberOfElements = MIN_CAPACITY); static JSHandle Delete(const JSThread *thread, const JSHandle &obj, const JSHandle &key); @@ -165,7 +164,7 @@ public: JSTaggedValue Get(JSTaggedValue key, int hash) const; static JSHandle Shrink(const JSThread *thread, const JSHandle &table, - int additional_capacity = 0); + int additionalCapacity = 0); bool Has(JSTaggedValue key, int hash) const; @@ -197,13 +196,13 @@ public: return static_cast(obj); } - static JSHandle Create(const JSThread *thread, int number_of_elements) + static JSHandle Create(const JSThread *thread, int numberOfElements) { - return Create(thread, false, number_of_elements); + return Create(thread, false, numberOfElements); } - static JSHandle Create(const JSThread *thread, bool is_weak = false, - int number_of_elements = MIN_CAPACITY); + static JSHandle Create(const JSThread *thread, bool isWeak = false, + int numberOfElements = MIN_CAPACITY); static JSHandle Delete(const JSThread *thread, const JSHandle &obj, const JSHandle &key); @@ -212,7 +211,7 @@ public: const JSHandle &key); static JSHandle Shrink(const JSThread *thread, const JSHandle &table, - int additional_capacity = 0); + int additionalCapacity = 0); bool Has(JSTaggedValue key, int hash) const; diff --git a/runtime/literal_data_extractor.cpp b/runtime/literal_data_extractor.cpp index 393ed807527c5c0a53ed5d823d9ce67a5e5182af..a711467fabbd9bb7a79fb44374833ae7d54bc69e 100644 --- a/runtime/literal_data_extractor.cpp +++ b/runtime/literal_data_extractor.cpp @@ -34,8 +34,8 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); LOG_ECMA(DEBUG) << "Panda File" << pf->GetFilename(); - panda_file::File::EntityId literal_arrays_id = pf->GetLiteralArraysId(); - panda_file::LiteralDataAccessor lda(*pf, literal_arrays_id); + panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId(); + panda_file::LiteralDataAccessor lda(*pf, literalArraysId); uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half elements.Update(factory->NewTaggedArray(num, JSTaggedValue::Hole(), panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT) @@ -45,7 +45,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file .GetTaggedValue()); uint32_t epos = 0; uint32_t ppos = 0; - const uint8_t pair_size = 2; + const uint8_t pairSize = 2; lda.EnumerateLiteralVals(index, [elements, properties, &epos, &ppos, factory, thread, pft, pf](const LiteralValue &value, const LiteralTag &tag) { JSTaggedValue jt = JSTaggedValue::Null(); @@ -65,41 +65,41 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file } case LiteralTag::STRING: { StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get(value))); - EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii); + EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16Length, sd.isAscii); jt = JSTaggedValue(str); uint32_t idx = 0; - if (JSTaggedValue::ToElementIndex(jt, &idx) && ppos % pair_size == 0) { + if (JSTaggedValue::ToElementIndex(jt, &idx) && ppos % pairSize == 0) { flag = true; } break; } case LiteralTag::METHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = pft->DefineMethodInLiteral(method_id, FunctionKind::NORMAL_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = pft->DefineMethodInLiteral(methodId, FunctionKind::NORMAL_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::GENERATORMETHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = pft->DefineMethodInLiteral(method_id, FunctionKind::GENERATOR_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = pft->DefineMethodInLiteral(methodId, FunctionKind::GENERATOR_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::ASYNCGENERATORMETHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = - pft->DefineMethodInLiteral(method_id, FunctionKind::ASYNC_GENERATOR_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = + pft->DefineMethodInLiteral(methodId, FunctionKind::ASYNC_GENERATOR_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::ASYNCMETHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = pft->DefineMethodInLiteral(method_id, FunctionKind::ASYNC_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = pft->DefineMethodInLiteral(methodId, FunctionKind::ASYNC_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::ACCESSOR: { @@ -116,7 +116,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file break; } } - if (epos % pair_size == 0 && !flag) { + if (epos % pairSize == 0 && !flag) { properties->Set(thread, ppos++, jt); } else { elements->Set(thread, epos++, jt); @@ -130,8 +130,8 @@ JSHandle LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); LOG_ECMA(DEBUG) << "Panda File" << pf->GetFilename(); - panda_file::File::EntityId literal_arrays_id = pf->GetLiteralArraysId(); - panda_file::LiteralDataAccessor lda(*pf, literal_arrays_id); + panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId(); + panda_file::LiteralDataAccessor lda(*pf, literalArraysId); uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half JSHandle literals = @@ -156,37 +156,37 @@ JSHandle LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, } case LiteralTag::STRING: { StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get(value))); - EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii); + EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16Length, sd.isAscii); jt = JSTaggedValue(str); break; } case LiteralTag::METHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = pft->DefineMethodInLiteral(method_id, FunctionKind::NORMAL_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = pft->DefineMethodInLiteral(methodId, FunctionKind::NORMAL_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::GENERATORMETHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = pft->DefineMethodInLiteral(method_id, FunctionKind::GENERATOR_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = pft->DefineMethodInLiteral(methodId, FunctionKind::GENERATOR_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::ASYNCGENERATORMETHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = - pft->DefineMethodInLiteral(method_id, FunctionKind::ASYNC_GENERATOR_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = + pft->DefineMethodInLiteral(methodId, FunctionKind::ASYNC_GENERATOR_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::ASYNCMETHOD: { ASSERT(pft != nullptr); - uint32_t method_id = std::get(value); - JSHandle js_func = pft->DefineMethodInLiteral(method_id, FunctionKind::ASYNC_FUNCTION); - jt = js_func.GetTaggedValue(); + uint32_t methodId = std::get(value); + JSHandle jsFunc = pft->DefineMethodInLiteral(methodId, FunctionKind::ASYNC_FUNCTION); + jt = jsFunc.GetTaggedValue(); break; } case LiteralTag::ACCESSOR: { diff --git a/runtime/mem/barriers.h b/runtime/mem/barriers.h index 7049e047d1277fa105854f8713ac66c91d59a304..74a183e61212b8d6240c1a3c6da228e2933ce743 100644 --- a/runtime/mem/barriers.h +++ b/runtime/mem/barriers.h @@ -20,10 +20,10 @@ namespace panda::ecmascript { class Barriers { public: template - static inline bool AtomicSetDynPrimitive(volatile void *obj, size_t offset, T old_value, T value) + static inline bool AtomicSetDynPrimitive(volatile void *obj, size_t offset, T oldValue, T value) { - volatile auto atomic_field = reinterpret_cast *>(ToUintPtr(obj) + offset); - return std::atomic_compare_exchange_strong_explicit(atomic_field, &old_value, value, std::memory_order_release, + volatile auto atomicField = reinterpret_cast *>(ToUintPtr(obj) + offset); + return std::atomic_compare_exchange_strong_explicit(atomicField, &oldValue, value, std::memory_order_release, std::memory_order_relaxed); } diff --git a/runtime/mem/ecma_reference_processor.cpp b/runtime/mem/ecma_reference_processor.cpp index ca91e36890a5ed9472b68c4ebc095ae410d7ea1c..3847e9cf2d3641cba9a00b167348c93107f4c6b0 100644 --- a/runtime/mem/ecma_reference_processor.cpp +++ b/runtime/mem/ecma_reference_processor.cpp @@ -45,8 +45,8 @@ bool EnumerateArrayElements(const panda::ecmascript::TaggedArray *array, const C template bool EnumerateKeys(Container *container, const Callback &cb) { - int total_elements = container->NumberOfElements() + container->NumberOfDeletedElements(); - for (int i = 0; i < total_elements; ++i) { + int totalElements = container->NumberOfElements() + container->NumberOfDeletedElements(); + for (int i = 0; i < totalElements; ++i) { panda::ecmascript::JSTaggedValue key = container->GetKey(i); if (key.IsHole()) { continue; @@ -59,8 +59,8 @@ bool EnumerateKeys(Container *container, const Callback &cb) return false; } -bool EcmaReferenceProcessor::IsReference([[maybe_unused]] const BaseClass *base_cls, const ObjectHeader *ref, - const ReferenceCheckPredicateT &ref_pred) const +bool EcmaReferenceProcessor::IsReference([[maybe_unused]] const BaseClass *baseCls, const ObjectHeader *ref, + const ReferenceCheckPredicateT &refPred) const { auto phase = gc_->GetGCPhase(); ASSERT(IsMarking(phase)); @@ -76,58 +76,57 @@ bool EcmaReferenceProcessor::IsReference([[maybe_unused]] const BaseClass *base_ if (!hcls->IsWeakContainer()) { return false; } - auto is_reference_checker = [this, &ref_pred](int /* unused */, ObjectHeader *key) { - return ref_pred(key) && !gc_->IsMarked(key); + auto isReferenceChecker = [this, &refPred](int /* unused */, ObjectHeader *key) { + return refPred(key) && !gc_->IsMarked(key); }; - auto object_type = hcls->GetObjectType(); - switch (object_type) { + auto objectType = hcls->GetObjectType(); + switch (objectType) { case panda::ecmascript::JSType::TAGGED_ARRAY: // Weak tagged array is used for inline caches. // It is reasonable to collect IC only in OOM case else it leads // to big perf degradation. if (gc_->GetLastGCCause() == GCTaskCause::OOM_CAUSE) { return EnumerateArrayElements(static_cast(ref), - is_reference_checker); + isReferenceChecker); } break; case panda::ecmascript::JSType::JS_WEAK_REF: { panda::ecmascript::JSTaggedValue referent = static_cast(ref)->GetReferent(); - return referent.IsHeapObject() ? is_reference_checker(0, referent.GetRawHeapObject()) : false; + return referent.IsHeapObject() ? isReferenceChecker(0, referent.GetRawHeapObject()) : false; } case panda::ecmascript::JSType::LINKED_HASH_MAP: - return EnumerateKeys(static_cast(ref), is_reference_checker); + return EnumerateKeys(static_cast(ref), isReferenceChecker); case panda::ecmascript::JSType::LINKED_HASH_SET: - return EnumerateKeys(static_cast(ref), is_reference_checker); + return EnumerateKeys(static_cast(ref), isReferenceChecker); default: LOG(FATAL, REF_PROC) << "Unknown weak container"; } return false; } -void EcmaReferenceProcessor::HandleReference([[maybe_unused]] GC *gc, - [[maybe_unused]] GCMarkingStackType *objects_stack, - [[maybe_unused]] const BaseClass *base_class, const ObjectHeader *object, +void EcmaReferenceProcessor::HandleReference([[maybe_unused]] GC *gc, [[maybe_unused]] GCMarkingStackType *objectsStack, + [[maybe_unused]] const BaseClass *baseClass, const ObjectHeader *object, [[maybe_unused]] const ReferenceProcessPredicateT &pred) { - os::memory::LockHolder lock(weak_ref_lock_); - dyn_weak_references_.insert(const_cast(object)); + os::memory::LockHolder lock(weakRefLock_); + dynWeakReferences_.insert(const_cast(object)); } void EcmaReferenceProcessor::ProcessReferences([[maybe_unused]] bool concurrent, - [[maybe_unused]] bool clear_soft_references, - [[maybe_unused]] GCPhase gc_phase, + [[maybe_unused]] bool clearSoftReferences, + [[maybe_unused]] GCPhase gcPhase, const mem::GC::ReferenceClearPredicateT &pred) { - os::memory::LockHolder lock(weak_ref_lock_); + os::memory::LockHolder lock(weakRefLock_); panda::ecmascript::JSThread *thread = vm_->GetAssociatedJSThread(); - while (!dyn_weak_references_.empty()) { - ObjectHeader *reference = *dyn_weak_references_.begin(); - dyn_weak_references_.erase(*dyn_weak_references_.begin()); + while (!dynWeakReferences_.empty()) { + ObjectHeader *reference = *dynWeakReferences_.begin(); + dynWeakReferences_.erase(*dynWeakReferences_.begin()); auto *hcls = panda::ecmascript::JSHClass::FromHClass(reference->ClassAddr()); ASSERT(hcls->IsWeakContainer()); - auto object_type = hcls->GetObjectType(); - if (object_type == panda::ecmascript::JSType::TAGGED_ARRAY) { + auto objectType = hcls->GetObjectType(); + if (objectType == panda::ecmascript::JSType::TAGGED_ARRAY) { auto *array = static_cast(reference); auto handler = [this, array](uint32_t index, ObjectHeader *elem) { if (!gc_->IsMarked(elem)) { @@ -138,37 +137,37 @@ void EcmaReferenceProcessor::ProcessReferences([[maybe_unused]] bool concurrent, return false; }; EnumerateArrayElements(array, handler); - } else if (object_type == panda::ecmascript::JSType::JS_WEAK_REF) { + } else if (objectType == panda::ecmascript::JSType::JS_WEAK_REF) { auto *ref = static_cast(reference); ASSERT(ref->GetReferent().IsHeapObject()); if (!gc_->IsMarked(ref->GetReferent().GetRawHeapObject())) { ObjectAccessor::SetDynValueWithoutBarrier(ref, panda::ecmascript::JSWeakRef::GetReferentOffset(), panda::ecmascript::JSTaggedValue::Undefined().GetRawData()); } - } else if (object_type == panda::ecmascript::JSType::LINKED_HASH_MAP) { + } else if (objectType == panda::ecmascript::JSType::LINKED_HASH_MAP) { auto *map = static_cast(reference); - auto map_handler = [this, map, thread](int index, ObjectHeader *key) { + auto mapHandler = [this, map, thread](int index, ObjectHeader *key) { if (!gc_->IsMarked(key)) { map->RemoveEntry(thread, index); } return false; }; - EnumerateKeys(map, map_handler); - } else if (object_type == panda::ecmascript::JSType::LINKED_HASH_SET) { + EnumerateKeys(map, mapHandler); + } else if (objectType == panda::ecmascript::JSType::LINKED_HASH_SET) { auto *set = static_cast(reference); - auto set_handler = [this, set, thread](int index, ObjectHeader *key) { + auto setHandler = [this, set, thread](int index, ObjectHeader *key) { if (!gc_->IsMarked(key)) { set->RemoveEntry(thread, index); } return false; }; - EnumerateKeys(set, set_handler); + EnumerateKeys(set, setHandler); } else { LOG(FATAL, REF_PROC) << "Unknown weak container"; } } - panda::ecmascript::WeakRootVisitor gc_update_weak = + panda::ecmascript::WeakRootVisitor gcUpdateWeak = [this, pred](panda::ecmascript::TaggedObject *header) -> panda::ecmascript::TaggedObject * { if (pred(header) && !gc_->IsMarked(header)) { return nullptr; @@ -176,7 +175,7 @@ void EcmaReferenceProcessor::ProcessReferences([[maybe_unused]] bool concurrent, return header; }; - vm_->ProcessReferences(gc_update_weak); + vm_->ProcessReferences(gcUpdateWeak); } } // namespace panda::mem::ecmascript diff --git a/runtime/mem/ecma_reference_processor.h b/runtime/mem/ecma_reference_processor.h index b1c8c60fdaa2353b23a9c060d44079dc84701837..1e1af1f32e1b0859077511fc55310aa46627b99a 100644 --- a/runtime/mem/ecma_reference_processor.h +++ b/runtime/mem/ecma_reference_processor.h @@ -38,13 +38,13 @@ class EcmaReferenceProcessor : public panda::mem::ReferenceProcessor { public: explicit EcmaReferenceProcessor(panda::ecmascript::EcmaVM *vm); - bool IsReference(const BaseClass *base_cls, const ObjectHeader *ref, - const ReferenceCheckPredicateT &ref_pred) const override; + bool IsReference(const BaseClass *baseCls, const ObjectHeader *ref, + const ReferenceCheckPredicateT &refPred) const override; - void HandleReference(GC *gc, GCMarkingStackType *objects_stack, const BaseClass *base_class, + void HandleReference(GC *gc, GCMarkingStackType *objectsStack, const BaseClass *baseClass, const ObjectHeader *object, const ReferenceProcessPredicateT &pred) override; - void ProcessReferences(bool concurrent, bool clear_soft_references, GCPhase gc_phase, + void ProcessReferences(bool concurrent, bool clearSoftReferences, GCPhase gcPhase, const mem::GC::ReferenceClearPredicateT &pred) override; panda::mem::Reference *CollectClearedReferences() override @@ -52,25 +52,25 @@ public: return nullptr; } - void ScheduleForEnqueue([[maybe_unused]] Reference *cleared_references) override + void ScheduleForEnqueue([[maybe_unused]] Reference *clearedReferences) override { UNREACHABLE(); } - void Enqueue([[maybe_unused]] panda::mem::Reference *cleared_references) override + void Enqueue([[maybe_unused]] panda::mem::Reference *clearedReferences) override { UNREACHABLE(); } size_t GetReferenceQueueSize() const override { - os::memory::LockHolder lock(weak_ref_lock_); - return dyn_weak_references_.size(); + os::memory::LockHolder lock(weakRefLock_); + return dynWeakReferences_.size(); } private: - mutable os::memory::Mutex weak_ref_lock_; - PandaUnorderedSet dyn_weak_references_ GUARDED_BY(weak_ref_lock_); + mutable os::memory::Mutex weakRefLock_; + PandaUnorderedSet dynWeakReferences_ GUARDED_BY(weakRefLock_); panda::ecmascript::EcmaVM *vm_; GC *gc_; }; diff --git a/runtime/mem/ecma_string.h b/runtime/mem/ecma_string.h index 3e80c10716f8b73da4f8887123856e7b59d2eb5b..384806a67b31b01b72393e97f3ff7f1392c10224 100644 --- a/runtime/mem/ecma_string.h +++ b/runtime/mem/ecma_string.h @@ -40,10 +40,10 @@ std::enable_if_t, PandaString> ToPandaString(T number) if (number == 0) { return PandaString("0"); } - bool is_neg = false; + bool isNeg = false; if (number < 0) { number = -number; - is_neg = true; + isNeg = true; } static constexpr uint32_t BUFF_SIZE = std::numeric_limits::digits10 + 3; // 3: Reserved for sign bit and '\0'. @@ -56,7 +56,7 @@ std::enable_if_t, PandaString> ToPandaString(T number) // NOLINTNEXTLINE(readability-magic-numbers) number /= 10; // 10 : decimal } - if (is_neg) { + if (isNeg) { buf[--position] = '-'; } return PandaString(&buf[position]); diff --git a/runtime/mem/mem_manager-inl.h b/runtime/mem/mem_manager-inl.h index e61d31676224fdedd1fd62b190a1bb86857dce60..44dc0252c30d190b5a8ac7f2448f778003372703 100644 --- a/runtime/mem/mem_manager-inl.h +++ b/runtime/mem/mem_manager-inl.h @@ -31,9 +31,9 @@ TaggedObject *MemManager::AllocateYoungGenerationOrHugeObject(JSHClass *hclass) } TaggedObject *MemManager::AllocateYoungGenerationOrHugeObject(JSHClass *hclass, size_t size, - mem::ObjectAllocatorBase::ObjMemInitPolicy obj_init) + mem::ObjectAllocatorBase::ObjMemInitPolicy objInit) { - auto object = heap_manager_->AllocateObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_, obj_init); + auto object = heapManager_->AllocateObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_, objInit); // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) return TaggedObject::Cast(object); } @@ -47,10 +47,10 @@ TaggedObject *MemManager::AllocateNonMovableOrHugeObject(JSHClass *hclass, size_ { ObjectHeader *object = nullptr; if (hclass == nullptr) { - object = heap_manager_->AllocateNonMovableObject(nullptr, size, TAGGED_OBJECT_ALIGNMENT, thread_); + object = heapManager_->AllocateNonMovableObject(nullptr, size, TAGGED_OBJECT_ALIGNMENT, thread_); } else { object = - heap_manager_->AllocateNonMovableObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_); + heapManager_->AllocateNonMovableObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_); } // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) return TaggedObject::Cast(object); @@ -69,14 +69,14 @@ TaggedObject *MemManager::AllocateNonMovableOrHugeObject(JSHClass *hclass) TaggedObject *MemManager::AllocateOldGenerationOrHugeObject(JSHClass *hclass, size_t size) { - auto object = heap_manager_->AllocateObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_); + auto object = heapManager_->AllocateObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_); // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) return TaggedObject::Cast(object); } TaggedObject *MemManager::AllocateHugeObject(JSHClass *hclass, size_t size) { - auto object = heap_manager_->AllocateObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_); + auto object = heapManager_->AllocateObject(hclass->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread_); // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) return TaggedObject::Cast(object); } diff --git a/runtime/mem/mem_manager.cpp b/runtime/mem/mem_manager.cpp index 0ab4753e01020a26619885a3242675168c8d40c8..0ea752c65ad8f82cde25fc6e36fcc195f2023fb4 100644 --- a/runtime/mem/mem_manager.cpp +++ b/runtime/mem/mem_manager.cpp @@ -18,7 +18,7 @@ namespace panda::ecmascript { MemManager::MemManager(EcmaVM *vm) { - heap_manager_ = vm->GetHeapManager(); + heapManager_ = vm->GetHeapManager(); thread_ = vm->GetAssociatedJSThread(); } } // namespace panda::ecmascript diff --git a/runtime/mem/mem_manager.h b/runtime/mem/mem_manager.h index 5cda140e9d03a1b5016873795bae8c22c93c5de8..0bb77b50ba48fe293eaa56924ff5d82541cceae7 100644 --- a/runtime/mem/mem_manager.h +++ b/runtime/mem/mem_manager.h @@ -31,7 +31,7 @@ public: inline TaggedObject *AllocateYoungGenerationOrHugeObject(JSHClass *hclass); inline TaggedObject *AllocateYoungGenerationOrHugeObject( JSHClass *hclass, size_t size, - mem::ObjectAllocatorBase::ObjMemInitPolicy obj_init = mem::ObjectAllocatorBase::ObjMemInitPolicy::REQUIRE_INIT); + mem::ObjectAllocatorBase::ObjMemInitPolicy objInit = mem::ObjectAllocatorBase::ObjMemInitPolicy::REQUIRE_INIT); inline TaggedObject *AllocateNonMovableOrHugeObject(JSHClass *hclass, size_t size); inline TaggedObject *AllocateDynClassClass(JSHClass *hclass, size_t size); inline TaggedObject *AllocateNonMovableOrHugeObject(JSHClass *hclass); @@ -41,7 +41,7 @@ public: inline void SetClass(TaggedObject *header, JSHClass *hclass); private: - mem::HeapManager *heap_manager_; + mem::HeapManager *heapManager_; ManagedThread *thread_; }; } // namespace panda::ecmascript diff --git a/runtime/mem/object_xray-inl.h b/runtime/mem/object_xray-inl.h index 406ef577a0ca04ed4448e41b930478224533cddc..548fbc6c53c8ad3cedc9c0ca4d26b3473f086fba 100644 --- a/runtime/mem/object_xray-inl.h +++ b/runtime/mem/object_xray-inl.h @@ -65,10 +65,10 @@ #include "plugins/ecmascript/runtime/mem/mem.h" namespace panda::ecmascript { -void ObjectXRay::VisitVMRoots(const RootVisitor &visitor, const RootRangeVisitor &range_visitor) const +void ObjectXRay::VisitVMRoots(const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor) const { - ecma_vm_->Iterate(visitor); - ecma_vm_->GetJSThread()->Iterate(visitor, range_visitor); + ecmaVm_->Iterate(visitor); + ecmaVm_->GetJSThread()->Iterate(visitor, rangeVisitor); } } // namespace panda::ecmascript diff --git a/runtime/mem/object_xray.h b/runtime/mem/object_xray.h index 9d855f6790dad973f7e89cb8232a5fee8691c259..5a2ba405aa2edd09c4127ef99527d878adba18b5 100644 --- a/runtime/mem/object_xray.h +++ b/runtime/mem/object_xray.h @@ -44,16 +44,16 @@ using WeakRootVisitor = std::function; class ObjectXRay { public: - explicit ObjectXRay(EcmaVM *ecma_vm) : ecma_vm_(ecma_vm) {} + explicit ObjectXRay(EcmaVM *ecmaVm) : ecmaVm_(ecmaVm) {} ~ObjectXRay() = default; - inline void VisitVMRoots(const RootVisitor &visitor, const RootRangeVisitor &range_visitor) const; + inline void VisitVMRoots(const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor) const; DEFAULT_MOVE_SEMANTIC(ObjectXRay); DEFAULT_COPY_SEMANTIC(ObjectXRay); private: - EcmaVM *ecma_vm_ {nullptr}; + EcmaVM *ecmaVm_ {nullptr}; }; } // namespace panda::ecmascript diff --git a/runtime/mem/slots.h b/runtime/mem/slots.h index f13a8b54256a29f545060ff5cd6affa05cefafcb..6c2f075f16a5b4381fd740f9f49111acfbd0baed 100644 --- a/runtime/mem/slots.h +++ b/runtime/mem/slots.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class ObjectSlot { public: - explicit ObjectSlot(uintptr_t slot_addr) : slot_address_(slot_addr) {} + explicit ObjectSlot(uintptr_t slotAddr) : slotAddress_(slotAddr) {} ~ObjectSlot() = default; DEFAULT_COPY_SEMANTIC(ObjectSlot); @@ -36,7 +36,7 @@ public: void Update(JSTaggedType value) { // NOLINTNEXTLINE(clang-analyzer-core.NullDereference) - *reinterpret_cast(slot_address_) = value; + *reinterpret_cast(slotAddress_) = value; } TaggedObject *GetTaggedObjectHeader() const @@ -47,12 +47,12 @@ public: JSTaggedType GetTaggedType() const { // NOLINTNEXTLINE(clang-analyzer-core.NullDereference) - return *reinterpret_cast(slot_address_); + return *reinterpret_cast(slotAddress_); } ObjectSlot &operator++() { - slot_address_ += sizeof(JSTaggedType); + slotAddress_ += sizeof(JSTaggedType); return *this; } @@ -60,42 +60,42 @@ public: ObjectSlot operator++(int) { ObjectSlot ret = *this; - slot_address_ += sizeof(JSTaggedType); + slotAddress_ += sizeof(JSTaggedType); return ret; } uintptr_t SlotAddress() const { - return slot_address_; + return slotAddress_; } bool operator<(const ObjectSlot &other) const { - return slot_address_ < other.slot_address_; + return slotAddress_ < other.slotAddress_; } bool operator<=(const ObjectSlot &other) const { - return slot_address_ <= other.slot_address_; + return slotAddress_ <= other.slotAddress_; } bool operator>(const ObjectSlot &other) const { - return slot_address_ > other.slot_address_; + return slotAddress_ > other.slotAddress_; } bool operator>=(const ObjectSlot &other) const { - return slot_address_ >= other.slot_address_; + return slotAddress_ >= other.slotAddress_; } bool operator==(const ObjectSlot &other) const { - return slot_address_ == other.slot_address_; + return slotAddress_ == other.slotAddress_; } bool operator!=(const ObjectSlot &other) const { - return slot_address_ != other.slot_address_; + return slotAddress_ != other.slotAddress_; } private: - uintptr_t slot_address_; + uintptr_t slotAddress_; }; } // namespace panda::ecmascript diff --git a/runtime/message_string.cpp b/runtime/message_string.cpp index 95bc056a881e370b3d2c1812659c4534db8cfdc8..00c619ad828b4122ac434252cda148c945984088 100644 --- a/runtime/message_string.cpp +++ b/runtime/message_string.cpp @@ -19,7 +19,7 @@ namespace panda::ecmascript { // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) -static std::array G_MESSAGE_STRING = { +static std::array g_gMessageString = { // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DEF_MESSAGE_ID(name, string) #string, MESSAGE_STRING_LIST(DEF_MESSAGE_ID) @@ -29,6 +29,6 @@ static std::array G_MESSAGE_STRIN const std::string &MessageString::GetMessageString(int id) { ASSERT(id < MessageString::MAX_MESSAGE_COUNT); - return G_MESSAGE_STRING[id]; + return g_gMessageString[id]; } } // namespace panda::ecmascript \ No newline at end of file diff --git a/runtime/napi/include/jsnapi.h b/runtime/napi/include/jsnapi.h index 41c762f17c49a4c307efd33739e5e239533dbafe..fc396486117cb5f9c27b1c3c2322058883a35ebc 100644 --- a/runtime/napi/include/jsnapi.h +++ b/runtime/napi/include/jsnapi.h @@ -214,9 +214,9 @@ protected: inline LocalScope(const EcmaVM *vm, JSTaggedType value); private: - void *prev_next_ = nullptr; - void *prev_end_ = nullptr; - int prev_handle_storage_index_ {-1}; + void *prevNext_ = nullptr; + void *prevEnd_ = nullptr; + int prevHandleStorageIndex_ {-1}; void *thread_ = nullptr; }; @@ -231,15 +231,15 @@ public: template inline Local Escape(Local current) { - ASSERT(!already_escape_); - already_escape_ = true; - *(reinterpret_cast(escape_handle_)) = **current; - return Local(escape_handle_); + ASSERT(!alreadyEscape_); + alreadyEscape_ = true; + *(reinterpret_cast(escapeHandle_)) = **current; + return Local(escapeHandle_); } private: - bool already_escape_ = false; - uintptr_t escape_handle_ = 0U; + bool alreadyEscape_ = false; + uintptr_t escapeHandle_ = 0U; }; class PUBLIC_API JSExecutionScope { @@ -250,8 +250,8 @@ public: ECMA_DISALLOW_MOVE(JSExecutionScope); private: - void *last_current_thread_ = nullptr; - bool is_revert_ = false; + void *lastCurrentThread_ = nullptr; + bool isRevert_ = false; }; class PUBLIC_API JSValueRef { @@ -385,8 +385,8 @@ public: using NativePointerCallback = void (*)(void *value, void *hint); class PUBLIC_API NativePointerRef : public JSValueRef { public: - static Local New(const EcmaVM *vm, void *native_pointer); - static Local New(const EcmaVM *vm, void *native_pointer, NativePointerCallback call_back, + static Local New(const EcmaVM *vm, void *nativePointer); + static Local New(const EcmaVM *vm, void *nativePointer, NativePointerCallback callBack, void *data); void *Value(); }; @@ -404,9 +404,9 @@ public: writable_(w), enumerable_(e), configurable_(c), - has_writable_(true), - has_enumerable_(true), - has_configurable_(true) + hasWritable_(true), + hasEnumerable_(true), + hasConfigurable_(true) { } ~PropertyAttribute() = default; @@ -418,7 +418,7 @@ public: void SetWritable(bool flag) { writable_ = flag; - has_writable_ = true; + hasWritable_ = true; } bool IsEnumerable() const { @@ -427,7 +427,7 @@ public: void SetEnumerable(bool flag) { enumerable_ = flag; - has_enumerable_ = true; + hasEnumerable_ = true; } bool IsConfigurable() const { @@ -436,19 +436,19 @@ public: void SetConfigurable(bool flag) { configurable_ = flag; - has_configurable_ = true; + hasConfigurable_ = true; } bool HasWritable() const { - return has_writable_; + return hasWritable_; } bool HasConfigurable() const { - return has_configurable_; + return hasConfigurable_; } bool HasEnumerable() const { - return has_enumerable_; + return hasEnumerable_; } Local GetValue(const EcmaVM *vm) const { @@ -503,9 +503,9 @@ private: bool writable_ = false; bool enumerable_ = false; bool configurable_ = false; - bool has_writable_ = false; - bool has_enumerable_ = false; - bool has_configurable_ = false; + bool hasWritable_ = false; + bool hasEnumerable_ = false; + bool hasConfigurable_ = false; }; class PUBLIC_API ObjectRef : public JSValueRef { @@ -539,7 +539,7 @@ public: void SetNativePointerFieldCount(int32_t count); int32_t GetNativePointerFieldCount(); void *GetNativePointerField(int32_t index); - void SetNativePointerField(int32_t index, void *native_pointer = nullptr, NativePointerCallback call_back = nullptr, + void SetNativePointerField(int32_t index, void *nativePointer = nullptr, NativePointerCallback callBack = nullptr, void *data = nullptr); }; @@ -552,12 +552,12 @@ using FunctionCallbackWithNewTarget = int32_t, void *); class PUBLIC_API FunctionRef : public ObjectRef { public: - static Local New(EcmaVM *vm, FunctionCallback native_func, void *data); - static Local New(EcmaVM *vm, FunctionCallback native_func, Deleter deleter, void *data); - static Local NewWithProperty(EcmaVM *vm, FunctionCallback native_func, void *data); - static Local NewClassFunction(EcmaVM *vm, FunctionCallbackWithNewTarget native_func, Deleter deleter, + static Local New(EcmaVM *vm, FunctionCallback nativeFunc, void *data); + static Local New(EcmaVM *vm, FunctionCallback nativeFunc, Deleter deleter, void *data); + static Local NewWithProperty(EcmaVM *vm, FunctionCallback nativeFunc, void *data); + static Local NewClassFunction(EcmaVM *vm, FunctionCallbackWithNewTarget nativeFunc, Deleter deleter, void *data); - Local Call(const EcmaVM *vm, Local this_obj, + Local Call(const EcmaVM *vm, Local thisObj, const Local argv[], // NOLINT(modernize-avoid-c-arrays) int32_t length); Local Constructor(const EcmaVM *vm, @@ -584,7 +584,7 @@ class PUBLIC_API PromiseRef : public ObjectRef { public: Local Catch(const EcmaVM *vm, Local handler); Local Then(const EcmaVM *vm, Local handler); - Local Then(const EcmaVM *vm, Local on_fulfilled, Local on_rejected); + Local Then(const EcmaVM *vm, Local onFulfilled, Local onRejected); }; class PUBLIC_API PromiseCapabilityRef : public ObjectRef { @@ -607,8 +607,8 @@ public: class PUBLIC_API DataViewRef : public ObjectRef { public: - static Local New(const EcmaVM *vm, Local array_buffer, int32_t byte_offset, - int32_t byte_length); + static Local New(const EcmaVM *vm, Local arrayBuffer, int32_t byteOffset, + int32_t byteLength); int32_t ByteLength(); int32_t ByteOffset(); Local GetArrayBuffer(const EcmaVM *vm); @@ -624,54 +624,51 @@ public: class PUBLIC_API Int8ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, int32_t length); + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Uint8ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, - int32_t length); + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Uint8ClampedArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Int16ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, - int32_t length); + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Uint16ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Int32ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, - int32_t length); + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Uint32ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Float32ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; class PUBLIC_API Float64ArrayRef : public TypedArrayRef { public: - static Local New(const EcmaVM *vm, Local buffer, int32_t byte_offset, + static Local New(const EcmaVM *vm, Local buffer, int32_t byteOffset, int32_t length); }; @@ -728,128 +725,128 @@ public: void SetExplicitConcurrentGcEnabled(bool value) { - is_explicit_concurrent_gc_enabled_ = value; + isExplicitConcurrentGcEnabled_ = value; } void SetGcType(GcType type) { - gc_type_ = type; + gcType_ = type; } void SetGcPoolSize(uint32_t size) { - gc_pool_size_ = size; + gcPoolSize_ = size; } - void SetLogLevel(LogLevel log_level) + void SetLogLevel(LogLevel logLevel) { - log_level_ = log_level; + logLevel_ = logLevel; } void SetLogBufPrint(LogPrint out) { - log_buf_print_ = out; + logBufPrint_ = out; } void SetDebuggerLibraryPath(const std::string &path) { - debugger_library_path_ = path; + debuggerLibraryPath_ = path; } void SetEnableArkTools(bool value) { - enable_ark_tools_ = value; + enableArkTools_ = value; } void SetArkProperties(int prop) { - ark_properties_ = prop; + arkProperties_ = prop; } private: std::string GetGcType() const { - std::string gc_type; - switch (gc_type_) { + std::string gcType; + switch (gcType_) { case GcType::GEN_GC: - gc_type = "gen-gc"; + gcType = "gen-gc"; break; case GcType::STW: - gc_type = "stw"; + gcType = "stw"; break; case GcType::EPSILON: - gc_type = "epsilon"; + gcType = "epsilon"; break; case GcType::G1_GC: - gc_type = "g1-gc"; + gcType = "g1-gc"; break; default: UNREACHABLE(); } - return gc_type; + return gcType; } std::string GetLogLevel() const { - std::string log_level; - switch (log_level_) { + std::string logLevel; + switch (logLevel_) { case LogLevel::INFO: case LogLevel::WARN: - log_level = "info"; + logLevel = "info"; break; case LogLevel::ERROR: - log_level = "error"; + logLevel = "error"; break; case LogLevel::FATAL: - log_level = "fatal"; + logLevel = "fatal"; break; case LogLevel::DEBUG: default: - log_level = "debug"; + logLevel = "debug"; break; } - return log_level; + return logLevel; } bool GetExplicitConcurrentGcEnabled() const { - return is_explicit_concurrent_gc_enabled_; + return isExplicitConcurrentGcEnabled_; } uint32_t GetGcPoolSize() const { - return gc_pool_size_; + return gcPoolSize_; } LogPrint GetLogBufPrint() const { - return log_buf_print_; + return logBufPrint_; } std::string GetDebuggerLibraryPath() const { - return debugger_library_path_; + return debuggerLibraryPath_; } bool GetEnableArkTools() const { - return enable_ark_tools_; + return enableArkTools_; } int GetArkProperties() const { - return ark_properties_; + return arkProperties_; } - GcType gc_type_ = GcType::EPSILON; - LogLevel log_level_ = LogLevel::DEBUG; - bool is_explicit_concurrent_gc_enabled_ {false}; - uint32_t gc_pool_size_ = DEFAULT_GC_POOL_SIZE; - LogPrint log_buf_print_ {nullptr}; - std::string debugger_library_path_ {}; - bool enable_ark_tools_ {false}; - int ark_properties_ {-1}; + GcType gcType_ = GcType::EPSILON; + LogLevel logLevel_ = LogLevel::DEBUG; + bool isExplicitConcurrentGcEnabled_ {false}; + uint32_t gcPoolSize_ = DEFAULT_GC_POOL_SIZE; + LogPrint logBufPrint_ {nullptr}; + std::string debuggerLibraryPath_ {}; + bool enableArkTools_ {false}; + int arkProperties_ {-1}; friend JSNApi; }; @@ -879,30 +876,30 @@ public: // JSVM enum class PUBLIC_API TriggerGcType : uint8_t { SEMI_GC, OLD_GC, COMPRESS_FULL_GC }; static EcmaVM *CreateJSVM(const RuntimeOption &option); - static void DestroyJSVM(EcmaVM *ecma_vm); + static void DestroyJSVM(EcmaVM *ecmaVm); // JS code - static bool Execute(EcmaVM *vm, Local file_name, Local entry); - static bool Execute(EcmaVM *vm, const std::string &file_name, const std::string &entry); + static bool Execute(EcmaVM *vm, Local fileName, Local entry); + static bool Execute(EcmaVM *vm, const std::string &fileName, const std::string &entry); static bool Execute(EcmaVM *vm, const uint8_t *data, int32_t size, Local entry); static bool Execute(EcmaVM *vm, const uint8_t *data, int32_t size, const std::string &entry); static bool ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size, const std::string &file); - static Local GetExportObject(EcmaVM *vm, const std::string &file, const std::string &item_name); + static Local GetExportObject(EcmaVM *vm, const std::string &file, const std::string &itemName); // ObjectRef Operation static Local GetGlobalObject(const EcmaVM *vm); static void ExecutePendingJob(const EcmaVM *vm); // Memory - static void TriggerGC(const EcmaVM *vm, TriggerGcType gc_type = TriggerGcType::SEMI_GC); + static void TriggerGC(const EcmaVM *vm, TriggerGcType gcType = TriggerGcType::SEMI_GC); // Exception static void ThrowException(const EcmaVM *vm, Local error); static Local GetUncaughtException(const EcmaVM *vm); static Local GetAndClearUncaughtException(const EcmaVM *vm); static void EnableUserUncaughtErrorHandler(EcmaVM *vm); - static bool StartDebugger(const char *library_path, EcmaVM *vm, bool is_debug_mode); - static bool StopDebugger(const char *library_path); + static bool StartDebugger(const char *libraryPath, EcmaVM *vm, bool isDebugMode); + static bool StopDebugger(const char *libraryPath); // Serialize & Deserialize. static void *SerializeValue(const EcmaVM *vm, Local value, Local transfer); static Local DeserializeValue(const EcmaVM *vm, void *recoder); @@ -915,10 +912,10 @@ private: static bool CreateRuntime(const RuntimeOption &option); static bool DestroyRuntime(); - static uintptr_t GetHandleAddr(const EcmaVM *vm, uintptr_t local_address); - static uintptr_t GetGlobalHandleAddr(const EcmaVM *vm, uintptr_t local_address); - static uintptr_t SetWeak(const EcmaVM *vm, uintptr_t local_address); - static bool IsWeak(const EcmaVM *vm, uintptr_t local_address); + static uintptr_t GetHandleAddr(const EcmaVM *vm, uintptr_t localAddress); + static uintptr_t GetGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress); + static uintptr_t SetWeak(const EcmaVM *vm, uintptr_t localAddress); + static bool IsWeak(const EcmaVM *vm, uintptr_t localAddress); static void DisposeGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr); template friend class Global; diff --git a/runtime/napi/jsnapi.cpp b/runtime/napi/jsnapi.cpp index 5b0a5d25104cb5bb5952e024f056be4c778c1ca3..3e3283c6a082139bc6db2cb6ccb3defb99546333 100644 --- a/runtime/napi/jsnapi.cpp +++ b/runtime/napi/jsnapi.cpp @@ -106,45 +106,45 @@ constexpr uint32_t COMPILER_POOL_SIZE = 2000000; // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) constexpr std::string_view ENTRY_POINTER = "_GLOBAL::func_main_0"; -LoadableAgentHandle S_DEBUGGER_AGENT; // NOLINT(fuchsia-statically-constructed-objects) +LoadableAgentHandle g_sDebuggerAgent; // NOLINT(fuchsia-statically-constructed-objects) } // namespace // ------------------------------------ Panda ----------------------------------------------- bool JSNApi::CreateRuntime(const RuntimeOption &option) { - JSRuntimeOptions runtime_options; + JSRuntimeOptions runtimeOptions; // GC - runtime_options.SetGcType(option.GetGcType()); - runtime_options.SetRunGcInPlace(true); - runtime_options.SetArkProperties(option.GetArkProperties()); - runtime_options.SetExplicitConcurrentGcEnabled(option.GetExplicitConcurrentGcEnabled()); + runtimeOptions.SetGcType(option.GetGcType()); + runtimeOptions.SetRunGcInPlace(true); + runtimeOptions.SetArkProperties(option.GetArkProperties()); + runtimeOptions.SetExplicitConcurrentGcEnabled(option.GetExplicitConcurrentGcEnabled()); // Mem - runtime_options.SetHeapSizeLimit(option.GetGcPoolSize()); - runtime_options.SetInternalMemorySizeLimit(INTERNAL_POOL_SIZE); - runtime_options.SetCodeCacheSizeLimit(CODE_POOL_SIZE); - runtime_options.SetCompilerMemorySizeLimit(COMPILER_POOL_SIZE); - runtime_options.SetInternalAllocatorType("malloc"); + runtimeOptions.SetHeapSizeLimit(option.GetGcPoolSize()); + runtimeOptions.SetInternalMemorySizeLimit(INTERNAL_POOL_SIZE); + runtimeOptions.SetCodeCacheSizeLimit(CODE_POOL_SIZE); + runtimeOptions.SetCompilerMemorySizeLimit(COMPILER_POOL_SIZE); + runtimeOptions.SetInternalAllocatorType("malloc"); // Boot - runtime_options.SetBootPandaFiles({}); - runtime_options.SetLoadRuntimes({"ecmascript"}); + runtimeOptions.SetBootPandaFiles({}); + runtimeOptions.SetLoadRuntimes({"ecmascript"}); // Dfx - base_options::Options base_options(""); - base_options.SetLogLevel(option.GetLogLevel()); - arg_list_t log_components; - log_components.emplace_back("all"); - base_options.SetLogComponents(log_components); - Logger::Initialize(base_options); + base_options::Options baseOptions(""); + baseOptions.SetLogLevel(option.GetLogLevel()); + arg_list_t logComponents; + logComponents.emplace_back("all"); + baseOptions.SetLogComponents(logComponents); + Logger::Initialize(baseOptions); if (option.GetLogBufPrint() != nullptr) { - runtime_options.SetMobileLog(reinterpret_cast(option.GetLogBufPrint())); + runtimeOptions.SetMobileLog(reinterpret_cast(option.GetLogBufPrint())); } - runtime_options.SetEnableArkTools(option.GetEnableArkTools()); - static EcmaLanguageContext lc_ecma; - if (!Runtime::Create(runtime_options, {&lc_ecma})) { + runtimeOptions.SetEnableArkTools(option.GetEnableArkTools()); + static EcmaLanguageContext lcEcma; + if (!Runtime::Create(runtimeOptions, {&lcEcma})) { std::cerr << "Error: cannot create runtime" << std::endl; return false; } @@ -167,35 +167,35 @@ EcmaVM *JSNApi::CreateJSVM(const RuntimeOption &option) runtime = Runtime::GetCurrent(); return EcmaVM::Cast(runtime->GetPandaVM()); } - JSRuntimeOptions runtime_options; - runtime_options.SetArkProperties(option.GetArkProperties()); + JSRuntimeOptions runtimeOptions; + runtimeOptions.SetArkProperties(option.GetArkProperties()); // GC - runtime_options.SetGcType("g1-gc"); - runtime_options.SetGcTriggerType("no-gc-for-start-up"); // A non-production gc strategy. Prohibit stw-gc 10 times. + runtimeOptions.SetGcType("g1-gc"); + runtimeOptions.SetGcTriggerType("no-gc-for-start-up"); // A non-production gc strategy. Prohibit stw-gc 10 times. - return EcmaVM::Cast(EcmaVM::Create(runtime_options)); + return EcmaVM::Cast(EcmaVM::Create(runtimeOptions)); } -void JSNApi::DestroyJSVM(EcmaVM *ecma_vm) +void JSNApi::DestroyJSVM(EcmaVM *ecmaVm) { - ecma_vm->GetNotificationManager()->VmDeathEvent(); + ecmaVm->GetNotificationManager()->VmDeathEvent(); auto runtime = Runtime::GetCurrent(); if (runtime != nullptr) { - PandaVM *main_vm = runtime->GetPandaVM(); + PandaVM *mainVm = runtime->GetPandaVM(); // Only Ark js app - if (main_vm == ecma_vm) { + if (mainVm == ecmaVm) { DestroyRuntime(); } else { - EcmaVM::Destroy(ecma_vm); + EcmaVM::Destroy(ecmaVm); } } } -void JSNApi::TriggerGC(const EcmaVM *vm, TriggerGcType gc_type) +void JSNApi::TriggerGC(const EcmaVM *vm, TriggerGcType gcType) { if (vm->GetJSThread() != nullptr && vm->IsInitialized()) { ScopedManagedCodeThread s(vm->GetAssociatedThread()); - switch (gc_type) { + switch (gcType) { case TriggerGcType::SEMI_GC: vm->CollectGarbage(); break; @@ -217,37 +217,37 @@ void JSNApi::ThrowException(const EcmaVM *vm, Local error) thread->SetException(JSNApiHelper::ToJSTaggedValue(*error)); } -bool JSNApi::StartDebugger(const char *library_path, EcmaVM *vm, bool is_debug_mode) +bool JSNApi::StartDebugger(const char *libraryPath, EcmaVM *vm, bool isDebugMode) { - auto agent = JSNApiDebuggerAgent::LoadInstance(library_path, vm, is_debug_mode); + auto agent = JSNApiDebuggerAgent::LoadInstance(libraryPath, vm, isDebugMode); if (!agent) { LOG_ECMA(ERROR) << "Could not load JSN debugger agent"; return false; } - S_DEBUGGER_AGENT = std::move(agent); + g_sDebuggerAgent = std::move(agent); return true; } -bool JSNApi::StopDebugger([[maybe_unused]] const char *library_path) +bool JSNApi::StopDebugger([[maybe_unused]] const char *libraryPath) { - S_DEBUGGER_AGENT.reset(); + g_sDebuggerAgent.reset(); return true; } -bool JSNApi::Execute(EcmaVM *vm, Local file_name, Local entry) +bool JSNApi::Execute(EcmaVM *vm, Local fileName, Local entry) { - return Execute(vm, file_name->ToString(), entry->ToString()); + return Execute(vm, fileName->ToString(), entry->ToString()); } -bool JSNApi::Execute(EcmaVM *vm, const std::string &file_name, const std::string &entry) +bool JSNApi::Execute(EcmaVM *vm, const std::string &fileName, const std::string &entry) { std::vector argv; - LOG_ECMA(DEBUG) << "start to execute ark file" << file_name; - if (!vm->ExecuteFromPf(file_name, entry, argv)) { - LOG_ECMA(ERROR) << "Cannot execute ark file" << file_name; - LOG_ECMA(ERROR) << "Cannot execute ark file '" << file_name << "' with entry '" << entry << "'" << std::endl; + LOG_ECMA(DEBUG) << "start to execute ark file" << fileName; + if (!vm->ExecuteFromPf(fileName, entry, argv)) { + LOG_ECMA(ERROR) << "Cannot execute ark file" << fileName; + LOG_ECMA(ERROR) << "Cannot execute ark file '" << fileName << "' with entry '" << entry << "'" << std::endl; return false; } return true; @@ -295,8 +295,8 @@ void JSNApi::EnableUserUncaughtErrorHandler(EcmaVM *vm) Local JSNApi::GetGlobalObject(const EcmaVM *vm) { - JSHandle global_env = vm->GetGlobalEnv(); - JSHandle global(vm->GetJSThread(), global_env->GetGlobalObject()); + JSHandle globalEnv = vm->GetGlobalEnv(); + JSHandle global(vm->GetJSThread(), globalEnv->GetGlobalObject()); return JSNApiHelper::ToLocal(global); } @@ -306,38 +306,38 @@ void JSNApi::ExecutePendingJob(const EcmaVM *vm) vm->ExecutePromisePendingJob(); } -uintptr_t JSNApi::GetHandleAddr(const EcmaVM *vm, uintptr_t local_address) +uintptr_t JSNApi::GetHandleAddr(const EcmaVM *vm, uintptr_t localAddress) { - if (local_address == 0) { + if (localAddress == 0) { return 0; } - JSTaggedType value = *(reinterpret_cast(local_address)); + JSTaggedType value = *(reinterpret_cast(localAddress)); return ecmascript::EcmaHandleScope::NewHandle(vm->GetJSThread(), value); } -uintptr_t JSNApi::GetGlobalHandleAddr(const EcmaVM *vm, uintptr_t local_address) +uintptr_t JSNApi::GetGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress) { - if (local_address == 0) { + if (localAddress == 0) { return 0; } - JSTaggedType value = *(reinterpret_cast(local_address)); + JSTaggedType value = *(reinterpret_cast(localAddress)); return vm->GetJSThread()->GetEcmaGlobalStorage()->NewGlobalHandle(value); } -uintptr_t JSNApi::SetWeak(const EcmaVM *vm, uintptr_t local_address) +uintptr_t JSNApi::SetWeak(const EcmaVM *vm, uintptr_t localAddress) { - if (local_address == 0) { + if (localAddress == 0) { return 0; } - return vm->GetJSThread()->GetEcmaGlobalStorage()->SetWeak(local_address); + return vm->GetJSThread()->GetEcmaGlobalStorage()->SetWeak(localAddress); } -bool JSNApi::IsWeak(const EcmaVM *vm, uintptr_t local_address) +bool JSNApi::IsWeak(const EcmaVM *vm, uintptr_t localAddress) { - if (local_address == 0) { + if (localAddress == 0) { return false; } - return vm->GetJSThread()->GetEcmaGlobalStorage()->IsWeak(local_address); + return vm->GetJSThread()->GetEcmaGlobalStorage()->IsWeak(localAddress); } void JSNApi::DisposeGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr) @@ -352,10 +352,10 @@ void *JSNApi::SerializeValue(const EcmaVM *vm, Local value, LocalGetJSThread(); ecmascript::Serializer serializer(thread); - JSHandle ark_value = JSNApiHelper::ToJSHandle(value); - JSHandle ark_transfer = JSNApiHelper::ToJSHandle(transfer); + JSHandle arkValue = JSNApiHelper::ToJSHandle(value); + JSHandle arkTransfer = JSNApiHelper::ToJSHandle(transfer); std::unique_ptr data; - if (serializer.WriteValue(thread, ark_value, ark_transfer)) { + if (serializer.WriteValue(thread, arkValue, arkTransfer)) { data = serializer.Release(); } return reinterpret_cast(data.release()); @@ -380,12 +380,12 @@ void HostPromiseRejectionTracker(const EcmaVM *vm, const JSHandle pro const JSHandle reason, const ecmascript::PromiseRejectionEvent operation, void *data) { - ecmascript::PromiseRejectCallback promise_reject_callback = vm->GetPromiseRejectCallback(); - if (promise_reject_callback != nullptr) { - Local promise_val = JSNApiHelper::ToLocal(JSHandle::Cast(promise)); - PromiseRejectInfo promise_reject_info(promise_val, JSNApiHelper::ToLocal(reason), - static_cast(operation), data); - promise_reject_callback(reinterpret_cast(&promise_reject_info)); + ecmascript::PromiseRejectCallback promiseRejectCallback = vm->GetPromiseRejectCallback(); + if (promiseRejectCallback != nullptr) { + Local promiseVal = JSNApiHelper::ToLocal(JSHandle::Cast(promise)); + PromiseRejectInfo promiseRejectInfo(promiseVal, JSNApiHelper::ToLocal(reason), + static_cast(operation), data); + promiseRejectCallback(reinterpret_cast(&promiseRejectInfo)); } } @@ -432,40 +432,40 @@ void *PromiseRejectInfo::GetData() const bool JSNApi::ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size, const std::string &file) { - auto module_manager = vm->GetModuleManager(); - module_manager->SetCurrentExportModuleName(file); + auto moduleManager = vm->GetModuleManager(); + moduleManager->SetCurrentExportModuleName(file); // Update Current Module std::vector argv; if (!vm->ExecuteFromBuffer(data, size, ENTRY_POINTER, argv)) { std::cerr << "Cannot execute panda file from memory" << std::endl; - module_manager->RestoreCurrentExportModuleName(); + moduleManager->RestoreCurrentExportModuleName(); return false; } // Restore Current Module - module_manager->RestoreCurrentExportModuleName(); + moduleManager->RestoreCurrentExportModuleName(); return true; } -Local JSNApi::GetExportObject(EcmaVM *vm, const std::string &file, const std::string &item_name) +Local JSNApi::GetExportObject(EcmaVM *vm, const std::string &file, const std::string &itemName) { ScopedManagedCodeThread s(vm->GetAssociatedThread()); - auto module_manager = vm->GetModuleManager(); + auto moduleManager = vm->GetModuleManager(); ObjectFactory *factory = vm->GetFactory(); - JSHandle module_name(factory->NewFromStdStringUnCheck(file, true)); - JSHandle module_obj = module_manager->GetModule(vm->GetJSThread(), module_name); - JSHandle item_string(factory->NewFromStdString(item_name)); - JSHandle export_obj = module_manager->GetModuleItem(vm->GetJSThread(), module_obj, item_string); - return JSNApiHelper::ToLocal(export_obj); + JSHandle moduleName(factory->NewFromStdStringUnCheck(file, true)); + JSHandle moduleObj = moduleManager->GetModule(vm->GetJSThread(), moduleName); + JSHandle itemString(factory->NewFromStdString(itemName)); + JSHandle exportObj = moduleManager->GetModuleItem(vm->GetJSThread(), moduleObj, itemString); + return JSNApiHelper::ToLocal(exportObj); } // ----------------------------------- HandleScope ------------------------------------- LocalScope::LocalScope(const EcmaVM *vm) : thread_(vm->GetJSThread()) { auto thread = reinterpret_cast(thread_); - prev_next_ = thread->GetHandleScopeStorageNext(); - prev_end_ = thread->GetHandleScopeStorageEnd(); - prev_handle_storage_index_ = thread->GetCurrentHandleStorageIndex(); + prevNext_ = thread->GetHandleScopeStorageNext(); + prevEnd_ = thread->GetHandleScopeStorageEnd(); + prevHandleStorageIndex_ = thread->GetCurrentHandleStorageIndex(); thread->HandleScopeCountAdd(); } @@ -473,9 +473,9 @@ LocalScope::LocalScope(const EcmaVM *vm, JSTaggedType value) : thread_(vm->GetJS { auto thread = reinterpret_cast(thread_); ecmascript::EcmaHandleScope::NewHandle(thread, value); - prev_next_ = thread->GetHandleScopeStorageNext(); - prev_end_ = thread->GetHandleScopeStorageEnd(); - prev_handle_storage_index_ = thread->GetCurrentHandleStorageIndex(); + prevNext_ = thread->GetHandleScopeStorageNext(); + prevEnd_ = thread->GetHandleScopeStorageEnd(); + prevHandleStorageIndex_ = thread->GetCurrentHandleStorageIndex(); thread->HandleScopeCountAdd(); } @@ -483,10 +483,10 @@ LocalScope::~LocalScope() { auto thread = reinterpret_cast(thread_); thread->HandleScopeCountDec(); - thread->SetHandleScopeStorageNext(static_cast(prev_next_)); - if (thread->GetHandleScopeStorageEnd() != prev_end_) { - thread->SetHandleScopeStorageEnd(static_cast(prev_end_)); - thread->ShrinkHandleStorage(prev_handle_storage_index_); + thread->SetHandleScopeStorageNext(static_cast(prevNext_)); + if (thread->GetHandleScopeStorageEnd() != prevEnd_) { + thread->SetHandleScopeStorageEnd(static_cast(prevEnd_)); + thread->ShrinkHandleStorage(prevHandleStorageIndex_); } } @@ -495,7 +495,7 @@ EscapeLocalScope::EscapeLocalScope(const EcmaVM *vm) : LocalScope(vm, 0U) { auto thread = vm->GetJSThread(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - escape_handle_ = ToUintPtr(thread->GetHandleScopeStorageNext() - 1); + escapeHandle_ = ToUintPtr(thread->GetHandleScopeStorageNext() - 1); } // ----------------------------------- NumberRef --------------------------------------- @@ -596,32 +596,32 @@ Local SymbolRef::GetDescription(const EcmaVM *vm) auto constants = vm->GetJSThread()->GlobalConstants(); return JSNApiHelper::ToLocal(constants->GetHandledEmptyString()); } - JSHandle description_handle(vm->GetJSThread(), description); - return JSNApiHelper::ToLocal(description_handle); + JSHandle descriptionHandle(vm->GetJSThread(), description); + return JSNApiHelper::ToLocal(descriptionHandle); } // -------------------------------- NativePointerRef ------------------------------------ -Local NativePointerRef::New(const EcmaVM *vm, void *native_pointer) +Local NativePointerRef::New(const EcmaVM *vm, void *nativePointer) { ScopedManagedCodeThread s(vm->GetAssociatedThread()); ObjectFactory *factory = vm->GetFactory(); - JSHandle obj = factory->NewJSNativePointer(native_pointer); + JSHandle obj = factory->NewJSNativePointer(nativePointer); return JSNApiHelper::ToLocal(JSHandle(obj)); } -Local NativePointerRef::New(const EcmaVM *vm, void *native_pointer, NativePointerCallback call_back, +Local NativePointerRef::New(const EcmaVM *vm, void *nativePointer, NativePointerCallback callBack, void *data) { ScopedManagedCodeThread s(vm->GetAssociatedThread()); ObjectFactory *factory = vm->GetFactory(); - JSHandle obj = factory->NewJSNativePointer(native_pointer, call_back, data); + JSHandle obj = factory->NewJSNativePointer(nativePointer, callBack, data); return JSNApiHelper::ToLocal(JSHandle(obj)); } void *NativePointerRef::Value() { - JSHandle native_pointer = JSNApiHelper::ToJSHandle(this); - return JSHandle(native_pointer)->GetExternalPointer(); + JSHandle nativePointer = JSNApiHelper::ToJSHandle(this); + return JSHandle(nativePointer)->GetExternalPointer(); } // ----------------------------------- ObjectRef ---------------------------------------- @@ -629,8 +629,8 @@ Local ObjectRef::New(const EcmaVM *vm) { ScopedManagedCodeThread s(vm->GetAssociatedThread()); ObjectFactory *factory = vm->GetFactory(); - JSHandle global_env = vm->GetGlobalEnv(); - JSHandle constructor = global_env->GetObjectFunction(); + JSHandle globalEnv = vm->GetGlobalEnv(); + JSHandle constructor = globalEnv->GetObjectFunction(); JSHandle object(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); RETURN_VALUE_IF_ABRUPT(vm->GetJSThread(), Local(JSValueRef::Exception(vm))); return JSNApiHelper::ToLocal(object); @@ -640,17 +640,17 @@ bool ObjectRef::Set(const EcmaVM *vm, Local key, Local v { ScopedManagedCodeThread s(vm->GetAssociatedThread()); JSHandle obj = JSNApiHelper::ToJSHandle(this); - JSHandle key_value = JSNApiHelper::ToJSHandle(key); - JSHandle value_value = JSNApiHelper::ToJSHandle(value); - bool result = JSTaggedValue::SetProperty(vm->GetJSThread(), obj, key_value, value_value); + JSHandle keyValue = JSNApiHelper::ToJSHandle(key); + JSHandle valueValue = JSNApiHelper::ToJSHandle(value); + bool result = JSTaggedValue::SetProperty(vm->GetJSThread(), obj, keyValue, valueValue); RETURN_VALUE_IF_ABRUPT(vm->GetJSThread(), false); return result; } bool ObjectRef::Set(const EcmaVM *vm, uint32_t key, Local value) { - Local key_value = Local(NumberRef::New(vm, key)); - return Set(vm, key_value, value); + Local keyValue = Local(NumberRef::New(vm, key)); + return Set(vm, keyValue, value); } bool ObjectRef::SetAccessorProperty(const EcmaVM *vm, Local key, Local getter, @@ -658,15 +658,15 @@ bool ObjectRef::SetAccessorProperty(const EcmaVM *vm, Local key, Loc { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); - JSHandle getter_value = JSNApiHelper::ToJSHandle(getter); - JSHandle setter_value = JSNApiHelper::ToJSHandle(setter); + JSHandle getterValue = JSNApiHelper::ToJSHandle(getter); + JSHandle setterValue = JSNApiHelper::ToJSHandle(setter); PropertyDescriptor desc(thread, attribute.IsWritable(), attribute.IsEnumerable(), attribute.IsConfigurable()); desc.SetValue(JSNApiHelper::ToJSHandle(attribute.GetValue(vm))); - desc.SetSetter(setter_value); - desc.SetGetter(getter_value); + desc.SetSetter(setterValue); + desc.SetGetter(getterValue); JSHandle obj = JSNApiHelper::ToJSHandle(this); - JSHandle key_value = JSNApiHelper::ToJSHandle(key); - bool result = JSTaggedValue::DefineOwnProperty(thread, obj, key_value, desc); + JSHandle keyValue = JSNApiHelper::ToJSHandle(key); + bool result = JSTaggedValue::DefineOwnProperty(thread, obj, keyValue, desc); RETURN_VALUE_IF_ABRUPT(thread, false); return result; } @@ -676,8 +676,8 @@ Local ObjectRef::Get(const EcmaVM *vm, Local key) JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); JSHandle obj = JSNApiHelper::ToJSHandle(this); - JSHandle key_value = JSNApiHelper::ToJSHandle(key); - OperationResult ret = JSTaggedValue::GetProperty(thread, obj, key_value); + JSHandle keyValue = JSNApiHelper::ToJSHandle(key); + OperationResult ret = JSTaggedValue::GetProperty(thread, obj, keyValue); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); if (!ret.GetPropertyMetaData().IsFound()) { return JSValueRef::Undefined(vm); @@ -687,8 +687,8 @@ Local ObjectRef::Get(const EcmaVM *vm, Local key) Local ObjectRef::Get(const EcmaVM *vm, int32_t key) { - Local key_value = IntegerRef::New(vm, key); - return Get(vm, key_value); + Local keyValue = IntegerRef::New(vm, key); + return Get(vm, keyValue); } bool ObjectRef::GetOwnProperty(const EcmaVM *vm, Local key, PropertyAttribute &property) @@ -696,9 +696,9 @@ bool ObjectRef::GetOwnProperty(const EcmaVM *vm, Local key, Property JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); JSHandle obj = JSNApiHelper::ToJSHandle(this); - JSHandle key_value = JSNApiHelper::ToJSHandle(key); + JSHandle keyValue = JSNApiHelper::ToJSHandle(key); PropertyDescriptor desc(thread); - bool ret = JSObject::GetOwnProperty(thread, JSHandle(obj), key_value, desc); + bool ret = JSObject::GetOwnProperty(thread, JSHandle(obj), keyValue, desc); if (!ret) { return false; } @@ -728,9 +728,9 @@ Local ObjectRef::GetOwnPropertyNames(const EcmaVM *vm) ScopedManagedCodeThread s(thread); JSHandle obj(JSNApiHelper::ToJSHandle(this)); JSHandle array(JSTaggedValue::GetOwnPropertyKeys(thread, obj)); - JSHandle js_array(JSArray::CreateArrayFromList(thread, array)); + JSHandle jsArray(JSArray::CreateArrayFromList(thread, array)); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); - return JSNApiHelper::ToLocal(js_array); + return JSNApiHelper::ToLocal(jsArray); } Local ObjectRef::GetOwnEnumerablePropertyNames(const EcmaVM *vm) @@ -739,9 +739,9 @@ Local ObjectRef::GetOwnEnumerablePropertyNames(const EcmaVM *vm) ScopedManagedCodeThread s(thread); JSHandle obj(JSNApiHelper::ToJSHandle(this)); JSHandle array(JSObject::EnumerableOwnNames(thread, obj)); - JSHandle js_array(JSArray::CreateArrayFromList(thread, array)); + JSHandle jsArray(JSArray::CreateArrayFromList(thread, array)); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); - return JSNApiHelper::ToLocal(js_array); + return JSNApiHelper::ToLocal(jsArray); } Local ObjectRef::GetPrototype(const EcmaVM *vm) @@ -759,10 +759,10 @@ bool ObjectRef::DefineProperty(const EcmaVM *vm, Local key, Property JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); JSHandle object(JSNApiHelper::ToJSHandle(this)); - JSHandle key_value(JSNApiHelper::ToJSHandle(key)); + JSHandle keyValue(JSNApiHelper::ToJSHandle(key)); PropertyDescriptor desc(thread, attribute.IsWritable(), attribute.IsEnumerable(), attribute.IsConfigurable()); desc.SetValue(JSNApiHelper::ToJSHandle(attribute.GetValue(vm))); - bool result = object->DefinePropertyOrThrow(thread, object, key_value, desc); + bool result = object->DefinePropertyOrThrow(thread, object, keyValue, desc); RETURN_VALUE_IF_ABRUPT(thread, false); return result; } @@ -771,8 +771,8 @@ bool ObjectRef::Has(const EcmaVM *vm, Local key) { JSThread *thread = vm->GetJSThread(); JSHandle object(JSNApiHelper::ToJSHandle(this)); - JSHandle key_value(JSNApiHelper::ToJSHandle(key)); - bool result = object->HasProperty(thread, object, key_value); + JSHandle keyValue(JSNApiHelper::ToJSHandle(key)); + bool result = object->HasProperty(thread, object, keyValue); RETURN_VALUE_IF_ABRUPT(thread, false); return result; } @@ -791,8 +791,8 @@ bool ObjectRef::Delete(const EcmaVM *vm, Local key) JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); JSHandle object(JSNApiHelper::ToJSHandle(this)); - JSHandle key_value(JSNApiHelper::ToJSHandle(key)); - bool result = object->DeleteProperty(thread, object, key_value); + JSHandle keyValue(JSNApiHelper::ToJSHandle(key)); + bool result = object->DeleteProperty(thread, object, keyValue); RETURN_VALUE_IF_ABRUPT(thread, false); return result; } @@ -802,8 +802,8 @@ bool ObjectRef::Delete(const EcmaVM *vm, uint32_t key) JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); JSHandle object(JSNApiHelper::ToJSHandle(this)); - JSHandle key_handle(thread, JSTaggedValue(key)); - bool result = object->DeleteProperty(thread, object, key_handle); + JSHandle keyHandle(thread, JSTaggedValue(key)); + bool result = object->DeleteProperty(thread, object, keyHandle); RETURN_VALUE_IF_ABRUPT(thread, false); return result; } @@ -826,45 +826,45 @@ void *ObjectRef::GetNativePointerField(int32_t index) return object->GetNativePointerField(index); } -void ObjectRef::SetNativePointerField(int32_t index, void *native_pointer, NativePointerCallback call_back, void *data) +void ObjectRef::SetNativePointerField(int32_t index, void *nativePointer, NativePointerCallback callBack, void *data) { JSHandle object(JSNApiHelper::ToJSHandle(this)); - object->SetNativePointerField(index, native_pointer, call_back, data); + object->SetNativePointerField(index, nativePointer, callBack, data); } // ----------------------------------- FunctionRef -------------------------------------- -Local FunctionRef::New(EcmaVM *vm, FunctionCallback native_func, void *data) +Local FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc, void *data) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); ObjectFactory *factory = vm->GetFactory(); JSHandle env = vm->GetGlobalEnv(); JSHandle current(factory->NewJSFunction(env, reinterpret_cast(Callback::RegisterCallback))); - JSHandle func_callback = factory->NewJSNativePointer(reinterpret_cast(native_func)); - JSHandle vm_caddress = factory->NewJSNativePointer(vm); - JSHandle data_caddress = factory->NewJSNativePointer(data); - JSHandle extra_info(factory->NewFunctionExtraInfo(func_callback, vm_caddress, data_caddress)); - current->SetFunctionExtraInfo(thread, extra_info.GetTaggedValue()); + JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); + JSHandle vmCaddress = factory->NewJSNativePointer(vm); + JSHandle dataCaddress = factory->NewJSNativePointer(data); + JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, vmCaddress, dataCaddress)); + current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); return JSNApiHelper::ToLocal(JSHandle(current)); } -Local FunctionRef::New(EcmaVM *vm, FunctionCallback native_func, Deleter deleter, void *data) +Local FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc, Deleter deleter, void *data) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); ObjectFactory *factory = vm->GetFactory(); JSHandle env = vm->GetGlobalEnv(); JSHandle current(factory->NewJSFunction(env, reinterpret_cast(Callback::RegisterCallback))); - JSHandle func_callback = factory->NewJSNativePointer(reinterpret_cast(native_func)); - JSHandle vm_caddress = factory->NewJSNativePointer(vm); - JSHandle data_caddress = factory->NewJSNativePointer(data, deleter, nullptr); - vm->PushToArrayDataList(*data_caddress); - JSHandle extra_info(factory->NewFunctionExtraInfo(func_callback, vm_caddress, data_caddress)); - current->SetFunctionExtraInfo(thread, extra_info.GetTaggedValue()); + JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); + JSHandle vmCaddress = factory->NewJSNativePointer(vm); + JSHandle dataCaddress = factory->NewJSNativePointer(data, deleter, nullptr); + vm->PushToArrayDataList(*dataCaddress); + JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, vmCaddress, dataCaddress)); + current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); return JSNApiHelper::ToLocal(JSHandle(current)); } -Local FunctionRef::NewWithProperty(EcmaVM *vm, FunctionCallback native_func, void *data) +Local FunctionRef::NewWithProperty(EcmaVM *vm, FunctionCallback nativeFunc, void *data) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); @@ -872,15 +872,15 @@ Local FunctionRef::NewWithProperty(EcmaVM *vm, FunctionCallback nat JSHandle env = vm->GetGlobalEnv(); JSHandle current = factory->NewJSFunction(env, reinterpret_cast(Callback::RegisterCallbackWithProperty)); - JSHandle func_callback = factory->NewJSNativePointer(reinterpret_cast(native_func)); - JSHandle vm_caddress = factory->NewJSNativePointer(vm); - JSHandle data_caddress = factory->NewJSNativePointer(data); - JSHandle extra_info(factory->NewFunctionExtraInfo(func_callback, vm_caddress, data_caddress)); - current->SetFunctionExtraInfo(thread, extra_info.GetTaggedValue()); + JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); + JSHandle vmCaddress = factory->NewJSNativePointer(vm); + JSHandle dataCaddress = factory->NewJSNativePointer(data); + JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, vmCaddress, dataCaddress)); + current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); return JSNApiHelper::ToLocal(JSHandle(current)); } -Local FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallbackWithNewTarget native_func, Deleter deleter, +Local FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallbackWithNewTarget nativeFunc, Deleter deleter, void *data) { JSThread *thread = vm->GetJSThread(); @@ -893,34 +893,34 @@ Local FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallbackWit JSHandle current = factory->NewJSFunctionByDynClass(method, dynclass, ecmascript::FunctionKind::CLASS_CONSTRUCTOR); - auto global_const = thread->GlobalConstants(); - JSHandle accessor = global_const->GetHandledFunctionPrototypeAccessor(); + auto globalConst = thread->GlobalConstants(); + JSHandle accessor = globalConst->GetHandledFunctionPrototypeAccessor(); current->SetPropertyInlinedProps(thread, JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); - JSHandle func_callback = factory->NewJSNativePointer(reinterpret_cast(native_func)); - JSHandle vm_caddress = factory->NewJSNativePointer(vm); - JSHandle data_caddress(thread, JSTaggedValue::Undefined()); + JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); + JSHandle vmCaddress = factory->NewJSNativePointer(vm); + JSHandle dataCaddress(thread, JSTaggedValue::Undefined()); if (deleter == nullptr) { - data_caddress = factory->NewJSNativePointer(data); + dataCaddress = factory->NewJSNativePointer(data); } else { - data_caddress = factory->NewJSNativePointer(data, deleter, nullptr); - vm->PushToArrayDataList(*data_caddress); + dataCaddress = factory->NewJSNativePointer(data, deleter, nullptr); + vm->PushToArrayDataList(*dataCaddress); } - JSHandle extra_info(factory->NewFunctionExtraInfo(func_callback, vm_caddress, data_caddress)); - current->SetFunctionExtraInfo(thread, extra_info.GetTaggedValue()); + JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, vmCaddress, dataCaddress)); + current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); - JSHandle cls_prototype = JSFunction::NewJSFunctionPrototype(thread, factory, current); - cls_prototype.GetTaggedValue().GetTaggedObject()->GetClass()->SetClassPrototype(true); + JSHandle clsPrototype = JSFunction::NewJSFunctionPrototype(thread, factory, current); + clsPrototype.GetTaggedValue().GetTaggedObject()->GetClass()->SetClassPrototype(true); JSHandle::Cast(current)->GetTaggedObject()->GetClass()->SetClassConstructor(true); current->SetClassConstructor(true); JSHandle parent = env->GetFunctionPrototype(); JSObject::SetPrototype(thread, JSHandle::Cast(current), parent); - current->SetHomeObject(thread, cls_prototype); + current->SetHomeObject(thread, clsPrototype); return JSNApiHelper::ToLocal(JSHandle(current)); } -Local FunctionRef::Call(const EcmaVM *vm, Local this_obj, +Local FunctionRef::Call(const EcmaVM *vm, Local thisObj, const Local argv[], // NOLINT(modernize-avoid-c-arrays) int32_t length) { @@ -930,14 +930,14 @@ Local FunctionRef::Call(const EcmaVM *vm, Local this_obj } ScopedManagedCodeThread s(thread); JSHandle func = JSNApiHelper::ToJSHandle(this); - JSHandle this_value; - if (this_obj.IsEmpty()) { - this_value = JSNApiHelper::ToJSHandle(this_obj); + JSHandle thisValue; + if (thisObj.IsEmpty()) { + thisValue = JSNApiHelper::ToJSHandle(thisObj); } else { - this_value = JSHandle(thread, thread->GlobalConstants()->GetUndefined()); + thisValue = JSHandle(thread, thread->GlobalConstants()->GetUndefined()); } - auto info = NewRuntimeCallInfo(thread, func, this_value, JSTaggedValue::Undefined(), length); + auto info = NewRuntimeCallInfo(thread, func, thisValue, JSTaggedValue::Undefined(), length); for (int32_t i = 0; i < length; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) info->SetCallArg(i, JSNApiHelper::ToJSHandle(argv[i]).GetTaggedValue()); @@ -945,12 +945,12 @@ Local FunctionRef::Call(const EcmaVM *vm, Local this_obj JSTaggedValue result = JSFunction::Call(info.Get()); RETURN_VALUE_IF_ABRUPT_NOT_CLEAR_EXCEPTION(thread, JSValueRef::Exception(vm)); - JSHandle result_value(thread, result); + JSHandle resultValue(thread, result); vm->ExecutePromisePendingJob(); RETURN_VALUE_IF_ABRUPT_NOT_CLEAR_EXCEPTION(thread, JSValueRef::Exception(vm)); - return JSNApiHelper::ToLocal(result_value); + return JSNApiHelper::ToLocal(resultValue); } Local FunctionRef::Constructor(const EcmaVM *vm, @@ -963,16 +963,16 @@ Local FunctionRef::Constructor(const EcmaVM *vm, } ScopedManagedCodeThread s(thread); JSHandle func = JSNApiHelper::ToJSHandle(this); - JSHandle new_target = func; - auto info = NewRuntimeCallInfo(thread, func, JSTaggedValue::Undefined(), new_target, length); + JSHandle newTarget = func; + auto info = NewRuntimeCallInfo(thread, func, JSTaggedValue::Undefined(), newTarget, length); for (int32_t i = 0; i < length; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) info->SetCallArg(i, JSNApiHelper::ToJSHandle(argv[i]).GetTaggedValue()); } JSTaggedValue result = JSFunction::Construct(info.Get()); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); - JSHandle result_value(vm->GetJSThread(), result); - return JSNApiHelper::ToLocal(result_value); + JSHandle resultValue(vm->GetJSThread(), result); + return JSNApiHelper::ToLocal(resultValue); } Local FunctionRef::GetFunctionPrototype(const EcmaVM *vm) @@ -988,18 +988,18 @@ bool FunctionRef::Inherit(const EcmaVM *vm, Local parent) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); - JSHandle parent_value = JSNApiHelper::ToJSHandle(parent); - JSHandle parent_handle = JSHandle::Cast(parent_value); - JSHandle this_handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(this)); + JSHandle parentValue = JSNApiHelper::ToJSHandle(parent); + JSHandle parentHandle = JSHandle::Cast(parentValue); + JSHandle thisHandle = JSHandle::Cast(JSNApiHelper::ToJSHandle(this)); // Set this.__proto__ to parent - bool res = JSObject::SetPrototype(thread, this_handle, parent_value); + bool res = JSObject::SetPrototype(thread, thisHandle, parentValue); if (!res) { return false; } // Set this.Prototype.__proto__ to parent.Prototype - JSHandle parent_proto_type(thread, JSFunction::PrototypeGetter(thread, parent_handle)); - JSHandle this_proto_type(thread, JSFunction::PrototypeGetter(thread, this_handle)); - return JSObject::SetPrototype(thread, JSHandle::Cast(this_proto_type), parent_proto_type); + JSHandle parentProtoType(thread, JSFunction::PrototypeGetter(thread, parentHandle)); + JSHandle thisProtoType(thread, JSFunction::PrototypeGetter(thread, thisHandle)); + return JSObject::SetPrototype(thread, JSHandle::Cast(thisProtoType), parentProtoType); } void FunctionRef::SetName(const EcmaVM *vm, Local name) @@ -1032,8 +1032,8 @@ Local ArrayRef::New(const EcmaVM *vm, int32_t length) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); - JSTaggedNumber array_len(length); - JSHandle array = JSArray::ArrayCreate(thread, array_len); + JSTaggedNumber arrayLen(length); + JSHandle array = JSArray::ArrayCreate(thread, arrayLen); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); return JSNApiHelper::ToLocal(array); } @@ -1055,17 +1055,17 @@ bool ArrayRef::SetValueAt(const EcmaVM *vm, Local obj, uint32_t inde { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); - JSHandle object_handle = JSNApiHelper::ToJSHandle(obj); - JSHandle value_handle = JSNApiHelper::ToJSHandle(value); - return JSArray::FastSetPropertyByValue(thread, object_handle, index, value_handle); + JSHandle objectHandle = JSNApiHelper::ToJSHandle(obj); + JSHandle valueHandle = JSNApiHelper::ToJSHandle(value); + return JSArray::FastSetPropertyByValue(thread, objectHandle, index, valueHandle); } // ---------------------------------- Promise -------------------------------------- Local PromiseCapabilityRef::New(const EcmaVM *vm) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); - JSHandle global_env = vm->GetGlobalEnv(); - JSHandle constructor(global_env->GetPromiseFunction()); + JSHandle globalEnv = vm->GetGlobalEnv(); + JSHandle constructor(globalEnv->GetPromiseFunction()); JSHandle capability(JSPromise::NewPromiseCapability(thread, constructor)); return JSNApiHelper::ToLocal(capability); } @@ -1126,12 +1126,12 @@ Local PromiseRef::Catch(const EcmaVM *vm, Local handler const GlobalEnvConstants *constants = thread->GlobalConstants(); JSHandle promise = JSNApiHelper::ToJSHandle(this); - JSHandle catch_key(thread, constants->GetPromiseCatchString()); + JSHandle catchKey(thread, constants->GetPromiseCatchString()); JSHandle reject = JSNApiHelper::ToJSHandle(handler); auto info = ecmascript::NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), promise, JSTaggedValue::Undefined(), 1); info->SetCallArgs(reject); - JSTaggedValue result = JSFunction::Invoke(info.Get(), catch_key); + JSTaggedValue result = JSFunction::Invoke(info.Get(), catchKey); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); return JSNApiHelper::ToLocal(JSHandle(thread, result)); @@ -1144,31 +1144,31 @@ Local PromiseRef::Then(const EcmaVM *vm, Local handler) const GlobalEnvConstants *constants = thread->GlobalConstants(); JSHandle promise = JSNApiHelper::ToJSHandle(this); - JSHandle then_key(thread, constants->GetPromiseThenString()); + JSHandle thenKey(thread, constants->GetPromiseThenString()); JSHandle resolver = JSNApiHelper::ToJSHandle(handler); auto info = ecmascript::NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), promise, JSTaggedValue::Undefined(), 2); info->SetCallArgs(resolver, JSTaggedValue::Undefined()); - JSTaggedValue result = JSFunction::Invoke(info.Get(), then_key); + JSTaggedValue result = JSFunction::Invoke(info.Get(), thenKey); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); return JSNApiHelper::ToLocal(JSHandle(thread, result)); } -Local PromiseRef::Then(const EcmaVM *vm, Local on_fulfilled, Local on_rejected) +Local PromiseRef::Then(const EcmaVM *vm, Local onFulfilled, Local onRejected) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); const GlobalEnvConstants *constants = thread->GlobalConstants(); JSHandle promise = JSNApiHelper::ToJSHandle(this); - JSHandle then_key(thread, constants->GetPromiseThenString()); - JSHandle resolve = JSNApiHelper::ToJSHandle(on_fulfilled); - JSHandle reject = JSNApiHelper::ToJSHandle(on_rejected); + JSHandle thenKey(thread, constants->GetPromiseThenString()); + JSHandle resolve = JSNApiHelper::ToJSHandle(onFulfilled); + JSHandle reject = JSNApiHelper::ToJSHandle(onRejected); auto info = ecmascript::NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), promise, JSTaggedValue::Undefined(), 2); info->SetCallArgs(resolve, reject); - JSTaggedValue result = JSFunction::Invoke(info.Get(), then_key); + JSTaggedValue result = JSFunction::Invoke(info.Get(), thenKey); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); return JSNApiHelper::ToLocal(JSHandle(thread, result)); @@ -1182,9 +1182,9 @@ Local ArrayBufferRef::New(const EcmaVM *vm, int32_t length) ScopedManagedCodeThread s(thread); ObjectFactory *factory = vm->GetFactory(); - JSHandle array_buffer = factory->NewJSArrayBuffer(length); + JSHandle arrayBuffer = factory->NewJSArrayBuffer(length); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); - return JSNApiHelper::ToLocal(JSHandle(array_buffer)); + return JSNApiHelper::ToLocal(JSHandle(arrayBuffer)); } Local ArrayBufferRef::New(const EcmaVM *vm, void *buffer, int32_t length, const Deleter &deleter, @@ -1194,17 +1194,17 @@ Local ArrayBufferRef::New(const EcmaVM *vm, void *buffer, int32_ ScopedManagedCodeThread s(thread); ObjectFactory *factory = vm->GetFactory(); - JSHandle array_buffer = + JSHandle arrayBuffer = factory->NewJSArrayBuffer(buffer, length, reinterpret_cast(deleter), data); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); - return JSNApiHelper::ToLocal(JSHandle(array_buffer)); + return JSNApiHelper::ToLocal(JSHandle(arrayBuffer)); } int32_t ArrayBufferRef::ByteLength(const EcmaVM *vm) { JSThread *thread = vm->GetJSThread(); - JSHandle array_buffer(JSNApiHelper::ToJSHandle(this)); - JSHandle length(thread, array_buffer->GetArrayBufferByteLength()); + JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); + JSHandle length(thread, arrayBuffer->GetArrayBufferByteLength()); if (!length->IsNumber()) { return 0; } @@ -1213,33 +1213,33 @@ int32_t ArrayBufferRef::ByteLength(const EcmaVM *vm) void *ArrayBufferRef::GetBuffer() { - JSHandle array_buffer(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue buffer_data = array_buffer->GetArrayBufferData(); - if (!buffer_data.IsJSNativePointer()) { + JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); + JSTaggedValue bufferData = arrayBuffer->GetArrayBufferData(); + if (!bufferData.IsJSNativePointer()) { return nullptr; } - return JSNativePointer::Cast(buffer_data.GetTaggedObject())->GetExternalPointer(); + return JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); } // ---------------------------------- Buffer ----------------------------------- // ---------------------------------- DataView ----------------------------------- -Local DataViewRef::New(const EcmaVM *vm, Local array_buffer, int32_t byte_offset, - int32_t byte_length) +Local DataViewRef::New(const EcmaVM *vm, Local arrayBuffer, int32_t byteOffset, + int32_t byteLength) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); ObjectFactory *factory = vm->GetFactory(); - JSHandle buffer(JSNApiHelper::ToJSHandle(array_buffer)); - JSHandle data_view = factory->NewJSDataView(buffer, byte_offset, byte_length); + JSHandle buffer(JSNApiHelper::ToJSHandle(arrayBuffer)); + JSHandle dataView = factory->NewJSDataView(buffer, byteOffset, byteLength); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); - return JSNApiHelper::ToLocal(JSHandle(data_view)); + return JSNApiHelper::ToLocal(JSHandle(dataView)); } int32_t DataViewRef::ByteLength() { - JSHandle data_view(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue length = data_view->GetByteLength(); + JSHandle dataView(JSNApiHelper::ToJSHandle(this)); + JSTaggedValue length = dataView->GetByteLength(); if (!length.IsNumber()) { return 0; } @@ -1248,8 +1248,8 @@ int32_t DataViewRef::ByteLength() int32_t DataViewRef::ByteOffset() { - JSHandle data_view(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue offset = data_view->GetByteOffset(); + JSHandle dataView(JSNApiHelper::ToJSHandle(this)); + JSTaggedValue offset = dataView->GetByteOffset(); if (!offset.IsNumber()) { return 0; } @@ -1259,17 +1259,17 @@ int32_t DataViewRef::ByteOffset() Local DataViewRef::GetArrayBuffer(const EcmaVM *vm) { JSThread *thread = vm->GetJSThread(); - JSHandle data_view(JSNApiHelper::ToJSHandle(this)); - JSHandle array_buffer(thread, data_view->GetViewedArrayBuffer()); - return JSNApiHelper::ToLocal(array_buffer); + JSHandle dataView(JSNApiHelper::ToJSHandle(this)); + JSHandle arrayBuffer(thread, dataView->GetViewedArrayBuffer()); + return JSNApiHelper::ToLocal(arrayBuffer); } // ---------------------------------- DataView ----------------------------------- // ---------------------------------- TypedArray ----------------------------------- int32_t TypedArrayRef::ByteLength([[maybe_unused]] const EcmaVM *vm) { - JSHandle typed_array(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue length = typed_array->GetByteLength(); + JSHandle typedArray(JSNApiHelper::ToJSHandle(this)); + JSTaggedValue length = typedArray->GetByteLength(); if (!length.IsNumber()) { return 0; } @@ -1278,8 +1278,8 @@ int32_t TypedArrayRef::ByteLength([[maybe_unused]] const EcmaVM *vm) int32_t TypedArrayRef::ByteOffset([[maybe_unused]] const EcmaVM *vm) { - JSHandle typed_array(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue length = typed_array->GetByteOffset(); + JSHandle typedArray(JSNApiHelper::ToJSHandle(this)); + JSTaggedValue length = typedArray->GetByteOffset(); if (!length.IsNumber()) { return 0; } @@ -1288,8 +1288,8 @@ int32_t TypedArrayRef::ByteOffset([[maybe_unused]] const EcmaVM *vm) int32_t TypedArrayRef::ArrayLength([[maybe_unused]] const EcmaVM *vm) { - JSHandle typed_array(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue length = typed_array->GetArrayLength(); + JSHandle typedArray(JSNApiHelper::ToJSHandle(this)); + JSTaggedValue length = typedArray->GetArrayLength(); if (!length.IsNumber()) { return 0; } @@ -1299,29 +1299,29 @@ int32_t TypedArrayRef::ArrayLength([[maybe_unused]] const EcmaVM *vm) Local TypedArrayRef::GetArrayBuffer(const EcmaVM *vm) { JSThread *thread = vm->GetJSThread(); - JSHandle type_array(JSNApiHelper::ToJSHandle(this)); - JSHandle array_buffer(thread, JSTypedArray::Cast(*type_array)->GetViewedArrayBuffer()); - return JSNApiHelper::ToLocal(array_buffer); + JSHandle typeArray(JSNApiHelper::ToJSHandle(this)); + JSHandle arrayBuffer(thread, JSTypedArray::Cast(*typeArray)->GetViewedArrayBuffer()); + return JSNApiHelper::ToLocal(arrayBuffer); } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define TYPED_ARRAY_NEW(Type) \ - Local Type##Ref::New(const EcmaVM *vm, Local buffer, int32_t byte_offset, \ - int32_t length) \ - { \ - JSThread *thread = vm->GetJSThread(); \ - ScopedManagedCodeThread s(thread); \ - JSHandle env = vm->GetGlobalEnv(); \ - \ - JSHandle func = env->Get##Type##Function(); \ - JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(buffer)); \ - uint32_t argc = 3; \ - auto info = NewRuntimeCallInfo(thread, func, JSTaggedValue::Undefined(), func, argc); \ - info->SetCallArgs(arrayBuffer, JSTaggedValue(byte_offset), JSTaggedValue(length)); \ - JSTaggedValue result = JSFunction::Construct(info.Get()); \ - RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); \ - JSHandle resultHandle(thread, result); \ - return JSNApiHelper::ToLocal(resultHandle); \ +#define TYPED_ARRAY_NEW(Type) \ + Local Type##Ref::New(const EcmaVM *vm, Local buffer, int32_t byteOffset, \ + int32_t length) \ + { \ + JSThread *thread = vm->GetJSThread(); \ + ScopedManagedCodeThread s(thread); \ + JSHandle env = vm->GetGlobalEnv(); \ + \ + JSHandle func = env->Get##Type##Function(); \ + JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(buffer)); \ + uint32_t argc = 3; \ + auto info = NewRuntimeCallInfo(thread, func, JSTaggedValue::Undefined(), func, argc); \ + info->SetCallArgs(arrayBuffer, JSTaggedValue(byteOffset), JSTaggedValue(length)); \ + JSTaggedValue result = JSFunction::Construct(info.Get()); \ + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); \ + JSHandle resultHandle(thread, result); \ + return JSNApiHelper::ToLocal(resultHandle); \ } TYPED_ARRAY_ALL(TYPED_ARRAY_NEW) @@ -1354,9 +1354,9 @@ Local JSON::Parse(const EcmaVM *vm, Local string) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); - auto ecma_str = EcmaString::Cast(JSNApiHelper::ToJSTaggedValue(*string).GetTaggedObject()); + auto ecmaStr = EcmaString::Cast(JSNApiHelper::ToJSTaggedValue(*string).GetTaggedObject()); JSHandle result; - if (ecma_str->IsUtf8()) { + if (ecmaStr->IsUtf8()) { JsonParser parser(thread); result = parser.ParseUtf8(EcmaString::Cast(JSNApiHelper::ToJSTaggedValue(*string).GetTaggedObject())); } else { @@ -1383,26 +1383,26 @@ Local RegExpRef::GetOriginalSource(const EcmaVM *vm) { JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); - JSHandle reg_exp(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue source = reg_exp->GetOriginalSource(); + JSHandle regExp(JSNApiHelper::ToJSHandle(this)); + JSTaggedValue source = regExp->GetOriginalSource(); if (!source.IsString()) { auto constants = thread->GlobalConstants(); return JSNApiHelper::ToLocal(constants->GetHandledEmptyString()); } - JSHandle source_handle(thread, source); - return JSNApiHelper::ToLocal(source_handle); + JSHandle sourceHandle(thread, source); + return JSNApiHelper::ToLocal(sourceHandle); } Local DateRef::New(const EcmaVM *vm, double time) { JSThread *thread = vm->GetJSThread(); ObjectFactory *factory = vm->GetFactory(); - JSHandle global_env = vm->GetGlobalEnv(); - JSHandle date_function = global_env->GetDateFunction(); - JSHandle date_object = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(date_function), date_function)); - date_object->SetTimeValue(thread, JSTaggedValue(time)); - return JSNApiHelper::ToLocal(JSHandle(date_object)); + JSHandle globalEnv = vm->GetGlobalEnv(); + JSHandle dateFunction = globalEnv->GetDateFunction(); + JSHandle dateObject = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(dateFunction), dateFunction)); + dateObject->SetTimeValue(thread, JSTaggedValue(time)); + return JSNApiHelper::ToLocal(JSHandle(dateObject)); } Local DateRef::ToString(const EcmaVM *vm) @@ -1410,13 +1410,13 @@ Local DateRef::ToString(const EcmaVM *vm) JSThread *thread = vm->GetJSThread(); ScopedManagedCodeThread s(thread); JSHandle date(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue date_str = date->ToString(thread); - if (!date_str.IsString()) { + JSTaggedValue dateStr = date->ToString(thread); + if (!dateStr.IsString()) { auto constants = thread->GlobalConstants(); return JSNApiHelper::ToLocal(constants->GetHandledEmptyString()); } - JSHandle date_str_handle(thread, date_str); - return JSNApiHelper::ToLocal(date_str_handle); + JSHandle dateStrHandle(thread, dateStr); + return JSNApiHelper::ToLocal(dateStrHandle); } double DateRef::GetTime() @@ -1445,41 +1445,41 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) { // Constructor JSThread *thread = info->GetThread(); - [[maybe_unused]] panda::ecmascript::EcmaHandleScope handle_scope(thread); + [[maybe_unused]] panda::ecmascript::EcmaHandleScope handleScope(thread); JSHandle constructor = ecmascript::builtins_common::GetConstructor(info); if (!constructor->IsJSFunction()) { return JSTaggedValue::False(); } JSHandle function(constructor); - JSHandle extra_info_value(thread, function->GetFunctionExtraInfo()); - if (!extra_info_value->IsJSFunctionExtraInfo()) { + JSHandle extraInfoValue(thread, function->GetFunctionExtraInfo()); + if (!extraInfoValue->IsJSFunctionExtraInfo()) { return JSTaggedValue::False(); } - JSHandle extra_info(extra_info_value); + JSHandle extraInfo(extraInfoValue); // vm - JSHandle vm_value(thread, extra_info->GetVm()); - if (!vm_value->IsHeapObject()) { + JSHandle vmValue(thread, extraInfo->GetVm()); + if (!vmValue->IsHeapObject()) { return JSTaggedValue::False(); } - JSHandle vm_obj(vm_value); - auto *vm = reinterpret_cast(vm_obj->GetExternalPointer()); + JSHandle vmObj(vmValue); + auto *vm = reinterpret_cast(vmObj->GetExternalPointer()); // data - JSHandle data(thread, extra_info->GetData()); + JSHandle data(thread, extraInfo->GetData()); if (!data->IsHeapObject()) { return JSTaggedValue::False(); } - JSHandle data_obj(data); + JSHandle dataObj(data); // callBack - JSHandle call_back(thread, extra_info->GetCallback()); - if (!call_back->IsHeapObject()) { + JSHandle callBack(thread, extraInfo->GetCallback()); + if (!callBack->IsHeapObject()) { return JSTaggedValue::False(); } - JSHandle call_back_obj(call_back); - FunctionCallback native_func = (reinterpret_cast(call_back_obj->GetExternalPointer())); + JSHandle callBackObj(callBack); + FunctionCallback nativeFunc = (reinterpret_cast(callBackObj->GetExternalPointer())); // this - JSHandle this_value(ecmascript::builtins_common::GetThis(info)); + JSHandle thisValue(ecmascript::builtins_common::GetThis(info)); // arguments std::vector> arguments; @@ -1489,8 +1489,8 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) } ScopedNativeCodeThread s(thread); - Local result = native_func(vm, JSNApiHelper::ToLocal(this_value), arguments.data(), - arguments.size(), data_obj->GetExternalPointer()); + Local result = nativeFunc(vm, JSNApiHelper::ToLocal(thisValue), arguments.data(), + arguments.size(), dataObj->GetExternalPointer()); return JSNApiHelper::ToJSHandle(result).GetTaggedValue(); } @@ -1503,28 +1503,28 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall return JSTaggedValue::False(); } JSHandle function(constructor); - JSHandle extra_info_value(thread, function->GetFunctionExtraInfo()); - if (!extra_info_value->IsJSFunctionExtraInfo()) { + JSHandle extraInfoValue(thread, function->GetFunctionExtraInfo()); + if (!extraInfoValue->IsJSFunctionExtraInfo()) { return JSTaggedValue::False(); } - JSHandle extra_info(extra_info_value); + JSHandle extraInfo(extraInfoValue); EcmaVM *vm = thread->GetEcmaVM(); // data - JSHandle data(thread, extra_info->GetData()); + JSHandle data(thread, extraInfo->GetData()); if (!data->IsHeapObject()) { return JSTaggedValue::False(); } - JSHandle data_obj(data); + JSHandle dataObj(data); // callBack - JSHandle call_back(thread, extra_info->GetCallback()); - if (!call_back->IsHeapObject()) { + JSHandle callBack(thread, extraInfo->GetCallback()); + if (!callBack->IsHeapObject()) { return JSTaggedValue::False(); } - JSHandle call_back_obj(call_back); - FunctionCallback native_func = (reinterpret_cast(call_back_obj->GetExternalPointer())); + JSHandle callBackObj(callBack); + FunctionCallback nativeFunc = (reinterpret_cast(callBackObj->GetExternalPointer())); // constructor - JSHandle this_value(ecmascript::builtins_common::GetConstructor(info)); + JSHandle thisValue(ecmascript::builtins_common::GetConstructor(info)); // arguments std::vector> arguments; @@ -1534,8 +1534,8 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall } ScopedNativeCodeThread s(thread); - Local result = native_func(vm, JSNApiHelper::ToLocal(this_value), arguments.data(), - arguments.size(), data_obj->GetExternalPointer()); + Local result = nativeFunc(vm, JSNApiHelper::ToLocal(thisValue), arguments.data(), + arguments.size(), dataObj->GetExternalPointer()); return JSNApiHelper::ToJSHandle(result).GetTaggedValue(); } @@ -1548,32 +1548,32 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal return JSTaggedValue::False(); } JSHandle function(constructor); - JSHandle extra_info_value(thread, function->GetFunctionExtraInfo()); - if (!extra_info_value->IsJSFunctionExtraInfo()) { + JSHandle extraInfoValue(thread, function->GetFunctionExtraInfo()); + if (!extraInfoValue->IsJSFunctionExtraInfo()) { return JSTaggedValue::False(); } - JSHandle extra_info(extra_info_value); + JSHandle extraInfo(extraInfoValue); EcmaVM *vm = thread->GetEcmaVM(); // data - JSHandle data(thread, extra_info->GetData()); + JSHandle data(thread, extraInfo->GetData()); if (!data->IsHeapObject()) { return JSTaggedValue::False(); } - JSHandle data_obj(data); + JSHandle dataObj(data); // callBack - JSHandle call_back(thread, extra_info->GetCallback()); - if (!call_back->IsHeapObject()) { + JSHandle callBack(thread, extraInfo->GetCallback()); + if (!callBack->IsHeapObject()) { return JSTaggedValue::False(); } - JSHandle call_back_obj(call_back); - FunctionCallbackWithNewTarget native_func = - (reinterpret_cast(call_back_obj->GetExternalPointer())); + JSHandle callBackObj(callBack); + FunctionCallbackWithNewTarget nativeFunc = + (reinterpret_cast(callBackObj->GetExternalPointer())); // new_target - JSHandle new_target(ecmascript::builtins_common::GetNewTarget(info)); + JSHandle newTarget(ecmascript::builtins_common::GetNewTarget(info)); // this - JSHandle this_value(ecmascript::builtins_common::GetThis(info)); + JSHandle thisValue(ecmascript::builtins_common::GetThis(info)); // arguments std::vector> arguments; @@ -1584,8 +1584,8 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal ScopedNativeCodeThread s(thread); Local result = - native_func(vm, JSNApiHelper::ToLocal(this_value), JSNApiHelper::ToLocal(new_target), - arguments.data(), arguments.size(), data_obj->GetExternalPointer()); + nativeFunc(vm, JSNApiHelper::ToLocal(thisValue), JSNApiHelper::ToLocal(newTarget), + arguments.data(), arguments.size(), dataObj->GetExternalPointer()); return JSNApiHelper::ToJSHandle(result).GetTaggedValue(); } @@ -1597,8 +1597,8 @@ JSExecutionScope::JSExecutionScope(const EcmaVM *vm) JSExecutionScope::~JSExecutionScope() { - last_current_thread_ = nullptr; - is_revert_ = false; + lastCurrentThread_ = nullptr; + isRevert_ = false; } // ----------------------------------- JSValueRef -------------------------------------- @@ -1693,8 +1693,8 @@ Local JSValueRef::ToBoolean(const EcmaVM *vm) { JSThread *thread = vm->GetJSThread(); JSHandle obj = JSNApiHelper::ToJSHandle(this); - JSHandle boolean_obj = JSHandle(thread, JSTaggedValue(obj->ToBoolean())); - return JSNApiHelper::ToLocal(boolean_obj); + JSHandle booleanObj = JSHandle(thread, JSTaggedValue(obj->ToBoolean())); + return JSNApiHelper::ToLocal(booleanObj); } Local JSValueRef::ToNumber(const EcmaVM *vm) @@ -1709,9 +1709,9 @@ Local JSValueRef::ToNumber(const EcmaVM *vm) bool JSValueRef::IsStrictEquals(const EcmaVM *vm, Local value) { JSThread *thread = vm->GetJSThread(); - JSHandle x_value = JSNApiHelper::ToJSHandle(this); - JSHandle y_value = JSNApiHelper::ToJSHandle(value); - return JSTaggedValue::StrictEqual(thread, x_value, y_value); + JSHandle xValue = JSNApiHelper::ToJSHandle(this); + JSHandle yValue = JSNApiHelper::ToJSHandle(value); + return JSTaggedValue::StrictEqual(thread, xValue, yValue); } Local JSValueRef::Typeof(const EcmaVM *vm) diff --git a/runtime/napi/jsnapi_debugger_agent.cpp b/runtime/napi/jsnapi_debugger_agent.cpp index 7b0ccdaa59144b8d6bde066bb25df34f002ad94f..5ef55200bb998fb7afa4b4c7cb72eb703c7df20b 100644 --- a/runtime/napi/jsnapi_debugger_agent.cpp +++ b/runtime/napi/jsnapi_debugger_agent.cpp @@ -18,18 +18,18 @@ #include "plugins/ecmascript/runtime/ecma_macros.h" namespace panda { -JSNApiDebuggerAgent::JSNApiDebuggerAgent(os::memory::Mutex &mutex, const char *library_path, EcmaVM *vm, - bool is_debug_mode) - : LibraryAgent(mutex, library_path, "StartDebug", "StopDebug"), vm_(vm), is_debug_mode_(is_debug_mode) +JSNApiDebuggerAgent::JSNApiDebuggerAgent(os::memory::Mutex &mutex, const char *libraryPath, EcmaVM *vm, + bool isDebugMode) + : LibraryAgent(mutex, libraryPath, "StartDebug", "StopDebug"), vm_(vm), isDebugMode_(isDebugMode) { } -bool JSNApiDebuggerAgent::CallLoadCallback(void *resolved_function) +bool JSNApiDebuggerAgent::CallLoadCallback(void *resolvedFunction) { - ASSERT(resolved_function); + ASSERT(resolvedFunction); using StartDebugger = bool (*)(const std::string &, EcmaVM *, bool); - if (!reinterpret_cast(resolved_function)("PandaDebugger", vm_, is_debug_mode_)) { + if (!reinterpret_cast(resolvedFunction)("PandaDebugger", vm_, isDebugMode_)) { LOG_ECMA(ERROR) << "'StartDebug' has failed"; return false; } @@ -37,12 +37,12 @@ bool JSNApiDebuggerAgent::CallLoadCallback(void *resolved_function) return true; } -bool JSNApiDebuggerAgent::CallUnloadCallback(void *resolved_function) +bool JSNApiDebuggerAgent::CallUnloadCallback(void *resolvedFunction) { - ASSERT(resolved_function); + ASSERT(resolvedFunction); using StopDebug = void (*)(const std::string &); - reinterpret_cast(resolved_function)("PandaDebugger"); + reinterpret_cast(resolvedFunction)("PandaDebugger"); return true; } diff --git a/runtime/napi/jsnapi_debugger_agent.h b/runtime/napi/jsnapi_debugger_agent.h index a6f0d38eb39cd1a3fd12f3cfec024b24f15817b3..849dcef6fb4f5c2ee18b6e2cd205406a4ba8fd23 100644 --- a/runtime/napi/jsnapi_debugger_agent.h +++ b/runtime/napi/jsnapi_debugger_agent.h @@ -22,14 +22,14 @@ namespace panda { class JSNApiDebuggerAgent : public LibraryAgent, public LibraryAgentLoader { public: - JSNApiDebuggerAgent(os::memory::Mutex &mutex, const char *library_path, EcmaVM *vm, bool is_debug_mode); + JSNApiDebuggerAgent(os::memory::Mutex &mutex, const char *libraryPath, EcmaVM *vm, bool isDebugMode); private: - bool CallLoadCallback(void *resolved_function) override; - bool CallUnloadCallback(void *resolved_function) override; + bool CallLoadCallback(void *resolvedFunction) override; + bool CallUnloadCallback(void *resolvedFunction) override; EcmaVM *vm_; - bool is_debug_mode_; + bool isDebugMode_; }; } // namespace panda diff --git a/runtime/object_factory-inl.h b/runtime/object_factory-inl.h index a4b5cc1526592a28dfbd494c417d1fb32b216f46..d297696996a5b6147ebf78468fc938d809e0d238 100644 --- a/runtime/object_factory-inl.h +++ b/runtime/object_factory-inl.h @@ -25,58 +25,58 @@ namespace panda::ecmascript { EcmaString *ObjectFactory::AllocNonMovableStringObject(size_t size) { NewObjectHook(); - return reinterpret_cast(heap_helper_.AllocateNonMovableOrHugeObject(string_class_, size)); + return reinterpret_cast(heapHelper_.AllocateNonMovableOrHugeObject(stringClass_, size)); } EcmaString *ObjectFactory::AllocStringObject(size_t size) { NewObjectHook(); - return reinterpret_cast(heap_helper_.AllocateYoungGenerationOrHugeObject( - string_class_, size, mem::ObjectAllocatorBase::ObjMemInitPolicy::NO_INIT)); + return reinterpret_cast(heapHelper_.AllocateYoungGenerationOrHugeObject( + stringClass_, size, mem::ObjectAllocatorBase::ObjMemInitPolicy::NO_INIT)); } -JSHandle ObjectFactory::NewJSNativePointer(void *external_pointer, const DeleteEntryPoint &call_back, - void *data, bool non_movable) +JSHandle ObjectFactory::NewJSNativePointer(void *externalPointer, const DeleteEntryPoint &callBack, + void *data, bool nonMovable) { NewObjectHook(); TaggedObject *header; - if (non_movable) { - header = heap_helper_.AllocateNonMovableOrHugeObject(js_native_pointer_class_); + if (nonMovable) { + header = heapHelper_.AllocateNonMovableOrHugeObject(jsNativePointerClass_); } else { - header = heap_helper_.AllocateYoungGenerationOrHugeObject(js_native_pointer_class_); + header = heapHelper_.AllocateYoungGenerationOrHugeObject(jsNativePointerClass_); } JSHandle obj(thread_, header); - obj->SetExternalPointer(external_pointer); - obj->SetDeleter(call_back); + obj->SetExternalPointer(externalPointer); + obj->SetDeleter(callBack); obj->SetData(data); return obj; } -LexicalEnv *ObjectFactory::InlineNewLexicalEnv(int num_slots) +LexicalEnv *ObjectFactory::InlineNewLexicalEnv(int numSlots) { NewObjectHook(); - size_t size = LexicalEnv::ComputeSize(num_slots); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(env_class_, size); + size_t size = LexicalEnv::ComputeSize(numSlots); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(envClass_, size); if (UNLIKELY(header == nullptr)) { return nullptr; } LexicalEnv *array = LexicalEnv::Cast(header); - array->InitializeWithSpecialValue(JSTaggedValue::Hole(), num_slots + LexicalEnv::RESERVED_ENV_LENGTH); + array->InitializeWithSpecialValue(JSTaggedValue::Hole(), numSlots + LexicalEnv::RESERVED_ENV_LENGTH); return array; } template void ObjectFactory::NewJSIntlIcuData(const JSHandle &obj, const S &icu, const DeleteEntryPoint &callback) { - S *icu_point = Runtime::GetCurrent()->GetInternalAllocator()->New(icu); - ASSERT(icu_point != nullptr); + S *icuPoint = Runtime::GetCurrent()->GetInternalAllocator()->New(icu); + ASSERT(icuPoint != nullptr); JSTaggedValue data = obj->GetIcuField(); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); - native->ResetExternalPointer(icu_point); + native->ResetExternalPointer(icuPoint); return; } - JSHandle pointer = NewJSNativePointer(icu_point, callback, vm_); + JSHandle pointer = NewJSNativePointer(icuPoint, callback, vm_); obj->SetIcuField(thread_, pointer.GetTaggedValue()); // push uint8_t* to ecma array_data_list vm_->PushToArrayDataList(*pointer); diff --git a/runtime/object_factory.cpp b/runtime/object_factory.cpp index cdfddbfde377b65a5383e34b1e9631f550b2a932..d8d7baaad3588c3b8a5ebc872ddb2c0595ad95fa 100644 --- a/runtime/object_factory.cpp +++ b/runtime/object_factory.cpp @@ -94,98 +94,95 @@ static void PandaFreeBufferFunc(void *buffer, void *size) } ObjectFactory::ObjectFactory(JSThread *thread) - : thread_(thread), heap_helper_(thread->GetEcmaVM()), vm_(thread->GetEcmaVM()) + : thread_(thread), heapHelper_(thread->GetEcmaVM()), vm_(thread->GetEcmaVM()) { } JSHandle ObjectFactory::NewEcmaDynClassClass(JSHClass *hclass, uint32_t size, JSType type) { NewObjectHook(); - uint32_t class_size = JSHClass::SIZE; - auto *new_class = static_cast(heap_helper_.AllocateDynClassClass(hclass, class_size)); - new_class->Initialize(thread_, size, type, 0, HClass::HCLASS); + uint32_t classSize = JSHClass::SIZE; + auto *newClass = static_cast(heapHelper_.AllocateDynClassClass(hclass, classSize)); + newClass->Initialize(thread_, size, type, 0, HClass::HCLASS); - return JSHandle(thread_, new_class); + return JSHandle(thread_, newClass); } JSHandle ObjectFactory::NewEcmaDynClass(JSHClass *hclass, uint32_t size, JSType type, uint32_t flags, - uint32_t inlined_props) + uint32_t inlinedProps) { NewObjectHook(); - uint32_t class_size = JSHClass::SIZE; - auto *new_class = static_cast(heap_helper_.AllocateNonMovableOrHugeObject(hclass, class_size)); - new_class->Initialize(thread_, size, type, inlined_props, flags); - - return JSHandle(thread_, new_class); -} - -JSHandle ObjectFactory::NewEcmaDynClass(uint32_t size, JSType type, uint32_t inlined_props) -{ - return NewEcmaDynClass(hclass_class_, size, type, 0, inlined_props); -} - -void ObjectFactory::ObtainRootClass([[maybe_unused]] const JSHandle &global_env) -{ - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - hclass_class_ = JSHClass::Cast(global_const->GetHClassClass().GetTaggedObject()); - string_class_ = JSHClass::Cast(global_const->GetStringClass().GetTaggedObject()); - array_class_ = JSHClass::Cast(global_const->GetArrayClass().GetTaggedObject()); - weak_array_class_ = JSHClass::Cast(global_const->GetWeakArrayClass().GetTaggedObject()); - big_int_class_ = JSHClass::Cast(global_const->GetBigIntClass().GetTaggedObject()); - dictionary_class_ = JSHClass::Cast(global_const->GetDictionaryClass().GetTaggedObject()); - js_native_pointer_class_ = JSHClass::Cast(global_const->GetJSNativePointerClass().GetTaggedObject()); - free_object_with_none_field_class_ = - JSHClass::Cast(global_const->GetFreeObjectWithNoneFieldClass().GetTaggedObject()); - free_object_with_one_field_class_ = - JSHClass::Cast(global_const->GetFreeObjectWithOneFieldClass().GetTaggedObject()); - free_object_with_two_field_class_ = - JSHClass::Cast(global_const->GetFreeObjectWithTwoFieldClass().GetTaggedObject()); - completion_record_class_ = JSHClass::Cast(global_const->GetCompletionRecordClass().GetTaggedObject()); - generator_context_class_ = JSHClass::Cast(global_const->GetGeneratorContextClass().GetTaggedObject()); - program_class_ = JSHClass::Cast(global_const->GetProgramClass().GetTaggedObject()); - ecma_module_class_ = JSHClass::Cast(global_const->GetEcmaModuleClass().GetTaggedObject()); - env_class_ = JSHClass::Cast(global_const->GetEnvClass().GetTaggedObject()); - symbol_class_ = JSHClass::Cast(global_const->GetSymbolClass().GetTaggedObject()); - accessor_data_class_ = JSHClass::Cast(global_const->GetAccessorDataClass().GetTaggedObject()); - internal_accessor_class_ = JSHClass::Cast(global_const->GetInternalAccessorClass().GetTaggedObject()); - capability_record_class_ = JSHClass::Cast(global_const->GetCapabilityRecordClass().GetTaggedObject()); - reactions_record_class_ = JSHClass::Cast(global_const->GetReactionsRecordClass().GetTaggedObject()); - promise_iterator_record_class_ = JSHClass::Cast(global_const->GetPromiseIteratorRecordClass().GetTaggedObject()); - micro_job_queue_class_ = JSHClass::Cast(global_const->GetMicroJobQueueClass().GetTaggedObject()); - pending_job_class_ = JSHClass::Cast(global_const->GetPendingJobClass().GetTaggedObject()); - js_proxy_ordinary_class_ = JSHClass::Cast(global_const->GetJSProxyOrdinaryClass().GetTaggedObject()); - js_proxy_callable_class_ = JSHClass::Cast(global_const->GetJSProxyCallableClass().GetTaggedObject()); - js_proxy_construct_class_ = JSHClass::Cast(global_const->GetJSProxyConstructClass().GetTaggedObject()); - object_wrapper_class_ = JSHClass::Cast(global_const->GetObjectWrapperClass().GetTaggedObject()); - property_box_class_ = JSHClass::Cast(global_const->GetPropertyBoxClass().GetTaggedObject()); - proto_change_marker_class_ = JSHClass::Cast(global_const->GetProtoChangeMarkerClass().GetTaggedObject()); - proto_change_details_class_ = JSHClass::Cast(global_const->GetProtoChangeDetailsClass().GetTaggedObject()); - promise_record_class_ = JSHClass::Cast(global_const->GetPromiseRecordClass().GetTaggedObject()); - promise_resolving_functions_record_ = - JSHClass::Cast(global_const->GetPromiseResolvingFunctionsRecordClass().GetTaggedObject()); - transition_handler_class_ = JSHClass::Cast(global_const->GetTransitionHandlerClass().GetTaggedObject()); - prototype_handler_class_ = JSHClass::Cast(global_const->GetPrototypeHandlerClass().GetTaggedObject()); - function_extra_info_ = JSHClass::Cast(global_const->GetFunctionExtraInfoClass().GetTaggedObject()); - js_realm_class_ = JSHClass::Cast(global_const->GetJSRealmClass().GetTaggedObject()); - class_info_extractor_h_class_ = JSHClass::Cast(global_const->GetClassInfoExtractorHClass().GetTaggedObject()); - - linked_hash_map_class_ = JSHClass::Cast(global_const->GetLinkedHashMapClass().GetTaggedObject()); - linked_hash_set_class_ = JSHClass::Cast(global_const->GetLinkedHashSetClass().GetTaggedObject()); - weak_ref_class_ = JSHClass::Cast(global_const->GetWeakRefClass().GetTaggedObject()); - weak_linked_hash_map_class_ = JSHClass::Cast(global_const->GetWeakLinkedHashMapClass().GetTaggedObject()); - weak_linked_hash_set_class_ = JSHClass::Cast(global_const->GetWeakLinkedHashSetClass().GetTaggedObject()); + uint32_t classSize = JSHClass::SIZE; + auto *newClass = static_cast(heapHelper_.AllocateNonMovableOrHugeObject(hclass, classSize)); + newClass->Initialize(thread_, size, type, inlinedProps, flags); + + return JSHandle(thread_, newClass); +} + +JSHandle ObjectFactory::NewEcmaDynClass(uint32_t size, JSType type, uint32_t inlinedProps) +{ + return NewEcmaDynClass(hclassClass_, size, type, 0, inlinedProps); +} + +void ObjectFactory::ObtainRootClass([[maybe_unused]] const JSHandle &globalEnv) +{ + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + hclassClass_ = JSHClass::Cast(globalConst->GetHClassClass().GetTaggedObject()); + stringClass_ = JSHClass::Cast(globalConst->GetStringClass().GetTaggedObject()); + arrayClass_ = JSHClass::Cast(globalConst->GetArrayClass().GetTaggedObject()); + weakArrayClass_ = JSHClass::Cast(globalConst->GetWeakArrayClass().GetTaggedObject()); + bigIntClass_ = JSHClass::Cast(globalConst->GetBigIntClass().GetTaggedObject()); + dictionaryClass_ = JSHClass::Cast(globalConst->GetDictionaryClass().GetTaggedObject()); + jsNativePointerClass_ = JSHClass::Cast(globalConst->GetJSNativePointerClass().GetTaggedObject()); + freeObjectWithNoneFieldClass_ = JSHClass::Cast(globalConst->GetFreeObjectWithNoneFieldClass().GetTaggedObject()); + freeObjectWithOneFieldClass_ = JSHClass::Cast(globalConst->GetFreeObjectWithOneFieldClass().GetTaggedObject()); + freeObjectWithTwoFieldClass_ = JSHClass::Cast(globalConst->GetFreeObjectWithTwoFieldClass().GetTaggedObject()); + completionRecordClass_ = JSHClass::Cast(globalConst->GetCompletionRecordClass().GetTaggedObject()); + generatorContextClass_ = JSHClass::Cast(globalConst->GetGeneratorContextClass().GetTaggedObject()); + programClass_ = JSHClass::Cast(globalConst->GetProgramClass().GetTaggedObject()); + ecmaModuleClass_ = JSHClass::Cast(globalConst->GetEcmaModuleClass().GetTaggedObject()); + envClass_ = JSHClass::Cast(globalConst->GetEnvClass().GetTaggedObject()); + symbolClass_ = JSHClass::Cast(globalConst->GetSymbolClass().GetTaggedObject()); + accessorDataClass_ = JSHClass::Cast(globalConst->GetAccessorDataClass().GetTaggedObject()); + internalAccessorClass_ = JSHClass::Cast(globalConst->GetInternalAccessorClass().GetTaggedObject()); + capabilityRecordClass_ = JSHClass::Cast(globalConst->GetCapabilityRecordClass().GetTaggedObject()); + reactionsRecordClass_ = JSHClass::Cast(globalConst->GetReactionsRecordClass().GetTaggedObject()); + promiseIteratorRecordClass_ = JSHClass::Cast(globalConst->GetPromiseIteratorRecordClass().GetTaggedObject()); + microJobQueueClass_ = JSHClass::Cast(globalConst->GetMicroJobQueueClass().GetTaggedObject()); + pendingJobClass_ = JSHClass::Cast(globalConst->GetPendingJobClass().GetTaggedObject()); + jsProxyOrdinaryClass_ = JSHClass::Cast(globalConst->GetJSProxyOrdinaryClass().GetTaggedObject()); + jsProxyCallableClass_ = JSHClass::Cast(globalConst->GetJSProxyCallableClass().GetTaggedObject()); + jsProxyConstructClass_ = JSHClass::Cast(globalConst->GetJSProxyConstructClass().GetTaggedObject()); + objectWrapperClass_ = JSHClass::Cast(globalConst->GetObjectWrapperClass().GetTaggedObject()); + propertyBoxClass_ = JSHClass::Cast(globalConst->GetPropertyBoxClass().GetTaggedObject()); + protoChangeMarkerClass_ = JSHClass::Cast(globalConst->GetProtoChangeMarkerClass().GetTaggedObject()); + protoChangeDetailsClass_ = JSHClass::Cast(globalConst->GetProtoChangeDetailsClass().GetTaggedObject()); + promiseRecordClass_ = JSHClass::Cast(globalConst->GetPromiseRecordClass().GetTaggedObject()); + promiseResolvingFunctionsRecord_ = + JSHClass::Cast(globalConst->GetPromiseResolvingFunctionsRecordClass().GetTaggedObject()); + transitionHandlerClass_ = JSHClass::Cast(globalConst->GetTransitionHandlerClass().GetTaggedObject()); + prototypeHandlerClass_ = JSHClass::Cast(globalConst->GetPrototypeHandlerClass().GetTaggedObject()); + functionExtraInfo_ = JSHClass::Cast(globalConst->GetFunctionExtraInfoClass().GetTaggedObject()); + jsRealmClass_ = JSHClass::Cast(globalConst->GetJSRealmClass().GetTaggedObject()); + classInfoExtractorHClass_ = JSHClass::Cast(globalConst->GetClassInfoExtractorHClass().GetTaggedObject()); + + linkedHashMapClass_ = JSHClass::Cast(globalConst->GetLinkedHashMapClass().GetTaggedObject()); + linkedHashSetClass_ = JSHClass::Cast(globalConst->GetLinkedHashSetClass().GetTaggedObject()); + weakRefClass_ = JSHClass::Cast(globalConst->GetWeakRefClass().GetTaggedObject()); + weakLinkedHashMapClass_ = JSHClass::Cast(globalConst->GetWeakLinkedHashMapClass().GetTaggedObject()); + weakLinkedHashSetClass_ = JSHClass::Cast(globalConst->GetWeakLinkedHashSetClass().GetTaggedObject()); } void ObjectFactory::InitObjectFields(TaggedObject *object) { auto *klass = object->GetClass(); - auto obj_body_size = klass->GetObjectSize() - TaggedObject::TaggedObjectSize(); - ASSERT(obj_body_size % JSTaggedValue::TaggedTypeSize() == 0); - int num_of_fields = static_cast(obj_body_size / JSTaggedValue::TaggedTypeSize()); - for (int i = 0; i < num_of_fields; i++) { - size_t field_offset = TaggedObject::TaggedObjectSize() + i * JSTaggedValue::TaggedTypeSize(); + auto objBodySize = klass->GetObjectSize() - TaggedObject::TaggedObjectSize(); + ASSERT(objBodySize % JSTaggedValue::TaggedTypeSize() == 0); + int numOfFields = static_cast(objBodySize / JSTaggedValue::TaggedTypeSize()); + for (int i = 0; i < numOfFields; i++) { + size_t fieldOffset = TaggedObject::TaggedObjectSize() + i * JSTaggedValue::TaggedTypeSize(); // Without barrier because 'object' is a just allocated object and it doesn't contain references. - ObjectAccessor::SetDynValueWithoutBarrier(reinterpret_cast(object), field_offset, + ObjectAccessor::SetDynValueWithoutBarrier(reinterpret_cast(object), fieldOffset, JSTaggedValue::Undefined().GetRawData()); } } @@ -200,22 +197,22 @@ void ObjectFactory::NewJSArrayBufferData(const JSHandle &array, i JSHandle data(thread_, array->GetArrayBufferData()); if (data.GetTaggedValue() != JSTaggedValue::Undefined()) { JSHandle pointer(data); - auto *new_data = vm_->AllocAndRegisterNative(size); - if (memset_s(new_data, length, 0, length) != EOK) { + auto *newData = vm_->AllocAndRegisterNative(size); + if (memset_s(newData, length, 0, length) != EOK) { LOG_ECMA(FATAL) << "memset_s failed"; UNREACHABLE(); } - pointer->ResetExternalPointer(new_data); + pointer->ResetExternalPointer(newData); return; } - auto *new_data = vm_->AllocAndRegisterNative(size); - if (memset_s(new_data, length, 0, length) != EOK) { + auto *newData = vm_->AllocAndRegisterNative(size); + if (memset_s(newData, length, 0, length) != EOK) { LOG_ECMA(FATAL) << "memset_s failed"; UNREACHABLE(); } JSHandle pointer = - NewJSNativePointer(new_data, PandaFreeBufferFunc, reinterpret_cast(size)); + NewJSNativePointer(newData, PandaFreeBufferFunc, reinterpret_cast(size)); array->SetArrayBufferData(thread_, pointer.GetTaggedValue()); vm_->PushToArrayDataList(*pointer); } @@ -225,22 +222,22 @@ JSHandle ObjectFactory::NewJSArrayBuffer(int32_t length) JSHandle env = vm_->GetGlobalEnv(); JSHandle constructor(env->GetArrayBufferFunction()); - JSHandle new_target(constructor); - JSHandle array_buffer(NewJSObjectByConstructor(constructor, new_target)); - array_buffer->SetArrayBufferByteLength(thread_, JSTaggedValue(length)); + JSHandle newTarget(constructor); + JSHandle arrayBuffer(NewJSObjectByConstructor(constructor, newTarget)); + arrayBuffer->SetArrayBufferByteLength(thread_, JSTaggedValue(length)); if (length > 0) { - auto *new_data = vm_->AllocAndRegisterNative(length); - if (memset_s(new_data, length, 0, length) != EOK) { + auto *newData = vm_->AllocAndRegisterNative(length); + if (memset_s(newData, length, 0, length) != EOK) { LOG_ECMA(FATAL) << "memset_s failed"; UNREACHABLE(); } JSHandle pointer = - NewJSNativePointer(new_data, PandaFreeBufferFunc, reinterpret_cast(length)); - array_buffer->SetArrayBufferData(thread_, pointer.GetTaggedValue()); - array_buffer->SetShared(thread_, JSTaggedValue::False()); + NewJSNativePointer(newData, PandaFreeBufferFunc, reinterpret_cast(length)); + arrayBuffer->SetArrayBufferData(thread_, pointer.GetTaggedValue()); + arrayBuffer->SetShared(thread_, JSTaggedValue::False()); vm_->PushToArrayDataList(*pointer); } - return array_buffer; + return arrayBuffer; } JSHandle ObjectFactory::NewJSArrayBuffer(void *buffer, int32_t length, const DeleteEntryPoint &deleter, @@ -249,40 +246,40 @@ JSHandle ObjectFactory::NewJSArrayBuffer(void *buffer, int32_t le JSHandle env = vm_->GetGlobalEnv(); JSHandle constructor(env->GetArrayBufferFunction()); - JSHandle new_target(constructor); - JSHandle array_buffer(NewJSObjectByConstructor(constructor, new_target)); + JSHandle newTarget(constructor); + JSHandle arrayBuffer(NewJSObjectByConstructor(constructor, newTarget)); length = buffer == nullptr ? 0 : length; - array_buffer->SetArrayBufferByteLength(thread_, JSTaggedValue(length)); + arrayBuffer->SetArrayBufferByteLength(thread_, JSTaggedValue(length)); if (length > 0) { JSHandle pointer = NewJSNativePointer(buffer, deleter, data); - array_buffer->SetArrayBufferData(thread_, pointer.GetTaggedValue()); - array_buffer->SetShared(thread_, JSTaggedValue(share)); + arrayBuffer->SetArrayBufferData(thread_, pointer.GetTaggedValue()); + arrayBuffer->SetShared(thread_, JSTaggedValue(share)); vm_->PushToArrayDataList(*pointer); } - return array_buffer; + return arrayBuffer; } JSHandle ObjectFactory::NewJSDataView(JSHandle buffer, int32_t offset, int32_t length) { - JSTaggedValue array_length = buffer->GetArrayBufferByteLength(); - if (!array_length.IsNumber()) { + JSTaggedValue arrayLength = buffer->GetArrayBufferByteLength(); + if (!arrayLength.IsNumber()) { THROW_TYPE_ERROR_AND_RETURN(thread_, "ArrayBuffer length error", JSHandle(thread_, JSTaggedValue::Undefined())); } - if (offset + length > array_length.GetNumber()) { + if (offset + length > arrayLength.GetNumber()) { THROW_TYPE_ERROR_AND_RETURN(thread_, "offset or length error", JSHandle(thread_, JSTaggedValue::Undefined())); } JSHandle env = vm_->GetGlobalEnv(); JSHandle constructor(env->GetDataViewFunction()); - JSHandle new_target(constructor); - JSHandle array_buffer(NewJSObjectByConstructor(constructor, new_target)); - array_buffer->SetDataView(thread_, JSTaggedValue::True()); - array_buffer->SetViewedArrayBuffer(thread_, buffer.GetTaggedValue()); - array_buffer->SetByteLength(thread_, JSTaggedValue(length)); - array_buffer->SetByteOffset(thread_, JSTaggedValue(offset)); - return array_buffer; + JSHandle newTarget(constructor); + JSHandle arrayBuffer(NewJSObjectByConstructor(constructor, newTarget)); + arrayBuffer->SetDataView(thread_, JSTaggedValue::True()); + arrayBuffer->SetViewedArrayBuffer(thread_, buffer.GetTaggedValue()); + arrayBuffer->SetByteLength(thread_, JSTaggedValue(length)); + arrayBuffer->SetByteOffset(thread_, JSTaggedValue(offset)); + return arrayBuffer; } void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle ®exp, void *buffer, size_t size) @@ -291,19 +288,19 @@ void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle ®exp, vo return; } - auto *new_buffer = vm_->AllocAndRegisterNative(size); - if (memcpy_s(new_buffer, size, buffer, size) != EOK) { + auto *newBuffer = vm_->AllocAndRegisterNative(size); + if (memcpy_s(newBuffer, size, buffer, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } JSTaggedValue data = regexp->GetByteCodeBuffer(); if (data != JSTaggedValue::Undefined()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); - native->ResetExternalPointer(new_buffer); + native->ResetExternalPointer(newBuffer); return; } JSHandle pointer = - NewJSNativePointer(new_buffer, PandaFreeBufferFunc, reinterpret_cast(size)); + NewJSNativePointer(newBuffer, PandaFreeBufferFunc, reinterpret_cast(size)); regexp->SetByteCodeBuffer(thread_, pointer.GetTaggedValue()); regexp->SetLength(thread_, JSTaggedValue(static_cast(size))); @@ -314,40 +311,40 @@ void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle ®exp, vo JSHandle ObjectFactory::NewEcmaDynClass(uint32_t size, JSType type, const JSHandle &prototype, uint32_t flags) { - JSHandle new_class = - NewEcmaDynClass(hclass_class_, size, type, flags, JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); - new_class->SetPrototype(thread_, prototype.GetTaggedValue()); - return new_class; + JSHandle newClass = + NewEcmaDynClass(hclassClass_, size, type, flags, JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); + newClass->SetPrototype(thread_, prototype.GetTaggedValue()); + return newClass; } JSHandle ObjectFactory::NewJSObject(const JSHandle &jshclass) { JSHandle obj(thread_, JSObject::Cast(NewDynObject(jshclass))); - JSHandle empty_array = EmptyArray(); + JSHandle emptyArray = EmptyArray(); obj->InitializeHash(); - obj->SetElements(thread_, empty_array, SKIP_BARRIER); - obj->SetProperties(thread_, empty_array, SKIP_BARRIER); + obj->SetElements(thread_, emptyArray, SKIP_BARRIER); + obj->SetProperties(thread_, emptyArray, SKIP_BARRIER); return obj; } JSHandle ObjectFactory::CloneProperties(const JSHandle &old) { - uint32_t new_length = old->GetLength(); - if (new_length == 0) { + uint32_t newLength = old->GetLength(); + if (newLength == 0) { return EmptyArray(); } NewObjectHook(); auto klass = old->GetClass(); - size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), new_length); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(klass, size); - JSHandle new_array(thread_, header); - new_array->SetLength(new_length); + size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(klass, size); + JSHandle newArray(thread_, header); + newArray->SetLength(newLength); - for (uint32_t i = 0; i < new_length; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i); - new_array->Set(thread_, i, value); + newArray->Set(thread_, i, value); } - return new_array; + return newArray; } JSHandle ObjectFactory::CloneObjectLiteral(JSHandle object) @@ -355,20 +352,20 @@ JSHandle ObjectFactory::CloneObjectLiteral(JSHandle object) NewObjectHook(); auto klass = JSHandle(thread_, object->GetClass()); - JSHandle clone_object = NewJSObject(klass); + JSHandle cloneObject = NewJSObject(klass); JSHandle elements(thread_, object->GetElements()); - auto new_elements = CloneProperties(elements); - clone_object->SetElements(thread_, new_elements.GetTaggedValue()); + auto newElements = CloneProperties(elements); + cloneObject->SetElements(thread_, newElements.GetTaggedValue()); JSHandle properties(thread_, object->GetProperties()); - auto new_properties = CloneProperties(properties); - clone_object->SetProperties(thread_, new_properties.GetTaggedValue()); + auto newProperties = CloneProperties(properties); + cloneObject->SetProperties(thread_, newProperties.GetTaggedValue()); for (uint32_t i = 0; i < klass->GetInlinedProperties(); i++) { - clone_object->SetPropertyInlinedProps(thread_, i, object->GetPropertyInlinedProps(i)); + cloneObject->SetPropertyInlinedProps(thread_, i, object->GetPropertyInlinedProps(i)); } - return clone_object; + return cloneObject; } JSHandle ObjectFactory::CloneArrayLiteral(JSHandle object) @@ -376,155 +373,155 @@ JSHandle ObjectFactory::CloneArrayLiteral(JSHandle object) NewObjectHook(); auto klass = JSHandle(thread_, object->GetClass()); - JSHandle clone_object(NewJSObject(klass)); - clone_object->SetArrayLength(thread_, object->GetArrayLength()); + JSHandle cloneObject(NewJSObject(klass)); + cloneObject->SetArrayLength(thread_, object->GetArrayLength()); JSHandle elements(thread_, object->GetElements()); - auto new_elements = CopyArray(elements, elements->GetLength(), elements->GetLength()); - clone_object->SetElements(thread_, new_elements.GetTaggedValue()); + auto newElements = CopyArray(elements, elements->GetLength(), elements->GetLength()); + cloneObject->SetElements(thread_, newElements.GetTaggedValue()); JSHandle properties(thread_, object->GetProperties()); - auto new_properties = CopyArray(properties, properties->GetLength(), properties->GetLength()); - clone_object->SetProperties(thread_, new_properties.GetTaggedValue()); + auto newProperties = CopyArray(properties, properties->GetLength(), properties->GetLength()); + cloneObject->SetProperties(thread_, newProperties.GetTaggedValue()); for (uint32_t i = 0; i < klass->GetInlinedProperties(); i++) { - clone_object->SetPropertyInlinedProps(thread_, i, object->GetPropertyInlinedProps(i)); + cloneObject->SetPropertyInlinedProps(thread_, i, object->GetPropertyInlinedProps(i)); } - return clone_object; + return cloneObject; } JSHandle ObjectFactory::CloneProperties(const JSHandle &old, const JSHandle &env, const JSHandle &obj, const JSHandle &constpool) { - uint32_t new_length = old->GetLength(); - if (new_length == 0) { + uint32_t newLength = old->GetLength(); + if (newLength == 0) { return EmptyArray(); } NewObjectHook(); auto klass = old->GetClass(); - size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), new_length); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(klass, size); - JSHandle new_array(thread_, header); - new_array->SetLength(new_length); + size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(klass, size); + JSHandle newArray(thread_, header); + newArray->SetLength(newLength); - for (uint32_t i = 0; i < new_length; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i); if (!value.IsJSFunction()) { - new_array->Set(thread_, i, value); + newArray->Set(thread_, i, value); } else { - JSHandle value_handle(thread_, value); - JSHandle new_func = CloneJSFuction(value_handle, value_handle->GetFunctionKind()); - new_func->SetLexicalEnv(thread_, env); - new_func->SetHomeObject(thread_, obj); - new_func->SetConstantPool(thread_, constpool); - new_array->Set(thread_, i, new_func); + JSHandle valueHandle(thread_, value); + JSHandle newFunc = CloneJSFuction(valueHandle, valueHandle->GetFunctionKind()); + newFunc->SetLexicalEnv(thread_, env); + newFunc->SetHomeObject(thread_, obj); + newFunc->SetConstantPool(thread_, constpool); + newArray->Set(thread_, i, newFunc); } } - return new_array; + return newArray; } JSHandle ObjectFactory::CloneObjectLiteral(JSHandle object, const JSHandle &env, - const JSHandle &constpool, bool can_share_hclass) + const JSHandle &constpool, bool canShareHclass) { NewObjectHook(); auto klass = JSHandle(thread_, object->GetClass()); - if (!can_share_hclass) { + if (!canShareHclass) { klass = JSHClass::Clone(thread_, klass); } - JSHandle clone_object = NewJSObject(klass); + JSHandle cloneObject = NewJSObject(klass); JSHandle elements(thread_, object->GetElements()); - auto new_elements = CloneProperties(elements, env, clone_object, constpool); - clone_object->SetElements(thread_, new_elements.GetTaggedValue()); + auto newElements = CloneProperties(elements, env, cloneObject, constpool); + cloneObject->SetElements(thread_, newElements.GetTaggedValue()); JSHandle properties(thread_, object->GetProperties()); - auto new_properties = CloneProperties(properties, env, clone_object, constpool); - clone_object->SetProperties(thread_, new_properties.GetTaggedValue()); + auto newProperties = CloneProperties(properties, env, cloneObject, constpool); + cloneObject->SetProperties(thread_, newProperties.GetTaggedValue()); for (uint32_t i = 0; i < klass->GetInlinedProperties(); i++) { JSTaggedValue value = object->GetPropertyInlinedProps(i); if (!value.IsJSFunction()) { - clone_object->SetPropertyInlinedProps(thread_, i, value); + cloneObject->SetPropertyInlinedProps(thread_, i, value); } else { - JSHandle value_handle(thread_, value); - JSHandle new_func = CloneJSFuction(value_handle, value_handle->GetFunctionKind()); - new_func->SetLexicalEnv(thread_, env); - new_func->SetHomeObject(thread_, clone_object); - new_func->SetConstantPool(thread_, constpool); - clone_object->SetPropertyInlinedProps(thread_, i, new_func.GetTaggedValue()); + JSHandle valueHandle(thread_, value); + JSHandle newFunc = CloneJSFuction(valueHandle, valueHandle->GetFunctionKind()); + newFunc->SetLexicalEnv(thread_, env); + newFunc->SetHomeObject(thread_, cloneObject); + newFunc->SetConstantPool(thread_, constpool); + cloneObject->SetPropertyInlinedProps(thread_, i, newFunc.GetTaggedValue()); } } - return clone_object; + return cloneObject; } JSHandle ObjectFactory::CloneJSFuction(JSHandle obj, FunctionKind kind) { JSHandle env = vm_->GetGlobalEnv(); JSHandle jshclass(thread_, obj->GetJSHClass()); - JSHandle clone_func = NewJSFunctionByDynClass(obj->GetCallTarget(), jshclass, kind); + JSHandle cloneFunc = NewJSFunctionByDynClass(obj->GetCallTarget(), jshclass, kind); if (kind == FunctionKind::GENERATOR_FUNCTION) { - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle initial_generator_func_prototype = - NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSObject::SetPrototype(thread_, initial_generator_func_prototype, env->GetGeneratorPrototype()); - clone_func->SetProtoOrDynClass(thread_, initial_generator_func_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle initialGeneratorFuncPrototype = + NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, env->GetGeneratorPrototype()); + cloneFunc->SetProtoOrDynClass(thread_, initialGeneratorFuncPrototype); } else if (kind == FunctionKind::ASYNC_GENERATOR_FUNCTION) { - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle initial_async_generator_func_prototype = - NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSObject::SetPrototype(thread_, initial_async_generator_func_prototype, env->GetAsyncGeneratorPrototype()); - clone_func->SetProtoOrDynClass(thread_, initial_async_generator_func_prototype); + JSHandle objFun = env->GetObjectFunction(); + JSHandle initialAsyncGeneratorFuncPrototype = + NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetPrototype(thread_, initialAsyncGeneratorFuncPrototype, env->GetAsyncGeneratorPrototype()); + cloneFunc->SetProtoOrDynClass(thread_, initialAsyncGeneratorFuncPrototype); } JSTaggedValue length = obj->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX); - clone_func->SetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, length); - return clone_func; + cloneFunc->SetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, length); + return cloneFunc; } JSHandle ObjectFactory::CloneClassCtor(JSHandle ctor, const JSHandle &lexenv, - bool can_share_hclass) + bool canShareHclass) { NewObjectHook(); JSHandle constpool(thread_, ctor->GetConstantPool()); JSHandle hclass(thread_, ctor->GetClass()); - if (!can_share_hclass) { + if (!canShareHclass) { hclass = JSHClass::Clone(thread_, hclass); } FunctionKind kind = ctor->GetFunctionKind(); ASSERT_PRINT(kind == FunctionKind::CLASS_CONSTRUCTOR || kind == FunctionKind::DERIVED_CONSTRUCTOR, "cloned function is not class"); - JSHandle clone_ctor = NewJSFunctionByDynClass(ctor->GetCallTarget(), hclass, kind); + JSHandle cloneCtor = NewJSFunctionByDynClass(ctor->GetCallTarget(), hclass, kind); for (uint32_t i = 0; i < hclass->GetInlinedProperties(); i++) { JSTaggedValue value = ctor->GetPropertyInlinedProps(i); if (!value.IsJSFunction()) { - clone_ctor->SetPropertyInlinedProps(thread_, i, value); + cloneCtor->SetPropertyInlinedProps(thread_, i, value); } else { - JSHandle value_handle(thread_, value); - JSHandle new_func = CloneJSFuction(value_handle, value_handle->GetFunctionKind()); - new_func->SetLexicalEnv(thread_, lexenv); - new_func->SetHomeObject(thread_, clone_ctor); - new_func->SetConstantPool(thread_, constpool); - clone_ctor->SetPropertyInlinedProps(thread_, i, new_func.GetTaggedValue()); + JSHandle valueHandle(thread_, value); + JSHandle newFunc = CloneJSFuction(valueHandle, valueHandle->GetFunctionKind()); + newFunc->SetLexicalEnv(thread_, lexenv); + newFunc->SetHomeObject(thread_, cloneCtor); + newFunc->SetConstantPool(thread_, constpool); + cloneCtor->SetPropertyInlinedProps(thread_, i, newFunc.GetTaggedValue()); } } JSHandle elements(thread_, ctor->GetElements()); - auto new_elements = CloneProperties(elements, lexenv, JSHandle(clone_ctor), constpool); - clone_ctor->SetElements(thread_, new_elements.GetTaggedValue()); + auto newElements = CloneProperties(elements, lexenv, JSHandle(cloneCtor), constpool); + cloneCtor->SetElements(thread_, newElements.GetTaggedValue()); JSHandle properties(thread_, ctor->GetProperties()); - auto new_properties = CloneProperties(properties, lexenv, JSHandle(clone_ctor), constpool); - clone_ctor->SetProperties(thread_, new_properties.GetTaggedValue()); + auto newProperties = CloneProperties(properties, lexenv, JSHandle(cloneCtor), constpool); + cloneCtor->SetProperties(thread_, newProperties.GetTaggedValue()); - clone_ctor->SetConstantPool(thread_, constpool); + cloneCtor->SetConstantPool(thread_, constpool); - return clone_ctor; + return cloneCtor; } JSHandle ObjectFactory::NewNonMovableJSObject(const JSHandle &jshclass) @@ -535,10 +532,10 @@ JSHandle ObjectFactory::NewNonMovableJSObject(const JSHandle return obj; } -JSHandle ObjectFactory::NewJSPrimitiveRef(const JSHandle &dyn_klass, +JSHandle ObjectFactory::NewJSPrimitiveRef(const JSHandle &dynKlass, const JSHandle &object) { - JSHandle obj = JSHandle::Cast(NewJSObject(dyn_klass)); + JSHandle obj = JSHandle::Cast(NewJSObject(dynKlass)); obj->SetValue(thread_, object); return obj; } @@ -554,7 +551,7 @@ JSHandle ObjectFactory::NewJSArray() JSHandle ObjectFactory::NewBigInt() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(big_int_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(bigIntClass_); JSHandle obj(thread_, BigInt::Cast(header)); obj->SetData(thread_, JSTaggedValue::Undefined()); obj->SetSign(false); @@ -576,100 +573,100 @@ JSHandle ObjectFactory::NewJSForinIterator(const JSHandle ObjectFactory::CreateJSRegExpInstanceClass(JSHandle proto) { - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle regexp_dynclass = CreateDynClass(JSType::JS_REG_EXP, proto); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle regexpDynclass = CreateDynClass(JSType::JS_REG_EXP, proto); - uint32_t field_order = 0; - JSHandle layout_info_handle = CreateLayoutInfo(1); + uint32_t fieldOrder = 0; + JSHandle layoutInfoHandle = CreateLayoutInfo(1); { PropertyAttributes attributes = PropertyAttributes::Default(true, false, false); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order++); - layout_info_handle->AddKey(thread_, 0, global_const->GetLastIndexString(), attributes); + attributes.SetOffset(fieldOrder++); + layoutInfoHandle->AddKey(thread_, 0, globalConst->GetLastIndexString(), attributes); } { - regexp_dynclass->SetLayout(thread_, layout_info_handle); - regexp_dynclass->SetNumberOfProps(field_order); + regexpDynclass->SetLayout(thread_, layoutInfoHandle); + regexpDynclass->SetNumberOfProps(fieldOrder); } - return regexp_dynclass; + return regexpDynclass; } JSHandle ObjectFactory::CreateJSArrayInstanceClass(JSHandle proto) { - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle array_dynclass = CreateDynClass(JSType::JS_ARRAY, proto); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle arrayDynclass = CreateDynClass(JSType::JS_ARRAY, proto); - uint32_t field_order = 0; - ASSERT(JSArray::LENGTH_INLINE_PROPERTY_INDEX == field_order); - JSHandle layout_info_handle = CreateLayoutInfo(1); + uint32_t fieldOrder = 0; + ASSERT(JSArray::LENGTH_INLINE_PROPERTY_INDEX == fieldOrder); + JSHandle layoutInfoHandle = CreateLayoutInfo(1); { PropertyAttributes attributes = PropertyAttributes::DefaultAccessor(true, false, false); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order++); - layout_info_handle->AddKey(thread_, 0, global_const->GetLengthString(), attributes); + attributes.SetOffset(fieldOrder++); + layoutInfoHandle->AddKey(thread_, 0, globalConst->GetLengthString(), attributes); } { - array_dynclass->SetLayout(thread_, layout_info_handle); - array_dynclass->SetNumberOfProps(field_order); + arrayDynclass->SetLayout(thread_, layoutInfoHandle); + arrayDynclass->SetNumberOfProps(fieldOrder); } - array_dynclass->SetIsStableElements(true); - array_dynclass->SetHasConstructor(false); + arrayDynclass->SetIsStableElements(true); + arrayDynclass->SetHasConstructor(false); - return array_dynclass; + return arrayDynclass; } JSHandle ObjectFactory::CreateJSArguments() { JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); JSHandle proto = env->GetObjectFunctionPrototype(); - JSHandle arguments_dynclass = CreateDynClass(JSType::JS_ARGUMENTS, proto); + JSHandle argumentsDynclass = CreateDynClass(JSType::JS_ARGUMENTS, proto); - uint32_t field_order = 0; - ASSERT(JSArguments::LENGTH_INLINE_PROPERTY_INDEX == field_order); - JSHandle layout_info_handle = CreateLayoutInfo(JSArguments::LENGTH_OF_INLINE_PROPERTIES); + uint32_t fieldOrder = 0; + ASSERT(JSArguments::LENGTH_INLINE_PROPERTY_INDEX == fieldOrder); + JSHandle layoutInfoHandle = CreateLayoutInfo(JSArguments::LENGTH_OF_INLINE_PROPERTIES); { PropertyAttributes attributes = PropertyAttributes::Default(true, false, true); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order++); - layout_info_handle->AddKey(thread_, JSArguments::LENGTH_INLINE_PROPERTY_INDEX, global_const->GetLengthString(), - attributes); + attributes.SetOffset(fieldOrder++); + layoutInfoHandle->AddKey(thread_, JSArguments::LENGTH_INLINE_PROPERTY_INDEX, globalConst->GetLengthString(), + attributes); } - ASSERT(JSArguments::ITERATOR_INLINE_PROPERTY_INDEX == field_order); + ASSERT(JSArguments::ITERATOR_INLINE_PROPERTY_INDEX == fieldOrder); { PropertyAttributes attributes = PropertyAttributes::Default(true, false, true); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order++); - layout_info_handle->AddKey(thread_, JSArguments::ITERATOR_INLINE_PROPERTY_INDEX, - env->GetIteratorSymbol().GetTaggedValue(), attributes); + attributes.SetOffset(fieldOrder++); + layoutInfoHandle->AddKey(thread_, JSArguments::ITERATOR_INLINE_PROPERTY_INDEX, + env->GetIteratorSymbol().GetTaggedValue(), attributes); } { - ASSERT(JSArguments::CALLEE_INLINE_PROPERTY_INDEX == field_order); + ASSERT(JSArguments::CALLEE_INLINE_PROPERTY_INDEX == fieldOrder); PropertyAttributes attributes = PropertyAttributes::Default(false, false, false); attributes.SetIsInlinedProps(true); attributes.SetIsAccessor(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order++); - layout_info_handle->AddKey(thread_, JSArguments::CALLEE_INLINE_PROPERTY_INDEX, - thread_->GlobalConstants()->GetHandledCalleeString().GetTaggedValue(), attributes); + attributes.SetOffset(fieldOrder++); + layoutInfoHandle->AddKey(thread_, JSArguments::CALLEE_INLINE_PROPERTY_INDEX, + thread_->GlobalConstants()->GetHandledCalleeString().GetTaggedValue(), attributes); } { - arguments_dynclass->SetLayout(thread_, layout_info_handle); - arguments_dynclass->SetNumberOfProps(field_order); + argumentsDynclass->SetLayout(thread_, layoutInfoHandle); + argumentsDynclass->SetNumberOfProps(fieldOrder); } - arguments_dynclass->SetIsStableElements(true); - return arguments_dynclass; + argumentsDynclass->SetIsStableElements(true); + return argumentsDynclass; } JSHandle ObjectFactory::NewJSArguments() @@ -680,78 +677,77 @@ JSHandle ObjectFactory::NewJSArguments() return obj; } -JSHandle ObjectFactory::GetJSError(const ErrorType &error_type, const char *data) +JSHandle ObjectFactory::GetJSError(const ErrorType &errorType, const char *data) { - ASSERT_PRINT(error_type == ErrorType::ERROR || error_type == ErrorType::EVAL_ERROR || - error_type == ErrorType::RANGE_ERROR || error_type == ErrorType::REFERENCE_ERROR || - error_type == ErrorType::SYNTAX_ERROR || error_type == ErrorType::TYPE_ERROR || - error_type == ErrorType::URI_ERROR, + ASSERT_PRINT(errorType == ErrorType::ERROR || errorType == ErrorType::EVAL_ERROR || + errorType == ErrorType::RANGE_ERROR || errorType == ErrorType::REFERENCE_ERROR || + errorType == ErrorType::SYNTAX_ERROR || errorType == ErrorType::TYPE_ERROR || + errorType == ErrorType::URI_ERROR, "The error type is not in the valid range."); if (data != nullptr) { - JSHandle handle_msg = NewFromString(data); - return NewJSError(error_type, handle_msg); + JSHandle handleMsg = NewFromString(data); + return NewJSError(errorType, handleMsg); } - JSHandle empty_string(thread_->GlobalConstants()->GetHandledEmptyString()); - return NewJSError(error_type, empty_string); + JSHandle emptyString(thread_->GlobalConstants()->GetHandledEmptyString()); + return NewJSError(errorType, emptyString); } -JSHandle ObjectFactory::NewJSError(const ErrorType &error_type, const JSHandle &message) +JSHandle ObjectFactory::NewJSError(const ErrorType &errorType, const JSHandle &message) { JSHandle env = vm_->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle native_constructor; - switch (error_type) { + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle nativeConstructor; + switch (errorType) { case ErrorType::RANGE_ERROR: - native_constructor = env->GetRangeErrorFunction(); + nativeConstructor = env->GetRangeErrorFunction(); break; case ErrorType::EVAL_ERROR: - native_constructor = env->GetEvalErrorFunction(); + nativeConstructor = env->GetEvalErrorFunction(); break; case ErrorType::REFERENCE_ERROR: - native_constructor = env->GetReferenceErrorFunction(); + nativeConstructor = env->GetReferenceErrorFunction(); break; case ErrorType::TYPE_ERROR: - native_constructor = env->GetTypeErrorFunction(); + nativeConstructor = env->GetTypeErrorFunction(); break; case ErrorType::URI_ERROR: - native_constructor = env->GetURIErrorFunction(); + nativeConstructor = env->GetURIErrorFunction(); break; case ErrorType::SYNTAX_ERROR: - native_constructor = env->GetSyntaxErrorFunction(); + nativeConstructor = env->GetSyntaxErrorFunction(); break; default: - native_constructor = env->GetErrorFunction(); + nativeConstructor = env->GetErrorFunction(); break; } - JSHandle native_func = JSHandle::Cast(native_constructor); - JSHandle native_prototype(thread_, native_func->GetFunctionPrototype()); - JSHandle ctor_key = global_const->GetHandledConstructorString(); + JSHandle nativeFunc = JSHandle::Cast(nativeConstructor); + JSHandle nativePrototype(thread_, nativeFunc->GetFunctionPrototype()); + JSHandle ctorKey = globalConst->GetHandledConstructorString(); - auto info = - NewRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), native_prototype, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), nativePrototype, JSTaggedValue::Undefined(), 1); info->SetCallArgs(message); - JSTaggedValue obj = JSFunction::Invoke(info.Get(), ctor_key); + JSTaggedValue obj = JSFunction::Invoke(info.Get(), ctorKey); - JSHandle handle_native_instance_obj(thread_, obj); - return handle_native_instance_obj; + JSHandle handleNativeInstanceObj(thread_, obj); + return handleNativeInstanceObj; } JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandle &constructor, - const JSHandle &new_target, - panda::SpaceType space_type) + const JSHandle &newTarget, + panda::SpaceType spaceType) { JSHandle jshclass; if (!constructor->HasFunctionPrototype() || (constructor->GetProtoOrDynClass().IsHeapObject() && constructor->GetFunctionPrototype().IsECMAObject())) { - jshclass = JSFunction::GetInstanceJSHClass(thread_, constructor, new_target); + jshclass = JSFunction::GetInstanceJSHClass(thread_, constructor, newTarget); } else { JSHandle env = vm_->GetGlobalEnv(); - jshclass = JSFunction::GetInstanceJSHClass(thread_, JSHandle(env->GetObjectFunction()), new_target); + jshclass = JSFunction::GetInstanceJSHClass(thread_, JSHandle(env->GetObjectFunction()), newTarget); } // Check this exception elsewhere RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread_); - JSHandle obj = space_type == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT + JSHandle obj = spaceType == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT ? NewNonMovableJSObject(jshclass) : NewJSObject(jshclass); { @@ -926,7 +922,7 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandle= FreeObject::GetTaggedSizeOffset() && size < FreeObject::SIZE) { object = reinterpret_cast(address); - object->SetClassWithoutBarrier(free_object_with_one_field_class_); + object->SetClassWithoutBarrier(freeObjectWithOneFieldClass_); object->SetNext(nullptr); } else if (size >= FreeObject::SIZE) { object = reinterpret_cast(address); - object->SetClassWithoutBarrier(free_object_with_two_field_class_); + object->SetClassWithoutBarrier(freeObjectWithTwoFieldClass_); object->SetAvailable(size); object->SetNext(nullptr); } else if (size == FreeObject::GetTaggedNextOffset()) { object = reinterpret_cast(address); - object->SetClassWithoutBarrier(free_object_with_none_field_class_); + object->SetClassWithoutBarrier(freeObjectWithNoneFieldClass_); } else { LOG_ECMA(DEBUG) << "Fill free object size is smaller"; } @@ -954,50 +950,49 @@ FreeObject *ObjectFactory::FillFreeObject([[maybe_unused]] uintptr_t address, [[ TaggedObject *ObjectFactory::NewDynObject(const JSHandle &dynclass) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(*dynclass); - uint32_t inobj_prop_count = dynclass->GetInlinedProperties(); - if (inobj_prop_count > 0) { - InitializeExtraProperties(dynclass, header, inobj_prop_count); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(*dynclass); + uint32_t inobjPropCount = dynclass->GetInlinedProperties(); + if (inobjPropCount > 0) { + InitializeExtraProperties(dynclass, header, inobjPropCount); } return header; } -TaggedObject *ObjectFactory::NewNonMovableDynObject(const JSHandle &dynclass, int inobj_prop_count) +TaggedObject *ObjectFactory::NewNonMovableDynObject(const JSHandle &dynclass, int inobjPropCount) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateNonMovableOrHugeObject(*dynclass); - if (inobj_prop_count > 0) { - InitializeExtraProperties(dynclass, header, inobj_prop_count); + TaggedObject *header = heapHelper_.AllocateNonMovableOrHugeObject(*dynclass); + if (inobjPropCount > 0) { + InitializeExtraProperties(dynclass, header, inobjPropCount); } return header; } -void ObjectFactory::InitializeExtraProperties(const JSHandle &dynclass, TaggedObject *obj, - int inobj_prop_count) +void ObjectFactory::InitializeExtraProperties(const JSHandle &dynclass, TaggedObject *obj, int inobjPropCount) { - ASSERT(inobj_prop_count * JSTaggedValue::TaggedTypeSize() < dynclass->GetObjectSize()); + ASSERT(inobjPropCount * JSTaggedValue::TaggedTypeSize() < dynclass->GetObjectSize()); auto offset = dynclass->GetObjectSize(); - JSTaggedType init_val = JSTaggedValue::Undefined().GetRawData(); - for (int i = 0; i < inobj_prop_count; ++i) { + JSTaggedType initVal = JSTaggedValue::Undefined().GetRawData(); + for (int i = 0; i < inobjPropCount; ++i) { offset -= JSTaggedValue::TaggedTypeSize(); // Without barrier because 'object' is a just allocated object and it doesn't contain references. - ObjectAccessor::SetDynValueWithoutBarrier(obj, offset, init_val); + ObjectAccessor::SetDynValueWithoutBarrier(obj, offset, initVal); } } JSHandle ObjectFactory::OrdinaryNewJSObjectCreate(const JSHandle &proto) { - JSHandle proto_value(proto); - JSHandle proto_dyn = CreateDynClass(JSType::JS_OBJECT, proto_value); - JSHandle new_obj = NewJSObject(proto_dyn); - new_obj->GetJSHClass()->SetExtensible(true); - return new_obj; + JSHandle protoValue(proto); + JSHandle protoDyn = CreateDynClass(JSType::JS_OBJECT, protoValue); + JSHandle newObj = NewJSObject(protoDyn); + newObj->GetJSHClass()->SetExtensible(true); + return newObj; } -JSHandle ObjectFactory::NewJSFunction(const JSHandle &env, const void *native_func, +JSHandle ObjectFactory::NewJSFunction(const JSHandle &env, const void *nativeFunc, FunctionKind kind) { - JSMethod *target = vm_->GetMethodForNativeFunction(native_func); + JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); return NewJSFunction(env, target, kind); } @@ -1015,73 +1010,73 @@ JSHandle ObjectFactory::NewJSFunction(const JSHandle &env return NewJSFunctionByDynClass(method, dynclass, kind); } -JSHandle ObjectFactory::CreateFunctionClass(FunctionKind kind, uint32_t size, JSAccessorsMaskType native_mask, +JSHandle ObjectFactory::CreateFunctionClass(FunctionKind kind, uint32_t size, JSAccessorsMaskType nativeMask, JSType type, const JSHandle &prototype) { - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle function_class = NewEcmaDynClass(size, type, prototype, HClass::IS_CALLABLE); - function_class->GetHClass()->SetNativeFieldMask(native_mask); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle functionClass = NewEcmaDynClass(size, type, prototype, HClass::IS_CALLABLE); + functionClass->GetHClass()->SetNativeFieldMask(nativeMask); { // FunctionKind = BASE_CONSTRUCTOR if (JSFunction::IsConstructorKind(kind)) { - function_class->SetConstructor(true); + functionClass->SetConstructor(true); } - function_class->SetExtensible(true); + functionClass->SetExtensible(true); } - uint32_t field_order = 0; - ASSERT(JSFunction::LENGTH_INLINE_PROPERTY_INDEX == field_order); - JSHandle layout_info_handle = CreateLayoutInfo(JSFunction::LENGTH_OF_INLINE_PROPERTIES); + uint32_t fieldOrder = 0; + ASSERT(JSFunction::LENGTH_INLINE_PROPERTY_INDEX == fieldOrder); + JSHandle layoutInfoHandle = CreateLayoutInfo(JSFunction::LENGTH_OF_INLINE_PROPERTIES); { PropertyAttributes attributes = PropertyAttributes::Default(false, false, true); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order); - layout_info_handle->AddKey(thread_, field_order, global_const->GetLengthString(), attributes); - field_order++; + attributes.SetOffset(fieldOrder); + layoutInfoHandle->AddKey(thread_, fieldOrder, globalConst->GetLengthString(), attributes); + fieldOrder++; } - ASSERT(JSFunction::NAME_INLINE_PROPERTY_INDEX == field_order); + ASSERT(JSFunction::NAME_INLINE_PROPERTY_INDEX == fieldOrder); // not set name in-object property on class which may have a name() method if (!JSFunction::IsClassConstructor(kind)) { PropertyAttributes attributes = PropertyAttributes::DefaultAccessor(false, false, true); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order); - layout_info_handle->AddKey(thread_, field_order, - thread_->GlobalConstants()->GetHandledNameString().GetTaggedValue(), attributes); - field_order++; + attributes.SetOffset(fieldOrder); + layoutInfoHandle->AddKey(thread_, fieldOrder, + thread_->GlobalConstants()->GetHandledNameString().GetTaggedValue(), attributes); + fieldOrder++; } if (JSFunction::HasPrototype(kind) && !JSFunction::IsClassConstructor(kind)) { - ASSERT(JSFunction::PROTOTYPE_INLINE_PROPERTY_INDEX == field_order); + ASSERT(JSFunction::PROTOTYPE_INLINE_PROPERTY_INDEX == fieldOrder); PropertyAttributes attributes = PropertyAttributes::DefaultAccessor(true, false, false); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order); - layout_info_handle->AddKey(thread_, field_order, global_const->GetPrototypeString(), attributes); - field_order++; + attributes.SetOffset(fieldOrder); + layoutInfoHandle->AddKey(thread_, fieldOrder, globalConst->GetPrototypeString(), attributes); + fieldOrder++; } else if (JSFunction::IsClassConstructor(kind)) { - ASSERT(JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX == field_order); + ASSERT(JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX == fieldOrder); PropertyAttributes attributes = PropertyAttributes::DefaultAccessor(false, false, false); attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order); - layout_info_handle->AddKey(thread_, field_order, global_const->GetPrototypeString(), attributes); - field_order++; + attributes.SetOffset(fieldOrder); + layoutInfoHandle->AddKey(thread_, fieldOrder, globalConst->GetPrototypeString(), attributes); + fieldOrder++; } { - function_class->SetLayout(thread_, layout_info_handle); - function_class->SetNumberOfProps(field_order); + functionClass->SetLayout(thread_, layoutInfoHandle); + functionClass->SetNumberOfProps(fieldOrder); } - return function_class; + return functionClass; } JSHandle ObjectFactory::NewJSFunctionByDynClass(JSMethod *method, const JSHandle &clazz, - FunctionKind kind, panda::SpaceType space_type) + FunctionKind kind, panda::SpaceType spaceType) { - JSHandle function = space_type == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT + JSHandle function = spaceType == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT ? JSHandle::Cast(NewNonMovableJSObject(clazz)) : JSHandle::Cast(NewJSObject(clazz)); ASSERT(clazz->IsCallable()); @@ -1092,23 +1087,23 @@ JSHandle ObjectFactory::NewJSFunctionByDynClass(JSMethod *method, co return function; } -JSHandle ObjectFactory::NewJSNativeErrorFunction(const JSHandle &env, const void *native_func) +JSHandle ObjectFactory::NewJSNativeErrorFunction(const JSHandle &env, const void *nativeFunc) { - JSMethod *target = vm_->GetMethodForNativeFunction(native_func); + JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); JSHandle dynclass = JSHandle::Cast(env->GetNativeErrorFunctionClass()); return NewJSFunctionByDynClass(target, dynclass, FunctionKind::BUILTIN_CONSTRUCTOR); } JSHandle ObjectFactory::NewSpecificTypedArrayFunction(const JSHandle &env, - const void *native_func) + const void *nativeFunc) { - JSMethod *target = vm_->GetMethodForNativeFunction(native_func); + JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); JSHandle dynclass = JSHandle::Cast(env->GetSpecificTypedArrayFunctionClass()); return NewJSFunctionByDynClass(target, dynclass, FunctionKind::BUILTIN_CONSTRUCTOR); } JSHandle ObjectFactory::NewJSBoundFunction(const JSHandle &target, - const JSHandle &bound_this, + const JSHandle &boundThis, const JSHandle &args) { JSHandle env = vm_->GetGlobalEnv(); @@ -1116,104 +1111,103 @@ JSHandle ObjectFactory::NewJSBoundFunction(const JSHandle dynclass = CreateDynClass(JSType::JS_BOUND_FUNCTION, proto, HClass::IS_CALLABLE); - JSHandle bundle_function = JSHandle::Cast(NewJSObject(dynclass)); - bundle_function->SetBoundTarget(thread_, target); - bundle_function->SetBoundThis(thread_, bound_this); - bundle_function->SetBoundArguments(thread_, args); + JSHandle bundleFunction = JSHandle::Cast(NewJSObject(dynclass)); + bundleFunction->SetBoundTarget(thread_, target); + bundleFunction->SetBoundThis(thread_, boundThis); + bundleFunction->SetBoundArguments(thread_, args); if (target.GetTaggedValue().IsConstructor()) { - bundle_function->SetConstructor(true); + bundleFunction->SetConstructor(true); } JSMethod *method = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::global::CallJsBoundFunction)); - bundle_function->SetCallTarget(thread_, method); - return bundle_function; + bundleFunction->SetCallTarget(thread_, method); + return bundleFunction; } -JSHandle ObjectFactory::NewJSIntlBoundFunction(const void *native_func, int function_length) +JSHandle ObjectFactory::NewJSIntlBoundFunction(const void *nativeFunc, int functionLength) { JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetJSIntlBoundFunctionClass()); - JSHandle intl_bound_func = JSHandle::Cast(NewJSObject(dynclass)); - JSMethod *method = vm_->GetMethodForNativeFunction(native_func); - intl_bound_func->SetCallTarget(thread_, method); - JSHandle function = JSHandle::Cast(intl_bound_func); + JSHandle intlBoundFunc = JSHandle::Cast(NewJSObject(dynclass)); + JSMethod *method = vm_->GetMethodForNativeFunction(nativeFunc); + intlBoundFunc->SetCallTarget(thread_, method); + JSHandle function = JSHandle::Cast(intlBoundFunc); JSFunction::InitializeJSFunction(thread_, function, FunctionKind::NORMAL_FUNCTION); - JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(function_length)); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle empty_string = global_const->GetHandledEmptyString(); - JSHandle name_key = global_const->GetHandledNameString(); - PropertyDescriptor name_desc(thread_, empty_string, false, false, true); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle::Cast(function), name_key, name_desc); - return intl_bound_func; + JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(functionLength)); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle emptyString = globalConst->GetHandledEmptyString(); + JSHandle nameKey = globalConst->GetHandledNameString(); + PropertyDescriptor nameDesc(thread_, emptyString, false, false, true); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle::Cast(function), nameKey, nameDesc); + return intlBoundFunc; } JSHandle ObjectFactory::NewJSProxyRevocFunction(const JSHandle &proxy, - const void *native_func) + const void *nativeFunc) { JSHandle env = vm_->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); JSHandle dynclass = JSHandle::Cast(env->GetProxyRevocFunctionClass()); - JSHandle revoc_function = JSHandle::Cast(NewJSObject(dynclass)); - revoc_function->SetRevocableProxy(thread_, proxy); + JSHandle revocFunction = JSHandle::Cast(NewJSObject(dynclass)); + revocFunction->SetRevocableProxy(thread_, proxy); - JSMethod *target = vm_->GetMethodForNativeFunction(native_func); - revoc_function->SetCallTarget(thread_, target); - JSHandle function = JSHandle::Cast(revoc_function); + JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); + revocFunction->SetCallTarget(thread_, target); + JSHandle function = JSHandle::Cast(revocFunction); JSFunction::InitializeJSFunction(thread_, function, FunctionKind::NORMAL_FUNCTION); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(0)); - JSHandle empty_string = global_const->GetHandledEmptyString(); - JSHandle name_key = global_const->GetHandledNameString(); - PropertyDescriptor name_desc(thread_, empty_string, false, false, true); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle::Cast(function), name_key, name_desc); - return revoc_function; + JSHandle emptyString = globalConst->GetHandledEmptyString(); + JSHandle nameKey = globalConst->GetHandledNameString(); + PropertyDescriptor nameDesc(thread_, emptyString, false, false, true); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle::Cast(function), nameKey, nameDesc); + return revocFunction; } -JSHandle ObjectFactory::NewJSAsyncAwaitStatusFunction(const void *native_func) +JSHandle ObjectFactory::NewJSAsyncAwaitStatusFunction(const void *nativeFunc) { JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetAsyncAwaitStatusFunctionClass()); - JSHandle await_function = + JSHandle awaitFunction = JSHandle::Cast(NewJSObject(dynclass)); - JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(await_function)); - JSMethod *target = vm_->GetMethodForNativeFunction(native_func); - await_function->SetCallTarget(thread_, target); - return await_function; + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(awaitFunction)); + JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); + awaitFunction->SetCallTarget(thread_, target); + return awaitFunction; } JSHandle ObjectFactory::NewJSAsyncGeneratorResolveNextFunction( - const void *native_func) + const void *nativeFunc) { NewObjectHook(); JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetAsyncGeneratorResolveNextFunctionClass()); - JSHandle resolve_next_function = + JSHandle resolveNextFunction = JSHandle::Cast(NewJSObject(dynclass)); - JSFunction::InitializeJSFunction(thread_, env, JSHandle::Cast(resolve_next_function)); - JSMethod *target = vm_->GetMethodForNativeFunction(native_func); - resolve_next_function->SetCallTarget(thread_, target); - return resolve_next_function; + JSFunction::InitializeJSFunction(thread_, env, JSHandle::Cast(resolveNextFunction)); + JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); + resolveNextFunction->SetCallTarget(thread_, target); + return resolveNextFunction; } JSHandle ObjectFactory::NewJSAsyncFromSyncIteratorValueUnwrapFunction( - const void *native_func) + const void *nativeFunc) { NewObjectHook(); JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetAsyncFromSyncIteratorValueUnwrapFunctionClass()); - JSHandle async_from_sync_iterator_unwrap_function = + JSHandle asyncFromSyncIteratorUnwrapFunction = JSHandle::Cast(NewJSObject(dynclass)); - JSFunction::InitializeJSFunction(thread_, env, - JSHandle::Cast(async_from_sync_iterator_unwrap_function)); - JSMethod *target = vm_->GetMethodForNativeFunction(native_func); - async_from_sync_iterator_unwrap_function->SetCallTarget(thread_, target); - return async_from_sync_iterator_unwrap_function; + JSFunction::InitializeJSFunction(thread_, env, JSHandle::Cast(asyncFromSyncIteratorUnwrapFunction)); + JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); + asyncFromSyncIteratorUnwrapFunction->SetCallTarget(thread_, target); + return asyncFromSyncIteratorUnwrapFunction; } JSHandle ObjectFactory::NewJSGeneratorFunction(JSMethod *method) @@ -1221,23 +1215,23 @@ JSHandle ObjectFactory::NewJSGeneratorFunction(JSMethod *method) JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); - JSHandle generator_func = JSHandle::Cast(NewJSObject(dynclass)); - JSFunction::InitializeJSFunction(thread_, generator_func, FunctionKind::GENERATOR_FUNCTION); - generator_func->SetCallTarget(thread_, method); - SlowRuntimeStub::NotifyInlineCache(thread_, *generator_func, method); - return generator_func; + JSHandle generatorFunc = JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION); + generatorFunc->SetCallTarget(thread_, method); + SlowRuntimeStub::NotifyInlineCache(thread_, *generatorFunc, method); + return generatorFunc; } -JSHandle ObjectFactory::NewJSGeneratorObject(JSHandle generator_function) +JSHandle ObjectFactory::NewJSGeneratorObject(JSHandle generatorFunction) { - JSHandle proto(thread_, JSHandle::Cast(generator_function)->GetProtoOrDynClass()); + JSHandle proto(thread_, JSHandle::Cast(generatorFunction)->GetProtoOrDynClass()); if (!proto->IsECMAObject()) { - JSHandle realm_handle = JSObject::GetFunctionRealm(thread_, generator_function); - proto = realm_handle->GetGeneratorPrototype(); + JSHandle realmHandle = JSObject::GetFunctionRealm(thread_, generatorFunction); + proto = realmHandle->GetGeneratorPrototype(); } JSHandle dynclass = CreateDynClass(JSType::JS_GENERATOR_OBJECT, proto); - JSHandle generator_object = JSHandle::Cast(NewJSObject(dynclass)); - return generator_object; + JSHandle generatorObject = JSHandle::Cast(NewJSObject(dynclass)); + return generatorObject; } JSHandle ObjectFactory::NewJSAsyncGeneratorFunction(JSMethod *method) @@ -1246,25 +1240,25 @@ JSHandle ObjectFactory::NewJSAsyncGeneratorFunction(JSMethod *method JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetAsyncGeneratorFunctionClass()); - JSHandle generator_func = JSHandle::Cast(NewJSObject(dynclass)); - JSFunction::InitializeJSFunction(thread_, env, generator_func, FunctionKind::ASYNC_GENERATOR_FUNCTION); - generator_func->SetCallTarget(thread_, method); - return generator_func; + JSHandle generatorFunc = JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, env, generatorFunc, FunctionKind::ASYNC_GENERATOR_FUNCTION); + generatorFunc->SetCallTarget(thread_, method); + return generatorFunc; } JSHandle ObjectFactory::NewJSAsyncGeneratorObject( - JSHandle async_generator_function) + JSHandle asyncGeneratorFunction) { NewObjectHook(); - JSHandle proto(thread_, JSHandle::Cast(async_generator_function)->GetProtoOrDynClass()); + JSHandle proto(thread_, JSHandle::Cast(asyncGeneratorFunction)->GetProtoOrDynClass()); if (!proto->IsECMAObject()) { - JSHandle realm_handle = JSObject::GetFunctionRealm(thread_, async_generator_function); - proto = realm_handle->GetAsyncGeneratorPrototype(); + JSHandle realmHandle = JSObject::GetFunctionRealm(thread_, asyncGeneratorFunction); + proto = realmHandle->GetAsyncGeneratorPrototype(); } JSHandle dynclass = CreateDynClass(JSType::JS_ASYNC_GENERATOR_OBJECT, proto); - JSHandle asyncgenerator_object = + JSHandle asyncgeneratorObject = JSHandle::Cast(NewJSObject(dynclass)); - return asyncgenerator_object; + return asyncgeneratorObject; } JSHandle ObjectFactory::NewJSAsyncFromSyncIteratorObject() @@ -1275,20 +1269,20 @@ JSHandle ObjectFactory::NewJSAsyncFromSyncIterato JSHandle dynclass = CreateDynClass(JSType::JS_ASYNC_FROM_SYNC_ITERATOR_OBJECT, proto); - JSHandle async_from_sync_iterator_object = + JSHandle asyncFromSyncIteratorObject = JSHandle::Cast(NewJSObject(dynclass)); - return async_from_sync_iterator_object; + return asyncFromSyncIteratorObject; } JSHandle ObjectFactory::NewAsyncFunction(JSMethod *method) { JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetAsyncFunctionClass()); - JSHandle async_function = JSHandle::Cast(NewJSObject(dynclass)); - JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(async_function)); - async_function->SetCallTarget(thread_, method); - SlowRuntimeStub::NotifyInlineCache(thread_, *async_function, method); - return async_function; + JSHandle asyncFunction = JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(asyncFunction)); + asyncFunction->SetCallTarget(thread_, method); + SlowRuntimeStub::NotifyInlineCache(thread_, *asyncFunction, method); + return asyncFunction; } JSHandle ObjectFactory::NewJSAsyncFuncObject() @@ -1296,14 +1290,14 @@ JSHandle ObjectFactory::NewJSAsyncFuncObject() JSHandle env = vm_->GetGlobalEnv(); JSHandle proto = env->GetInitialGenerator(); JSHandle dynclass = CreateDynClass(JSType::JS_ASYNC_FUNC_OBJECT, proto); - JSHandle async_func_object = JSHandle::Cast(NewJSObject(dynclass)); - return async_func_object; + JSHandle asyncFuncObject = JSHandle::Cast(NewJSObject(dynclass)); + return asyncFuncObject; } JSHandle ObjectFactory::NewCompletionRecord(uint8_t type, const JSHandle &value) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(completion_record_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(completionRecordClass_); JSHandle obj(thread_, header); obj->SetType(thread_, JSTaggedValue(static_cast(type))); obj->SetValue(thread_, value.GetTaggedValue()); @@ -1313,7 +1307,7 @@ JSHandle ObjectFactory::NewCompletionRecord(uint8_t type, cons JSHandle ObjectFactory::NewGeneratorContext() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(generator_context_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(generatorContextClass_); JSHandle obj(thread_, header); obj->SetRegsArray(thread_, JSTaggedValue::Undefined()); obj->SetMethod(thread_, JSTaggedValue::Undefined()); @@ -1333,13 +1327,13 @@ JSHandle ObjectFactory::NewJSPrimitiveRef(const JSHandleSetValue(thread_, object); JSHandle env = vm_->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); if (function.GetTaggedValue() == env->GetStringFunction().GetTaggedValue()) { - JSHandle length_str = global_const->GetHandledLengthString(); + JSHandle lengthStr = globalConst->GetHandledLengthString(); int32_t length = EcmaString::Cast(object.GetTaggedValue().GetTaggedObject())->GetLength(); PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(length)), false, false, false); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), length_str, desc); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), lengthStr, desc); } return obj; @@ -1369,45 +1363,45 @@ JSHandle ObjectFactory::NewJSPrimitiveRef(PrimitiveType type, co default: break; } - JSHandle func_handle(function); - return factory->NewJSPrimitiveRef(func_handle, object); + JSHandle funcHandle(function); + return factory->NewJSPrimitiveRef(funcHandle, object); } JSHandle ObjectFactory::NewJSString(const JSHandle &str) { JSHandle env = vm_->GetGlobalEnv(); - JSHandle string_func = env->GetStringFunction(); + JSHandle stringFunc = env->GetStringFunction(); JSHandle obj = - JSHandle::Cast(NewJSObjectByConstructor(JSHandle(string_func), string_func)); + JSHandle::Cast(NewJSObjectByConstructor(JSHandle(stringFunc), stringFunc)); obj->SetValue(thread_, str); return obj; } -JSHandle ObjectFactory::NewGlobalEnv(JSHClass *global_env_class) +JSHandle ObjectFactory::NewGlobalEnv(JSHClass *globalEnvClass) { NewObjectHook(); // Note: Global env must be allocated in non-movable heap, since its getters will directly return // the offsets of the properties as the address of Handles. - TaggedObject *header = heap_helper_.AllocateNonMovableOrHugeObject(global_env_class); + TaggedObject *header = heapHelper_.AllocateNonMovableOrHugeObject(globalEnvClass); InitObjectFields(header); return JSHandle(thread_, GlobalEnv::Cast(header)); } -JSHandle ObjectFactory::NewLexicalEnv(int num_slots) +JSHandle ObjectFactory::NewLexicalEnv(int numSlots) { NewObjectHook(); - size_t size = LexicalEnv::ComputeSize(num_slots); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(env_class_, size); + size_t size = LexicalEnv::ComputeSize(numSlots); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(envClass_, size); JSHandle array(thread_, header); - array->InitializeWithSpecialValue(JSTaggedValue::Undefined(), num_slots + LexicalEnv::RESERVED_ENV_LENGTH); + array->InitializeWithSpecialValue(JSTaggedValue::Undefined(), numSlots + LexicalEnv::RESERVED_ENV_LENGTH); return array; } JSHandle ObjectFactory::NewJSSymbol() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(symbol_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(symbolClass_); JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetDescription(thread_, JSTaggedValue::Undefined()); obj->SetFlags(thread_, JSTaggedValue(0)); @@ -1426,7 +1420,7 @@ JSHandle ObjectFactory::NewPrivateSymbol() JSHandle ObjectFactory::NewPrivateNameSymbol(const JSHandle &name) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(symbol_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(symbolClass_); JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetFlags(thread_, JSTaggedValue(0)); obj->SetPrivateNameSymbol(thread_); @@ -1439,7 +1433,7 @@ JSHandle ObjectFactory::NewPrivateNameSymbol(const JSHandle ObjectFactory::NewWellKnownSymbol(const JSHandle &name) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(symbol_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(symbolClass_); JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetFlags(thread_, JSTaggedValue(0)); obj->SetWellKnownSymbol(thread_); @@ -1452,7 +1446,7 @@ JSHandle ObjectFactory::NewWellKnownSymbol(const JSHandle ObjectFactory::NewPublicSymbol(const JSHandle &name) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(symbol_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(symbolClass_); JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetFlags(thread_, JSTaggedValue(0)); obj->SetDescription(thread_, name); @@ -1464,16 +1458,16 @@ JSHandle ObjectFactory::NewPublicSymbol(const JSHandle JSHandle ObjectFactory::NewSymbolWithTable(const JSHandle &name) { JSHandle env = vm_->GetGlobalEnv(); - JSHandle table_handle(env->GetRegisterSymbols()); - if (table_handle->ContainsKey(thread_, name.GetTaggedValue())) { - JSTaggedValue obj_value = table_handle->GetSymbol(name.GetTaggedValue()); - return JSHandle(thread_, obj_value); + JSHandle tableHandle(env->GetRegisterSymbols()); + if (tableHandle->ContainsKey(thread_, name.GetTaggedValue())) { + JSTaggedValue objValue = tableHandle->GetSymbol(name.GetTaggedValue()); + return JSHandle(thread_, objValue); } JSHandle obj = NewPublicSymbol(name); - JSHandle value_handle(obj); - JSHandle key_handle(name); - JSHandle table = SymbolTable::Insert(thread_, table_handle, key_handle, value_handle); + JSHandle valueHandle(obj); + JSHandle keyHandle(name); + JSHandle table = SymbolTable::Insert(thread_, tableHandle, keyHandle, valueHandle); env->SetRegisterSymbols(thread_, table); return obj; } @@ -1502,12 +1496,12 @@ JSHandle ObjectFactory::NewSymbolWithTableWithChar(const char *descrip return NewSymbolWithTable(JSHandle(string)); } -JSHandle ObjectFactory::NewAccessorData(panda::SpaceType space_type) +JSHandle ObjectFactory::NewAccessorData(panda::SpaceType spaceType) { NewObjectHook(); - TaggedObject *header = space_type == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT - ? heap_helper_.AllocateNonMovableOrHugeObject(accessor_data_class_) - : heap_helper_.AllocateYoungGenerationOrHugeObject(accessor_data_class_); + TaggedObject *header = spaceType == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT + ? heapHelper_.AllocateNonMovableOrHugeObject(accessorDataClass_) + : heapHelper_.AllocateYoungGenerationOrHugeObject(accessorDataClass_); JSHandle acc(thread_, AccessorData::Cast(header)); acc->SetGetter(thread_, JSTaggedValue::Undefined()); acc->SetSetter(thread_, JSTaggedValue::Undefined()); @@ -1517,25 +1511,25 @@ JSHandle ObjectFactory::NewAccessorData(panda::SpaceType space_typ JSHandle ObjectFactory::NewInternalAccessor(void *setter, void *getter) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateNonMovableOrHugeObject(internal_accessor_class_); + TaggedObject *header = heapHelper_.AllocateNonMovableOrHugeObject(internalAccessorClass_); JSHandle obj(thread_, AccessorData::Cast(header)); if (setter != nullptr) { - JSHandle set_func = NewJSNativePointer(setter, nullptr, nullptr, true); - obj->SetSetter(thread_, set_func.GetTaggedValue()); + JSHandle setFunc = NewJSNativePointer(setter, nullptr, nullptr, true); + obj->SetSetter(thread_, setFunc.GetTaggedValue()); } else { - JSTaggedValue set_func = JSTaggedValue::Undefined(); - obj->SetSetter(thread_, set_func); + JSTaggedValue setFunc = JSTaggedValue::Undefined(); + obj->SetSetter(thread_, setFunc); ASSERT(!obj->HasSetter()); } - JSHandle get_func = NewJSNativePointer(getter, nullptr, nullptr, true); - obj->SetGetter(thread_, get_func); + JSHandle getFunc = NewJSNativePointer(getter, nullptr, nullptr, true); + obj->SetGetter(thread_, getFunc); return obj; } JSHandle ObjectFactory::NewPromiseCapability() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(capability_record_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(capabilityRecordClass_); JSHandle obj(thread_, header); obj->SetPromise(thread_, JSTaggedValue::Undefined()); obj->SetResolve(thread_, JSTaggedValue::Undefined()); @@ -1546,7 +1540,7 @@ JSHandle ObjectFactory::NewPromiseCapability() JSHandle ObjectFactory::NewPromiseReaction() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(reactions_record_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(reactionsRecordClass_); JSHandle obj(thread_, header); obj->SetPromiseCapability(thread_, JSTaggedValue::Undefined()); obj->SetHandler(thread_, JSTaggedValue::Undefined()); @@ -1558,7 +1552,7 @@ JSHandle ObjectFactory::NewPromiseIteratorRecord(const JS const JSHandle &done) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(promise_iterator_record_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(promiseIteratorRecordClass_); JSHandle obj(thread_, header); obj->SetIterator(thread_, itor.GetTaggedValue()); obj->SetDone(thread_, done.GetTaggedValue()); @@ -1568,7 +1562,7 @@ JSHandle ObjectFactory::NewPromiseIteratorRecord(const JS JSHandle ObjectFactory::NewMicroJobQueue() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateNonMovableOrHugeObject(micro_job_queue_class_); + TaggedObject *header = heapHelper_.AllocateNonMovableOrHugeObject(microJobQueueClass_); JSHandle obj(thread_, header); obj->SetPromiseJobQueue(thread_, GetEmptyTaggedQueue().GetTaggedValue()); obj->SetScriptJobQueue(thread_, GetEmptyTaggedQueue().GetTaggedValue()); @@ -1579,21 +1573,21 @@ JSHandle ObjectFactory::NewPendingJob(const JSHandle &argv) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(pending_job_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(pendingJobClass_); JSHandle obj(thread_, header); obj->SetJob(thread_, func.GetTaggedValue()); obj->SetArguments(thread_, argv.GetTaggedValue()); return obj; } -JSHandle ObjectFactory::NewFunctionExtraInfo(const JSHandle &call_back, +JSHandle ObjectFactory::NewFunctionExtraInfo(const JSHandle &callBack, const JSHandle &vm, const JSHandle &data) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(function_extra_info_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(functionExtraInfo_); JSHandle obj(thread_, header); - obj->SetCallback(thread_, call_back.GetTaggedValue()); + obj->SetCallback(thread_, callBack.GetTaggedValue()); obj->SetVm(thread_, vm.GetTaggedValue()); obj->SetData(thread_, data.GetTaggedValue()); return obj; @@ -1605,10 +1599,10 @@ JSHandle ObjectFactory::NewJSProxy(const JSHandle &targe NewObjectHook(); TaggedObject *header = nullptr; if (target->IsCallable()) { - header = target->IsConstructor() ? heap_helper_.AllocateYoungGenerationOrHugeObject(js_proxy_construct_class_) - : heap_helper_.AllocateYoungGenerationOrHugeObject(js_proxy_callable_class_); + header = target->IsConstructor() ? heapHelper_.AllocateYoungGenerationOrHugeObject(jsProxyConstructClass_) + : heapHelper_.AllocateYoungGenerationOrHugeObject(jsProxyCallableClass_); } else { - header = heap_helper_.AllocateYoungGenerationOrHugeObject(js_proxy_ordinary_class_); + header = heapHelper_.AllocateYoungGenerationOrHugeObject(jsProxyOrdinaryClass_); } JSHandle proxy(thread_, header); @@ -1627,29 +1621,29 @@ JSHandle ObjectFactory::NewJSProxy(const JSHandle &targe JSHandle ObjectFactory::NewJSRealm() { JSHandle env = vm_->GetGlobalEnv(); - JSHandle realm_env_class = CreateDynClass(hclass_class_, JSType::GLOBAL_ENV); - JSHandle realm_env_handle = NewGlobalEnv(*realm_env_class); + JSHandle realmEnvClass = CreateDynClass(hclassClass_, JSType::GLOBAL_ENV); + JSHandle realmEnvHandle = NewGlobalEnv(*realmEnvClass); ObtainRootClass(env); - JSHandle empty_arr = NewEmptyArray(); - realm_env_handle->SetEmptyArray(thread_, empty_arr); - auto tagged_queue_handle = NewTaggedQueue(0); - realm_env_handle->SetEmptyTaggedQueue(thread_, tagged_queue_handle); + JSHandle emptyArr = NewEmptyArray(); + realmEnvHandle->SetEmptyArray(thread_, emptyArr); + auto taggedQueueHandle = NewTaggedQueue(0); + realmEnvHandle->SetEmptyTaggedQueue(thread_, taggedQueueHandle); auto result = TemplateMap::Create(thread_); - realm_env_handle->SetTemplateMap(thread_, result); + realmEnvHandle->SetTemplateMap(thread_, result); builtins::Builtins builtins; - builtins.Initialize(realm_env_handle, thread_); - JSHandle proto_value = thread_->GlobalConstants()->GetHandledJSRealmClass(); - JSHandle dyn_handle = CreateDynClass(JSType::JS_REALM, proto_value); - JSHandle realm(NewJSObject(dyn_handle)); - realm->SetGlobalEnv(thread_, realm_env_handle.GetTaggedValue()); + builtins.Initialize(realmEnvHandle, thread_); + JSHandle protoValue = thread_->GlobalConstants()->GetHandledJSRealmClass(); + JSHandle dynHandle = CreateDynClass(JSType::JS_REALM, protoValue); + JSHandle realm(NewJSObject(dynHandle)); + realm->SetGlobalEnv(thread_, realmEnvHandle.GetTaggedValue()); - JSHandle realm_obj = realm_env_handle->GetJSGlobalObject(); + JSHandle realmObj = realmEnvHandle->GetJSGlobalObject(); JSHandle realmkey(thread_->GlobalConstants()->GetHandledGlobalString()); - PropertyDescriptor realm_desc(thread_, JSHandle::Cast(realm_obj), true, false, true); + PropertyDescriptor realmDesc(thread_, JSHandle::Cast(realmObj), true, false, true); [[maybe_unused]] bool status = - JSObject::DefineOwnProperty(thread_, JSHandle::Cast(realm), realmkey, realm_desc); + JSObject::DefineOwnProperty(thread_, JSHandle::Cast(realm), realmkey, realmDesc); ASSERT_PRINT(status, "Realm defineOwnProperty failed"); return realm; @@ -1658,15 +1652,13 @@ JSHandle ObjectFactory::NewJSRealm() JSHandle ObjectFactory::NewEmptyArray(bool weak) { NewObjectHook(); - auto header = - heap_helper_.AllocateNonMovableOrHugeObject(weak ? weak_array_class_ : array_class_, TaggedArray::SIZE); + auto header = heapHelper_.AllocateNonMovableOrHugeObject(weak ? weakArrayClass_ : arrayClass_, TaggedArray::SIZE); JSHandle array(thread_, header); array->SetLength(0); return array; } -JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedValue init_val, - panda::SpaceType space_type) +JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedValue initVal, panda::SpaceType spaceType) { NewObjectHook(); if (length == 0) { @@ -1675,43 +1667,43 @@ JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedVal size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); TaggedObject *header = nullptr; - if (space_type == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT) { - header = heap_helper_.AllocateNonMovableOrHugeObject(array_class_, size); + if (spaceType == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT) { + header = heapHelper_.AllocateNonMovableOrHugeObject(arrayClass_, size); } else { - header = heap_helper_.AllocateYoungGenerationOrHugeObject(array_class_, size); + header = heapHelper_.AllocateYoungGenerationOrHugeObject(arrayClass_, size); } JSHandle array(thread_, header); // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - array->InitializeWithSpecialValue(init_val, length); + array->InitializeWithSpecialValue(initVal, length); return array; } -JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedValue init_val) +JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedValue initVal) { - return NewTaggedArrayImpl(length, init_val, false); + return NewTaggedArrayImpl(length, initVal, false); } -JSHandle ObjectFactory::NewWeakTaggedArray(uint32_t length, JSTaggedValue init_val) +JSHandle ObjectFactory::NewWeakTaggedArray(uint32_t length, JSTaggedValue initVal) { - return NewTaggedArrayImpl(length, init_val, true); + return NewTaggedArrayImpl(length, initVal, true); } -JSHandle ObjectFactory::NewTaggedArrayImpl(uint32_t length, JSTaggedValue init_val, bool weak) +JSHandle ObjectFactory::NewTaggedArrayImpl(uint32_t length, JSTaggedValue initVal, bool weak) { NewObjectHook(); if (length == 0) { return weak ? EmptyWeakArray() : EmptyArray(); } - ASSERT(!init_val.IsHeapObject()); + ASSERT(!initVal.IsHeapObject()); size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(weak ? weak_array_class_ : array_class_, size); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(weak ? weakArrayClass_ : arrayClass_, size); JSHandle array(thread_, header); // NOTE(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - array->InitializeWithSpecialValue(init_val, length); + array->InitializeWithSpecialValue(initVal, length); return array; } @@ -1721,54 +1713,54 @@ JSHandle ObjectFactory::NewDictionaryArray(uint32_t length) ASSERT(length > 0); size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(dictionary_class_, size); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(dictionaryClass_, size); JSHandle array(thread_, header); array->InitializeWithSpecialValue(JSTaggedValue::Undefined(), length); return array; } -JSHandle ObjectFactory::NewLinkedHashTable(ArraySizeT length, JSType table_type, bool is_weak) +JSHandle ObjectFactory::NewLinkedHashTable(ArraySizeT length, JSType tableType, bool isWeak) { NewObjectHook(); ASSERT(length > 0); size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); - JSHClass *table_class = nullptr; - if (table_type == JSType::LINKED_HASH_MAP) { - table_class = is_weak ? weak_linked_hash_map_class_ : linked_hash_map_class_; - } else if (table_type == JSType::LINKED_HASH_SET) { - table_class = is_weak ? weak_linked_hash_set_class_ : linked_hash_set_class_; + JSHClass *tableClass = nullptr; + if (tableType == JSType::LINKED_HASH_MAP) { + tableClass = isWeak ? weakLinkedHashMapClass_ : linkedHashMapClass_; + } else if (tableType == JSType::LINKED_HASH_SET) { + tableClass = isWeak ? weakLinkedHashSetClass_ : linkedHashSetClass_; } else { - table_class = array_class_; + tableClass = arrayClass_; } - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(table_class, size); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(tableClass, size); JSHandle array(thread_, header); array->InitializeWithSpecialValue(JSTaggedValue::Hole(), length); return array; } JSHandle ObjectFactory::ExtendArray(const JSHandle &old, uint32_t length, - JSTaggedValue init_val) + JSTaggedValue initVal) { bool weak = old->GetClass()->IsWeakContainer(); ASSERT(length > old->GetLength()); NewObjectHook(); size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(weak ? weak_array_class_ : array_class_, size); - JSHandle new_array(thread_, header); - new_array->SetLength(length); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(weak ? weakArrayClass_ : arrayClass_, size); + JSHandle newArray(thread_, header); + newArray->SetLength(length); - uint32_t old_length = old->GetLength(); - for (uint32_t i = 0; i < old_length; i++) { + uint32_t oldLength = old->GetLength(); + for (uint32_t i = 0; i < oldLength; i++) { JSTaggedValue value = old->Get(i); - new_array->Set(thread_, i, value); + newArray->Set(thread_, i, value); } - for (uint32_t i = old_length; i < length; i++) { - new_array->Set(thread_, i, init_val); + for (uint32_t i = oldLength; i < length; i++) { + newArray->Set(thread_, i, initVal); } - return new_array; + return newArray; } JSHandle ObjectFactory::CopyPartArray(const JSHandle &old, uint32_t start, uint32_t end) @@ -1777,85 +1769,85 @@ JSHandle ObjectFactory::CopyPartArray(const JSHandle & ASSERT(end <= old->GetLength()); bool weak = old->GetClass()->IsWeakContainer(); - uint32_t new_length = end - start; - if (new_length == 0) { + uint32_t newLength = end - start; + if (newLength == 0) { return weak ? EmptyWeakArray() : EmptyArray(); } NewObjectHook(); - size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), new_length); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(weak ? weak_array_class_ : array_class_, size); - JSHandle new_array(thread_, header); - new_array->SetLength(new_length); + size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(weak ? weakArrayClass_ : arrayClass_, size); + JSHandle newArray(thread_, header); + newArray->SetLength(newLength); - for (uint32_t i = 0; i < new_length; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i + start); if (value.IsHole()) { break; } - new_array->Set(thread_, i, value); + newArray->Set(thread_, i, value); } - return new_array; + return newArray; } -JSHandle ObjectFactory::CopyArray(const JSHandle &old, [[maybe_unused]] uint32_t old_length, - uint32_t new_length, JSTaggedValue init_val) +JSHandle ObjectFactory::CopyArray(const JSHandle &old, [[maybe_unused]] uint32_t oldLength, + uint32_t newLength, JSTaggedValue initVal) { bool weak = old->GetClass()->IsWeakContainer(); - if (new_length == 0) { + if (newLength == 0) { return weak ? EmptyWeakArray() : EmptyArray(); } - if (new_length > old_length) { - return ExtendArray(old, new_length, init_val); + if (newLength > oldLength) { + return ExtendArray(old, newLength, initVal); } NewObjectHook(); - size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), new_length); - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(weak ? weak_array_class_ : array_class_, size); - JSHandle new_array(thread_, header); - new_array->SetLength(new_length); + size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(weak ? weakArrayClass_ : arrayClass_, size); + JSHandle newArray(thread_, header); + newArray->SetLength(newLength); - for (uint32_t i = 0; i < new_length; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i); - new_array->Set(thread_, i, value); + newArray->Set(thread_, i, value); } - return new_array; + return newArray; } -JSHandle ObjectFactory::CreateLayoutInfo(int properties, JSTaggedValue init_val) +JSHandle ObjectFactory::CreateLayoutInfo(int properties, JSTaggedValue initVal) { - int array_length = LayoutInfo::ComputeArrayLength(LayoutInfo::ComputeGrowCapacity(properties)); - JSHandle layout_info_handle = JSHandle::Cast(NewTaggedArray(array_length, init_val)); - layout_info_handle->SetNumberOfElements(thread_, 0); - return layout_info_handle; + int arrayLength = LayoutInfo::ComputeArrayLength(LayoutInfo::ComputeGrowCapacity(properties)); + JSHandle layoutInfoHandle = JSHandle::Cast(NewTaggedArray(arrayLength, initVal)); + layoutInfoHandle->SetNumberOfElements(thread_, 0); + return layoutInfoHandle; } JSHandle ObjectFactory::ExtendLayoutInfo(const JSHandle &old, int properties, - JSTaggedValue init_val) + JSTaggedValue initVal) { ASSERT(properties > old->NumberOfElements()); - int array_length = LayoutInfo::ComputeArrayLength(LayoutInfo::ComputeGrowCapacity(properties)); - return JSHandle(ExtendArray(JSHandle(old), array_length, init_val)); + int arrayLength = LayoutInfo::ComputeArrayLength(LayoutInfo::ComputeGrowCapacity(properties)); + return JSHandle(ExtendArray(JSHandle(old), arrayLength, initVal)); } JSHandle ObjectFactory::CopyLayoutInfo(const JSHandle &old) { - int new_length = old->GetLength(); - return JSHandle(CopyArray(JSHandle::Cast(old), new_length, new_length)); + int newLength = old->GetLength(); + return JSHandle(CopyArray(JSHandle::Cast(old), newLength, newLength)); } JSHandle ObjectFactory::CopyAndReSort(const JSHandle &old, int end, int capacity) { ASSERT(capacity >= end); - JSHandle new_arr = CreateLayoutInfo(capacity); + JSHandle newArr = CreateLayoutInfo(capacity); Span sp(old->GetProperties(), end); int i = 0; for (; i < end; i++) { - new_arr->AddKey(thread_, i, sp[i].key, PropertyAttributes(sp[i].attr)); + newArr->AddKey(thread_, i, sp[i].key, PropertyAttributes(sp[i].attr)); } - return new_arr; + return newArr; } JSHandle ObjectFactory::NewConstantPool(uint32_t capacity) @@ -1865,7 +1857,7 @@ JSHandle ObjectFactory::NewConstantPool(uint32_t capacity) return JSHandle::Cast(EmptyArray()); } size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), capacity); - auto header = heap_helper_.AllocateNonMovableOrHugeObject(array_class_, size); + auto header = heapHelper_.AllocateNonMovableOrHugeObject(arrayClass_, size); JSHandle array(thread_, header); array->InitializeWithSpecialValue(JSTaggedValue::Undefined(), capacity); return array; @@ -1874,7 +1866,7 @@ JSHandle ObjectFactory::NewConstantPool(uint32_t capacity) JSHandle ObjectFactory::NewProgram() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateNonMovableOrHugeObject(program_class_); + TaggedObject *header = heapHelper_.AllocateNonMovableOrHugeObject(programClass_); JSHandle p(thread_, header); p->SetLocation(thread_, JSTaggedValue::Undefined()); p->SetConstantPool(thread_, JSTaggedValue::Undefined()); @@ -1886,7 +1878,7 @@ JSHandle ObjectFactory::NewProgram() JSHandle ObjectFactory::NewEmptyEcmaModule() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(ecma_module_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(ecmaModuleClass_); JSHandle module(thread_, header); module->SetNameDictionary(thread_, JSTaggedValue::Undefined()); return module; @@ -1912,34 +1904,32 @@ JSHandle ObjectFactory::EmptyWeakArray() const JSHandle ObjectFactory::NewObjectWrapper(const JSHandle &value) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(object_wrapper_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(objectWrapperClass_); ObjectWrapper *obj = ObjectWrapper::Cast(header); obj->SetValue(thread_, value); return JSHandle(thread_, obj); } -JSHandle ObjectFactory::GetStringFromStringTable(const uint8_t *utf8_data, uint32_t utf8_len, - bool can_be_compress, panda::SpaceType space_type) const +JSHandle ObjectFactory::GetStringFromStringTable(const uint8_t *utf8Data, uint32_t utf8Len, + bool canBeCompress, panda::SpaceType spaceType) const { NewObjectHook(); - if (utf8_len == 0) { + if (utf8Len == 0) { return GetEmptyString(); } - auto string_table = vm_->GetEcmaStringTable(); - return JSHandle(thread_, - string_table->GetOrInternString(utf8_data, utf8_len, can_be_compress, space_type)); + auto stringTable = vm_->GetEcmaStringTable(); + return JSHandle(thread_, stringTable->GetOrInternString(utf8Data, utf8Len, canBeCompress, spaceType)); } -JSHandle ObjectFactory::GetStringFromStringTable(const uint16_t *utf16_data, uint32_t utf16_len, - bool can_be_compress, panda::SpaceType space_type) const +JSHandle ObjectFactory::GetStringFromStringTable(const uint16_t *utf16Data, uint32_t utf16Len, + bool canBeCompress, panda::SpaceType spaceType) const { NewObjectHook(); - if (utf16_len == 0) { + if (utf16Len == 0) { return GetEmptyString(); } - auto string_table = vm_->GetEcmaStringTable(); - return JSHandle(thread_, - string_table->GetOrInternString(utf16_data, utf16_len, can_be_compress, space_type)); + auto stringTable = vm_->GetEcmaStringTable(); + return JSHandle(thread_, stringTable->GetOrInternString(utf16Data, utf16Len, canBeCompress, spaceType)); } JSHandle ObjectFactory::GetStringFromStringTable(EcmaString *string) const @@ -1948,32 +1938,32 @@ JSHandle ObjectFactory::GetStringFromStringTable(EcmaString *string) if (string->GetLength() == 0) { return GetEmptyString(); } - auto string_table = vm_->GetEcmaStringTable(); - return JSHandle(thread_, string_table->GetOrInternString(string)); + auto stringTable = vm_->GetEcmaStringTable(); + return JSHandle(thread_, stringTable->GetOrInternString(string)); } // NB! don't do special case for C0 80, it means '\u0000', so don't convert to UTF-8 -EcmaString *ObjectFactory::GetRawStringFromStringTable(const uint8_t *mutf8_data, uint32_t utf16_len, - bool can_be_compressed, panda::SpaceType space_type) const +EcmaString *ObjectFactory::GetRawStringFromStringTable(const uint8_t *mutf8Data, uint32_t utf16Len, + bool canBeCompressed, panda::SpaceType spaceType) const { NewObjectHook(); - if (UNLIKELY(utf16_len == 0)) { + if (UNLIKELY(utf16Len == 0)) { return *GetEmptyString(); } - if (can_be_compressed) { - return EcmaString::Cast(vm_->GetEcmaStringTable()->GetOrInternString(mutf8_data, utf16_len, true, space_type)); + if (canBeCompressed) { + return EcmaString::Cast(vm_->GetEcmaStringTable()->GetOrInternString(mutf8Data, utf16Len, true, spaceType)); } - PandaVector utf16_data(utf16_len); - auto len = utf::ConvertRegionMUtf8ToUtf16(mutf8_data, utf16_data.data(), utf::Mutf8Size(mutf8_data), utf16_len, 0); - return EcmaString::Cast(vm_->GetEcmaStringTable()->GetOrInternString(utf16_data.data(), len, false, space_type)); + PandaVector utf16Data(utf16Len); + auto len = utf::ConvertRegionMUtf8ToUtf16(mutf8Data, utf16Data.data(), utf::Mutf8Size(mutf8Data), utf16Len, 0); + return EcmaString::Cast(vm_->GetEcmaStringTable()->GetOrInternString(utf16Data.data(), len, false, spaceType)); } JSHandle ObjectFactory::NewPropertyBox(const JSHandle &value) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateNonMovableOrHugeObject(property_box_class_); + TaggedObject *header = heapHelper_.AllocateNonMovableOrHugeObject(propertyBoxClass_); JSHandle box(thread_, header); box->SetValue(thread_, value); return box; @@ -1982,7 +1972,7 @@ JSHandle ObjectFactory::NewPropertyBox(const JSHandle ObjectFactory::NewProtoChangeMarker() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(proto_change_marker_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(protoChangeMarkerClass_); JSHandle marker(thread_, header); marker->SetHasChanged(false); return marker; @@ -1991,11 +1981,11 @@ JSHandle ObjectFactory::NewProtoChangeMarker() JSHandle ObjectFactory::NewProtoChangeDetails() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(proto_change_details_class_); - JSHandle proto_info(thread_, header); - proto_info->SetChangeListener(thread_, JSTaggedValue(0)); - proto_info->SetRegisterIndex(thread_, JSTaggedValue(ProtoChangeDetails::UNREGISTERED)); - return proto_info; + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(protoChangeDetailsClass_); + JSHandle protoInfo(thread_, header); + protoInfo->SetChangeListener(thread_, JSTaggedValue(0)); + protoInfo->SetRegisterIndex(thread_, JSTaggedValue(ProtoChangeDetails::UNREGISTERED)); + return protoInfo; } JSHandle ObjectFactory::NewProfileTypeInfo(uint32_t length) @@ -2004,7 +1994,7 @@ JSHandle ObjectFactory::NewProfileTypeInfo(uint32_t length) ASSERT(length > 0); size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); - auto header = heap_helper_.AllocateNonMovableOrHugeObject(weak_array_class_, size); + auto header = heapHelper_.AllocateNonMovableOrHugeObject(weakArrayClass_, size); JSHandle array(thread_, header); array->InitializeWithSpecialValue(JSTaggedValue::Undefined(), length); @@ -2016,8 +2006,8 @@ void ObjectFactory::NewObjectHook() const {} JSHandle ObjectFactory::NewTaggedQueue(uint32_t length) { - uint32_t queue_length = TaggedQueue::QueueToArrayIndex(length); - auto queue = JSHandle::Cast(NewTaggedArray(queue_length, JSTaggedValue::Hole())); + uint32_t queueLength = TaggedQueue::QueueToArrayIndex(length); + auto queue = JSHandle::Cast(NewTaggedArray(queueLength, JSTaggedValue::Hole())); queue->SetStart(thread_, JSTaggedValue(0)); // equal to 0 when add 1. queue->SetEnd(thread_, JSTaggedValue(0)); queue->SetCapacity(thread_, JSTaggedValue(length)); @@ -2033,7 +2023,7 @@ JSHandle ObjectFactory::GetEmptyTaggedQueue() const JSHandle ObjectFactory::NewWeakRef(const JSHandle &referent) { - auto header = heap_helper_.AllocateYoungGenerationOrHugeObject(weak_ref_class_); + auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(weakRefClass_); if (header == nullptr) { return JSHandle(); } @@ -2045,9 +2035,9 @@ JSHandle ObjectFactory::NewWeakRef(const JSHandle &referent JSHandle ObjectFactory::NewJSSetIterator(const JSHandle &set, IterationKind kind) { JSHandle env = vm_->GetGlobalEnv(); - JSHandle proto_value = env->GetSetIteratorPrototype(); - JSHandle dyn_handle = CreateDynClass(JSType::JS_SET_ITERATOR, proto_value); - JSHandle iter(NewJSObject(dyn_handle)); + JSHandle protoValue = env->GetSetIteratorPrototype(); + JSHandle dynHandle = CreateDynClass(JSType::JS_SET_ITERATOR, protoValue); + JSHandle iter(NewJSObject(dynHandle)); iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedSet(thread_, set->GetLinkedSet()); iter->SetNextIndex(thread_, JSTaggedValue(0)); @@ -2056,18 +2046,18 @@ JSHandle ObjectFactory::NewJSSetIterator(const JSHandle &s } JSHandle ObjectFactory::NewJSRegExpIterator(const JSHandle &matcher, - const JSHandle &input_str, bool global, - bool full_unicode) + const JSHandle &inputStr, bool global, + bool fullUnicode) { JSHandle env = vm_->GetGlobalEnv(); - JSHandle proto_value = env->GetRegExpIteratorPrototype(); - JSHandle dyn_handle = CreateDynClass(JSType::JS_REG_EXP_ITERATOR, proto_value); - JSHandle iter(NewJSObject(dyn_handle)); + JSHandle protoValue = env->GetRegExpIteratorPrototype(); + JSHandle dynHandle = CreateDynClass(JSType::JS_REG_EXP_ITERATOR, protoValue); + JSHandle iter(NewJSObject(dynHandle)); iter->GetJSHClass()->SetExtensible(true); iter->SetIteratingRegExp(thread_, matcher.GetTaggedValue()); - iter->SetIteratedString(thread_, input_str.GetTaggedValue()); + iter->SetIteratedString(thread_, inputStr.GetTaggedValue()); iter->SetGlobal(global); - iter->SetUnicode(full_unicode); + iter->SetUnicode(fullUnicode); iter->SetDone(false); return iter; } @@ -2075,9 +2065,9 @@ JSHandle ObjectFactory::NewJSRegExpIterator(const JSHandle ObjectFactory::NewJSMapIterator(const JSHandle &map, IterationKind kind) { JSHandle env = vm_->GetGlobalEnv(); - JSHandle proto_value = env->GetMapIteratorPrototype(); - JSHandle dyn_handle = CreateDynClass(JSType::JS_MAP_ITERATOR, proto_value); - JSHandle iter(NewJSObject(dyn_handle)); + JSHandle protoValue = env->GetMapIteratorPrototype(); + JSHandle dynHandle = CreateDynClass(JSType::JS_MAP_ITERATOR, protoValue); + JSHandle iter(NewJSObject(dynHandle)); iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedMap(thread_, map->GetLinkedMap()); iter->SetNextIndex(thread_, JSTaggedValue(0)); @@ -2088,9 +2078,9 @@ JSHandle ObjectFactory::NewJSMapIterator(const JSHandle &m JSHandle ObjectFactory::NewJSArrayIterator(const JSHandle &array, IterationKind kind) { JSHandle env = vm_->GetGlobalEnv(); - JSHandle proto_value = env->GetArrayIteratorPrototype(); - JSHandle dyn_handle = CreateDynClass(JSType::JS_ARRAY_ITERATOR, proto_value); - JSHandle iter(NewJSObject(dyn_handle)); + JSHandle protoValue = env->GetArrayIteratorPrototype(); + JSHandle dynHandle = CreateDynClass(JSType::JS_ARRAY_ITERATOR, protoValue); + JSHandle iter(NewJSObject(dynHandle)); iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedArray(thread_, array); iter->SetNextIndex(thread_, JSTaggedValue(0)); @@ -2098,37 +2088,37 @@ JSHandle ObjectFactory::NewJSArrayIterator(const JSHandle ObjectFactory::CreateJSPromiseReactionsFunction(const void *native_func) +JSHandle ObjectFactory::CreateJSPromiseReactionsFunction(const void *nativeFunc) { JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetPromiseReactionFunctionClass()); - JSHandle reactions_function = + JSHandle reactionsFunction = JSHandle::Cast(NewJSObject(dynclass)); - reactions_function->SetPromise(thread_, JSTaggedValue::Hole()); - reactions_function->SetAlreadyResolved(thread_, JSTaggedValue::Hole()); - JSMethod *method = vm_->GetMethodForNativeFunction(native_func); - reactions_function->SetCallTarget(thread_, method); - JSHandle function = JSHandle::Cast(reactions_function); + reactionsFunction->SetPromise(thread_, JSTaggedValue::Hole()); + reactionsFunction->SetAlreadyResolved(thread_, JSTaggedValue::Hole()); + JSMethod *method = vm_->GetMethodForNativeFunction(nativeFunc); + reactionsFunction->SetCallTarget(thread_, method); + JSHandle function = JSHandle::Cast(reactionsFunction); JSFunction::InitializeJSFunction(thread_, function); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(1)); - return reactions_function; + return reactionsFunction; } -JSHandle ObjectFactory::CreateJSPromiseExecutorFunction(const void *native_func) +JSHandle ObjectFactory::CreateJSPromiseExecutorFunction(const void *nativeFunc) { JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetPromiseExecutorFunctionClass()); - JSHandle executor_function = + JSHandle executorFunction = JSHandle::Cast(NewJSObject(dynclass)); - executor_function->SetCapability(thread_, JSTaggedValue::Hole()); - JSMethod *method = vm_->GetMethodForNativeFunction(native_func); - executor_function->SetCallTarget(thread_, method); - executor_function->SetCapability(thread_, JSTaggedValue::Undefined()); - JSHandle function = JSHandle::Cast(executor_function); + executorFunction->SetCapability(thread_, JSTaggedValue::Hole()); + JSMethod *method = vm_->GetMethodForNativeFunction(nativeFunc); + executorFunction->SetCallTarget(thread_, method); + executorFunction->SetCapability(thread_, JSTaggedValue::Undefined()); + JSHandle function = JSHandle::Cast(executorFunction); JSFunction::InitializeJSFunction(thread_, function, FunctionKind::NORMAL_FUNCTION); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(builtins::FunctionLength::TWO)); - return executor_function; + return executorFunction; } JSHandle ObjectFactory::CreateBuiltinFunction(EcmaEntrypoint steps, uint8_t length, @@ -2139,21 +2129,21 @@ JSHandle ObjectFactory::CreateBuiltinFunction(EcmaEntrypoint steps, function->SetFunctionPrototype(thread_, proto.GetTaggedValue()); function->GetJSHClass()->SetExtensible(true); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle base_function(function); - JSFunction::SetFunctionName(thread_, base_function, name, prefix); + JSHandle baseFunction(function); + JSFunction::SetFunctionName(thread_, baseFunction, name, prefix); return function; } JSHandle ObjectFactory::NewJSPromiseAllResolveElementFunction( - const void *native_func) + const void *nativeFunc) { JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetPromiseAllResolveElementFunctionClass()); JSHandle function = JSHandle::Cast(NewJSObject(dynclass)); JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); - JSMethod *method = vm_->GetMethodForNativeFunction(native_func); + JSMethod *method = vm_->GetMethodForNativeFunction(nativeFunc); function->SetCallTarget(thread_, method); JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(1)); return function; @@ -2166,15 +2156,15 @@ EcmaString *ObjectFactory::InternString(const JSHandle &key) return str; } - EcmaStringTable *string_table = vm_->GetEcmaStringTable(); - return string_table->GetOrInternString(str); + EcmaStringTable *stringTable = vm_->GetEcmaStringTable(); + return stringTable->GetOrInternString(str); } JSHandle ObjectFactory::NewTransitionHandler() { NewObjectHook(); TransitionHandler *handler = - TransitionHandler::Cast(heap_helper_.AllocateYoungGenerationOrHugeObject(transition_handler_class_)); + TransitionHandler::Cast(heapHelper_.AllocateYoungGenerationOrHugeObject(transitionHandlerClass_)); return JSHandle(thread_, handler); } @@ -2182,7 +2172,7 @@ JSHandle ObjectFactory::NewPrototypeHandler() { NewObjectHook(); PrototypeHandler *header = - PrototypeHandler::Cast(heap_helper_.AllocateYoungGenerationOrHugeObject(prototype_handler_class_)); + PrototypeHandler::Cast(heapHelper_.AllocateYoungGenerationOrHugeObject(prototypeHandlerClass_)); JSHandle handler(thread_, header); handler->SetHandlerInfo(thread_, JSTaggedValue::Undefined()); handler->SetProtoCell(thread_, JSTaggedValue::Undefined()); @@ -2193,7 +2183,7 @@ JSHandle ObjectFactory::NewPrototypeHandler() JSHandle ObjectFactory::NewPromiseRecord() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(promise_record_class_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(promiseRecordClass_); JSHandle obj(thread_, header); obj->SetValue(thread_, JSTaggedValue::Undefined()); return obj; @@ -2202,7 +2192,7 @@ JSHandle ObjectFactory::NewPromiseRecord() JSHandle ObjectFactory::NewResolvingFunctionsRecord() { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateYoungGenerationOrHugeObject(promise_resolving_functions_record_); + TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(promiseResolvingFunctionsRecord_); JSHandle obj(thread_, header); obj->SetResolveFunction(thread_, JSTaggedValue::Undefined()); obj->SetRejectFunction(thread_, JSTaggedValue::Undefined()); @@ -2214,161 +2204,160 @@ JSHandle ObjectFactory::CreateObjectClass(const JSHandle JSHandle env = vm_->GetGlobalEnv(); JSHandle proto = env->GetObjectFunctionPrototype(); - uint32_t field_order = 0; + uint32_t fieldOrder = 0; JSMutableHandle key(thread_, JSTaggedValue::Undefined()); - JSHandle layout_info_handle = CreateLayoutInfo(length); - while (field_order < length) { - key.Update(properties->Get(field_order * 2)); // 2: Meaning to double + JSHandle layoutInfoHandle = CreateLayoutInfo(length); + while (fieldOrder < length) { + key.Update(properties->Get(fieldOrder * 2)); // 2: Meaning to double ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attributes = PropertyAttributes::Default(); - if (properties->Get(field_order * 2 + 1).IsAccessor()) { // 2: Meaning to double + if (properties->Get(fieldOrder * 2 + 1).IsAccessor()) { // 2: Meaning to double attributes.SetIsAccessor(true); } attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::MIXED); - attributes.SetOffset(field_order); - layout_info_handle->AddKey(thread_, field_order, key.GetTaggedValue(), attributes); - field_order++; + attributes.SetOffset(fieldOrder); + layoutInfoHandle->AddKey(thread_, fieldOrder, key.GetTaggedValue(), attributes); + fieldOrder++; } - ASSERT(field_order <= PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES); - JSHandle obj_class = CreateDynClass(JSType::JS_OBJECT, field_order); - obj_class->SetPrototype(thread_, proto.GetTaggedValue()); + ASSERT(fieldOrder <= PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES); + JSHandle objClass = CreateDynClass(JSType::JS_OBJECT, fieldOrder); + objClass->SetPrototype(thread_, proto.GetTaggedValue()); { - obj_class->SetExtensible(true); - obj_class->SetIsLiteral(true); - obj_class->SetLayout(thread_, layout_info_handle); - obj_class->SetNumberOfProps(field_order); + objClass->SetExtensible(true); + objClass->SetIsLiteral(true); + objClass->SetLayout(thread_, layoutInfoHandle); + objClass->SetNumberOfProps(fieldOrder); } - return obj_class; + return objClass; } JSHandle ObjectFactory::NewJSObjectByClass(const JSHandle &properties, size_t length, - panda::SpaceType space_type) + panda::SpaceType spaceType) { JSHandle dynclass = CreateObjectClass(properties, length); - JSHandle obj = space_type == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT + JSHandle obj = spaceType == panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT ? NewNonMovableJSObject(dynclass) : NewJSObject(dynclass); return obj; } -JSHandle ObjectFactory::NewEmptyJSObject(panda::SpaceType space_type) +JSHandle ObjectFactory::NewEmptyJSObject(panda::SpaceType spaceType) { JSHandle env = vm_->GetGlobalEnv(); - JSHandle builtin_obj = env->GetObjectFunction(); - return NewJSObjectByConstructor(JSHandle(builtin_obj), builtin_obj, space_type); + JSHandle builtinObj = env->GetObjectFunction(); + return NewJSObjectByConstructor(JSHandle(builtinObj), builtinObj, spaceType); } -EcmaString *ObjectFactory::ResolveString(uint32_t string_id) +EcmaString *ObjectFactory::ResolveString(uint32_t stringId) { auto *caller = panda::StackWalker::Create(thread_).GetMethod(); auto *pf = caller->GetPandaFile(); - auto id = panda_file::File::EntityId(string_id); - auto found_str = pf->GetStringData(id); + auto id = panda_file::File::EntityId(stringId); + auto foundStr = pf->GetStringData(id); - return GetRawStringFromStringTable(found_str.data, found_str.utf16_length, found_str.is_ascii); + return GetRawStringFromStringTable(foundStr.data, foundStr.utf16Length, foundStr.isAscii); } -JSHandle ObjectFactory::NewClassInfoExtractor(JSMethod *ctor_method) +JSHandle ObjectFactory::NewClassInfoExtractor(JSMethod *ctorMethod) { NewObjectHook(); - TaggedObject *header = heap_helper_.AllocateNonMovableOrHugeObject(class_info_extractor_h_class_); + TaggedObject *header = heapHelper_.AllocateNonMovableOrHugeObject(classInfoExtractorHClass_); JSHandle obj(thread_, header); obj->InitializeBitField(); - obj->SetConstructorMethod(ctor_method); - JSHandle empty_array = EmptyArray(); + obj->SetConstructorMethod(ctorMethod); + JSHandle emptyArray = EmptyArray(); obj->SetPrototypeHClass(thread_, JSTaggedValue::Undefined()); - obj->SetNonStaticKeys(thread_, empty_array, SKIP_BARRIER); - obj->SetNonStaticProperties(thread_, empty_array, SKIP_BARRIER); - obj->SetNonStaticElements(thread_, empty_array, SKIP_BARRIER); + obj->SetNonStaticKeys(thread_, emptyArray, SKIP_BARRIER); + obj->SetNonStaticProperties(thread_, emptyArray, SKIP_BARRIER); + obj->SetNonStaticElements(thread_, emptyArray, SKIP_BARRIER); obj->SetConstructorHClass(thread_, JSTaggedValue::Undefined()); - obj->SetStaticKeys(thread_, empty_array, SKIP_BARRIER); - obj->SetStaticProperties(thread_, empty_array, SKIP_BARRIER); - obj->SetStaticElements(thread_, empty_array, SKIP_BARRIER); + obj->SetStaticKeys(thread_, emptyArray, SKIP_BARRIER); + obj->SetStaticProperties(thread_, emptyArray, SKIP_BARRIER); + obj->SetStaticElements(thread_, emptyArray, SKIP_BARRIER); return obj; } // ----------------------------------- new string ---------------------------------------- JSHandle ObjectFactory::NewFromString(const PandaString &data) { - auto utf8_data = reinterpret_cast(data.c_str()); - bool can_be_compress = EcmaString::CanBeCompressed(utf8_data, data.length()); - return GetStringFromStringTable(utf8_data, data.length(), can_be_compress); + auto utf8Data = reinterpret_cast(data.c_str()); + bool canBeCompress = EcmaString::CanBeCompressed(utf8Data, data.length()); + return GetStringFromStringTable(utf8Data, data.length(), canBeCompress); } JSHandle ObjectFactory::NewFromCanBeCompressString(const PandaString &data) { - auto utf8_data = reinterpret_cast(data.c_str()); - ASSERT(EcmaString::CanBeCompressed(utf8_data, data.length())); - return GetStringFromStringTable(utf8_data, data.length(), true); + auto utf8Data = reinterpret_cast(data.c_str()); + ASSERT(EcmaString::CanBeCompressed(utf8Data, data.length())); + return GetStringFromStringTable(utf8Data, data.length(), true); } JSHandle ObjectFactory::NewFromStdString(const std::string &data) { - auto utf8_data = reinterpret_cast(data.c_str()); - bool can_be_compress = EcmaString::CanBeCompressed(utf8_data, data.length()); - return GetStringFromStringTable(utf8_data, data.size(), can_be_compress); + auto utf8Data = reinterpret_cast(data.c_str()); + bool canBeCompress = EcmaString::CanBeCompressed(utf8Data, data.length()); + return GetStringFromStringTable(utf8Data, data.size(), canBeCompress); } -JSHandle ObjectFactory::NewFromStdStringUnCheck(const std::string &data, bool can_be_compress, - panda::SpaceType space_type) +JSHandle ObjectFactory::NewFromStdStringUnCheck(const std::string &data, bool canBeCompress, + panda::SpaceType spaceType) { - auto utf8_data = reinterpret_cast(data.c_str()); - return GetStringFromStringTable(utf8_data, data.size(), can_be_compress, space_type); + auto utf8Data = reinterpret_cast(data.c_str()); + return GetStringFromStringTable(utf8Data, data.size(), canBeCompress, spaceType); } -JSHandle ObjectFactory::NewFromUtf8(const uint8_t *utf8_data, uint32_t utf8_len) +JSHandle ObjectFactory::NewFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len) { - bool can_be_compress = EcmaString::CanBeCompressed(utf8_data, utf8_len); - return GetStringFromStringTable(utf8_data, utf8_len, can_be_compress); + bool canBeCompress = EcmaString::CanBeCompressed(utf8Data, utf8Len); + return GetStringFromStringTable(utf8Data, utf8Len, canBeCompress); } -JSHandle ObjectFactory::NewFromUtf8UnCheck(const uint8_t *utf8_data, uint32_t utf8_len, - bool can_be_compress) +JSHandle ObjectFactory::NewFromUtf8UnCheck(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress) { - return GetStringFromStringTable(utf8_data, utf8_len, can_be_compress); + return GetStringFromStringTable(utf8Data, utf8Len, canBeCompress); } -JSHandle ObjectFactory::NewFromUtf16(const uint16_t *utf16_data, uint32_t utf16_len) +JSHandle ObjectFactory::NewFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len) { - bool can_be_compress = EcmaString::CanBeCompressed(utf16_data, utf16_len); - return GetStringFromStringTable(utf16_data, utf16_len, can_be_compress); + bool canBeCompress = EcmaString::CanBeCompressed(utf16Data, utf16Len); + return GetStringFromStringTable(utf16Data, utf16Len, canBeCompress); } -JSHandle ObjectFactory::NewFromUtf16UnCheck(const uint16_t *utf16_data, uint32_t utf16_len, - bool can_be_compress) +JSHandle ObjectFactory::NewFromUtf16UnCheck(const uint16_t *utf16Data, uint32_t utf16Len, + bool canBeCompress) { - return GetStringFromStringTable(utf16_data, utf16_len, can_be_compress); + return GetStringFromStringTable(utf16Data, utf16Len, canBeCompress); } -JSHandle ObjectFactory::NewFromUtf8Literal(const uint8_t *utf8_data, uint32_t utf8_len) +JSHandle ObjectFactory::NewFromUtf8Literal(const uint8_t *utf8Data, uint32_t utf8Len) { NewObjectHook(); - bool can_be_compress = EcmaString::CanBeCompressed(utf8_data, utf8_len); - return JSHandle(thread_, EcmaString::CreateFromUtf8(utf8_data, utf8_len, vm_, can_be_compress)); + bool canBeCompress = EcmaString::CanBeCompressed(utf8Data, utf8Len); + return JSHandle(thread_, EcmaString::CreateFromUtf8(utf8Data, utf8Len, vm_, canBeCompress)); } -JSHandle ObjectFactory::NewFromUtf8LiteralUnCheck(const uint8_t *utf8_data, uint32_t utf8_len, - bool can_be_compress) +JSHandle ObjectFactory::NewFromUtf8LiteralUnCheck(const uint8_t *utf8Data, uint32_t utf8Len, + bool canBeCompress) { NewObjectHook(); - return JSHandle(thread_, EcmaString::CreateFromUtf8(utf8_data, utf8_len, vm_, can_be_compress)); + return JSHandle(thread_, EcmaString::CreateFromUtf8(utf8Data, utf8Len, vm_, canBeCompress)); } -JSHandle ObjectFactory::NewFromUtf16Literal(const uint16_t *utf16_data, uint32_t utf16_len) +JSHandle ObjectFactory::NewFromUtf16Literal(const uint16_t *utf16Data, uint32_t utf16Len) { NewObjectHook(); - bool can_be_compress = EcmaString::CanBeCompressed(utf16_data, utf16_len); - return JSHandle(thread_, EcmaString::CreateFromUtf16(utf16_data, utf16_len, vm_, can_be_compress)); + bool canBeCompress = EcmaString::CanBeCompressed(utf16Data, utf16Len); + return JSHandle(thread_, EcmaString::CreateFromUtf16(utf16Data, utf16Len, vm_, canBeCompress)); } -JSHandle ObjectFactory::NewFromUtf16LiteralUnCheck(const uint16_t *utf16_data, uint32_t utf16_len, - bool can_be_compress) +JSHandle ObjectFactory::NewFromUtf16LiteralUnCheck(const uint16_t *utf16Data, uint32_t utf16Len, + bool canBeCompress) { NewObjectHook(); - return JSHandle(thread_, EcmaString::CreateFromUtf16(utf16_data, utf16_len, vm_, can_be_compress)); + return JSHandle(thread_, EcmaString::CreateFromUtf16(utf16Data, utf16Len, vm_, canBeCompress)); } JSHandle ObjectFactory::NewFromString(EcmaString *str) @@ -2379,7 +2368,7 @@ JSHandle ObjectFactory::NewFromString(EcmaString *str) JSHandle ObjectFactory::ConcatFromString(const JSHandle &prefix, const JSHandle &suffix) { - EcmaString *concat_string = EcmaString::Concat(prefix, suffix, vm_); - return GetStringFromStringTable(concat_string); + EcmaString *concatString = EcmaString::Concat(prefix, suffix, vm_); + return GetStringFromStringTable(concatString); } } // namespace panda::ecmascript diff --git a/runtime/object_factory.h b/runtime/object_factory.h index 9982574adf37c2a589f7a599a53cdc115f820a7d..9d7ac98489573ccfcc69c58924f9c3d4fd8bdb20 100644 --- a/runtime/object_factory.h +++ b/runtime/object_factory.h @@ -123,53 +123,53 @@ public: JSHandle NewProgram(); JSHandle NewEmptyEcmaModule(); - JSHandle GetJSError(const ErrorType &error_type, const char *data = nullptr); + JSHandle GetJSError(const ErrorType &errorType, const char *data = nullptr); - JSHandle NewJSError(const ErrorType &error_type, const JSHandle &message); + JSHandle NewJSError(const ErrorType &errorType, const JSHandle &message); JSHandle NewTransitionHandler(); JSHandle NewPrototypeHandler(); - JSHandle NewEmptyJSObject(panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); + JSHandle NewEmptyJSObject(panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); // use for others create, prototype is Function.prototype // use for native function PANDA_PUBLIC_API JSHandle NewJSFunction(const JSHandle &env, - const void *native_func = nullptr, + const void *nativeFunc = nullptr, FunctionKind kind = FunctionKind::NORMAL_FUNCTION); // use for method JSHandle NewJSFunction(const JSHandle &env, JSMethod *method, FunctionKind kind = FunctionKind::NORMAL_FUNCTION); - JSHandle NewJSNativeErrorFunction(const JSHandle &env, const void *native_func = nullptr); + JSHandle NewJSNativeErrorFunction(const JSHandle &env, const void *nativeFunc = nullptr); JSHandle NewSpecificTypedArrayFunction(const JSHandle &env, - const void *native_func = nullptr); + const void *nativeFunc = nullptr); JSHandle OrdinaryNewJSObjectCreate(const JSHandle &proto); JSHandle NewJSBoundFunction(const JSHandle &target, - const JSHandle &bound_this, + const JSHandle &boundThis, const JSHandle &args); - JSHandle NewJSIntlBoundFunction(const void *native_func = nullptr, int function_length = 1); + JSHandle NewJSIntlBoundFunction(const void *nativeFunc = nullptr, int functionLength = 1); JSHandle NewJSProxyRevocFunction(const JSHandle &proxy, - const void *native_func = nullptr); + const void *nativeFunc = nullptr); - JSHandle NewJSAsyncAwaitStatusFunction(const void *native_func); - JSHandle NewJSAsyncGeneratorResolveNextFunction(const void *native_func); + JSHandle NewJSAsyncAwaitStatusFunction(const void *nativeFunc); + JSHandle NewJSAsyncGeneratorResolveNextFunction(const void *nativeFunc); JSHandle NewJSAsyncFromSyncIteratorValueUnwrapFunction( - const void *native_func); + const void *nativeFunc); JSHandle NewJSGeneratorFunction(JSMethod *method); JSHandle NewJSAsyncGeneratorFunction(JSMethod *method); JSHandle NewAsyncFunction(JSMethod *method); - JSHandle NewJSGeneratorObject(JSHandle generator_function); - JSHandle NewJSAsyncGeneratorObject(JSHandle async_generator_function); + JSHandle NewJSGeneratorObject(JSHandle generatorFunction); + JSHandle NewJSAsyncGeneratorObject(JSHandle asyncGeneratorFunction); JSHandle NewJSAsyncFromSyncIteratorObject(); JSHandle NewJSAsyncFuncObject(); @@ -179,12 +179,12 @@ public: JSHandle NewJSPrimitiveRef(PrimitiveType type, const JSHandle &object); // get JSHClass for Ecma ClassLinker - JSHandle NewGlobalEnv(JSHClass *global_env_class); + JSHandle NewGlobalEnv(JSHClass *globalEnvClass); // get JSHClass for Ecma ClassLinker - JSHandle NewLexicalEnv(int num_slots); + JSHandle NewLexicalEnv(int numSlots); - inline LexicalEnv *InlineNewLexicalEnv(int num_slots); + inline LexicalEnv *InlineNewLexicalEnv(int numSlots); JSHandle NewJSSymbol(); @@ -206,7 +206,7 @@ public: JSHandle NewSymbolWithTableWithChar(const char *description); - JSHandle NewAccessorData(panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); + JSHandle NewAccessorData(panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); JSHandle NewInternalAccessor(void *setter, void *getter); JSHandle NewPromiseCapability(); @@ -224,7 +224,7 @@ public: JSHandle NewPendingJob(const JSHandle &func, const JSHandle &argv); - JSHandle NewFunctionExtraInfo(const JSHandle &call_back, + JSHandle NewFunctionExtraInfo(const JSHandle &callBack, const JSHandle &vm, const JSHandle &data); @@ -239,14 +239,14 @@ public: JSHandle NewJSString(const JSHandle &str); PANDA_PUBLIC_API JSHandle NewTaggedArray(uint32_t length, - JSTaggedValue init_val = JSTaggedValue::Hole()); - JSHandle NewTaggedArray(uint32_t length, JSTaggedValue init_val, panda::SpaceType space_type); - JSHandle NewWeakTaggedArray(uint32_t length, JSTaggedValue init_val = JSTaggedValue::Hole()); + JSTaggedValue initVal = JSTaggedValue::Hole()); + JSHandle NewTaggedArray(uint32_t length, JSTaggedValue initVal, panda::SpaceType spaceType); + JSHandle NewWeakTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle NewDictionaryArray(uint32_t length); JSHandle NewJSForinIterator(const JSHandle &obj); - JSHandle NewLinkedHashTable(ArraySizeT length, JSType table_type, bool is_weak); + JSHandle NewLinkedHashTable(ArraySizeT length, JSType tableType, bool isWeak); JSHandle NewPropertyBox(const JSHandle &value); JSHandle NewProtoChangeMarker(); @@ -255,18 +255,18 @@ public: // use for copy properties keys's array to another array JSHandle ExtendArray(const JSHandle &old, uint32_t length, - JSTaggedValue init_val = JSTaggedValue::Hole()); + JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle CopyPartArray(const JSHandle &old, uint32_t start, uint32_t end); - JSHandle CopyArray(const JSHandle &old, uint32_t old_length, uint32_t new_length, - JSTaggedValue init_val = JSTaggedValue::Hole()); + JSHandle CopyArray(const JSHandle &old, uint32_t oldLength, uint32_t newLength, + JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle CloneProperties(const JSHandle &old); JSHandle CloneProperties(const JSHandle &old, const JSHandle &env, const JSHandle &obj, const JSHandle &constpool); - JSHandle CreateLayoutInfo(int properties, JSTaggedValue init_val = JSTaggedValue::Hole()); + JSHandle CreateLayoutInfo(int properties, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle ExtendLayoutInfo(const JSHandle &old, int properties, - JSTaggedValue init_val = JSTaggedValue::Hole()); + JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle CopyLayoutInfo(const JSHandle &old); @@ -279,13 +279,13 @@ public: JSHandle NewObjectWrapper(const JSHandle &value); - FreeObject *FillFreeObject(uintptr_t address, size_t size, RemoveSlots remove_slots = RemoveSlots::NO); + FreeObject *FillFreeObject(uintptr_t address, size_t size, RemoveSlots removeSlots = RemoveSlots::NO); TaggedObject *NewDynObject(const JSHandle &dynclass); - TaggedObject *NewNonMovableDynObject(const JSHandle &dynclass, int inobj_prop_count = 0); + TaggedObject *NewNonMovableDynObject(const JSHandle &dynclass, int inobjPropCount = 0); - void InitializeExtraProperties(const JSHandle &dynclass, TaggedObject *obj, int inobj_prop_count); + void InitializeExtraProperties(const JSHandle &dynclass, TaggedObject *obj, int inobjPropCount); JSHandle NewTaggedQueue(uint32_t length); @@ -296,8 +296,7 @@ public: JSHandle NewJSSetIterator(const JSHandle &set, IterationKind kind); JSHandle NewJSRegExpIterator(const JSHandle &matcher, - const JSHandle &input_str, bool global, - bool full_unicode); + const JSHandle &inputStr, bool global, bool fullUnicode); JSHandle NewJSMapIterator(const JSHandle &map, IterationKind kind); @@ -307,22 +306,22 @@ public: JSHandle NewGeneratorContext(); - JSHandle CreateJSPromiseReactionsFunction(const void *native_func); + JSHandle CreateJSPromiseReactionsFunction(const void *nativeFunc); - JSHandle CreateJSPromiseExecutorFunction(const void *native_func); + JSHandle CreateJSPromiseExecutorFunction(const void *nativeFunc); JSHandle CreateBuiltinFunction(EcmaEntrypoint steps, uint8_t length, JSHandle name, JSHandle proto, JSHandle prefix); - JSHandle NewJSPromiseAllResolveElementFunction(const void *native_func); + JSHandle NewJSPromiseAllResolveElementFunction(const void *nativeFunc); JSHandle CloneObjectLiteral(JSHandle object, const JSHandle &env, - const JSHandle &constpool, bool can_share_hclass = true); + const JSHandle &constpool, bool canShareHclass = true); JSHandle CloneObjectLiteral(JSHandle object); JSHandle CloneArrayLiteral(JSHandle object); JSHandle CloneJSFuction(JSHandle obj, FunctionKind kind); JSHandle CloneClassCtor(JSHandle ctor, const JSHandle &lexenv, - bool can_share_hclass); + bool canShareHclass); void NewJSArrayBufferData(const JSHandle &array, int32_t length); @@ -340,32 +339,32 @@ public: EcmaString *InternString(const JSHandle &key); - inline JSHandle NewJSNativePointer(void *external_pointer, - const DeleteEntryPoint &call_back = nullptr, - void *data = nullptr, bool non_movable = false); + inline JSHandle NewJSNativePointer(void *externalPointer, + const DeleteEntryPoint &callBack = nullptr, + void *data = nullptr, bool nonMovable = false); JSHandle NewJSObjectByClass(const JSHandle &properties, size_t length, - panda::SpaceType space_type); + panda::SpaceType spaceType); // only use for creating Function.prototype and Function JSHandle NewJSFunctionByDynClass(JSMethod *method, const JSHandle &clazz, FunctionKind kind = FunctionKind::NORMAL_FUNCTION, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); - EcmaString *ResolveString(uint32_t string_id); + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); + EcmaString *ResolveString(uint32_t stringId); - void ObtainRootClass(const JSHandle &global_env); + void ObtainRootClass(const JSHandle &globalEnv); const MemManager &GetHeapManager() const { - return heap_helper_; + return heapHelper_; } // used for creating jsobject by constructor PANDA_PUBLIC_API JSHandle NewJSObjectByConstructor( - const JSHandle &constructor, const JSHandle &new_target, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); + const JSHandle &constructor, const JSHandle &newTarget, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); - JSHandle NewClassInfoExtractor(JSMethod *ctor_method); + JSHandle NewClassInfoExtractor(JSMethod *ctorMethod); ~ObjectFactory() = default; @@ -374,21 +373,20 @@ public: PANDA_PUBLIC_API JSHandle NewFromCanBeCompressString(const PandaString &data); PANDA_PUBLIC_API JSHandle NewFromStdString(const std::string &data); - JSHandle NewFromStdStringUnCheck(const std::string &data, bool can_be_compress, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT); + JSHandle NewFromStdStringUnCheck(const std::string &data, bool canBeCompress, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT); - PANDA_PUBLIC_API JSHandle NewFromUtf8(const uint8_t *utf8_data, uint32_t utf8_len); - JSHandle NewFromUtf8UnCheck(const uint8_t *utf8_data, uint32_t utf8_len, bool can_be_compress); + PANDA_PUBLIC_API JSHandle NewFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len); + JSHandle NewFromUtf8UnCheck(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress); - PANDA_PUBLIC_API JSHandle NewFromUtf16(const uint16_t *utf16_data, uint32_t utf16_len); - JSHandle NewFromUtf16UnCheck(const uint16_t *utf16_data, uint32_t utf16_len, bool can_be_compress); + PANDA_PUBLIC_API JSHandle NewFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len); + JSHandle NewFromUtf16UnCheck(const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress); - PANDA_PUBLIC_API JSHandle NewFromUtf8Literal(const uint8_t *utf8_data, uint32_t utf8_len); - JSHandle NewFromUtf8LiteralUnCheck(const uint8_t *utf8_data, uint32_t utf8_len, bool can_be_compress); + PANDA_PUBLIC_API JSHandle NewFromUtf8Literal(const uint8_t *utf8Data, uint32_t utf8Len); + JSHandle NewFromUtf8LiteralUnCheck(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress); - PANDA_PUBLIC_API JSHandle NewFromUtf16Literal(const uint16_t *utf16_data, uint32_t utf16_len); - JSHandle NewFromUtf16LiteralUnCheck(const uint16_t *utf16_data, uint32_t utf16_len, - bool can_be_compress); + PANDA_PUBLIC_API JSHandle NewFromUtf16Literal(const uint16_t *utf16Data, uint32_t utf16Len); + JSHandle NewFromUtf16LiteralUnCheck(const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress); JSHandle NewFromString(EcmaString *str); JSHandle ConcatFromString(const JSHandle &prefix, const JSHandle &suffix); @@ -402,9 +400,9 @@ public: // used for creating jshclass in GlobalEnv, EcmaVM template inline JSHandle CreateDynClass(JSHClass *hclass, JSType type, uint32_t flags = 0, - uint32_t inlined_props = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS) + uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS) { - JSHandle cls = NewEcmaDynClass(hclass, T::SIZE, type, flags, inlined_props); + JSHandle cls = NewEcmaDynClass(hclass, T::SIZE, type, flags, inlinedProps); if constexpr (T::NATIVE_FIELDS_MASK != 0) { cls->GetHClass()->SetNativeFieldMask(T::NATIVE_FIELDS_MASK); } @@ -422,18 +420,18 @@ public: } // used for creating jshclass in GlobalEnv, EcmaVM JSHandle NewEcmaDynClass(JSHClass *hclass, uint32_t size, JSType type, uint32_t flags = 0, - uint32_t inlined_props = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); + uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); // used for creating jshclass in Builtins, Function, Class_Linker JSHandle NewEcmaDynClass(uint32_t size, JSType type, const JSHandle &prototype, uint32_t flags = 0); void SetTriggerGc(bool status) { - is_trigger_gc_ = status; + isTriggerGc_ = status; } private: - JSHandle NewTaggedArrayImpl(uint32_t length, JSTaggedValue init_val, bool weak); + JSHandle NewTaggedArrayImpl(uint32_t length, JSTaggedValue initVal, bool weak); friend class GlobalEnv; friend class GlobalEnvConstants; @@ -443,52 +441,52 @@ private: void InitObjectFields(TaggedObject *object); JSThread *thread_ {nullptr}; - bool is_trigger_gc_ {false}; - bool trigger_semi_gc_ {false}; - MemManager heap_helper_; - - JSHClass *hclass_class_ {nullptr}; - JSHClass *string_class_ {nullptr}; - JSHClass *array_class_ {nullptr}; - JSHClass *weak_array_class_ {nullptr}; - JSHClass *big_int_class_ {nullptr}; - JSHClass *dictionary_class_ {nullptr}; - JSHClass *free_object_with_none_field_class_ {nullptr}; - JSHClass *free_object_with_one_field_class_ {nullptr}; - JSHClass *free_object_with_two_field_class_ {nullptr}; - JSHClass *completion_record_class_ {nullptr}; - JSHClass *generator_context_class_ {nullptr}; - JSHClass *env_class_ {nullptr}; - JSHClass *symbol_class_ {nullptr}; - JSHClass *accessor_data_class_ {nullptr}; - JSHClass *internal_accessor_class_ {nullptr}; - JSHClass *capability_record_class_ {nullptr}; - JSHClass *reactions_record_class_ {nullptr}; - JSHClass *promise_iterator_record_class_ {nullptr}; - JSHClass *micro_job_queue_class_ {nullptr}; - JSHClass *pending_job_class_ {nullptr}; - JSHClass *js_proxy_ordinary_class_ {nullptr}; - JSHClass *js_proxy_callable_class_ {nullptr}; - JSHClass *js_proxy_construct_class_ {nullptr}; - JSHClass *object_wrapper_class_ {nullptr}; - JSHClass *property_box_class_ {nullptr}; - JSHClass *proto_change_details_class_ {nullptr}; - JSHClass *proto_change_marker_class_ {nullptr}; - JSHClass *promise_record_class_ {nullptr}; - JSHClass *promise_resolving_functions_record_ {nullptr}; - JSHClass *js_native_pointer_class_ {nullptr}; - JSHClass *transition_handler_class_ {nullptr}; - JSHClass *prototype_handler_class_ {nullptr}; - JSHClass *function_extra_info_ {nullptr}; - JSHClass *js_realm_class_ {nullptr}; - JSHClass *program_class_ {nullptr}; - JSHClass *ecma_module_class_ {nullptr}; - JSHClass *class_info_extractor_h_class_ {nullptr}; - JSHClass *linked_hash_map_class_ {nullptr}; - JSHClass *linked_hash_set_class_ {nullptr}; - JSHClass *weak_ref_class_ {nullptr}; - JSHClass *weak_linked_hash_map_class_ {nullptr}; - JSHClass *weak_linked_hash_set_class_ {nullptr}; + bool isTriggerGc_ {false}; + bool triggerSemiGc_ {false}; + MemManager heapHelper_; + + JSHClass *hclassClass_ {nullptr}; + JSHClass *stringClass_ {nullptr}; + JSHClass *arrayClass_ {nullptr}; + JSHClass *weakArrayClass_ {nullptr}; + JSHClass *bigIntClass_ {nullptr}; + JSHClass *dictionaryClass_ {nullptr}; + JSHClass *freeObjectWithNoneFieldClass_ {nullptr}; + JSHClass *freeObjectWithOneFieldClass_ {nullptr}; + JSHClass *freeObjectWithTwoFieldClass_ {nullptr}; + JSHClass *completionRecordClass_ {nullptr}; + JSHClass *generatorContextClass_ {nullptr}; + JSHClass *envClass_ {nullptr}; + JSHClass *symbolClass_ {nullptr}; + JSHClass *accessorDataClass_ {nullptr}; + JSHClass *internalAccessorClass_ {nullptr}; + JSHClass *capabilityRecordClass_ {nullptr}; + JSHClass *reactionsRecordClass_ {nullptr}; + JSHClass *promiseIteratorRecordClass_ {nullptr}; + JSHClass *microJobQueueClass_ {nullptr}; + JSHClass *pendingJobClass_ {nullptr}; + JSHClass *jsProxyOrdinaryClass_ {nullptr}; + JSHClass *jsProxyCallableClass_ {nullptr}; + JSHClass *jsProxyConstructClass_ {nullptr}; + JSHClass *objectWrapperClass_ {nullptr}; + JSHClass *propertyBoxClass_ {nullptr}; + JSHClass *protoChangeDetailsClass_ {nullptr}; + JSHClass *protoChangeMarkerClass_ {nullptr}; + JSHClass *promiseRecordClass_ {nullptr}; + JSHClass *promiseResolvingFunctionsRecord_ {nullptr}; + JSHClass *jsNativePointerClass_ {nullptr}; + JSHClass *transitionHandlerClass_ {nullptr}; + JSHClass *prototypeHandlerClass_ {nullptr}; + JSHClass *functionExtraInfo_ {nullptr}; + JSHClass *jsRealmClass_ {nullptr}; + JSHClass *programClass_ {nullptr}; + JSHClass *ecmaModuleClass_ {nullptr}; + JSHClass *classInfoExtractorHClass_ {nullptr}; + JSHClass *linkedHashMapClass_ {nullptr}; + JSHClass *linkedHashSetClass_ {nullptr}; + JSHClass *weakRefClass_ {nullptr}; + JSHClass *weakLinkedHashMapClass_ {nullptr}; + JSHClass *weakLinkedHashSetClass_ {nullptr}; EcmaVM *vm_ {nullptr}; @@ -500,9 +498,9 @@ private: // used for creating jshclass in Builtins, Function, Class_Linker template inline JSHandle CreateDynClass(JSType type, - uint32_t inlined_props = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS) + uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS) { - JSHandle cls = NewEcmaDynClass(T::SIZE, type, inlined_props); + JSHandle cls = NewEcmaDynClass(T::SIZE, type, inlinedProps); if constexpr (T::NATIVE_FIELDS_MASK != 0) { cls->GetHClass()->SetNativeFieldMask(T::NATIVE_FIELDS_MASK); } @@ -510,12 +508,12 @@ private: } // used for creating jshclass in Builtins, Function, Class_Linker JSHandle NewEcmaDynClass(uint32_t size, JSType type, - uint32_t inlined_props = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); + uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); // used for creating jshclass in GlobalEnv, EcmaVM JSHandle NewEcmaDynClassClass(JSHClass *hclass, uint32_t size, JSType type); // used for creating Function - JSHandle NewJSFunction(const JSHandle &env, const JSHandle &dyn_klass); + JSHandle NewJSFunction(const JSHandle &env, const JSHandle &dynKlass); JSHandle CreateObjectClass(const JSHandle &properties, size_t length); template @@ -524,23 +522,23 @@ private: { return CreateFunctionClass(kind, T::SIZE, T::NATIVE_FIELDS_MASK, type, prototype); } - JSHandle CreateFunctionClass(FunctionKind kind, uint32_t size, JSAccessorsMaskType native_mask, + JSHandle CreateFunctionClass(FunctionKind kind, uint32_t size, JSAccessorsMaskType nativeMask, JSType type, const JSHandle &prototype); // used for creating ref.prototype in buildins, such as Number.prototype - JSHandle NewJSPrimitiveRef(const JSHandle &dyn_klass, + JSHandle NewJSPrimitiveRef(const JSHandle &dynKlass, const JSHandle &object); JSHandle GetStringFromStringTable( - const uint8_t *utf8_data, uint32_t utf8_len, bool can_be_compress, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT) const; + const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT) const; // For MUtf-8 string data - EcmaString *GetRawStringFromStringTable(const uint8_t *mutf8_data, uint32_t utf16_len, bool can_be_compressed, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT) const; + EcmaString *GetRawStringFromStringTable(const uint8_t *mutf8Data, uint32_t utf16Len, bool canBeCompressed, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT) const; JSHandle GetStringFromStringTable( - const uint16_t *utf16_data, uint32_t utf16_len, bool can_be_compress, - panda::SpaceType space_type = panda::SpaceType::SPACE_TYPE_OBJECT) const; + const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress, + panda::SpaceType spaceType = panda::SpaceType::SPACE_TYPE_OBJECT) const; JSHandle GetStringFromStringTable(EcmaString *string) const; diff --git a/runtime/object_operator.cpp b/runtime/object_operator.cpp index 4151498c7263348a769a7d23f6b045f0e82d7c22..c643a4a6f40d652a9e9aa269dc953a0cccda279e 100644 --- a/runtime/object_operator.cpp +++ b/runtime/object_operator.cpp @@ -34,12 +34,12 @@ namespace panda::ecmascript { void ObjectOperator::HandleKey(const JSHandle &key) { if (key->IsInt()) { - int32_t key_int = key->GetInt(); - if (key_int >= 0) { - element_index_ = static_cast(key_int); + int32_t keyInt = key->GetInt(); + if (keyInt >= 0) { + elementIndex_ = static_cast(keyInt); return; } - key_ = JSHandle::Cast(base::NumberHelper::NumberToString(thread_, JSTaggedValue(key_int))); + key_ = JSHandle::Cast(base::NumberHelper::NumberToString(thread_, JSTaggedValue(keyInt))); return; } @@ -47,7 +47,7 @@ void ObjectOperator::HandleKey(const JSHandle &key) uint32_t index = 0; if (JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index)) { ASSERT(index < JSObject::MAX_ELEMENT_INDEX); - element_index_ = index; + elementIndex_ = index; return; } if (EcmaString::Cast(key->GetTaggedObject())->IsInternString()) { @@ -63,7 +63,7 @@ void ObjectOperator::HandleKey(const JSHandle &key) if (number >= 0 && number < JSObject::MAX_ELEMENT_INDEX) { auto integer = static_cast(number); if (integer == number) { - element_index_ = static_cast(number); + elementIndex_ = static_cast(number); return; } } @@ -76,20 +76,20 @@ void ObjectOperator::HandleKey(const JSHandle &key) return; } - JSHandle key_handle(thread_, JSTaggedValue::ToPrimitive(thread_, key, PREFER_STRING)); + JSHandle keyHandle(thread_, JSTaggedValue::ToPrimitive(thread_, key, PREFER_STRING)); if (key->IsSymbol()) { - key_ = key_handle; + key_ = keyHandle; return; } key_ = JSHandle(thread_, thread_->GetEcmaVM()->GetFactory()->InternString( - JSHandle::Cast(JSTaggedValue::ToString(thread_, key_handle)))); + JSHandle::Cast(JSTaggedValue::ToString(thread_, keyHandle)))); } void ObjectOperator::UpdateHolder() { if (holder_->IsString() && - (IsElement() && element_index_ < EcmaString::Cast(holder_->GetTaggedObject())->GetLength())) { + (IsElement() && elementIndex_ < EcmaString::Cast(holder_->GetTaggedObject())->GetLength())) { holder_.Update(JSPrimitiveRef::StringCreate(thread_, holder_).GetTaggedValue()); } else { holder_.Update(JSTaggedValue::ToPrototypeOrObj(thread_, holder_).GetTaggedValue()); @@ -148,7 +148,7 @@ ObjectOperator::ObjectOperator(JSThread *thread, const JSHandle & : thread_(thread), holder_(thread, holder.GetTaggedValue()), receiver_(thread, holder.GetTaggedValue()), - element_index_(index) + elementIndex_(index) { StartLookUp(type); } @@ -320,13 +320,13 @@ void ObjectOperator::LookupPropertyInlinedProps(const JSHandle &obj) if (!array->IsDictionaryMode()) { JSHClass *jshclass = obj->GetJSHClass(); JSTaggedValue attrs = jshclass->GetLayout(); - LayoutInfo *layout_info = LayoutInfo::Cast(attrs.GetTaggedObject()); - int props_number = jshclass->NumberOfProps(); - int entry = layout_info->FindElementWithCache(thread_, jshclass, key_.GetTaggedValue(), props_number); + LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); + int propsNumber = jshclass->NumberOfProps(); + int entry = layoutInfo->FindElementWithCache(thread_, jshclass, key_.GetTaggedValue(), propsNumber); if (entry == -1) { return; } - PropertyAttributes attr(layout_info->GetAttr(entry)); + PropertyAttributes attr(layoutInfo->GetAttr(entry)); ASSERT(entry == static_cast(attr.GetOffset())); JSTaggedValue value; if (attr.IsInlinedProps()) { @@ -369,8 +369,8 @@ void ObjectOperator::TransitionForAttributeChanged(const JSHandle &rec // update found result UpdateFound(index, attr.GetValue(), false, true); } else if (receiver->IsJSGlobalObject()) { - JSHandle dict_handle(thread_, receiver->GetProperties()); - GlobalDictionary::InvalidatePropertyBox(thread_, dict_handle, GetIndex(), attr); + JSHandle dictHandle(thread_, receiver->GetProperties()); + GlobalDictionary::InvalidatePropertyBox(thread_, dictHandle, GetIndex(), attr); } else { uint32_t index = GetIndex(); if (!receiver->GetJSHClass()->IsDictionaryMode()) { @@ -389,17 +389,17 @@ void ObjectOperator::TransitionForAttributeChanged(const JSHandle &rec } bool ObjectOperator::UpdateValueAndDetails(const JSHandle &receiver, const JSHandle &value, - PropertyAttributes attr, bool attr_changed) + PropertyAttributes attr, bool attrChanged) { - bool is_internal_accessor = IsAccessorDescriptor() && AccessorData::Cast(GetValue().GetHeapObject())->IsInternal(); - if (attr_changed) { + bool isInternalAccessor = IsAccessorDescriptor() && AccessorData::Cast(GetValue().GetHeapObject())->IsInternal(); + if (attrChanged) { TransitionForAttributeChanged(receiver, attr); } - return UpdateDataValue(receiver, value, is_internal_accessor); + return UpdateDataValue(receiver, value, isInternalAccessor); } bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const JSHandle &value, - bool is_internal_accessor, bool may_throw) + bool isInternalAccessor, bool mayThrow) { if (IsElement()) { TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); @@ -421,10 +421,10 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J return true; } - if (is_internal_accessor) { + if (isInternalAccessor) { auto accessor = AccessorData::Cast(GetValue().GetHeapObject()); if (accessor->HasSetter()) { - return accessor->CallInternalSet(thread_, JSHandle(receiver), value, may_throw); + return accessor->CallInternalSet(thread_, JSHandle(receiver), value, mayThrow); } } @@ -445,16 +445,16 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const PropertyDescriptor &desc) { PropertyAttributes attr = GetAttr(); - bool attr_changed = false; + bool attrChanged = false; // composed new attribute from desc if (desc.HasConfigurable() && attr.IsConfigurable() != desc.IsConfigurable()) { attr.SetConfigurable(desc.IsConfigurable()); - attr_changed = true; + attrChanged = true; } if (desc.HasEnumerable() && attr.IsEnumerable() != desc.IsEnumerable()) { attr.SetEnumerable(desc.IsEnumerable()); - attr_changed = true; + attrChanged = true; } if (IsAccessorDescriptor() && value_->IsPropertyBox()) { @@ -464,10 +464,10 @@ bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const if (!desc.IsAccessorDescriptor()) { if (desc.HasWritable() && attr.IsWritable() != desc.IsWritable()) { attr.SetWritable(desc.IsWritable()); - attr_changed = true; + attrChanged = true; } if (!desc.HasValue()) { - if (attr_changed) { + if (attrChanged) { TransitionForAttributeChanged(receiver, attr); } return true; @@ -477,11 +477,11 @@ bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const auto accessor = AccessorData::Cast(GetValue().GetHeapObject()); if (!accessor->IsInternal() || !accessor->HasSetter()) { attr.SetIsAccessor(false); - attr_changed = true; + attrChanged = true; } } - return UpdateValueAndDetails(receiver, desc.GetValue(), attr, attr_changed); + return UpdateValueAndDetails(receiver, desc.GetValue(), attr, attrChanged); } if (IsAccessorDescriptor() && !IsElement()) { @@ -522,11 +522,11 @@ bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const if (!IsAccessorDescriptor()) { attr.SetIsAccessor(true); - attr_changed = true; + attrChanged = true; } JSHandle value = JSHandle::Cast(accessor); - return UpdateValueAndDetails(receiver, value, attr, attr_changed); + return UpdateValueAndDetails(receiver, value, attr, attrChanged); } void ObjectOperator::DeletePropertyInHolder() @@ -542,9 +542,9 @@ bool ObjectOperator::AddProperty(const JSHandle &receiver, const JSHan PropertyAttributes attr) { if (IsElement()) { - bool ret = JSObject::AddElementInternal(thread_, receiver, element_index_, value, attr); - bool is_dict = receiver->GetJSHClass()->IsDictionaryElement(); - SetFound(element_index_, value.GetTaggedValue(), attr.GetValue(), !is_dict); + bool ret = JSObject::AddElementInternal(thread_, receiver, elementIndex_, value, attr); + bool isDict = receiver->GetJSHClass()->IsDictionaryElement(); + SetFound(elementIndex_, value.GetTaggedValue(), attr.GetValue(), !isDict); return ret; } @@ -579,9 +579,9 @@ void ObjectOperator::DeleteElementInHolder() const elements->Set(thread_, index_, JSTaggedValue::Hole()); JSObject::ElementsToDictionary(thread_, JSHandle(holder_)); } else { - JSHandle dict_handle(thread_, elements); - JSHandle new_dict = NumberDictionary::Remove(thread_, dict_handle, GetIndex()); - obj->SetElements(thread_, new_dict); + JSHandle dictHandle(thread_, elements); + JSHandle newDict = NumberDictionary::Remove(thread_, dictHandle, GetIndex()); + obj->SetElements(thread_, newDict); } } @@ -618,10 +618,10 @@ void ObjectOperator::LookupElementInlinedProps(const JSHandle &obj) // if is js string, do special. if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(obj.GetTaggedValue().GetTaggedObject())->IsString()) { PropertyDescriptor desc(thread_); - bool status = JSPrimitiveRef::StringGetIndexProperty(thread_, obj, element_index_, &desc); + bool status = JSPrimitiveRef::StringGetIndexProperty(thread_, obj, elementIndex_, &desc); if (status) { PropertyAttributes attr(desc); - SetFound(element_index_, desc.GetValue().GetTaggedValue(), attr.GetValue(), true); + SetFound(elementIndex_, desc.GetValue().GetTaggedValue(), attr.GetValue(), true); return; } } @@ -632,18 +632,18 @@ void ObjectOperator::LookupElementInlinedProps(const JSHandle &obj) } if (!elements->IsDictionaryMode()) { - if (elements->GetLength() <= element_index_) { + if (elements->GetLength() <= elementIndex_) { return; } - JSTaggedValue value = elements->Get(element_index_); + JSTaggedValue value = elements->Get(elementIndex_); if (value.IsHole()) { return; } - SetFound(element_index_, value, PropertyAttributes::GetDefaultAttributes(), true); + SetFound(elementIndex_, value, PropertyAttributes::GetDefaultAttributes(), true); } else { NumberDictionary *dictionary = NumberDictionary::Cast(obj->GetElements().GetTaggedObject()); - JSTaggedValue key(static_cast(element_index_)); + JSTaggedValue key(static_cast(elementIndex_)); int entry = dictionary->FindEntry(key); if (entry == -1) { return; @@ -667,16 +667,16 @@ void ObjectOperator::AddPropertyInternal(const JSHandle &value) } // Add PropertyBox to global dictionary - JSHandle cell_handle = factory->NewPropertyBox(key_); - cell_handle->SetValue(thread_, value.GetTaggedValue()); - PropertyBoxType cell_type = value->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; - attr.SetBoxType(cell_type); + JSHandle cellHandle = factory->NewPropertyBox(key_); + cellHandle->SetValue(thread_, value.GetTaggedValue()); + PropertyBoxType cellType = value->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; + attr.SetBoxType(cellType); JSHandle properties = - GlobalDictionary::PutIfAbsent(thread_, dict, key_, JSHandle(cell_handle), attr); + GlobalDictionary::PutIfAbsent(thread_, dict, key_, JSHandle(cellHandle), attr); obj->SetProperties(thread_, properties); // index and fastMode is not essential for global obj; - SetFound(0, cell_handle.GetTaggedValue(), attr.GetValue(), true); + SetFound(0, cellHandle.GetTaggedValue(), attr.GetValue(), true); return; } diff --git a/runtime/object_operator.h b/runtime/object_operator.h index fb77752a215f5a9da57b1534cc72ad6e99f43f3c..06b3f6bd03dbb1d7baaf5207ce68eeae6e34cf2c 100644 --- a/runtime/object_operator.h +++ b/runtime/object_operator.h @@ -76,12 +76,12 @@ public: inline bool IsFastMode() const { - return IsFastModeField::Get(meta_data_); + return IsFastModeField::Get(metaData_); } inline void SetFastMode(bool flag) { - IsFastModeField::Set(flag, &meta_data_); + IsFastModeField::Set(flag, &metaData_); } inline bool IsElement() const @@ -91,32 +91,32 @@ public: inline bool IsOnPrototype() const { - return IsOnPrototypeField::Get(meta_data_); + return IsOnPrototypeField::Get(metaData_); } inline void SetIsOnPrototype(bool flag) { - IsOnPrototypeField::Set(flag, &meta_data_); + IsOnPrototypeField::Set(flag, &metaData_); } inline bool HasReceiver() const { - return HasReceiverField::Get(meta_data_); + return HasReceiverField::Get(metaData_); } inline void SetHasReceiver(bool flag) { - HasReceiverField::Set(flag, &meta_data_); + HasReceiverField::Set(flag, &metaData_); } inline bool IsTransition() const { - return IsTransitionField::Get(meta_data_); + return IsTransitionField::Get(metaData_); } inline void SetIsTransition(bool flag) { - IsTransitionField::Set(flag, &meta_data_); + IsTransitionField::Set(flag, &metaData_); } inline PropertyAttributes GetAttr() const @@ -216,7 +216,7 @@ public: inline uint32_t GetElementIndex() const { - return element_index_; + return elementIndex_; } inline JSThread *GetThread() const @@ -237,7 +237,7 @@ public: SetFound(NOT_FOUND_INDEX, JSTaggedValue::Undefined(), PropertyAttributes::GetDefaultAttributes(), false, false); } bool UpdateDataValue(const JSHandle &receiver, const JSHandle &value, - bool is_internal_accessor, bool may_throw = false); + bool isInternalAccessor, bool mayThrow = false); bool WriteDataPropertyInHolder(const PropertyDescriptor &desc) { JSHandle receiver(holder_); @@ -270,7 +270,7 @@ private: void StartLookUp(OperatorType type); void StartGlobalLookUp(OperatorType type); void HandleKey(const JSHandle &key); - uint32_t ComputeElementCapacity(uint32_t old_capacity); + uint32_t ComputeElementCapacity(uint32_t oldCapacity); void SetFound(uint32_t index, JSTaggedValue value, uint32_t attr, bool mode, bool transition = false); void UpdateFound(uint32_t index, uint32_t attr, bool mode, bool transition); void ResetState(); @@ -291,17 +291,17 @@ private: void WriteElement(const JSHandle &receiver, JSTaggedValue value) const; void DeleteElementInHolder() const; bool UpdateValueAndDetails(const JSHandle &receiver, const JSHandle &value, - PropertyAttributes attr, bool attr_changed); + PropertyAttributes attr, bool attrChanged); void TransitionForAttributeChanged(const JSHandle &receiver, PropertyAttributes attr); JSThread *thread_ {nullptr}; JSMutableHandle value_ {}; JSMutableHandle holder_ {}; JSMutableHandle receiver_ {}; JSHandle key_ {}; - uint32_t element_index_ {NOT_FOUND_INDEX}; + uint32_t elementIndex_ {NOT_FOUND_INDEX}; uint32_t index_ {NOT_FOUND_INDEX}; PropertyAttributes attributes_; - uint32_t meta_data_ {0}; + uint32_t metaData_ {0}; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_OBJECT_OPERATOR_H diff --git a/runtime/profiling/plugin_clear_profile.h b/runtime/profiling/plugin_clear_profile.h index 051770f3e78e9c82674018f83bc731ac81ebc502..0cee5e5ee68fa6c1d11e68c54a444387baea22e0 100644 --- a/runtime/profiling/plugin_clear_profile.h +++ b/runtime/profiling/plugin_clear_profile.h @@ -14,20 +14,20 @@ */ case panda_file::SourceLang::ECMASCRIPT: { - auto js_method = static_cast(method); - if (js_method->GetProfileSize() == 0) { + auto jsMethod = static_cast(method); + if (jsMethod->GetProfileSize() == 0) { return; } - auto prof_id = inst.GetProfileId(); - if (prof_id == -1) { + auto profId = inst.GetProfileId(); + if (profId == -1) { return; } - ASSERT(static_cast(prof_id) < js_method->GetProfileSize()); + ASSERT(static_cast(profId) < jsMethod->GetProfileSize()); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto prof_data = js_method->GetProfilingVector() + prof_id; + auto profData = jsMethod->GetProfilingVector() + profId; ASSERT(profiling::GetProfileKind(inst.GetOpcode()) == profiling::ProfilingKind::CALL); - auto profile = ecmascript::CallProfile::FromBuffer(prof_data); + auto profile = ecmascript::CallProfile::FromBuffer(profData); ASSERT(profile != nullptr); - auto *profile_table = static_cast(vm)->GetEcmaCallProfileTable(); - profile->Clear(profile_table); + auto *profileTable = static_cast(vm)->GetEcmaCallProfileTable(); + profile->Clear(profileTable); } diff --git a/runtime/profiling/plugin_dump_profile.h b/runtime/profiling/plugin_dump_profile.h index c55ed85e6aec02c30995b38c48d9c47d34495756..3ce6c70fd48ab2ba6cc0022b199489c9068d65d8 100644 --- a/runtime/profiling/plugin_dump_profile.h +++ b/runtime/profiling/plugin_dump_profile.h @@ -16,23 +16,23 @@ case panda_file::SourceLang::ECMASCRIPT: { auto kind = profiling::GetProfileKind(inst->GetOpcode()); stm << profiling::GetProfilingKindName(kind) << ' '; - auto &ecma_prof = *reinterpret_cast(profile); - auto prof_id = inst->GetProfileId(); + auto &ecmaProf = *reinterpret_cast(profile); + auto profId = inst->GetProfileId(); switch (kind) { case profiling::ProfilingKind::UNARY_ARITH: { - ecmascript::UnaryOperationProfile p(&ecma_prof[prof_id]); + ecmascript::UnaryOperationProfile p(&ecmaProf[profId]); p.GetOperandType(0).Dump(stm); break; } case profiling::ProfilingKind::BINARY_ARITH: { - ecmascript::BinaryOperationProfile p(&ecma_prof[prof_id]); + ecmascript::BinaryOperationProfile p(&ecmaProf[profId]); p.GetOperandType(0).Dump(stm); stm << ", "; p.GetOperandType(1).Dump(stm); break; } case profiling::ProfilingKind::CALL: { - ecmascript::CallProfile *p = ecmascript::CallProfile::FromBuffer(&ecma_prof[prof_id]); + ecmascript::CallProfile *p = ecmascript::CallProfile::FromBuffer(&ecmaProf[profId]); stm << (int)p->GetCallKind(); break; } diff --git a/runtime/profiling/plugin_find_method_in_profile.h b/runtime/profiling/plugin_find_method_in_profile.h index 473da6e5f02661dbc848f15f19f28fbed7f6158a..9ecf881ae0334ce5a0c6cf6d4773f5d81a45ceda 100644 --- a/runtime/profiling/plugin_find_method_in_profile.h +++ b/runtime/profiling/plugin_find_method_in_profile.h @@ -15,9 +15,9 @@ case panda_file::SourceLang::ECMASCRIPT: { auto container = reinterpret_cast(profile); - auto item = container->find(method_name); + auto item = container->find(methodName); if (item == container->end()) { - LOG(FATAL, RUNTIME) << "Profile not found for method: " << method_name; + LOG(FATAL, RUNTIME) << "Profile not found for method: " << methodName; } return reinterpret_cast(&item->second); } break; \ No newline at end of file diff --git a/runtime/property_attributes.h b/runtime/property_attributes.h index 19a1a849cb70a40f3256516b9e63b5a3cbb39082..21774eb093149e0c2bb1ceb3c83ccef0d59be179 100644 --- a/runtime/property_attributes.h +++ b/runtime/property_attributes.h @@ -94,10 +94,10 @@ public: return PropertyAttributes(GetDefaultAttributes()); } - static PropertyAttributes Default(bool w, bool e, bool c, bool is_accessor = false) + static PropertyAttributes Default(bool w, bool e, bool c, bool isAccessor = false) { uint32_t value = WritableField::Encode(w) | EnumerableField::Encode(e) | ConfigurableField::Encode(c) | - IsAccessorField::Encode(is_accessor); + IsAccessorField::Encode(isAccessor); return PropertyAttributes(value); } @@ -130,25 +130,25 @@ public: return Representation::OBJECT; } - static Representation UpdateRepresentation(Representation old_rep, JSTaggedValue value) + static Representation UpdateRepresentation(Representation oldRep, JSTaggedValue value) { - if (old_rep == Representation::MIXED) { - return old_rep; + if (oldRep == Representation::MIXED) { + return oldRep; } - Representation new_rep = TaggedToRepresentation(value); - if (old_rep == Representation::NONE) { - return new_rep; + Representation newRep = TaggedToRepresentation(value); + if (oldRep == Representation::NONE) { + return newRep; } - if (old_rep == new_rep) { - return old_rep; + if (oldRep == newRep) { + return oldRep; } - switch (old_rep) { + switch (oldRep) { case Representation::INT: case Representation::DOUBLE: case Representation::NUMBER: - if (new_rep != Representation::OBJECT) { + if (newRep != Representation::OBJECT) { return Representation::NUMBER; } return Representation::MIXED; @@ -256,18 +256,18 @@ public: return OffsetField::Get(value_); } - inline void SetSortedIndex(uint32_t sorted_index) + inline void SetSortedIndex(uint32_t sortedIndex) { - SortedIndexField::Set(sorted_index, &value_); + SortedIndexField::Set(sortedIndex, &value_); } inline uint32_t GetSortedIndex() const { return SortedIndexField::Get(value_); } - inline void SetNormalAttr(uint32_t normal_attr) + inline void SetNormalAttr(uint32_t normalAttr) { - NormalAttrField::Set(normal_attr, &value_); + NormalAttrField::Set(normalAttr, &value_); } inline uint32_t GetNormalAttr() const @@ -285,9 +285,9 @@ public: return value_; } - inline void SetBoxType(PropertyBoxType cell_type) + inline void SetBoxType(PropertyBoxType cellType) { - PropertyBoxTypeField::Set(cell_type, &value_); + PropertyBoxTypeField::Set(cellType, &value_); } inline PropertyBoxType GetBoxType() const diff --git a/runtime/regexp/regexp_executor.cpp b/runtime/regexp/regexp_executor.cpp index 07d9b433cab4a47012cf4e8fdb7ab4a3222fa890..a38203e261065477f265bd224c42448770ffda66 100644 --- a/runtime/regexp/regexp_executor.cpp +++ b/runtime/regexp/regexp_executor.cpp @@ -21,35 +21,35 @@ namespace panda::ecmascript { -RegExpMatchResult> RegExpExecutor::GetResult(const JSThread *thread, bool is_success) const +RegExpMatchResult> RegExpExecutor::GetResult(const JSThread *thread, bool isSuccess) const { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); RegExpMatchResult> result; PandaVector>> captures; - result.is_success = is_success; - if (is_success) { + result.isSuccess = isSuccess; + if (isSuccess) { for (uint32_t i = 0; i < GetCaptureCount(); i++) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - CaptureState *capture_state = &GetCaptureResultList()[i]; + CaptureState *captureState = &GetCaptureResultList()[i]; if (i == 0) { - result.index = capture_state->capture_start - GetInputPtr(); + result.index = captureState->captureStart - GetInputPtr(); if (IsWideChar()) { result.index /= WIDE_CHAR_SIZE; } } - int32_t len = capture_state->capture_end - capture_state->capture_start; + int32_t len = captureState->captureEnd - captureState->captureStart; std::pair> pair; - if ((capture_state->capture_start != nullptr && capture_state->capture_end != nullptr) && (len >= 0)) { + if ((captureState->captureStart != nullptr && captureState->captureEnd != nullptr) && (len >= 0)) { pair.first = false; if (IsWideChar()) { // create utf-16 string - pair.second = factory->NewFromUtf16( - reinterpret_cast(capture_state->capture_start), len / 2); + pair.second = + factory->NewFromUtf16(reinterpret_cast(captureState->captureStart), len / 2); } else { // create utf-8 string PandaVector buffer(len + 1); uint8_t *dest = buffer.data(); - if (memcpy_s(dest, len + 1, reinterpret_cast(capture_state->capture_start), len) != + if (memcpy_s(dest, len + 1, reinterpret_cast(captureState->captureStart), len) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); @@ -64,9 +64,9 @@ RegExpMatchResult> RegExpExecutor::GetResult(const JSThread captures.emplace_back(pair); } result.captures = std::move(captures); - result.end_index = GetCurrentPtr() - GetInputPtr(); + result.endIndex = GetCurrentPtr() - GetInputPtr(); if (IsWideChar()) { - result.end_index /= WIDE_CHAR_SIZE; + result.endIndex /= WIDE_CHAR_SIZE; } } return result; diff --git a/runtime/regexp/regexp_executor.h b/runtime/regexp/regexp_executor.h index 457c7bd731be093c4dda24e64693947c168a4d61..9da39fd78595fea32e47d17a606f1fd78122b112 100644 --- a/runtime/regexp/regexp_executor.h +++ b/runtime/regexp/regexp_executor.h @@ -24,7 +24,7 @@ namespace panda::ecmascript { class RegExpExecutor : public panda::RegExpExecutor { public: - RegExpMatchResult> GetResult(const JSThread *thread, bool is_success) const; + RegExpMatchResult> GetResult(const JSThread *thread, bool isSuccess) const; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_REGEXP_REGEXP_EXECUTOR_H diff --git a/runtime/regexp/regexp_parser_cache.cpp b/runtime/regexp/regexp_parser_cache.cpp index e35fdb61d17fd5d9d06581ac268cdc42051bef6e..71133d0faa36f92933c7d47b0f88df245f465bb7 100644 --- a/runtime/regexp/regexp_parser_cache.cpp +++ b/runtime/regexp/regexp_parser_cache.cpp @@ -31,8 +31,8 @@ void RegExpParserCache::Clear() for (ParserKey &info : info_) { info.pattern = nullptr; info.flags = UINT32_MAX; // flags cannot be UINT32_MAX, so it means invalid. - info.code_buffer = JSTaggedValue::Hole(); - info.buffer_size = 0; + info.codeBuffer = JSTaggedValue::Hole(); + info.bufferSize = 0; } } @@ -42,26 +42,26 @@ size_t RegExpParserCache::GetHash(EcmaString *pattern, const uint32_t flags) } std::pair RegExpParserCache::GetCache(EcmaString *pattern, const uint32_t flags, - PandaVector &group_name) + PandaVector &groupName) { size_t hash = GetHash(pattern, flags); ParserKey &info = info_[hash]; if (info.flags != flags || !EcmaString::StringsAreEqual(info.pattern, pattern)) { return std::pair(JSTaggedValue::Hole(), 0); } - group_name = info.new_group_names; - return std::pair(info.code_buffer, info.buffer_size); + groupName = info.newGroupNames; + return std::pair(info.codeBuffer, info.bufferSize); } -void RegExpParserCache::SetCache(EcmaString *pattern, const uint32_t flags, const JSTaggedValue code_buffer, - const size_t buffer_size, PandaVector &&group_name) +void RegExpParserCache::SetCache(EcmaString *pattern, const uint32_t flags, const JSTaggedValue codeBuffer, + const size_t bufferSize, PandaVector &&groupName) { size_t hash = GetHash(pattern, flags); ParserKey &info = info_[hash]; info.pattern = pattern; info.flags = flags; - info.code_buffer = code_buffer; - info.buffer_size = buffer_size; - info.new_group_names = group_name; + info.codeBuffer = codeBuffer; + info.bufferSize = bufferSize; + info.newGroupNames = groupName; } } // namespace panda::ecmascript \ No newline at end of file diff --git a/runtime/regexp/regexp_parser_cache.h b/runtime/regexp/regexp_parser_cache.h index 34580416209028cd384bb6a3be68ddbfd8d5aaec..e8dc9ece2f65a1f5d2d43bfc9494847415c6b27a 100644 --- a/runtime/regexp/regexp_parser_cache.h +++ b/runtime/regexp/regexp_parser_cache.h @@ -32,10 +32,9 @@ public: static constexpr size_t CACHE_SIZE = 128; bool IsInCache(EcmaString *pattern, uint32_t flags); - std::pair GetCache(EcmaString *pattern, uint32_t flags, - PandaVector &group_name); - void SetCache(EcmaString *pattern, uint32_t flags, JSTaggedValue code_buffer, size_t buffer_size, - PandaVector &&group_name); + std::pair GetCache(EcmaString *pattern, uint32_t flags, PandaVector &groupName); + void SetCache(EcmaString *pattern, uint32_t flags, JSTaggedValue codeBuffer, size_t bufferSize, + PandaVector &&groupName); void Clear(); private: @@ -44,9 +43,9 @@ private: struct ParserKey { EcmaString *pattern {nullptr}; uint32_t flags {UINT32_MAX}; - JSTaggedValue code_buffer {JSTaggedValue::Hole()}; - size_t buffer_size {0}; - PandaVector new_group_names; + JSTaggedValue codeBuffer {JSTaggedValue::Hole()}; + size_t bufferSize {0}; + PandaVector newGroupNames; }; std::array info_ {}; diff --git a/runtime/symbol_table-inl.h b/runtime/symbol_table-inl.h index f20f2ad615450180314b2e78a4e76db0a0b8df44..9e21c52eda1d1bae6adac7880bbaca55680d75a1 100644 --- a/runtime/symbol_table-inl.h +++ b/runtime/symbol_table-inl.h @@ -26,8 +26,8 @@ uint32_t SymbolTable::Hash(const JSTaggedValue &obj) { if (obj.IsHeapObject()) { if (obj.IsString()) { - auto *name_string = static_cast(obj.GetTaggedObject()); - return name_string->GetHashcode(); + auto *nameString = static_cast(obj.GetTaggedObject()); + return nameString->GetHashcode(); } return JSSymbol::ComputeHash(); } @@ -40,9 +40,9 @@ bool SymbolTable::IsMatch(const JSTaggedValue &name, const JSTaggedValue &other) return false; } - auto *name_string = static_cast(name.GetTaggedObject()); - auto *other_string = static_cast(other.GetTaggedObject()); - return EcmaString::StringsAreEqual(name_string, other_string); + auto *nameString = static_cast(name.GetTaggedObject()); + auto *otherString = static_cast(other.GetTaggedObject()); + return EcmaString::StringsAreEqual(nameString, otherString); } bool SymbolTable::ContainsKey([[maybe_unused]] JSThread *thread, const JSTaggedValue &key) diff --git a/runtime/symbol_table.h b/runtime/symbol_table.h index 8773bff11b4adf4b4f2abd7c1cc34680c01e8ca1..6500fa408facc7cfed21d2339a061a64d66da736 100644 --- a/runtime/symbol_table.h +++ b/runtime/symbol_table.h @@ -48,9 +48,9 @@ public: static inline uint32_t Hash(const JSTaggedValue &obj); static const int DEFAULT_ELEMENTS_NUMBER = 64; - static JSHandle Create(JSThread *thread, int number_of_elements = DEFAULT_ELEMENTS_NUMBER) + static JSHandle Create(JSThread *thread, int numberOfElements = DEFAULT_ELEMENTS_NUMBER) { - return HashTable::Create(thread, number_of_elements); + return HashTable::Create(thread, numberOfElements); } inline bool ContainsKey(JSThread *thread, const JSTaggedValue &key); diff --git a/runtime/tagged_array-inl.h b/runtime/tagged_array-inl.h index 15c1c39f8b5e8ce586757d4fd3024641812338e5..3a0a9295a2e0c349149b337a182bf720b3d00777 100644 --- a/runtime/tagged_array-inl.h +++ b/runtime/tagged_array-inl.h @@ -70,46 +70,46 @@ inline void TaggedArray::Set(const JSThread *thread, uint32_t idx, const JSTagge JSHandle TaggedArray::Append(const JSThread *thread, const JSHandle &first, const JSHandle &second) { - uint32_t first_length = first->GetLength(); - uint32_t second_length = second->GetLength(); - uint32_t length = first_length + second_length; + uint32_t firstLength = first->GetLength(); + uint32_t secondLength = second->GetLength(); + uint32_t length = firstLength + secondLength; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle argument = factory->NewTaggedArray(length); uint32_t index = 0; - for (; index < first_length; ++index) { + for (; index < firstLength; ++index) { argument->Set(thread, index, first->Get(index)); } for (; index < length; ++index) { - argument->Set(thread, index, second->Get(index - first_length)); + argument->Set(thread, index, second->Get(index - firstLength)); } return argument; } JSHandle TaggedArray::AppendSkipHole(const JSThread *thread, const JSHandle &first, - const JSHandle &second, uint32_t copy_length) + const JSHandle &second, uint32_t copyLength) { - uint32_t first_length = first->GetLength(); - uint32_t second_length = second->GetLength(); - ASSERT(first_length + second_length >= copy_length); + uint32_t firstLength = first->GetLength(); + uint32_t secondLength = second->GetLength(); + ASSERT(firstLength + secondLength >= copyLength); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle argument = factory->NewTaggedArray(copy_length); + JSHandle argument = factory->NewTaggedArray(copyLength); uint32_t index = 0; - for (; index < first_length; ++index) { + for (; index < firstLength; ++index) { JSTaggedValue val = first->Get(index); if (val.IsHole()) { break; } argument->Set(thread, index, val); - ASSERT(copy_length >= index); + ASSERT(copyLength >= index); } - for (uint32_t i = 0; i < second_length; ++i) { + for (uint32_t i = 0; i < secondLength; ++i) { JSTaggedValue val = second->Get(i); if (val.IsHole()) { break; } argument->Set(thread, index++, val); - ASSERT(copy_length >= index); + ASSERT(copyLength >= index); } return argument; } @@ -127,14 +127,14 @@ inline bool TaggedArray::HasDuplicateEntry() const return false; } -void TaggedArray::InitializeWithSpecialValue(JSTaggedValue init_value, uint32_t length) +void TaggedArray::InitializeWithSpecialValue(JSTaggedValue initValue, uint32_t length) { - ASSERT(init_value.IsSpecial()); + ASSERT(initValue.IsSpecial()); SetLength(length); for (uint32_t i = 0; i < length; i++) { size_t offset = JSTaggedValue::TaggedTypeSize() * i; // Without barrier because 'this' is just allocated object and it doesn't contains references. - ObjectAccessor::SetDynValueWithoutBarrier(this, DATA_OFFSET + offset, init_value.GetRawData()); + ObjectAccessor::SetDynValueWithoutBarrier(this, DATA_OFFSET + offset, initValue.GetRawData()); } } @@ -142,9 +142,9 @@ inline JSHandle TaggedArray::SetCapacity(const JSThread *thread, co uint32_t capa) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t old_length = array->GetLength(); - JSHandle new_array = factory->CopyArray(array, old_length, capa); - return new_array; + uint32_t oldLength = array->GetLength(); + JSHandle newArray = factory->CopyArray(array, oldLength, capa); + return newArray; } inline bool TaggedArray::IsDictionaryMode() const @@ -152,15 +152,15 @@ inline bool TaggedArray::IsDictionaryMode() const return GetClass()->IsDictionary(); } -void TaggedArray::Trim(JSThread *thread, uint32_t new_length) +void TaggedArray::Trim(JSThread *thread, uint32_t newLength) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t old_length = GetLength(); - ASSERT(old_length > new_length); - size_t trim_bytes = (old_length - new_length) * JSTaggedValue::TaggedTypeSize(); - size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), new_length); - factory->FillFreeObject(ToUintPtr(this) + size, trim_bytes, RemoveSlots::YES); - SetLength(new_length); + uint32_t oldLength = GetLength(); + ASSERT(oldLength > newLength); + size_t trimBytes = (oldLength - newLength) * JSTaggedValue::TaggedTypeSize(); + size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength); + factory->FillFreeObject(ToUintPtr(this) + size, trimBytes, RemoveSlots::YES); + SetLength(newLength); } } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_ARRAY_INL_H diff --git a/runtime/tagged_array.h b/runtime/tagged_array.h index 01df2f741a6b5b221393a6a6232aae788e50f7a9..f16c785caae219125132ed0a3c4c83e95b197d0d 100644 --- a/runtime/tagged_array.h +++ b/runtime/tagged_array.h @@ -48,15 +48,15 @@ public: static inline JSHandle Append(const JSThread *thread, const JSHandle &first, const JSHandle &second); static inline JSHandle AppendSkipHole(const JSThread *thread, const JSHandle &first, - const JSHandle &second, uint32_t copy_length); + const JSHandle &second, uint32_t copyLength); - static inline size_t ComputeSize(size_t elem_size, uint32_t length) + static inline size_t ComputeSize(size_t elemSize, uint32_t length) { - ASSERT(elem_size != 0); - size_t size = DATA_OFFSET + elem_size * length; + ASSERT(elemSize != 0); + size_t size = DATA_OFFSET + elemSize * length; #ifdef PANDA_TARGET_32 - size_t size_limit = (std::numeric_limits::max() - DATA_OFFSET) / elem_size; - if (UNLIKELY(size_limit < static_cast(length))) { + size_t sizeLimit = (std::numeric_limits::max() - DATA_OFFSET) / elemSize; + if (UNLIKELY(sizeLimit < static_cast(length))) { return 0; } #endif @@ -74,13 +74,13 @@ public: static JSHandle SetCapacity(const JSThread *thread, const JSHandle &array, uint32_t capa); - inline void InitializeWithSpecialValue(JSTaggedValue init_value, uint32_t length); + inline void InitializeWithSpecialValue(JSTaggedValue initValue, uint32_t length); - static inline bool ShouldTrim([[maybe_unused]] JSThread *thread, uint32_t old_length, uint32_t new_length) + static inline bool ShouldTrim([[maybe_unused]] JSThread *thread, uint32_t oldLength, uint32_t newLength) { - return (old_length - new_length > MAX_END_UNUSED); + return (oldLength - newLength > MAX_END_UNUSED); } - inline void Trim(JSThread *thread, uint32_t new_length); + inline void Trim(JSThread *thread, uint32_t newLength); static inline constexpr size_t GetElementOffset(uint32_t idx) { diff --git a/runtime/tagged_dictionary.cpp b/runtime/tagged_dictionary.cpp index 7f3c340894425b41c95b831dad41c412d7bcd1c2..6be5692591ef75cd39e5bb8cbd7e724dd1af6880 100644 --- a/runtime/tagged_dictionary.cpp +++ b/runtime/tagged_dictionary.cpp @@ -20,14 +20,14 @@ namespace panda::ecmascript { int NameDictionary::Hash(const JSTaggedValue &key) { if (key.IsHeapObject()) { - JSTaggedValue js_key(key); - if (js_key.IsSymbol()) { - auto symbol_string = JSSymbol::Cast(key.GetTaggedObject()); - return static_cast(symbol_string->GetHashField()).GetInt(); + JSTaggedValue jsKey(key); + if (jsKey.IsSymbol()) { + auto symbolString = JSSymbol::Cast(key.GetTaggedObject()); + return static_cast(symbolString->GetHashField()).GetInt(); } - if (js_key.IsString()) { - auto key_string = reinterpret_cast(key.GetTaggedObject()); - return key_string->GetHashcode(); + if (jsKey.IsString()) { + auto keyString = reinterpret_cast(key.GetTaggedObject()); + return keyString->GetHashcode(); } } // key must be object @@ -39,52 +39,52 @@ bool NameDictionary::IsMatch(const JSTaggedValue &key, const JSTaggedValue &othe return key == other; } -void NameDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArray *key_array) const +void NameDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const { - int array_index = 0; + int arrayIndex = 0; int size = Size(); - PandaVector> sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = GetKey(hash_index); + PandaVector> sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = GetAttributes(hash_index); + PropertyAttributes attr = GetAttributes(hashIndex); std::pair pair(key, attr); - sort_arr.push_back(pair); + sortArr.push_back(pair); } } - std::sort(sort_arr.begin(), sort_arr.end(), CompKey); - for (const auto &entry : sort_arr) { - key_array->Set(thread, array_index + offset, entry.first); - array_index++; + std::sort(sortArr.begin(), sortArr.end(), CompKey); + for (const auto &entry : sortArr) { + keyArray->Set(thread, arrayIndex + offset, entry.first); + arrayIndex++; } } -void NameDictionary::GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *key_array, uint32_t *keys) const +void NameDictionary::GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const { - uint32_t array_index = 0; + uint32_t arrayIndex = 0; int size = Size(); - PandaVector> sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = GetKey(hash_index); + PandaVector> sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = GetKey(hashIndex); if (key.IsString()) { - PropertyAttributes attr = GetAttributes(hash_index); + PropertyAttributes attr = GetAttributes(hashIndex); if (attr.IsEnumerable()) { std::pair pair(key, attr); - sort_arr.push_back(pair); + sortArr.push_back(pair); } } } - std::sort(sort_arr.begin(), sort_arr.end(), CompKey); - for (auto entry : sort_arr) { - key_array->Set(thread, array_index + offset, entry.first); - array_index++; + std::sort(sortArr.begin(), sortArr.end(), CompKey); + for (auto entry : sortArr) { + keyArray->Set(thread, arrayIndex + offset, entry.first); + arrayIndex++; } - *keys += array_index; + *keys += arrayIndex; } -JSHandle NameDictionary::Create(const JSThread *thread, int number_of_elements) +JSHandle NameDictionary::Create(const JSThread *thread, int numberOfElements) { - return OrderHashTableT::Create(thread, number_of_elements); + return OrderHashTableT::Create(thread, numberOfElements); } PropertyAttributes NameDictionary::GetAttributes(int entry) const @@ -93,25 +93,25 @@ PropertyAttributes NameDictionary::GetAttributes(int entry) const return PropertyAttributes(Get(index).GetInt()); } -void NameDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &meta_data) +void NameDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData) { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - Set(thread, index, meta_data.GetTaggedValue()); + Set(thread, index, metaData.GetTaggedValue()); } void NameDictionary::SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { SetKey(thread, entry, key); SetValue(thread, entry, value); - SetAttributes(thread, entry, meta_data); + SetAttributes(thread, entry, metaData); } void NameDictionary::UpdateValueAndAttributes(const JSThread *thread, int entry, const JSTaggedValue &value, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { SetValue(thread, entry, value); - SetAttributes(thread, entry, meta_data); + SetAttributes(thread, entry, metaData); } void NameDictionary::UpdateValue(const JSThread *thread, int entry, const JSTaggedValue &value) @@ -122,15 +122,15 @@ void NameDictionary::UpdateValue(const JSThread *thread, int entry, const JSTagg void NameDictionary::ClearEntry(const JSThread *thread, int entry) { JSTaggedValue hole = JSTaggedValue::Hole(); - PropertyAttributes meta_data; - SetEntry(thread, entry, hole, hole, meta_data); + PropertyAttributes metaData; + SetEntry(thread, entry, hole, hole, metaData); } int NumberDictionary::Hash(const JSTaggedValue &key) { if (key.IsInt()) { - int key_value = key.GetInt(); - return GetHash32(reinterpret_cast(&key_value), sizeof(key_value) / sizeof(uint8_t)); + int keyValue = key.GetInt(); + return GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); } // key must be object UNREACHABLE(); @@ -153,60 +153,60 @@ bool NumberDictionary::IsMatch(const JSTaggedValue &key, const JSTaggedValue &ot } void NumberDictionary::GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array) + const JSHandle &keyArray) { - ASSERT_PRINT(offset + obj->EntriesCount() <= static_cast(key_array->GetLength()), + ASSERT_PRINT(offset + obj->EntriesCount() <= static_cast(keyArray->GetLength()), "key_array capacity is not enough for dictionary"); - int array_index = 0; + int arrayIndex = 0; int size = obj->Size(); - PandaVector sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = obj->GetKey(hash_index); + PandaVector sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = obj->GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - sort_arr.push_back(JSTaggedValue(static_cast(key.GetInt()))); + sortArr.push_back(JSTaggedValue(static_cast(key.GetInt()))); } } - std::sort(sort_arr.begin(), sort_arr.end(), CompKey); - for (auto entry : sort_arr) { - JSHandle key_handle(thread, entry); - JSHandle str = JSTaggedValue::ToString(const_cast(thread), key_handle); + std::sort(sortArr.begin(), sortArr.end(), CompKey); + for (auto entry : sortArr) { + JSHandle keyHandle(thread, entry); + JSHandle str = JSTaggedValue::ToString(const_cast(thread), keyHandle); ASSERT_NO_ABRUPT_COMPLETION(thread); - key_array->Set(thread, array_index + offset, str.GetTaggedValue()); - array_index++; + keyArray->Set(thread, arrayIndex + offset, str.GetTaggedValue()); + arrayIndex++; } } void NumberDictionary::GetAllEnumKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array, uint32_t *keys) + const JSHandle &keyArray, uint32_t *keys) { - ASSERT_PRINT(offset + obj->EntriesCount() <= static_cast(key_array->GetLength()), + ASSERT_PRINT(offset + obj->EntriesCount() <= static_cast(keyArray->GetLength()), "key_array capacity is not enough for dictionary"); - uint32_t array_index = 0; + uint32_t arrayIndex = 0; int size = obj->Size(); - PandaVector sort_arr; - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = obj->GetKey(hash_index); + PandaVector sortArr; + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = obj->GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = obj->GetAttributes(hash_index); + PropertyAttributes attr = obj->GetAttributes(hashIndex); if (attr.IsEnumerable()) { - sort_arr.push_back(JSTaggedValue(static_cast(key.GetInt()))); + sortArr.push_back(JSTaggedValue(static_cast(key.GetInt()))); } } } - std::sort(sort_arr.begin(), sort_arr.end(), CompKey); - for (auto entry : sort_arr) { - JSHandle key_handle(thread, entry); - JSHandle str = JSTaggedValue::ToString(const_cast(thread), key_handle); + std::sort(sortArr.begin(), sortArr.end(), CompKey); + for (auto entry : sortArr) { + JSHandle keyHandle(thread, entry); + JSHandle str = JSTaggedValue::ToString(const_cast(thread), keyHandle); ASSERT_NO_ABRUPT_COMPLETION(thread); - key_array->Set(thread, array_index + offset, str.GetTaggedValue()); - array_index++; + keyArray->Set(thread, arrayIndex + offset, str.GetTaggedValue()); + arrayIndex++; } - *keys += array_index; + *keys += arrayIndex; } -JSHandle NumberDictionary::Create(const JSThread *thread, int number_of_elements) +JSHandle NumberDictionary::Create(const JSThread *thread, int numberOfElements) { - return OrderHashTableT::Create(thread, number_of_elements); + return OrderHashTableT::Create(thread, numberOfElements); } PropertyAttributes NumberDictionary::GetAttributes(int entry) const @@ -215,25 +215,25 @@ PropertyAttributes NumberDictionary::GetAttributes(int entry) const return PropertyAttributes(Get(index).GetInt()); } -void NumberDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &meta_data) +void NumberDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData) { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - Set(thread, index, meta_data.GetTaggedValue()); + Set(thread, index, metaData.GetTaggedValue()); } void NumberDictionary::SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { SetKey(thread, entry, key); SetValue(thread, entry, value); - SetAttributes(thread, entry, meta_data); + SetAttributes(thread, entry, metaData); } void NumberDictionary::UpdateValueAndAttributes(const JSThread *thread, int entry, const JSTaggedValue &value, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { SetValue(thread, entry, value); - SetAttributes(thread, entry, meta_data); + SetAttributes(thread, entry, metaData); } void NumberDictionary::UpdateValue(const JSThread *thread, int entry, const JSTaggedValue &value) @@ -244,7 +244,7 @@ void NumberDictionary::UpdateValue(const JSThread *thread, int entry, const JSTa void NumberDictionary::ClearEntry(const JSThread *thread, int entry) { JSTaggedValue hole = JSTaggedValue::Hole(); - PropertyAttributes meta_data; - SetEntry(thread, entry, hole, hole, meta_data); + PropertyAttributes metaData; + SetEntry(thread, entry, hole, hole, metaData); } } // namespace panda::ecmascript diff --git a/runtime/tagged_dictionary.h b/runtime/tagged_dictionary.h index cd4c621574db5c4af7d7425edea15772b5043771..ee495c18fd27790227df99c87a1ba314da227e4f 100644 --- a/runtime/tagged_dictionary.h +++ b/runtime/tagged_dictionary.h @@ -41,19 +41,19 @@ public: static int Hash(const JSTaggedValue &key); static bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &other); static JSHandle Create(const JSThread *thread, - int number_of_elements = OrderHashTableT::DEFAULT_ELEMENTS_NUMBER); + int numberOfElements = OrderHashTableT::DEFAULT_ELEMENTS_NUMBER); // Returns the property meta_data for the property at entry. PropertyAttributes GetAttributes(int entry) const; - void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &meta_data); + void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData); void SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, - const PropertyAttributes &meta_data); + const PropertyAttributes &metaData); void UpdateValueAndAttributes(const JSThread *thread, int entry, const JSTaggedValue &value, - const PropertyAttributes &meta_data); + const PropertyAttributes &metaData); void UpdateValue(const JSThread *thread, int entry, const JSTaggedValue &value); - void UpdateAttributes(int entry, const PropertyAttributes &meta_data); + void UpdateAttributes(int entry, const PropertyAttributes &metaData); void ClearEntry(const JSThread *thread, int entry); - void GetAllKeys(const JSThread *thread, int offset, TaggedArray *key_array) const; - void GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *key_array, uint32_t *keys) const; + void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const; + void GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const; static inline bool CompKey(const std::pair &a, const std::pair &b) { @@ -101,22 +101,22 @@ public: static int Hash(const JSTaggedValue &key); static bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &other); static JSHandle Create(const JSThread *thread, - int number_of_elements = OrderHashTableT::DEFAULT_ELEMENTS_NUMBER); + int numberOfElements = OrderHashTableT::DEFAULT_ELEMENTS_NUMBER); // Returns the property meta_data for the property at entry. PropertyAttributes GetAttributes(int entry) const; - void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &meta_data); + void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData); void SetEntry([[maybe_unused]] const JSThread *thread, int entry, const JSTaggedValue &key, - const JSTaggedValue &value, const PropertyAttributes &meta_data); + const JSTaggedValue &value, const PropertyAttributes &metaData); void UpdateValueAndAttributes(const JSThread *thread, int entry, const JSTaggedValue &value, - const PropertyAttributes &meta_data); + const PropertyAttributes &metaData); void UpdateValue(const JSThread *thread, int entry, const JSTaggedValue &value); - void UpdateAttributes(int entry, const PropertyAttributes &meta_data); + void UpdateAttributes(int entry, const PropertyAttributes &metaData); void ClearEntry(const JSThread *thread, int entry); static void GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array); + const JSHandle &keyArray); static void GetAllEnumKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &key_array, uint32_t *keys); + const JSHandle &keyArray, uint32_t *keys); static inline bool CompKey(const JSTaggedValue &a, const JSTaggedValue &b) { ASSERT(a.IsNumber() && b.IsNumber()); diff --git a/runtime/tagged_hash_table-inl.h b/runtime/tagged_hash_table-inl.h index 24d2d87f194fedd9566ebcb83fa4994f46ad6503..3e6300d03da10a040c20618ea18b575e0b51eba1 100644 --- a/runtime/tagged_hash_table-inl.h +++ b/runtime/tagged_hash_table-inl.h @@ -71,17 +71,17 @@ void TaggedHashTable::SetHashTableSize(const JSThread *thread, int size } template -void TaggedHashTable::GetAllKeys(const JSThread *thread, int offset, TaggedArray *key_array) const +void TaggedHashTable::GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const { - ASSERT_PRINT(offset + EntriesCount() <= static_cast(key_array->GetLength()), + ASSERT_PRINT(offset + EntriesCount() <= static_cast(keyArray->GetLength()), "key_array size is not enough for dictionary"); - int array_index = 0; + int arrayIndex = 0; int size = Size(); - for (int hash_index = 0; hash_index < size; hash_index++) { - JSTaggedValue key = GetKey(hash_index); + for (int hashIndex = 0; hashIndex < size; hashIndex++) { + JSTaggedValue key = GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - key_array->Set(thread, array_index + offset, key); - array_index++; + keyArray->Set(thread, arrayIndex + offset, key); + arrayIndex++; } } } @@ -92,18 +92,18 @@ int TaggedHashTable::FindEntry(const JSTaggedValue &key) { size_t size = Size(); int count = 1; - JSTaggedValue key_value; + JSTaggedValue keyValue; int hash = Derived::Hash(key); for (int entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { - key_value = GetKey(entry); - if (key_value.IsHole()) { + keyValue = GetKey(entry); + if (keyValue.IsHole()) { continue; } - if (key_value.IsUndefined()) { + if (keyValue.IsUndefined()) { return -1; } - if (Derived::IsMatch(key, key_value)) { + if (Derived::IsMatch(key, keyValue)) { return entry; } } @@ -112,56 +112,56 @@ int TaggedHashTable::FindEntry(const JSTaggedValue &key) // static template -int TaggedHashTable::RecalculateTableSize(int current_size, int at_least_size) +int TaggedHashTable::RecalculateTableSize(int currentSize, int atLeastSize) { - // When the filled entries is greater than a quart of current_size + // When the filled entries is greater than a quart of currentSize // it need not to shrink - if (at_least_size > (current_size / 4)) { // 4 : quarter - return current_size; + if (atLeastSize > (currentSize / 4)) { // 4 : quarter + return currentSize; } // Recalculate table size - int new_size = ComputeHashTableSize(at_least_size); - ASSERT_PRINT(new_size > at_least_size, "new size must greater than at_least_size"); + int newSize = ComputeHashTableSize(atLeastSize); + ASSERT_PRINT(newSize > atLeastSize, "new size must greater than atLeastSize"); // Don't go lower than room for MIN_SHRINK_SIZE elements. - if (new_size < MIN_SHRINK_SIZE) { - return current_size; + if (newSize < MIN_SHRINK_SIZE) { + return currentSize; } - return new_size; + return newSize; } // static template JSHandle TaggedHashTable::Shrink(const JSThread *thread, const JSHandle &table, - int additional_size) + int additionalSize) { - int new_size = RecalculateTableSize(table->Size(), table->EntriesCount() + additional_size); - if (new_size == table->Size()) { + int newSize = RecalculateTableSize(table->Size(), table->EntriesCount() + additionalSize); + if (newSize == table->Size()) { return table; } - JSHandle new_table = TaggedHashTable::Create(thread, new_size); - if (new_table.IsEmpty()) { + JSHandle newTable = TaggedHashTable::Create(thread, newSize); + if (newTable.IsEmpty()) { return table; } - table->Rehash(thread, *new_table); - return new_table; + table->Rehash(thread, *newTable); + return newTable; } template -bool TaggedHashTable::IsNeedGrowHashTable(int num_of_add_entries) +bool TaggedHashTable::IsNeedGrowHashTable(int numOfAddEntries) { - int entries_count = EntriesCount(); - int num_of_del_entries = HoleEntriesCount(); - int current_size = Size(); - int number_filled = entries_count + num_of_add_entries; + int entriesCount = EntriesCount(); + int numOfDelEntries = HoleEntriesCount(); + int currentSize = Size(); + int numberFilled = entriesCount + numOfAddEntries; // needn't to grow table: // 1. after adding number entries, table have half free entries. // 2. deleted entries are less than half of the free entries. - const int half_free = 2; - if ((number_filled < current_size) && ((num_of_del_entries <= (current_size - number_filled) / half_free))) { - int needed_free = number_filled / half_free; - if (number_filled + needed_free <= current_size) { + const int halfFree = 2; + if ((numberFilled < currentSize) && ((numOfDelEntries <= (currentSize - numberFilled) / halfFree))) { + int neededFree = numberFilled / halfFree; + if (numberFilled + neededFree <= currentSize) { return false; } } @@ -180,9 +180,9 @@ void TaggedHashTable::AddElement(const JSThread *thread, int entry, con template void TaggedHashTable::RemoveElement(const JSThread *thread, int entry) { - JSTaggedValue default_value(JSTaggedValue::Hole()); - this->SetKey(thread, entry, default_value); - this->SetValue(thread, entry, default_value); + JSTaggedValue defaultValue(JSTaggedValue::Hole()); + this->SetKey(thread, entry, defaultValue); + this->SetValue(thread, entry, defaultValue); this->IncreaseHoleEntriesCount(thread); } @@ -199,9 +199,9 @@ JSHandle TaggedHashTable::Insert(const JSThread *thread, JSHan return table; } - JSHandle new_table = GrowHashTable(thread, table); - new_table->AddElement(thread, new_table->FindInsertIndex(hash), key, value); - return new_table; + JSHandle newTable = GrowHashTable(thread, table); + newTable->AddElement(thread, newTable->FindInsertIndex(hash), key, value); + return newTable; } template @@ -218,65 +218,65 @@ JSHandle TaggedHashTable::Remove(const JSThread *thread, JSHan } template -void TaggedHashTable::Rehash(const JSThread *thread, Derived *new_table) +void TaggedHashTable::Rehash(const JSThread *thread, Derived *newTable) { - if ((new_table == nullptr) || (new_table->Size() < EntriesCount())) { + if ((newTable == nullptr) || (newTable->Size() < EntriesCount())) { return; } - int current_size = this->Size(); + int currentSize = this->Size(); // Rehash elements to new table - for (int i = 0; i < current_size; i++) { - int from_index = Derived::GetKeyIndex(i); + for (int i = 0; i < currentSize; i++) { + int fromIndex = Derived::GetKeyIndex(i); JSTaggedValue k = this->GetKey(i); if (!IsKey(k)) { continue; } int hash = Derived::Hash(k); - int insertion_index = Derived::GetKeyIndex(new_table->FindInsertIndex(hash)); - JSTaggedValue tv = Get(from_index); - new_table->Set(thread, insertion_index, tv); + int insertionIndex = Derived::GetKeyIndex(newTable->FindInsertIndex(hash)); + JSTaggedValue tv = Get(fromIndex); + newTable->Set(thread, insertionIndex, tv); for (int j = 1; j < Derived::GetEntrySize(); j++) { - tv = Get(from_index + j); - new_table->Set(thread, insertion_index + j, tv); + tv = Get(fromIndex + j); + newTable->Set(thread, insertionIndex + j, tv); } } - new_table->SetEntriesCount(thread, EntriesCount()); - new_table->SetHoleEntriesCount(thread, 0); + newTable->SetEntriesCount(thread, EntriesCount()); + newTable->SetHoleEntriesCount(thread, 0); } // static template -int TaggedHashTable::ComputeHashTableSize(uint32_t at_least_size) +int TaggedHashTable::ComputeHashTableSize(uint32_t atLeastSize) { // increase size for hash-collision - uint32_t raw_size = at_least_size + (at_least_size >> 1UL); - int new_size = static_cast(helpers::math::GetPowerOfTwoValue32(raw_size)); - return (new_size > MIN_SIZE) ? new_size : MIN_SIZE; + uint32_t rawSize = atLeastSize + (atLeastSize >> 1UL); + int newSize = static_cast(helpers::math::GetPowerOfTwoValue32(rawSize)); + return (newSize > MIN_SIZE) ? newSize : MIN_SIZE; } template JSHandle TaggedHashTable::GrowHashTable(const JSThread *thread, const JSHandle &table, - int num_of_added_elements) + int numOfAddedElements) { - if (!table->IsNeedGrowHashTable(num_of_added_elements)) { + if (!table->IsNeedGrowHashTable(numOfAddedElements)) { return table; } - int new_size = ComputeHashTableSize(table->Size() + num_of_added_elements); - int length = Derived::GetEntryIndex(new_size); - JSHandle new_table(thread->GetEcmaVM()->GetFactory()->NewDictionaryArray(length)); - new_table->SetHashTableSize(thread, new_size); - table->Rehash(thread, *new_table); - return new_table; + int newSize = ComputeHashTableSize(table->Size() + numOfAddedElements); + int length = Derived::GetEntryIndex(newSize); + JSHandle newTable(thread->GetEcmaVM()->GetFactory()->NewDictionaryArray(length)); + newTable->SetHashTableSize(thread, newSize); + table->Rehash(thread, *newTable); + return newTable; } template -JSHandle TaggedHashTable::Create(const JSThread *thread, int entries_count) +JSHandle TaggedHashTable::Create(const JSThread *thread, int entriesCount) { - ASSERT_PRINT((entries_count > 0), "the size must be greater than zero"); - auto size = static_cast(entries_count); - ASSERT_PRINT(helpers::math::IsPowerOfTwo(static_cast(entries_count)), "the size must be power of two"); + ASSERT_PRINT((entriesCount > 0), "the size must be greater than zero"); + auto size = static_cast(entriesCount); + ASSERT_PRINT(helpers::math::IsPowerOfTwo(static_cast(entriesCount)), "the size must be power of two"); - int length = Derived::GetEntryIndex(entries_count); + int length = Derived::GetEntryIndex(entriesCount); JSHandle table(thread->GetEcmaVM()->GetFactory()->NewDictionaryArray(length)); table->SetEntriesCount(thread, 0); @@ -339,9 +339,9 @@ int TaggedHashTable::FindInsertIndex(int hash) } template -JSHandle OrderTaggedHashTable::Create(const JSThread *thread, int number_of_elements) +JSHandle OrderTaggedHashTable::Create(const JSThread *thread, int numberOfElements) { - JSHandle dict = HashTableT::Create(thread, number_of_elements); + JSHandle dict = HashTableT::Create(thread, numberOfElements); dict->SetNextEnumerationIndex(thread, PropertyAttributes::INTIAL_PROPERTY_INDEX); return dict; } @@ -350,7 +350,7 @@ template JSHandle OrderTaggedHashTable::PutIfAbsent(const JSThread *thread, const JSHandle &table, const JSHandle &key, const JSHandle &value, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { int hash = Derived::Hash(key.GetTaggedValue()); @@ -359,46 +359,46 @@ JSHandle OrderTaggedHashTable::PutIfAbsent(const JSThread *thr if (entry != -1) { return table; } - int enum_index = table->NextEnumerationIndex(thread); - PropertyAttributes attr(meta_data); - attr.SetDictionaryOrder(enum_index); + int enumIndex = table->NextEnumerationIndex(thread); + PropertyAttributes attr(metaData); + attr.SetDictionaryOrder(enumIndex); // Check whether the table should be growed. - JSHandle new_table = HashTableT::GrowHashTable(thread, table); + JSHandle newTable = HashTableT::GrowHashTable(thread, table); // Compute the key object. - entry = new_table->FindInsertIndex(hash); - new_table->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); + entry = newTable->FindInsertIndex(hash); + newTable->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); - new_table->IncreaseEntries(thread); - new_table->SetNextEnumerationIndex(thread, enum_index + 1); - return new_table; + newTable->IncreaseEntries(thread); + newTable->SetNextEnumerationIndex(thread, enumIndex + 1); + return newTable; } template JSHandle OrderTaggedHashTable::Put(const JSThread *thread, const JSHandle &table, const JSHandle &key, const JSHandle &value, - const PropertyAttributes &meta_data) + const PropertyAttributes &metaData) { int hash = Derived::Hash(key.GetTaggedValue()); - int enum_index = table->NextEnumerationIndex(thread); - PropertyAttributes attr(meta_data); - attr.SetDictionaryOrder(enum_index); + int enumIndex = table->NextEnumerationIndex(thread); + PropertyAttributes attr(metaData); + attr.SetDictionaryOrder(enumIndex); int entry = table->FindEntry(key.GetTaggedValue()); if (entry != -1) { table->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); return table; } // Check whether the table should be extended. - JSHandle new_table = HashTableT::GrowHashTable(thread, table); + JSHandle newTable = HashTableT::GrowHashTable(thread, table); // Compute the key object. - entry = new_table->FindInsertIndex(hash); - new_table->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); + entry = newTable->FindInsertIndex(hash); + newTable->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); - new_table->IncreaseEntries(thread); - new_table->SetNextEnumerationIndex(thread, enum_index + 1); - return new_table; + newTable->IncreaseEntries(thread); + newTable->SetNextEnumerationIndex(thread, enumIndex + 1); + return newTable; } template @@ -406,8 +406,8 @@ void TaggedHashTable::GetAllKeysIntoVector([[maybe_unused]] const JSThr std::vector &vector) const { int capacity = Size(); - for (int hash_index = 0; hash_index < capacity; hash_index++) { - JSTaggedValue key = GetKey(hash_index); + for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { + JSTaggedValue key = GetKey(hashIndex); if (!key.IsUndefined() && !key.IsHole()) { vector.push_back(key); } @@ -433,14 +433,14 @@ int OrderTaggedHashTable::NextEnumerationIndex(const JSThread *thread) auto table = Derived::Cast(this); if (!PropertyAttributes::IsValidIndex(index)) { - std::vector index_order = GetEnumerationOrder(); - int length = index_order.size(); + std::vector indexOrder = GetEnumerationOrder(); + int length = indexOrder.size(); for (int i = 0; i < length; i++) { - int old_index = index_order[i]; - int enum_index = PropertyAttributes::INTIAL_PROPERTY_INDEX + i; - PropertyAttributes attr = table->GetAttributes(old_index); - attr.SetDictionaryOrder(enum_index); - table->SetAttributes(thread, old_index, attr); + int oldIndex = indexOrder[i]; + int enumIndex = PropertyAttributes::INTIAL_PROPERTY_INDEX + i; + PropertyAttributes attr = table->GetAttributes(oldIndex); + attr.SetDictionaryOrder(enumIndex); + table->SetAttributes(thread, oldIndex, attr); } index = PropertyAttributes::INTIAL_PROPERTY_INDEX + length; } @@ -459,9 +459,9 @@ std::vector OrderTaggedHashTable::GetEnumerationOrder() } } std::sort(result.begin(), result.end(), [table](int a, int b) { - PropertyAttributes attr_a = table->GetAttributes(a); - PropertyAttributes attr_b = table->GetAttributes(b); - return attr_a.GetDictionaryOrder() < attr_b.GetDictionaryOrder(); + PropertyAttributes attrA = table->GetAttributes(a); + PropertyAttributes attrB = table->GetAttributes(b); + return attrA.GetDictionaryOrder() < attrB.GetDictionaryOrder(); }); return result; } diff --git a/runtime/tagged_hash_table.h b/runtime/tagged_hash_table.h index e9ee251b6de1c672125586afff55f24af03a907f..9d4d5357f0abad85a24fe26db52ea7e4b3eb2b38 100644 --- a/runtime/tagged_hash_table.h +++ b/runtime/tagged_hash_table.h @@ -35,12 +35,12 @@ public: inline void IncreaseHoleEntriesCount(const JSThread *thread, int number = 1); - inline static int ComputeHashTableSize(uint32_t at_least_size); + inline static int ComputeHashTableSize(uint32_t atLeastSize); static JSHandle GrowHashTable(const JSThread *thread, const JSHandle &table, - int num_of_added_elements = 1); + int numOfAddedElements = 1); - static JSHandle Create(const JSThread *thread, int entries_count); + static JSHandle Create(const JSThread *thread, int entriesCount); static JSHandle Insert(const JSThread *thread, JSHandle &table, const JSHandle &key, const JSHandle &value); @@ -48,17 +48,17 @@ public: static JSHandle Remove(const JSThread *thread, JSHandle &table, const JSHandle &key); - inline static int RecalculateTableSize(int current_size, int at_least_size); + inline static int RecalculateTableSize(int currentSize, int atLeastSize); - inline static JSHandle Shrink(const JSThread *thread, const JSHandle &table, int additional_size); + inline static JSHandle Shrink(const JSThread *thread, const JSHandle &table, int additionalSize); - bool IsNeedGrowHashTable(int num_of_add_entries); + bool IsNeedGrowHashTable(int numOfAddEntries); JSTaggedValue GetKey(int entry) const; JSTaggedValue GetValue(int entry) const; - inline void GetAllKeys(const JSThread *thread, int offset, TaggedArray *key_array) const; + inline void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const; inline void GetAllKeysIntoVector(const JSThread *thread, std::vector &vector) const; @@ -114,7 +114,7 @@ protected: inline void RemoveElement(const JSThread *thread, int entry); // Rehash element to new_table - void Rehash(const JSThread *thread, Derived *new_table); + void Rehash(const JSThread *thread, Derived *newTable); }; template @@ -129,18 +129,18 @@ public: static JSHandle Shrink(const JSThread *thread, const JSHandle &table) { int index = table->GetNextEnumerationIndex(); - JSHandle new_table = HashTableT::Shrink(thread, table, 0); - new_table->SetNextEnumerationIndex(thread, index); - return new_table; + JSHandle newTable = HashTableT::Shrink(thread, table, 0); + newTable->SetNextEnumerationIndex(thread, index); + return newTable; } - static JSHandle Create(const JSThread *thread, int number_of_elements = DEFAULT_ELEMENTS_NUMBER); + static JSHandle Create(const JSThread *thread, int numberOfElements = DEFAULT_ELEMENTS_NUMBER); static JSHandle PutIfAbsent(const JSThread *thread, const JSHandle &table, const JSHandle &key, const JSHandle &value, - const PropertyAttributes &meta_data); + const PropertyAttributes &metaData); static JSHandle Put(const JSThread *thread, const JSHandle &table, const JSHandle &key, const JSHandle &value, - const PropertyAttributes &meta_data); + const PropertyAttributes &metaData); static JSHandle Remove(const JSThread *thread, const JSHandle &table, int entry); inline void SetNextEnumerationIndex(const JSThread *thread, int index) diff --git a/runtime/tagged_queue-inl.h b/runtime/tagged_queue-inl.h index 8fdb48df85389da042fe0a798e81e70df84f7769..40015f6a8676fb0f987b9b2f7df245d1458a3f7b 100644 --- a/runtime/tagged_queue-inl.h +++ b/runtime/tagged_queue-inl.h @@ -19,11 +19,11 @@ #include "plugins/ecmascript/runtime/tagged_queue.h" namespace panda::ecmascript { -inline TaggedQueue *TaggedQueue::Create(JSThread *thread, uint32_t capacity, JSTaggedValue init_val) +inline TaggedQueue *TaggedQueue::Create(JSThread *thread, uint32_t capacity, JSTaggedValue initVal) { uint32_t length = QueueToArrayIndex(capacity); - auto queue = TaggedQueue::Cast(*thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length, init_val)); + auto queue = TaggedQueue::Cast(*thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length, initVal)); queue->SetStart(thread, JSTaggedValue(0)); // equal to 0 when add 1. queue->SetEnd(thread, JSTaggedValue(0)); queue->SetCapacity(thread, JSTaggedValue(capacity)); diff --git a/runtime/tagged_queue.h b/runtime/tagged_queue.h index fb0d065bf7eaf8f0f36edca7890ed451ba855eba..3a95f672a2d9025e7bfcf86433c285f4bbe15392 100644 --- a/runtime/tagged_queue.h +++ b/runtime/tagged_queue.h @@ -37,12 +37,12 @@ public: if (capacity == 0) { // If there is no capacity, directly create a queue whose capacity is MIN_CAPACITY. Add elements. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_queue = factory->NewTaggedQueue(MIN_CAPACITY); - new_queue->Set(thread, 0, value.GetTaggedValue()); - new_queue->SetCapacity(thread, JSTaggedValue(MIN_CAPACITY)); - new_queue->SetStart(thread, JSTaggedValue(0)); - new_queue->SetEnd(thread, JSTaggedValue(1)); - return *new_queue; + JSHandle newQueue = factory->NewTaggedQueue(MIN_CAPACITY); + newQueue->Set(thread, 0, value.GetTaggedValue()); + newQueue->SetCapacity(thread, JSTaggedValue(MIN_CAPACITY)); + newQueue->SetStart(thread, JSTaggedValue(0)); + newQueue->SetEnd(thread, JSTaggedValue(1)); + return *newQueue; } uint32_t start = queue->GetStart().GetArrayLength(); @@ -56,20 +56,20 @@ public: } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Grow Array for 1.5 times - uint32_t new_capacity = capacity + (capacity >> 1U); - new_capacity = new_capacity < capacity ? MAX_QUEUE_INDEX : new_capacity; - JSHandle new_queue = factory->NewTaggedQueue(new_capacity); - uint32_t new_end = 0; - for (uint32_t i = start; new_end < size; i = (i + 1) % capacity) { - new_queue->Set(thread, new_end, queue->Get(i)); - new_end++; + uint32_t newCapacity = capacity + (capacity >> 1U); + newCapacity = newCapacity < capacity ? MAX_QUEUE_INDEX : newCapacity; + JSHandle newQueue = factory->NewTaggedQueue(newCapacity); + uint32_t newEnd = 0; + for (uint32_t i = start; newEnd < size; i = (i + 1) % capacity) { + newQueue->Set(thread, newEnd, queue->Get(i)); + newEnd++; } - new_queue->SetCapacity(thread, JSTaggedValue(new_capacity)); - new_queue->SetStart(thread, JSTaggedValue(0)); - new_queue->Set(thread, new_end++, value.GetTaggedValue()); - new_queue->SetEnd(thread, JSTaggedValue(new_end)); - return *new_queue; + newQueue->SetCapacity(thread, JSTaggedValue(newCapacity)); + newQueue->SetStart(thread, JSTaggedValue(0)); + newQueue->Set(thread, newEnd++, value.GetTaggedValue()); + newQueue->SetEnd(thread, JSTaggedValue(newEnd)); + return *newQueue; } queue->Set(thread, end, value.GetTaggedValue()); queue->SetEnd(thread, JSTaggedValue((end + 1) % capacity)); @@ -175,7 +175,7 @@ private: return TaggedArray::Get(END_INDEX); } - static TaggedQueue *Create(JSThread *thread, uint32_t capacity, JSTaggedValue init_val = JSTaggedValue::Hole()); + static TaggedQueue *Create(JSThread *thread, uint32_t capacity, JSTaggedValue initVal = JSTaggedValue::Hole()); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_QUEUE_H diff --git a/runtime/template_map.h b/runtime/template_map.h index 48fadccba56aa8c065a4b2b756f741b13297a31b..0528f32f77b9fc3d2916c113ee1a1ac96d1e3971 100644 --- a/runtime/template_map.h +++ b/runtime/template_map.h @@ -55,9 +55,9 @@ public: return reinterpret_cast(object); } static const int DEFAULT_ELEMENTS_NUMBER = 16; - static JSHandle Create(JSThread *thread, int number_of_elements = DEFAULT_ELEMENTS_NUMBER) + static JSHandle Create(JSThread *thread, int numberOfElements = DEFAULT_ELEMENTS_NUMBER) { - return HashTable::Create(thread, number_of_elements); + return HashTable::Create(thread, numberOfElements); } static const int ENTRY_SIZE = 2; static const int ENTRY_KEY_INDEX = 0; diff --git a/runtime/template_string.cpp b/runtime/template_string.cpp index c2f1f8538e597e8bc7324c4889fd97e1611a46b9..b121a177341fe96ea56b430df64e78c9779d76d2 100644 --- a/runtime/template_string.cpp +++ b/runtime/template_string.cpp @@ -23,40 +23,40 @@ #include "plugins/ecmascript/runtime/template_map.h" namespace panda::ecmascript { -JSHandle TemplateString::GetTemplateObject(JSThread *thread, JSHandle template_literal) +JSHandle TemplateString::GetTemplateObject(JSThread *thread, JSHandle templateLiteral) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle raw_strings_tag = JSObject::GetProperty(thread, template_literal, 0).GetValue(); - JSHandle template_map_tag = env->GetTemplateMap(); - JSHandle template_map(template_map_tag); - int32_t element = template_map->FindEntry(raw_strings_tag.GetTaggedValue()); + JSHandle rawStringsTag = JSObject::GetProperty(thread, templateLiteral, 0).GetValue(); + JSHandle templateMapTag = env->GetTemplateMap(); + JSHandle templateMap(templateMapTag); + int32_t element = templateMap->FindEntry(rawStringsTag.GetTaggedValue()); if (element != -1) { - return JSHandle(thread, template_map->GetValue(element)); + return JSHandle(thread, templateMap->GetValue(element)); } - JSHandle cooked_strings_tag = JSObject::GetProperty(thread, template_literal, 1).GetValue(); - JSHandle cooked_strings(cooked_strings_tag); - int32_t count = cooked_strings->GetArrayLength(); - auto count_num = JSTaggedNumber(count); - JSHandle template_arr = JSArray::ArrayCreate(thread, count_num); - JSHandle raw_arr = JSArray::ArrayCreate(thread, count_num); - JSHandle template_obj(template_arr); - JSHandle raw_obj(raw_arr); + JSHandle cookedStringsTag = JSObject::GetProperty(thread, templateLiteral, 1).GetValue(); + JSHandle cookedStrings(cookedStringsTag); + int32_t count = cookedStrings->GetArrayLength(); + auto countNum = JSTaggedNumber(count); + JSHandle templateArr = JSArray::ArrayCreate(thread, countNum); + JSHandle rawArr = JSArray::ArrayCreate(thread, countNum); + JSHandle templateObj(templateArr); + JSHandle rawObj(rawArr); for (int32_t i = 0; i < count; i++) { - JSHandle cooked_value = JSObject::GetProperty(thread, cooked_strings_tag, i).GetValue(); - PropertyDescriptor desc_cooked(thread, cooked_value, true, false, false); - JSArray::DefineOwnProperty(thread, template_obj, i, desc_cooked); - JSHandle raw_value = JSObject::GetProperty(thread, raw_strings_tag, i).GetValue(); - PropertyDescriptor desc_raw(thread, raw_value, true, false, false); - JSArray::DefineOwnProperty(thread, raw_obj, i, desc_raw); + JSHandle cookedValue = JSObject::GetProperty(thread, cookedStringsTag, i).GetValue(); + PropertyDescriptor descCooked(thread, cookedValue, true, false, false); + JSArray::DefineOwnProperty(thread, templateObj, i, descCooked); + JSHandle rawValue = JSObject::GetProperty(thread, rawStringsTag, i).GetValue(); + PropertyDescriptor descRaw(thread, rawValue, true, false, false); + JSArray::DefineOwnProperty(thread, rawObj, i, descRaw); } - JSObject::SetIntegrityLevel(thread, raw_obj, IntegrityLevel::FROZEN); + JSObject::SetIntegrityLevel(thread, rawObj, IntegrityLevel::FROZEN); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle raw(factory->NewFromCanBeCompressString("raw")); - PropertyDescriptor desc(thread, raw_arr, false, false, false); - JSArray::DefineOwnProperty(thread, template_obj, raw, desc); - JSObject::SetIntegrityLevel(thread, template_obj, IntegrityLevel::FROZEN); - TemplateMap::Insert(thread, template_map, raw_strings_tag, template_arr); - env->SetTemplateMap(thread, template_map.GetTaggedValue()); - return template_arr; + PropertyDescriptor desc(thread, rawArr, false, false, false); + JSArray::DefineOwnProperty(thread, templateObj, raw, desc); + JSObject::SetIntegrityLevel(thread, templateObj, IntegrityLevel::FROZEN); + TemplateMap::Insert(thread, templateMap, rawStringsTag, templateArr); + env->SetTemplateMap(thread, templateMap.GetTaggedValue()); + return templateArr; } } // namespace panda::ecmascript diff --git a/runtime/template_string.h b/runtime/template_string.h index 93ea34aa899427cbf7d7527a187a83b3a7d1dfef..dcfb423670f5ce50f0710996ea7c763eba09d8f6 100644 --- a/runtime/template_string.h +++ b/runtime/template_string.h @@ -21,7 +21,7 @@ namespace panda::ecmascript { class TemplateString { public: - static JSHandle GetTemplateObject(JSThread *thread, JSHandle template_literal); + static JSHandle GetTemplateObject(JSThread *thread, JSHandle templateLiteral); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_TEMPLATE_STRING_H diff --git a/runtime/tooling/pt_js_extractor.h b/runtime/tooling/pt_js_extractor.h index 69dbbfc5044716c8e92b80dc50c33e088468e830..1c97ee2906eecc6d6c7ea130744196d6c60a5141 100644 --- a/runtime/tooling/pt_js_extractor.h +++ b/runtime/tooling/pt_js_extractor.h @@ -47,14 +47,14 @@ public: } template - bool MatchWithOffset(const Callback &cb, File::EntityId method_id, uint32_t offset) + bool MatchWithOffset(const Callback &cb, File::EntityId methodId, uint32_t offset) { - auto line_table = GetLineNumberTable(method_id); - auto column_table = GetColumnNumberTable(method_id); + auto lineTable = GetLineNumberTable(methodId); + auto columnTable = GetColumnNumberTable(methodId); size_t line = 0; size_t column = 0; - for (const auto &pair : line_table) { + for (const auto &pair : lineTable) { if (offset < pair.offset) { break; } @@ -65,7 +65,7 @@ public: line = pair.line; } - for (const auto &pair : column_table) { + for (const auto &pair : columnTable) { if (offset < pair.offset) { break; } diff --git a/runtime/transitions_dictionary.h b/runtime/transitions_dictionary.h index c33966a9c4b3f100b19688eec5dd73a22098e194..6dec46562e8b3a9d06103d655e4f2f580c21f81f 100644 --- a/runtime/transitions_dictionary.h +++ b/runtime/transitions_dictionary.h @@ -26,7 +26,7 @@ class TransitionsDictionary : public TaggedHashTable { public: using HashTableT = TaggedHashTable; static inline bool IsMatch([[maybe_unused]] const JSTaggedValue &key, - [[maybe_unused]] const JSTaggedValue &other_key) + [[maybe_unused]] const JSTaggedValue &otherKey) { UNREACHABLE(); } @@ -35,13 +35,13 @@ public: UNREACHABLE(); } - static inline bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &meta_data, const JSTaggedValue &other_key, - const JSTaggedValue &other_details) + static inline bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &metaData, const JSTaggedValue &otherKey, + const JSTaggedValue &otherDetails) { - return key == other_key && meta_data == other_details; + return key == otherKey && metaData == otherDetails; } - static inline int Hash(const JSTaggedValue &key, const JSTaggedValue &meta_data) + static inline int Hash(const JSTaggedValue &key, const JSTaggedValue &metaData) { ASSERT(key.IsStringOrSymbol()); @@ -51,8 +51,8 @@ public: } else if (key.IsSymbol()) { hash = static_cast(JSSymbol::Cast(key.GetTaggedObject())->GetHashField()).GetInt(); } - int meta_data_hash = meta_data.IsInt() ? meta_data.GetInt() : static_cast(meta_data.GetRawData()); - return hash + meta_data_hash; + int metaDataHash = metaData.IsInt() ? metaData.GetInt() : static_cast(metaData.GetRawData()); + return hash + metaDataHash; } inline static int GetKeyIndex(int entry) @@ -79,9 +79,9 @@ public: static constexpr int DEFAULT_ELEMENTS_NUMBER = 16; static JSHandle Create(const JSThread *thread, - int number_of_elements = DEFAULT_ELEMENTS_NUMBER) + int numberOfElements = DEFAULT_ELEMENTS_NUMBER) { - return HashTableT::Create(thread, number_of_elements); + return HashTableT::Create(thread, numberOfElements); } // Attempt to shrink the dictionary after deletion of key. @@ -96,18 +96,18 @@ public: int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; return HashTableT::Get(index); } - inline void SetAttributes(const JSThread *thread, int entry, JSTaggedValue meta_data) + inline void SetAttributes(const JSThread *thread, int entry, JSTaggedValue metaData) { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - HashTableT::Set(thread, index, meta_data); + HashTableT::Set(thread, index, metaData); } inline void SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, - const JSTaggedValue &meta_data) + const JSTaggedValue &metaData) { SetKey(thread, entry, key); SetValue(thread, entry, value); - SetAttributes(thread, entry, meta_data); + SetAttributes(thread, entry, metaData); } inline void RemoveElement(const JSThread *thread, int entry) @@ -118,15 +118,15 @@ public: IncreaseHoleEntriesCount(thread); } - int FindEntry(const JSTaggedValue &key, const JSTaggedValue &meta_data); + int FindEntry(const JSTaggedValue &key, const JSTaggedValue &metaData); static JSHandle PutIfAbsent(const JSThread *thread, const JSHandle &dictionary, const JSHandle &key, const JSHandle &value, - const JSHandle &meta_data); + const JSHandle &metaData); static JSHandle Remove(const JSThread *thread, const JSHandle &table, - const JSHandle &key, const JSTaggedValue &meta_data); - void Rehash(const JSThread *thread, TransitionsDictionary *new_table); + const JSHandle &key, const JSTaggedValue &metaData); + void Rehash(const JSThread *thread, TransitionsDictionary *newTable); static constexpr int ENTRY_SIZE = 3; static constexpr int ENTRY_KEY_INDEX = 0; diff --git a/runtime/vmstat/caller_stat.cpp b/runtime/vmstat/caller_stat.cpp index 1983d95de803d2fdb9eb4a32ee8e1b20bc631032..67a1742189d3aea850b1545d26d43f6497d4c64c 100644 --- a/runtime/vmstat/caller_stat.cpp +++ b/runtime/vmstat/caller_stat.cpp @@ -16,23 +16,23 @@ #include "caller_stat.h" namespace panda::ecmascript { -void PandaRuntimeTimer::Start(PandaRuntimeCallerStat *caller_stat, PandaRuntimeTimer *parent) +void PandaRuntimeTimer::Start(PandaRuntimeCallerStat *callerStat, PandaRuntimeTimer *parent) { parent_ = parent; - caller_stat_ = caller_stat; - uint64_t now_time = Now(); + callerStat_ = callerStat; + uint64_t nowTime = Now(); if (parent != nullptr) { - parent_->Pause(now_time); + parent_->Pause(nowTime); } - Resume(now_time); + Resume(nowTime); } PandaRuntimeTimer *PandaRuntimeTimer::Stop() { - uint64_t now_time = Now(); - Pause(now_time); + uint64_t nowTime = Now(); + Pause(nowTime); if (parent_ != nullptr) { - parent_->Resume(now_time); + parent_->Resume(nowTime); } UpdateCallerState(); elapsed_ = 0; @@ -58,14 +58,14 @@ void PandaRuntimeTimer::Resume(uint64_t now) void PandaRuntimeTimer::Snapshot() { - uint64_t now_time = Now(); - Pause(now_time); + uint64_t nowTime = Now(); + Pause(nowTime); PandaRuntimeTimer *timer = this; while (timer != nullptr) { timer->UpdateCallerState(); timer = timer->parent_; } - Resume(now_time); + Resume(nowTime); } } // namespace panda::ecmascript \ No newline at end of file diff --git a/runtime/vmstat/caller_stat.h b/runtime/vmstat/caller_stat.h index 8712ef89e6743559b4f393f0ec25c50eb3f64098..3ae921ea68f777d9ce5b818daf0c661636c0d038 100644 --- a/runtime/vmstat/caller_stat.h +++ b/runtime/vmstat/caller_stat.h @@ -38,9 +38,9 @@ public: void UpdateState(uint64_t elapsed) { - total_count_++; - total_time_ += elapsed; - max_time_ = elapsed < max_time_ ? max_time_ : elapsed; + totalCount_++; + totalTime_ += elapsed; + maxTime_ = elapsed < maxTime_ ? maxTime_ : elapsed; } const char *Name() const { @@ -48,39 +48,39 @@ public: } uint64_t TotalCount() const { - return total_count_; + return totalCount_; } uint64_t TotalTime() const { - return total_time_; + return totalTime_; } uint64_t MaxTime() const { - return max_time_; + return maxTime_; } void Reset() { - total_count_ = 0; - total_time_ = 0; - max_time_ = 0; + totalCount_ = 0; + totalTime_ = 0; + maxTime_ = 0; } private: PandaString name_ {}; - uint64_t total_count_ {0}; - uint64_t total_time_ {0}; - uint64_t max_time_ {0}; + uint64_t totalCount_ {0}; + uint64_t totalTime_ {0}; + uint64_t maxTime_ {0}; }; class PandaRuntimeTimer { public: - void Start(PandaRuntimeCallerStat *caller_stat, PandaRuntimeTimer *parent); + void Start(PandaRuntimeCallerStat *callerStat, PandaRuntimeTimer *parent); inline static uint64_t Now() { - struct timespec time_now = {0, 0}; - clock_gettime(CLOCK_REALTIME, &time_now); - return time_now.tv_sec * NANOSECONDSINSECOND + time_now.tv_nsec; + struct timespec timeNow = {0, 0}; + clock_gettime(CLOCK_REALTIME, &timeNow); + return timeNow.tv_sec * NANOSECONDSINSECOND + timeNow.tv_nsec; } uint64_t Elapsed() const @@ -102,7 +102,7 @@ public: inline void UpdateCallerState() { - caller_stat_->UpdateState(elapsed_); + callerStat_->UpdateState(elapsed_); } private: @@ -110,7 +110,7 @@ private: PandaRuntimeTimer *Stop(); void Pause(uint64_t now); void Resume(uint64_t now); - PandaRuntimeCallerStat *caller_stat_ {nullptr}; + PandaRuntimeCallerStat *callerStat_ {nullptr}; PandaRuntimeTimer *parent_ {nullptr}; uint64_t start_ {0}; uint64_t elapsed_ {0}; diff --git a/runtime/vmstat/runtime_stat.cpp b/runtime/vmstat/runtime_stat.cpp index 85baa062ba253b734f72db5d711fdc26ba978915..ff9186fce05d349a1e63f09ce24d48c94b1f87fd 100644 --- a/runtime/vmstat/runtime_stat.cpp +++ b/runtime/vmstat/runtime_stat.cpp @@ -22,49 +22,49 @@ namespace panda::ecmascript { // NOLINTNEXTLINE(modernize-avoid-c-arrays) -EcmaRuntimeStat::EcmaRuntimeStat(const char *const runtime_caller_names[], int count) +EcmaRuntimeStat::EcmaRuntimeStat(const char *const runtimeCallerNames[], int count) { for (int i = 0; i < count; i++) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - caller_stat_.emplace_back(PandaRuntimeCallerStat(PandaString(runtime_caller_names[i]))); + callerStat_.emplace_back(PandaRuntimeCallerStat(PandaString(runtimeCallerNames[i]))); } } -void EcmaRuntimeStat::StartCount(PandaRuntimeTimer *timer, int caller_id) +void EcmaRuntimeStat::StartCount(PandaRuntimeTimer *timer, int callerId) { - if (current_timer_ != nullptr) { - timer->SetParent(current_timer_); + if (currentTimer_ != nullptr) { + timer->SetParent(currentTimer_); } - PandaRuntimeTimer *parent = current_timer_; - current_timer_ = timer; - PandaRuntimeCallerStat *caller_stat = &caller_stat_[caller_id]; - timer->Start(caller_stat, parent); + PandaRuntimeTimer *parent = currentTimer_; + currentTimer_ = timer; + PandaRuntimeCallerStat *callerStat = &callerStat_[callerId]; + timer->Start(callerStat, parent); } -void EcmaRuntimeStat::StopCount(const PandaRuntimeTimer *now_timer) +void EcmaRuntimeStat::StopCount(const PandaRuntimeTimer *nowTimer) { - if (now_timer != current_timer_) { + if (nowTimer != currentTimer_) { return; } - PandaRuntimeTimer *parent_timer = current_timer_->Stop(); - current_timer_ = parent_timer; + PandaRuntimeTimer *parentTimer = currentTimer_->Stop(); + currentTimer_ = parentTimer; } void EcmaRuntimeStat::Print() const { - if (current_timer_ != nullptr) { - current_timer_->Snapshot(); + if (currentTimer_ != nullptr) { + currentTimer_->Snapshot(); } LOG_ECMA(ERROR) << GetAllStats(); } void EcmaRuntimeStat::ResetAllCount() { - while (current_timer_ != nullptr) { - StopCount(current_timer_); + while (currentTimer_ != nullptr) { + StopCount(currentTimer_); } - for (auto &run_caller_stat : caller_stat_) { - run_caller_stat.Reset(); + for (auto &runCallerStat : callerStat_) { + runCallerStat.Reset(); } } @@ -81,14 +81,14 @@ PandaString EcmaRuntimeStat::GetAllStats() const statistic << "===========================================================================================" << "=======================================" << std::endl; - for (auto &run_caller_stat : caller_stat_) { - if (run_caller_stat.TotalCount() != 0) { - statistic << std::right << std::setw(NAME_RIGHT_ADJUSTMENT) << run_caller_stat.Name() - << std::setw(NUMBER_RIGHT_ADJUSTMENT) << run_caller_stat.TotalTime() - << std::setw(NUMBER_RIGHT_ADJUSTMENT) << run_caller_stat.TotalCount() - << std::setw(NUMBER_RIGHT_ADJUSTMENT) << run_caller_stat.MaxTime() - << std::setw(NUMBER_RIGHT_ADJUSTMENT) - << run_caller_stat.TotalTime() / run_caller_stat.TotalCount() << std::endl; + for (auto &runCallerStat : callerStat_) { + if (runCallerStat.TotalCount() != 0) { + statistic << std::right << std::setw(NAME_RIGHT_ADJUSTMENT) << runCallerStat.Name() + << std::setw(NUMBER_RIGHT_ADJUSTMENT) << runCallerStat.TotalTime() + << std::setw(NUMBER_RIGHT_ADJUSTMENT) << runCallerStat.TotalCount() + << std::setw(NUMBER_RIGHT_ADJUSTMENT) << runCallerStat.MaxTime() + << std::setw(NUMBER_RIGHT_ADJUSTMENT) << runCallerStat.TotalTime() / runCallerStat.TotalCount() + << std::endl; } } return statistic.str(); diff --git a/runtime/vmstat/runtime_stat.h b/runtime/vmstat/runtime_stat.h index f62c09d9fc9e38272c08cc4177b653359317d278..9748c1c11bdfbf588e88ca9fb55460b368ca425e 100644 --- a/runtime/vmstat/runtime_stat.h +++ b/runtime/vmstat/runtime_stat.h @@ -24,43 +24,43 @@ namespace panda::ecmascript { class EcmaRuntimeStat { public: // NOLINTNEXTLINE(modernize-avoid-c-arrays) - explicit EcmaRuntimeStat(const char *const runtime_caller_names[], int count); + explicit EcmaRuntimeStat(const char *const runtimeCallerNames[], int count); EcmaRuntimeStat() = default; virtual ~EcmaRuntimeStat() = default; DEFAULT_NOEXCEPT_MOVE_SEMANTIC(EcmaRuntimeStat); DEFAULT_COPY_SEMANTIC(EcmaRuntimeStat); - void StartCount(PandaRuntimeTimer *timer, int caller_id); + void StartCount(PandaRuntimeTimer *timer, int callerId); void StopCount(const PandaRuntimeTimer *timer); PandaString GetAllStats() const; void ResetAllCount(); void Print() const; private: - PandaRuntimeTimer *current_timer_ = nullptr; - PandaVector caller_stat_ {}; + PandaRuntimeTimer *currentTimer_ = nullptr; + PandaVector callerStat_ {}; }; class RuntimeTimerScope { public: - explicit RuntimeTimerScope(JSThread *thread, int caller_id, EcmaRuntimeStat *stat) + explicit RuntimeTimerScope(JSThread *thread, int callerId, EcmaRuntimeStat *stat) { - bool stat_enabled = thread->GetEcmaVM()->IsRuntimeStatEnabled(); - if (!stat_enabled || stat == nullptr) { + bool statEnabled = thread->GetEcmaVM()->IsRuntimeStatEnabled(); + if (!statEnabled || stat == nullptr) { return; } stats_ = stat; - stats_->StartCount(&timer_, caller_id); + stats_->StartCount(&timer_, callerId); } - RuntimeTimerScope(const EcmaVM *vm, int caller_id, EcmaRuntimeStat *stat) + RuntimeTimerScope(const EcmaVM *vm, int callerId, EcmaRuntimeStat *stat) { - bool stat_enabled = vm->IsRuntimeStatEnabled(); - if (!stat_enabled || stat == nullptr) { + bool statEnabled = vm->IsRuntimeStatEnabled(); + if (!statEnabled || stat == nullptr) { return; } stats_ = stat; - stats_->StartCount(&timer_, caller_id); + stats_->StartCount(&timer_, callerId); } ~RuntimeTimerScope() { diff --git a/runtime/weak_vector.cpp b/runtime/weak_vector.cpp index 688820c37a57d1414817eac5d0b1f78c99adbe2c..21bcc2bcf7d6ebe5e19b150142c535f18e43e1cf 100644 --- a/runtime/weak_vector.cpp +++ b/runtime/weak_vector.cpp @@ -39,23 +39,23 @@ bool WeakVector::Delete(const JSThread *thread, uint32_t index) return false; } -JSHandle WeakVector::Grow(const JSThread *thread, const JSHandle &old, uint32_t new_capacity) +JSHandle WeakVector::Grow(const JSThread *thread, const JSHandle &old, uint32_t newCapacity) { - uint32_t old_capacity = old->GetCapacity(); - ASSERT(new_capacity > old_capacity); - if (old_capacity == MAX_VECTOR_INDEX) { + uint32_t oldCapacity = old->GetCapacity(); + ASSERT(newCapacity > oldCapacity); + if (oldCapacity == MAX_VECTOR_INDEX) { return old; } - if (new_capacity > MAX_VECTOR_INDEX) { - new_capacity = MAX_VECTOR_INDEX; + if (newCapacity > MAX_VECTOR_INDEX) { + newCapacity = MAX_VECTOR_INDEX; } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_vec = factory->CopyArray(JSHandle(old), VectorToArrayIndex(old_capacity), - VectorToArrayIndex(new_capacity)); + JSHandle newVec = factory->CopyArray(JSHandle(old), VectorToArrayIndex(oldCapacity), + VectorToArrayIndex(newCapacity)); - return JSHandle(new_vec); + return JSHandle(newVec); } uint32_t WeakVector::PushBack(const JSThread *thread, JSTaggedValue value) diff --git a/runtime/weak_vector.h b/runtime/weak_vector.h index 12eeda9be6fd418b14d2f6dd01dc77874edecb17..28f09a9a6223ab48d8f3fbe0e245e3cbad4c73ff 100644 --- a/runtime/weak_vector.h +++ b/runtime/weak_vector.h @@ -30,7 +30,7 @@ public: static constexpr uint32_t DEFALUT_CAPACITY = 4; static JSHandle Create(const JSThread *thread, uint32_t capacity = DEFALUT_CAPACITY); - static JSHandle Grow(const JSThread *thread, const JSHandle &old, uint32_t new_capacity); + static JSHandle Grow(const JSThread *thread, const JSHandle &old, uint32_t newCapacity); uint32_t PushBack(const JSThread *thread, JSTaggedValue value); // just set index value to Hole bool Delete(const JSThread *thread, uint32_t index); diff --git a/tests/assembler/emitter_test_ecmascript.cpp b/tests/assembler/emitter_test_ecmascript.cpp index cabc2be1713de885215f4072af7c746c9497a900..a75cb5d802f686ce5051ac6794aa41cd26dd0d43 100644 --- a/tests/assembler/emitter_test_ecmascript.cpp +++ b/tests/assembler/emitter_test_ecmascript.cpp @@ -53,8 +53,8 @@ TEST(emittertests, ecmascript_debuginfo) } )"; - std::string source_filename = "source.pa"; - auto res = p.Parse(source, source_filename); + std::string sourceFilename = "source.pa"; + auto res = p.Parse(source, sourceFilename); ASSERT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); auto pf = AsmEmitter::Emit(res.Value()); @@ -63,11 +63,11 @@ TEST(emittertests, ecmascript_debuginfo) panda_file::DebugInfoExtractor extractor(pf.get()); auto methods = extractor.GetMethodIdList(); ASSERT_EQ(methods.size(), 1); - const auto &line_table = extractor.GetLineNumberTable(methods[0]); - const auto &column_table = extractor.GetColumnNumberTable(methods[0]); + const auto &lineTable = extractor.GetLineNumberTable(methods[0]); + const auto &columnTable = extractor.GetColumnNumberTable(methods[0]); - EXPECT_EQ(line_table.size(), 1); - EXPECT_EQ(column_table.size(), 1); + EXPECT_EQ(lineTable.size(), 1); + EXPECT_EQ(columnTable.size(), 1); } } // namespace panda::test diff --git a/tests/bytecode_optimizer/reg_encoder_test_ecmascript.cpp b/tests/bytecode_optimizer/reg_encoder_test_ecmascript.cpp index d71b2a10fd178f7aefd4358c1adccb6ee1d81057..11079a1926853a6b8381db9ab47fffadeaa43371 100644 --- a/tests/bytecode_optimizer/reg_encoder_test_ecmascript.cpp +++ b/tests/bytecode_optimizer/reg_encoder_test_ecmascript.cpp @@ -24,8 +24,8 @@ TEST_F(CommonTest, RegEncoderEcmaSuperCallIntrinsic) { auto graph = CreateEmptyGraph(); graph->SetDynamicMethod(); - ArenaVector reg_mask(254, false, graph->GetLocalAllocator()->Adapter()); - graph->InitUsedRegs(®_mask); + ArenaVector regMask(254, false, graph->GetLocalAllocator()->Adapter()); + graph->InitUsedRegs(®Mask); GRAPH(graph) { PARAMETER(0, 0).any().DstReg(compiler::ACC_REG_ID - 3); @@ -94,14 +94,14 @@ TEST_F(CommonTest, RegEncoderEcmaSuperCallIntrinsic) EXPECT_TRUE(GraphComparator().Compare(graph, expected)); - auto expected_data = std::vector {std::make_tuple(compiler::LocationType::REGISTER, - compiler::LocationType::REGISTER, compiler::INVALID_REG_ID, 0U), - std::make_tuple(compiler::LocationType::REGISTER, - compiler::LocationType::REGISTER, compiler::INVALID_REG_ID, 1U), - std::make_tuple(compiler::LocationType::REGISTER, - compiler::LocationType::REGISTER, compiler::INVALID_REG_ID, 2U)}; + auto expectedData = std::vector {std::make_tuple(compiler::LocationType::REGISTER, compiler::LocationType::REGISTER, + compiler::INVALID_REG_ID, 0U), + std::make_tuple(compiler::LocationType::REGISTER, compiler::LocationType::REGISTER, + compiler::INVALID_REG_ID, 1U), + std::make_tuple(compiler::LocationType::REGISTER, compiler::LocationType::REGISTER, + compiler::INVALID_REG_ID, 2U)}; - size_t spill_fills = 0; + size_t spillFills = 0; for (auto block : graph->GetVectorBlocks()) { if (block == nullptr) { continue; @@ -113,21 +113,21 @@ TEST_F(CommonTest, RegEncoderEcmaSuperCallIntrinsic) auto sf = inst->CastToSpillFill(); auto &data = sf->GetSpillFills(); - ASSERT_EQ(data.size(), expected_data.size()); + ASSERT_EQ(data.size(), expectedData.size()); for (size_t i = 0; i < data.size(); i++) { - auto &sf_data = data[i]; - auto &[src_type, dst_type, src, dst] = expected_data[i]; - EXPECT_EQ(sf_data.SrcType(), src_type); - EXPECT_EQ(sf_data.DstType(), dst_type); - EXPECT_EQ(sf_data.SrcValue(), src); - EXPECT_EQ(sf_data.DstValue(), dst); + auto &sfData = data[i]; + auto &[src_type, dst_type, src, dst] = expectedData[i]; + EXPECT_EQ(sfData.SrcType(), src_type); + EXPECT_EQ(sfData.DstType(), dst_type); + EXPECT_EQ(sfData.SrcValue(), src); + EXPECT_EQ(sfData.DstValue(), dst); } - spill_fills++; + spillFills++; } } - EXPECT_EQ(spill_fills, 1); + EXPECT_EQ(spillFills, 1); } // NOLINTEND(readability-magic-numbers) diff --git a/tests/compiler/branch_elimination_ecma_test.cpp b/tests/compiler/branch_elimination_ecma_test.cpp index 2812ee4dd6c58b937901b1aa49c2733a7561059d..7ea470876125c464054f79d7de2d73a767912b4f 100644 --- a/tests/compiler/branch_elimination_ecma_test.cpp +++ b/tests/compiler/branch_elimination_ecma_test.cpp @@ -68,8 +68,8 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNDiffTypesTrue) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(4, 1).s32(); @@ -92,7 +92,7 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNDiffTypesTrue) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNDiffTypesFalse1) @@ -133,14 +133,14 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNDiffTypesFalse1) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNDiffTypesFalse2) @@ -181,14 +181,14 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNDiffTypesFalse2) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue1) @@ -234,8 +234,8 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue1) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(4, 1).s32(); @@ -258,7 +258,7 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue1) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue2) @@ -304,8 +304,8 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue2) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(4, 1).s32(); @@ -328,7 +328,7 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue2) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue3) @@ -373,8 +373,8 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue3) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(4, 1).s32(); @@ -397,7 +397,7 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeVNEqTypesTrue3) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeSubtype1) @@ -443,8 +443,8 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeSubtype1) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(4, 1).s32(); @@ -467,7 +467,7 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeSubtype1) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeSubtype2) @@ -508,14 +508,14 @@ TEST_F(IrBranchEliminationTest, EliminateCompareAnyTypeSubtype2) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOLINTEND(readability-magic-numbers) diff --git a/tests/compiler/checks_elimination_ecma_test.cpp b/tests/compiler/checks_elimination_ecma_test.cpp index 63d8184d49e002b5c6176870b4c31cb9c9c4ed4d..efab9ab9b6545ab5a013e65bf8f53236e401ec75 100644 --- a/tests/compiler/checks_elimination_ecma_test.cpp +++ b/tests/compiler/checks_elimination_ecma_test.cpp @@ -25,8 +25,8 @@ public: // NOLINTBEGIN(readability-magic-numbers) template - void TestAnyTypeCheck(AnyBaseType type1, profiling::AnyInputType input_type1, AnyBaseType type2, - profiling::AnyInputType input_type2) + void TestAnyTypeCheck(AnyBaseType type1, profiling::AnyInputType inputType1, AnyBaseType type2, + profiling::AnyInputType inputType2) { auto graph = CreateGraphDynWithDefaultRuntime(); GRAPH(graph) @@ -36,23 +36,23 @@ public: BASIC_BLOCK(2, -1) { INST(2, Opcode::SaveState).Inputs(0).SrcVregs({0}); - INST(3, Opcode::AnyTypeCheck).any().AnyType(type1).Inputs(0, 2).AllowedInputType(input_type1); - INST(4, Opcode::AnyTypeCheck).any().AnyType(type2).Inputs(0, 2).AllowedInputType(input_type2); + INST(3, Opcode::AnyTypeCheck).any().AnyType(type1).Inputs(0, 2).AllowedInputType(inputType1); + INST(4, Opcode::AnyTypeCheck).any().AnyType(type2).Inputs(0, 2).AllowedInputType(inputType2); INST(5, Opcode::ReturnVoid).v0id(); } } - Graph *graph_opt; + Graph *graphOpt; if constexpr (IS_APPLIED) { - graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); BASIC_BLOCK(2, -1) { INST(2, Opcode::SaveState).Inputs(0).SrcVregs({0}); - INST(3, Opcode::AnyTypeCheck).any().AnyType(type1).Inputs(0, 2).AllowedInputType(input_type1); + INST(3, Opcode::AnyTypeCheck).any().AnyType(type1).Inputs(0, 2).AllowedInputType(inputType1); INST(5, Opcode::ReturnVoid).v0id(); } } @@ -60,12 +60,12 @@ public: EXPECT_TRUE(graph->RunPass()); EXPECT_TRUE(graph->RunPass()); } else { - graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); EXPECT_FALSE(graph->RunPass()); } GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOLINTEND(readability-magic-numbers) }; @@ -98,8 +98,8 @@ TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckAfterCastValueToAnyType) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(1, 1.0); @@ -117,12 +117,12 @@ TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckAfterCastValueToAnyType) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckAfterCastIntToAnyType) { - for (auto int_was_seen : {true, false}) { + for (auto intWasSeen : {true, false}) { auto graph = CreateGraphDynStubWithDefaultRuntime(); GRAPH(graph) { @@ -136,20 +136,20 @@ TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckAfterCastIntToAnyType) .any() .AnyType(AnyBaseType::ECMASCRIPT_DOUBLE_TYPE) .Inputs(1, 5) - .IntegerWasSeen(int_was_seen); + .IntegerWasSeen(intWasSeen); INST(3, Opcode::CastAnyTypeValue) .f64() .AnyType(AnyBaseType::ECMASCRIPT_DOUBLE_TYPE) .Inputs(2) - .IntegerWasSeen(int_was_seen); + .IntegerWasSeen(intWasSeen); INST(4, Opcode::Return).f64().Inputs(3); } } - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); - if (int_was_seen) { - GRAPH(graph_opt) + if (intWasSeen) { + GRAPH(graphOpt) { PARAMETER(0, 0).s32(); @@ -161,7 +161,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckAfterCastIntToAnyType) } } } else { - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).s32(); @@ -177,7 +177,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckAfterCastIntToAnyType) EXPECT_TRUE(graph->RunPass()); graph->RunPass(); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } } @@ -207,9 +207,9 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheck) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); @@ -225,7 +225,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheck) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckCase3) @@ -255,9 +255,9 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckCase3) GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); @@ -275,7 +275,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckCase3) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckCase4) @@ -303,9 +303,9 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckCase4) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); @@ -319,7 +319,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckCase4) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckIntWasSeen) @@ -360,9 +360,9 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckIntWasSeen) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -382,7 +382,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateAnyTypeCheckIntWasSeen) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, NotEliminateAnyTypeCheckIntWasSeen) @@ -419,11 +419,11 @@ TEST_F(CheckEliminationEcmaTest, NotEliminateAnyTypeCheckIntWasSeen) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, TestAnyTypeCheckDoubleSpecialTypes) @@ -497,14 +497,14 @@ TEST_F(CheckEliminationEcmaTest, NotEliminateAnyTypeCheck) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, MoveAnyTypeCheckFromLoop) @@ -535,20 +535,20 @@ TEST_F(CheckEliminationEcmaTest, MoveAnyTypeCheckFromLoop) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto &save_state = INS(1); + auto &saveState = INS(1); Inst *check = nullptr; - for (auto user_it = save_state.GetUsers().begin(); user_it != save_state.GetUsers().end();) { - if (user_it->GetInst()->GetOpcode() == Opcode::AnyTypeCheck) { - check = user_it->GetInst(); + for (auto userIt = saveState.GetUsers().begin(); userIt != saveState.GetUsers().end();) { + if (userIt->GetInst()->GetOpcode() == Opcode::AnyTypeCheck) { + check = userIt->GetInst(); break; } } ASSERT_NE(check, nullptr); - ASSERT_EQ(check->GetPc(), save_state.GetPc()); + ASSERT_EQ(check->GetPc(), saveState.GetPc()); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(5, 1); @@ -568,7 +568,7 @@ TEST_F(CheckEliminationEcmaTest, MoveAnyTypeCheckFromLoop) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, MoveAnyTypeCheckFromLoop2) @@ -599,11 +599,11 @@ TEST_F(CheckEliminationEcmaTest, MoveAnyTypeCheckFromLoop2) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckWithUndefinedType) @@ -627,9 +627,9 @@ TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckWithUndefinedType) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); @@ -639,7 +639,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateAnyTypeCheckWithUndefinedType) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOTE(kaskov) Not shue that we can eliminate duplicate LoadObject and HclassCheck @@ -692,9 +692,9 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateHclassCheck) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -724,7 +724,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateDuplicateHclassCheck) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(CheckEliminationEcmaTest, EliminateHclassCheckInlined) @@ -777,9 +777,9 @@ TEST_F(CheckEliminationEcmaTest, EliminateHclassCheckInlined) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -821,7 +821,7 @@ TEST_F(CheckEliminationEcmaTest, EliminateHclassCheckInlined) INST(9, Opcode::Return).any().Inputs(5); } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOTE(kaskov) To deal with the correctness of the HclassCheck @@ -883,9 +883,9 @@ TEST_F(CheckEliminationEcmaTest, MoveHclassCheckFromLoop) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); + auto graphOpt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + GRAPH(graphOpt) { CONSTANT(0, 0); // initial CONSTANT(1, 1); // increment @@ -935,7 +935,7 @@ TEST_F(CheckEliminationEcmaTest, MoveHclassCheckFromLoop) INST(16, Opcode::ReturnVoid).v0id(); } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOLINTEND(readability-magic-numbers) diff --git a/tests/compiler/codegen_ecma_test.cpp b/tests/compiler/codegen_ecma_test.cpp index fc6d5ceac7cfee8a4bdf881e4fb3004323b1fe17..3696f005bccea7ec9883fba417dac205f3ba3b0b 100644 --- a/tests/compiler/codegen_ecma_test.cpp +++ b/tests/compiler/codegen_ecma_test.cpp @@ -31,23 +31,23 @@ namespace panda::compiler { class CodegenEcmaTest : public GraphTest { public: - CodegenEcmaTest() : exec_module_(GetAllocator(), GetGraph()->GetRuntime()) {} + CodegenEcmaTest() : execModule_(GetAllocator(), GetGraph()->GetRuntime()) {} ~CodegenEcmaTest() override = default; NO_COPY_SEMANTIC(CodegenEcmaTest); NO_MOVE_SEMANTIC(CodegenEcmaTest); - void TestCompareAnyType(AnyBaseType any_type, uint64_t val, bool expected_value); - void TestAnyTypeCheck(AnyBaseType any_type, uint64_t val); + void TestCompareAnyType(AnyBaseType anyType, uint64_t val, bool expectedValue); + void TestAnyTypeCheck(AnyBaseType anyType, uint64_t val); template - void CastAnyTypeValue(AnyBaseType boxed_type, TaggedValue boxed_value, T expected_unboxed_value); + void CastAnyTypeValue(AnyBaseType boxedType, TaggedValue boxedValue, T expectedUnboxedValue); template - void CastValueToAnyType(T unboxed_value, AnyBaseType boxed_type, uint64_t expected_boxed_value); + void CastValueToAnyType(T unboxedValue, AnyBaseType boxedType, uint64_t expectedBoxedValue); template - void CheckReturnValue(Graph *graph, T expected_value); + void CheckReturnValue(Graph *graph, T expectedValue); private: - VixlExecModule exec_module_; + VixlExecModule execModule_; }; static bool RunCodegen(Graph *graph) @@ -57,26 +57,26 @@ static bool RunCodegen(Graph *graph) // NOLINTBEGIN(readability-magic-numbers) template -void CodegenEcmaTest::CheckReturnValue(Graph *graph, T expected_value) +void CodegenEcmaTest::CheckReturnValue(Graph *graph, T expectedValue) { SetNumVirtRegs(0); ASSERT_TRUE(RegAlloc(graph)); ASSERT_TRUE(RunCodegen(graph)); - auto code_entry = reinterpret_cast(graph->GetData().Data()); - auto code_exit = code_entry + graph->GetData().Size(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto codeEntry = reinterpret_cast(graph->GetData().Data()); + auto codeExit = codeEntry + graph->GetData().Size(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - ASSERT(code_entry != nullptr && code_exit != nullptr); + ASSERT(codeEntry != nullptr && codeExit != nullptr); - exec_module_.SetInstructions(code_entry, code_exit); - exec_module_.SetDump(false); + execModule_.SetInstructions(codeEntry, codeExit); + execModule_.SetDump(false); - exec_module_.Execute(); - auto rv = exec_module_.GetRetValue(); - EXPECT_EQ(rv, expected_value); + execModule_.Execute(); + auto rv = execModule_.GetRetValue(); + EXPECT_EQ(rv, expectedValue); } -void CodegenEcmaTest::TestCompareAnyType(AnyBaseType any_type, uint64_t val, bool expected_value) +void CodegenEcmaTest::TestCompareAnyType(AnyBaseType anyType, uint64_t val, bool expectedValue) { auto graph = GetGraph(); graph->SetDynamicMethod(); @@ -86,12 +86,12 @@ void CodegenEcmaTest::TestCompareAnyType(AnyBaseType any_type, uint64_t val, boo BASIC_BLOCK(2, -1) { - INST(2, Opcode::CompareAnyType).b().AnyType(any_type).Inputs(0); + INST(2, Opcode::CompareAnyType).b().AnyType(anyType).Inputs(0); INST(3, Opcode::Return).b().Inputs(2); } } - CheckReturnValue(graph, expected_value); + CheckReturnValue(graph, expectedValue); } TEST_F(CodegenEcmaTest, CompareAnyTypeInstBoolTrue1) @@ -171,26 +171,26 @@ TEST_F(CodegenEcmaTest, CompareAnyTypeInstUndefinedFalse) } template -void CodegenEcmaTest::CastAnyTypeValue(AnyBaseType boxed_type, TaggedValue boxed_value, T expected_unboxed_value) +void CodegenEcmaTest::CastAnyTypeValue(AnyBaseType boxedType, TaggedValue boxedValue, T expectedUnboxedValue) { auto graph = GetGraph(); graph->SetDynamicMethod(); GRAPH(graph) { - CONSTANT(0, boxed_value.GetRawData()).any(); + CONSTANT(0, boxedValue.GetRawData()).any(); BASIC_BLOCK(2, -1) { - INST(2, Opcode::CastAnyTypeValue).AnyType(boxed_type).Inputs(0); - INS(2).SetType(AnyBaseTypeToDataType(boxed_type)); + INST(2, Opcode::CastAnyTypeValue).AnyType(boxedType).Inputs(0); + INS(2).SetType(AnyBaseTypeToDataType(boxedType)); INS(2).SetFlag(inst_flags::Flags::NO_CSE); INS(2).SetFlag(inst_flags::Flags::NO_HOIST); INST(3, Opcode::Return).Inputs(2); - INS(3).SetType(AnyBaseTypeToDataType(boxed_type)); + INS(3).SetType(AnyBaseTypeToDataType(boxedType)); } } - CheckReturnValue(graph, expected_unboxed_value); + CheckReturnValue(graph, expectedUnboxedValue); } TEST_F(CodegenEcmaTest, DISABLED_CastAnyTypeValueInstNull) @@ -239,34 +239,34 @@ TEST_F(CodegenEcmaTest, CastAnyTypeValueInstObject) { // As long as tagging remains the same for all heap objects (strings, array, objects, etc.), // this single test is enough. - const auto *payload_ptr = reinterpret_cast(0xbee8); - const auto payload_int = reinterpret_cast(payload_ptr); - auto value = TaggedValue(payload_ptr); + const auto *payloadPtr = reinterpret_cast(0xbee8); + const auto payloadInt = reinterpret_cast(payloadPtr); + auto value = TaggedValue(payloadPtr); ASSERT_TRUE(value.IsHeapObject()); - ASSERT_TRUE(value.GetHeapObject() == payload_ptr); - ASSERT_TRUE(reinterpret_cast(value.GetHeapObject()) == static_cast(payload_int)); - CastAnyTypeValue(AnyBaseType::ECMASCRIPT_OBJECT_TYPE, value, payload_int); + ASSERT_TRUE(value.GetHeapObject() == payloadPtr); + ASSERT_TRUE(reinterpret_cast(value.GetHeapObject()) == static_cast(payloadInt)); + CastAnyTypeValue(AnyBaseType::ECMASCRIPT_OBJECT_TYPE, value, payloadInt); } template -void CodegenEcmaTest::CastValueToAnyType(T unboxed_value, AnyBaseType boxed_type, uint64_t expected_boxed_value) +void CodegenEcmaTest::CastValueToAnyType(T unboxedValue, AnyBaseType boxedType, uint64_t expectedBoxedValue) { auto graph = GetGraph(); graph->SetDynamicMethod(); GRAPH(graph) { - CONSTANT(0, unboxed_value); + CONSTANT(0, unboxedValue); BASIC_BLOCK(2, -1) { - INST(2, Opcode::CastValueToAnyType).any().AnyType(boxed_type).Inputs(0); + INST(2, Opcode::CastValueToAnyType).any().AnyType(boxedType).Inputs(0); INS(2).SetFlag(inst_flags::Flags::NO_CSE); INS(2).SetFlag(inst_flags::Flags::NO_HOIST); INST(3, Opcode::Return).any().Inputs(2); } } - CheckReturnValue(graph, expected_boxed_value); + CheckReturnValue(graph, expectedBoxedValue); } TEST_F(CodegenEcmaTest, DISABLED_CastValueToAnyTypeInstNull) @@ -315,17 +315,17 @@ TEST_F(CodegenEcmaTest, CastValueToAnyTypeInstObject) { // As long as tagging remains the same for all heap objects (strings, array, objects, etc.), // this single test is enough. - const auto *payload_ptr = reinterpret_cast(0xbee8); - const auto payload_int = reinterpret_cast(payload_ptr); - auto value = TaggedValue(payload_ptr); + const auto *payloadPtr = reinterpret_cast(0xbee8); + const auto payloadInt = reinterpret_cast(payloadPtr); + auto value = TaggedValue(payloadPtr); ASSERT_TRUE(value.IsHeapObject()); - ASSERT_TRUE(value.GetHeapObject() == payload_ptr); - ASSERT_TRUE(reinterpret_cast(value.GetHeapObject()) == static_cast(payload_int)); - CastValueToAnyType(payload_int, AnyBaseType::ECMASCRIPT_OBJECT_TYPE, value.GetRawData()); + ASSERT_TRUE(value.GetHeapObject() == payloadPtr); + ASSERT_TRUE(reinterpret_cast(value.GetHeapObject()) == static_cast(payloadInt)); + CastValueToAnyType(payloadInt, AnyBaseType::ECMASCRIPT_OBJECT_TYPE, value.GetRawData()); } -void CodegenEcmaTest::TestAnyTypeCheck(AnyBaseType any_type, uint64_t val) +void CodegenEcmaTest::TestAnyTypeCheck(AnyBaseType anyType, uint64_t val) { auto graph = CreateEmptyGraph(); graph->SetDynamicMethod(); @@ -340,7 +340,7 @@ void CodegenEcmaTest::TestAnyTypeCheck(AnyBaseType any_type, uint64_t val) BASIC_BLOCK(2, -1) { INST(4, Opcode::SaveState).Inputs(0).SrcVregs({0}); - INST(2, Opcode::AnyTypeCheck).b().AnyType(any_type).Inputs(0, 4); + INST(2, Opcode::AnyTypeCheck).b().AnyType(anyType).Inputs(0, 4); INST(3, Opcode::Return).b().Inputs(1); } } diff --git a/tests/compiler/inline_intrinsics_ecma_test.cpp b/tests/compiler/inline_intrinsics_ecma_test.cpp index 00882cdda80b85119bb2a25e29718dbccbb7ec5d..02d054b3fdba1aa10419df6b76c4fa55a3b7cfa2 100644 --- a/tests/compiler/inline_intrinsics_ecma_test.cpp +++ b/tests/compiler/inline_intrinsics_ecma_test.cpp @@ -28,7 +28,7 @@ public: Graph *ConstructGraphWithIntrinsic(RuntimeInterface::IntrinsicId id); Graph *ConstructGraphWithIntrinsic(AnyBaseType type, RuntimeInterface::IntrinsicId id, - profiling::AnyInputType allowed_type = profiling::AnyInputType::DEFAULT); + profiling::AnyInputType allowedType = profiling::AnyInputType::DEFAULT); Graph *ConstructGraphWithIntrinsic(AnyBaseType type1, AnyBaseType type2, RuntimeInterface::IntrinsicId id); Graph *ConstructGraphWithOpcode1(AnyBaseType type, Opcode opcode); Graph *ConstructGraphWithOpcode2(AnyBaseType type, Opcode opcode); @@ -37,7 +37,7 @@ public: using TestArray = std::array, N>; template - Graph *ConstructGraphWithConst(AnyBaseType any_type, T cnst); + Graph *ConstructGraphWithConst(AnyBaseType anyType, T cnst); Graph *ConstructGraphWithConst(DataType::Any cnst); @@ -47,7 +47,7 @@ public: // NOLINTBEGIN(readability-magic-numbers) template -Graph *InlineIntrinsicsTest::ConstructGraphWithConst(AnyBaseType any_type, T cnst) +Graph *InlineIntrinsicsTest::ConstructGraphWithConst(AnyBaseType anyType, T cnst) { auto graph = CreateGraphDynWithDefaultRuntime(); GRAPH(graph) @@ -55,7 +55,7 @@ Graph *InlineIntrinsicsTest::ConstructGraphWithConst(AnyBaseType any_type, T cns CONSTANT(0, cnst); BASIC_BLOCK(2, -1) { - INST(3, Opcode::CastValueToAnyType).any().AnyType(any_type).Inputs(0); + INST(3, Opcode::CastValueToAnyType).any().AnyType(anyType).Inputs(0); INST(4, Opcode::Return).any().Inputs(3); } } @@ -84,13 +84,13 @@ void InlineIntrinsicsTest::TestLdConsts(TestArray tests) ASSERT_TRUE(graph->template RunPass()); ASSERT_TRUE(graph->template RunPass()); GraphChecker(graph).Check(); - Graph *graph_opt = nullptr; + Graph *graphOpt = nullptr; if constexpr (std::is_same_v) { - graph_opt = ConstructGraphWithConst(cnst); + graphOpt = ConstructGraphWithConst(cnst); } else { - graph_opt = ConstructGraphWithConst(any_type, cnst); + graphOpt = ConstructGraphWithConst(any_type, cnst); } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } } @@ -110,7 +110,7 @@ Graph *InlineIntrinsicsTest::ConstructGraphWithIntrinsic(RuntimeInterface::Intri } Graph *InlineIntrinsicsTest::ConstructGraphWithIntrinsic(AnyBaseType type, RuntimeInterface::IntrinsicId id, - profiling::AnyInputType allowed_type) + profiling::AnyInputType allowedType) { auto graph = CreateGraphDynWithDefaultRuntime(); GRAPH(graph) @@ -121,7 +121,7 @@ Graph *InlineIntrinsicsTest::ConstructGraphWithIntrinsic(AnyBaseType type, Runti BASIC_BLOCK(2, -1) { INST(2, Opcode::SaveState).Inputs(0, 1).SrcVregs({0, 1}); - INST(4, Opcode::AnyTypeCheck).any().AnyType(type).AllowedInputType(allowed_type).Inputs(0, 2); + INST(4, Opcode::AnyTypeCheck).any().AnyType(type).AllowedInputType(allowedType).Inputs(0, 2); INST(5, Opcode::Intrinsic).any().IntrinsicId(id).Inputs({{DataType::ANY, 4}, {DataType::NO_TYPE, 2}}); INST(6, Opcode::Return).any().Inputs(5); } @@ -132,7 +132,7 @@ Graph *InlineIntrinsicsTest::ConstructGraphWithIntrinsic(AnyBaseType type, Runti Graph *InlineIntrinsicsTest::ConstructGraphWithOpcode1(AnyBaseType type, Opcode opcode) { auto graph = CreateGraphDynWithDefaultRuntime(); - auto date_type = AnyBaseTypeToDataType(type); + auto dateType = AnyBaseTypeToDataType(type); GRAPH(graph) { PARAMETER(0, 0).any(); @@ -142,8 +142,8 @@ Graph *InlineIntrinsicsTest::ConstructGraphWithOpcode1(AnyBaseType type, Opcode { INST(2, Opcode::SaveState).Inputs(0, 1).SrcVregs({0, 1}); INST(3, Opcode::AnyTypeCheck).any().AnyType(type).Inputs(0, 2); - INST(5, Opcode::CastAnyTypeValue).SetType(date_type).AnyType(type).Inputs(3); - INST(7, opcode).SetType(date_type).Inputs(5); + INST(5, Opcode::CastAnyTypeValue).SetType(dateType).AnyType(type).Inputs(3); + INST(7, opcode).SetType(dateType).Inputs(5); INST(8, Opcode::CastValueToAnyType).any().AnyType(type).Inputs(7); INST(9, Opcode::Return).any().Inputs(8); } @@ -154,7 +154,7 @@ Graph *InlineIntrinsicsTest::ConstructGraphWithOpcode1(AnyBaseType type, Opcode Graph *InlineIntrinsicsTest::ConstructGraphWithOpcode2(AnyBaseType type, Opcode opcode) { auto graph = CreateGraphDynWithDefaultRuntime(); - auto date_type = AnyBaseTypeToDataType(type); + auto dateType = AnyBaseTypeToDataType(type); GRAPH(graph) { PARAMETER(0, 0).any(); @@ -165,9 +165,9 @@ Graph *InlineIntrinsicsTest::ConstructGraphWithOpcode2(AnyBaseType type, Opcode INST(2, Opcode::SaveState).Inputs(0, 1).SrcVregs({0, 1}); INST(3, Opcode::AnyTypeCheck).any().AnyType(type).Inputs(0, 2); INST(4, Opcode::AnyTypeCheck).any().AnyType(type).Inputs(1, 2); - INST(5, Opcode::CastAnyTypeValue).SetType(date_type).AnyType(type).Inputs(3); - INST(6, Opcode::CastAnyTypeValue).SetType(date_type).AnyType(type).Inputs(4); - INST(7, opcode).SetType(date_type).Inputs(5, 6); + INST(5, Opcode::CastAnyTypeValue).SetType(dateType).AnyType(type).Inputs(3); + INST(6, Opcode::CastAnyTypeValue).SetType(dateType).AnyType(type).Inputs(4); + INST(7, opcode).SetType(dateType).Inputs(5, 6); INST(8, Opcode::CastValueToAnyType).any().AnyType(type).Inputs(7); INST(9, Opcode::Return).any().Inputs(8); } @@ -241,8 +241,8 @@ TEST_F(InlineIntrinsicsTest, ToNumber) graph->RunPass(); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -255,7 +255,7 @@ TEST_F(InlineIntrinsicsTest, ToNumber) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // Case with Int when boolean and null inputs are allowed @@ -267,8 +267,8 @@ TEST_F(InlineIntrinsicsTest, ToNumber) graph->RunPass(); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -287,19 +287,19 @@ TEST_F(InlineIntrinsicsTest, ToNumber) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // Case with Double - for (auto allowed_type : {profiling::AnyInputType::DEFAULT, profiling::AnyInputType::INTEGER}) { + for (auto allowedType : {profiling::AnyInputType::DEFAULT, profiling::AnyInputType::INTEGER}) { auto graph = ConstructGraphWithIntrinsic(AnyBaseType::ECMASCRIPT_DOUBLE_TYPE, - RuntimeInterface::IntrinsicId::INTRINSIC_TONUMBER, allowed_type); + RuntimeInterface::IntrinsicId::INTRINSIC_TONUMBER, allowedType); ASSERT_TRUE(graph->RunPass()); graph->RunPass(); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -312,7 +312,7 @@ TEST_F(InlineIntrinsicsTest, ToNumber) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // Case with Double when boolean, undefined and null inputs are allowed @@ -324,8 +324,8 @@ TEST_F(InlineIntrinsicsTest, ToNumber) graph->RunPass(); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -344,7 +344,7 @@ TEST_F(InlineIntrinsicsTest, ToNumber) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // Case with Object @@ -456,12 +456,12 @@ TEST_F(InlineIntrinsicsTest, LdLexVarDynApply) ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(11, 0).any(); - CONSTANT(0, graph_opt->GetRuntime()->GetLexicalEnvParentEnvIndex()); - CONSTANT(1, graph_opt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); + CONSTANT(0, graphOpt->GetRuntime()->GetLexicalEnvParentEnvIndex()); + CONSTANT(1, graphOpt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); BASIC_BLOCK(2, -1) { @@ -471,23 +471,23 @@ TEST_F(InlineIntrinsicsTest, LdLexVarDynApply) .Inputs(2) .AnyType(AnyBaseType::ECMASCRIPT_ARRAY_TYPE) .SetFlag(inst_flags::NO_HOIST); - int last_index = 3; - for (auto cur_level = level; cur_level > 0U; --cur_level) { - INST(last_index + 1, Opcode::LoadArray).any().Inputs(last_index, 0); - INST(last_index + 2, Opcode::CastAnyTypeValue) + int lastIndex = 3; + for (auto curLevel = level; curLevel > 0U; --curLevel) { + INST(lastIndex + 1, Opcode::LoadArray).any().Inputs(lastIndex, 0); + INST(lastIndex + 2, Opcode::CastAnyTypeValue) .ref() - .Inputs(last_index + 1) + .Inputs(lastIndex + 1) .AnyType(AnyBaseType::ECMASCRIPT_ARRAY_TYPE) .SetFlag(inst_flags::NO_HOIST); - last_index += 2; + lastIndex += 2; } - INST(last_index + 1, Opcode::LoadArray).any().Inputs(last_index, 1); - INST(last_index + 2, Opcode::Return).any().Inputs(last_index + 1); + INST(lastIndex + 1, Opcode::LoadArray).any().Inputs(lastIndex, 1); + INST(lastIndex + 2, Opcode::Return).any().Inputs(lastIndex + 1); } } - graph_opt->RunPass(); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + graphOpt->RunPass(); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } } @@ -517,8 +517,8 @@ TEST_F(InlineIntrinsicsTest, LdLexVarDynSkip) ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); BASIC_BLOCK(2, -1) @@ -534,7 +534,7 @@ TEST_F(InlineIntrinsicsTest, LdLexVarDynSkip) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(InlineIntrinsicsTest, LdLexDyn) @@ -567,8 +567,8 @@ TEST_F(InlineIntrinsicsTest, LdLexDyn) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(1, DataType::Any(panda::coretypes::TaggedValue::VALUE_HOLE)); @@ -590,7 +590,7 @@ TEST_F(InlineIntrinsicsTest, LdLexDyn) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(InlineIntrinsicsTest, InlineLdlexenvDyn) @@ -613,8 +613,8 @@ TEST_F(InlineIntrinsicsTest, InlineLdlexenvDyn) ASSERT_TRUE(graph->RunPass()); ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); BASIC_BLOCK(2, -1) @@ -623,8 +623,8 @@ TEST_F(InlineIntrinsicsTest, InlineLdlexenvDyn) INST(2, Opcode::Return).any().Inputs(1); } } - GraphChecker(graph_opt).Check(); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + GraphChecker(graphOpt).Check(); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(InlineIntrinsicsTest, StLexVarDyn) @@ -653,12 +653,12 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) ASSERT_TRUE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(1, 1); - CONSTANT(7, graph_opt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); + CONSTANT(7, graphOpt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); BASIC_BLOCK(2, -1) { @@ -672,9 +672,9 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) INST(4, Opcode::ReturnVoid).v0id(); } } - graph_opt->RunPass(); - GraphChecker(graph_opt).Check(); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + graphOpt->RunPass(); + GraphChecker(graphOpt).Check(); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); level = 1U; graph = CreateGraphDynStubWithDefaultRuntime(); @@ -699,13 +699,13 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(1, 1); - CONSTANT(7, graph_opt->GetRuntime()->GetLexicalEnvParentEnvIndex()); - CONSTANT(10, graph_opt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); + CONSTANT(7, graphOpt->GetRuntime()->GetLexicalEnvParentEnvIndex()); + CONSTANT(10, graphOpt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); BASIC_BLOCK(2, -1) { @@ -725,8 +725,8 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) INST(4, Opcode::ReturnVoid).v0id(); } } - graph_opt->RunPass(); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + graphOpt->RunPass(); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); level = 2U; graph = CreateGraphDynStubWithDefaultRuntime(); @@ -751,13 +751,13 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(1, 1); - CONSTANT(7, graph_opt->GetRuntime()->GetLexicalEnvParentEnvIndex()); - CONSTANT(12, graph_opt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); + CONSTANT(7, graphOpt->GetRuntime()->GetLexicalEnvParentEnvIndex()); + CONSTANT(12, graphOpt->GetRuntime()->GetLexicalEnvStartDataIndex() + SLOT); BASIC_BLOCK(2, -1) { @@ -783,8 +783,8 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) INST(4, Opcode::ReturnVoid).v0id(); } } - graph_opt->RunPass(); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + graphOpt->RunPass(); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); level = 3U; graph = CreateGraphDynStubWithDefaultRuntime(); @@ -809,8 +809,8 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(1, 1); @@ -827,8 +827,8 @@ TEST_F(InlineIntrinsicsTest, StLexVarDyn) INST(4, Opcode::ReturnVoid).v0id(); } } - graph_opt->RunPass(); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + graphOpt->RunPass(); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(InlineIntrinsicsTest, PopLexenvDyn) @@ -852,11 +852,11 @@ TEST_F(InlineIntrinsicsTest, PopLexenvDyn) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); - CONSTANT(5, graph_opt->GetRuntime()->GetLexicalEnvParentEnvIndex()); + CONSTANT(5, graphOpt->GetRuntime()->GetLexicalEnvParentEnvIndex()); BASIC_BLOCK(2, -1) { INST(1, Opcode::LoadLexicalEnv).any().Inputs(0); @@ -871,7 +871,7 @@ TEST_F(InlineIntrinsicsTest, PopLexenvDyn) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOLINTEND(readability-magic-numbers) diff --git a/tests/compiler/lowering_ecma_test.cpp b/tests/compiler/lowering_ecma_test.cpp index 554c06f26aa3514124bb42ba205113ab2fc6d332..dcef9db1989a1c5b02c6dee0a5026022148af4c6 100644 --- a/tests/compiler/lowering_ecma_test.cpp +++ b/tests/compiler/lowering_ecma_test.cpp @@ -41,8 +41,8 @@ TEST_F(LoweringEcmaTest, CastValueToAnyTypeWithConst) INST(3, Opcode::Return).any().Inputs(2); } } - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { CONSTANT(5, 0x6).any(); @@ -58,7 +58,7 @@ TEST_F(LoweringEcmaTest, CastValueToAnyTypeWithConst) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(LoweringEcmaTest, CastValueToAnyTypeWithSaveState) @@ -79,8 +79,8 @@ TEST_F(LoweringEcmaTest, CastValueToAnyTypeWithSaveState) INST(7, Opcode::Return).any().Inputs(6); } } - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(1, 1.1); @@ -99,7 +99,7 @@ TEST_F(LoweringEcmaTest, CastValueToAnyTypeWithSaveState) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOLINTEND(readability-magic-numbers) diff --git a/tests/compiler/peepholes_ecma_test.cpp b/tests/compiler/peepholes_ecma_test.cpp index ca676b3b12f45c4c06acab7b64ff3c2c74aa0ff6..4aaba1fa2ac9a9b195a5cc98ebb1784810762e34 100644 --- a/tests/compiler/peepholes_ecma_test.cpp +++ b/tests/compiler/peepholes_ecma_test.cpp @@ -52,8 +52,8 @@ TEST_F(PeepholesTest, CastTrueSimple) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).s32(); @@ -70,7 +70,7 @@ TEST_F(PeepholesTest, CastTrueSimple) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CastTrueComplex) @@ -111,8 +111,8 @@ TEST_F(PeepholesTest, CastTrueComplex) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).s32(); @@ -142,7 +142,7 @@ TEST_F(PeepholesTest, CastTrueComplex) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CastFalse) @@ -162,13 +162,13 @@ TEST_F(PeepholesTest, CastFalse) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CastIntToAnyToDouble) @@ -200,8 +200,8 @@ TEST_F(PeepholesTest, CastIntToAnyToDouble) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).s32(); @@ -215,7 +215,7 @@ TEST_F(PeepholesTest, CastIntToAnyToDouble) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CastBoolToAnyToInt) @@ -237,8 +237,8 @@ TEST_F(PeepholesTest, CastBoolToAnyToInt) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).b(); @@ -249,7 +249,7 @@ TEST_F(PeepholesTest, CastBoolToAnyToInt) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CastAnyToValueAndBack) @@ -272,8 +272,8 @@ TEST_F(PeepholesTest, CastAnyToValueAndBack) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); @@ -283,7 +283,7 @@ TEST_F(PeepholesTest, CastAnyToValueAndBack) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CastAnyToValueAndBackNotApplied) @@ -306,9 +306,9 @@ TEST_F(PeepholesTest, CastAnyToValueAndBackNotApplied) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareCastToAnyAndCastToAny) @@ -337,8 +337,8 @@ TEST_F(PeepholesTest, CompareCastToAnyAndCastToAny) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -355,7 +355,7 @@ TEST_F(PeepholesTest, CompareCastToAnyAndCastToAny) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareCastToAnyAndCastToAnyNotApply) @@ -379,13 +379,13 @@ TEST_F(PeepholesTest, CompareCastToAnyAndCastToAnyNotApply) INST(10, Opcode::Return).any().Inputs(9); } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareCastToAnyAndConstTrue) @@ -413,8 +413,8 @@ TEST_F(PeepholesTest, CompareCastToAnyAndConstTrue) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -429,7 +429,7 @@ TEST_F(PeepholesTest, CompareCastToAnyAndConstTrue) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareCastToAnyAndConstFalse) @@ -457,8 +457,8 @@ TEST_F(PeepholesTest, CompareCastToAnyAndConstFalse) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -475,7 +475,7 @@ TEST_F(PeepholesTest, CompareCastToAnyAndConstFalse) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareCastToAnyAndConst) @@ -503,8 +503,8 @@ TEST_F(PeepholesTest, CompareCastToAnyAndConst) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { CONSTANT(19, 0); @@ -515,7 +515,7 @@ TEST_F(PeepholesTest, CompareCastToAnyAndConst) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareAnyTypeAfterCastValueToAny) @@ -554,8 +554,8 @@ TEST_F(PeepholesTest, CompareAnyTypeAfterCastValueToAny) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { CONSTANT(0, 0); CONSTANT(1, 1); @@ -574,7 +574,7 @@ TEST_F(PeepholesTest, CompareAnyTypeAfterCastValueToAny) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, AddOverflowCheckXor) @@ -605,8 +605,8 @@ TEST_F(PeepholesTest, AddOverflowCheckXor) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -625,7 +625,7 @@ TEST_F(PeepholesTest, AddOverflowCheckXor) INST(13, Opcode::Return).any().Inputs(12); } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareAnyTypeAfterAnyTypeCheck) @@ -665,8 +665,8 @@ TEST_F(PeepholesTest, CompareAnyTypeAfterAnyTypeCheck) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(16, 0); @@ -689,7 +689,7 @@ TEST_F(PeepholesTest, CompareAnyTypeAfterAnyTypeCheck) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, CompareAnyTypeAfterAnyTypeCheckSpecial) @@ -733,8 +733,8 @@ TEST_F(PeepholesTest, CompareAnyTypeAfterAnyTypeCheckSpecial) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynStubWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynStubWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); CONSTANT(16, 0); @@ -766,7 +766,7 @@ TEST_F(PeepholesTest, CompareAnyTypeAfterAnyTypeCheckSpecial) INST(15, Opcode::Return).any().Inputs(14); } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PeepholesTest, SubOverflowCheckDynCast) @@ -797,8 +797,8 @@ TEST_F(PeepholesTest, SubOverflowCheckDynCast) ASSERT_TRUE(graph->RunPass()); ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); PARAMETER(1, 1).any(); @@ -812,7 +812,7 @@ TEST_F(PeepholesTest, SubOverflowCheckDynCast) INST(11, Opcode::Return).any().Inputs(10); } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOLINTEND(readability-magic-numbers) diff --git a/tests/compiler/phi_type_resolving_ecma_test.cpp b/tests/compiler/phi_type_resolving_ecma_test.cpp index 5316caf1be164588c7df7b34dd9b6ca6b629b297..17f8155805601884045f0a3b95fc09a8ddb70b7f 100644 --- a/tests/compiler/phi_type_resolving_ecma_test.cpp +++ b/tests/compiler/phi_type_resolving_ecma_test.cpp @@ -53,8 +53,8 @@ TEST_F(PhiTypeResolvingTest, ResolvePhi) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { CONSTANT(0, 0).i64(); CONSTANT(1, 1).i64(); @@ -75,7 +75,7 @@ TEST_F(PhiTypeResolvingTest, ResolvePhi) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PhiTypeResolvingTest, Resolve2Phi) @@ -117,8 +117,8 @@ TEST_F(PhiTypeResolvingTest, Resolve2Phi) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { CONSTANT(0, 0).i64(); CONSTANT(1, 1).i64(); @@ -149,7 +149,7 @@ TEST_F(PhiTypeResolvingTest, Resolve2Phi) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PhiTypeResolvingTest, ResolvePhiNotApply) @@ -176,13 +176,13 @@ TEST_F(PhiTypeResolvingTest, ResolvePhiNotApply) INST(9, Opcode::Return).any().Inputs(8); } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(PhiTypeResolvingTest, ResolvePhiUserNotAnyType) @@ -214,8 +214,8 @@ TEST_F(PhiTypeResolvingTest, ResolvePhiUserNotAnyType) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { CONSTANT(0, 0).f64(); CONSTANT(1, 1).f64(); @@ -237,7 +237,7 @@ TEST_F(PhiTypeResolvingTest, ResolvePhiUserNotAnyType) } } - ASSERT_TRUE(GraphComparator().Compare(graph, graph_opt)); + ASSERT_TRUE(GraphComparator().Compare(graph, graphOpt)); } // NOLINTEND(readability-magic-numbers) diff --git a/tests/compiler/unit_ecma_test.cpp b/tests/compiler/unit_ecma_test.cpp index 964e8bfb05467decbcf020db53f7076fcce5acac..e7816fc640eca9ca5473cf98e66aaa8eeadd08fc 100644 --- a/tests/compiler/unit_ecma_test.cpp +++ b/tests/compiler/unit_ecma_test.cpp @@ -37,34 +37,34 @@ namespace panda::compiler { void PandaRuntimeTest::Initialize([[maybe_unused]] int argc, char **argv) { ASSERT(argc > 0); - exec_path_ = argv[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + execPath_ = argv[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } PandaRuntimeTest::PandaRuntimeTest() { - ASSERT(exec_path_ != nullptr); + ASSERT(execPath_ != nullptr); #if !defined(PANDA_TARGET_MOBILE) #if defined(USE_STD_FILESYSTEM) - std::filesystem::path exec_name(exec_path_); + std::filesystem::path execName(execPath_); #else - std::experimental::filesystem::path exec_name(exec_path_); + std::experimental::filesystem::path execName(exec_path_); #endif // defined(USE_STD_FILESYSTEM) - std::string pandastdlib_path = exec_name.parent_path() / "../pandastdlib/arkstdlib.abc"; + std::string pandastdlibPath = execName.parent_path() / "../pandastdlib/arkstdlib.abc"; #else - std::string exec_name = "compiler_unit_tests"; - std::string pandastdlib_path = "../pandastdlib/arkstdlib.abc"; + std::string execName = "compiler_unit_tests"; + std::string pandastdlibPath = "../pandastdlib/arkstdlib.abc"; #endif - panda::RuntimeOptions runtime_options(exec_name); - runtime_options.SetBootPandaFiles({pandastdlib_path}); - runtime_options.SetLoadRuntimes({"ecmascript"}); - runtime_options.SetHeapSizeLimit(50_MB); // NOLINT(readability-magic-numbers) - runtime_options.SetEnableAn(true); - runtime_options.SetGcType("epsilon"); + panda::RuntimeOptions runtimeOptions(execName); + runtimeOptions.SetBootPandaFiles({pandastdlibPath}); + runtimeOptions.SetLoadRuntimes({"ecmascript"}); + runtimeOptions.SetHeapSizeLimit(50_MB); // NOLINT(readability-magic-numbers) + runtimeOptions.SetEnableAn(true); + runtimeOptions.SetGcType("epsilon"); Logger::InitializeStdLogging(Logger::Level::ERROR, Logger::Component::COMPILER); - EXPECT_TRUE(panda::Runtime::Create(runtime_options)); + EXPECT_TRUE(panda::Runtime::Create(runtimeOptions)); allocator_ = new ArenaAllocator(panda::SpaceType::SPACE_TYPE_INTERNAL); - local_allocator_ = new ArenaAllocator(panda::SpaceType::SPACE_TYPE_INTERNAL); + localAllocator_ = new ArenaAllocator(panda::SpaceType::SPACE_TYPE_INTERNAL); builder_ = new IrConstructor(); graph_ = CreateGraph(); @@ -74,7 +74,7 @@ PandaRuntimeTest::~PandaRuntimeTest() { delete builder_; delete allocator_; - delete local_allocator_; + delete localAllocator_; panda::Runtime::Destroy(); } @@ -98,26 +98,26 @@ public: RuntimeInterface *PandaRuntimeTest::GetDefaultRuntime() { - static EcmaDefaultRuntimeInterface runtime_interface; - return &runtime_interface; + static EcmaDefaultRuntimeInterface runtimeInterface; + return &runtimeInterface; } -std::unique_ptr AsmTest::ParseToFile(const char *source, const char *file_name) +std::unique_ptr AsmTest::ParseToFile(const char *source, const char *fileName) { panda::pandasm::Parser parser; - auto res = parser.Parse(source, file_name); + auto res = parser.Parse(source, fileName); if (parser.ShowError().err != pandasm::Error::ErrorType::ERR_NONE) { std::cerr << "Parse failed: " << parser.ShowError().message << std::endl - << parser.ShowError().whole_line << std::endl; + << parser.ShowError().wholeLine << std::endl; ADD_FAILURE(); return nullptr; } return pandasm::AsmEmitter::Emit(res.Value()); } -bool AsmTest::Parse(const char *source, const char *file_name) +bool AsmTest::Parse(const char *source, const char *fileName) { - auto pfile = ParseToFile(source, file_name); + auto pfile = ParseToFile(source, fileName); if (pfile == nullptr) { ADD_FAILURE(); return false; @@ -126,7 +126,7 @@ bool AsmTest::Parse(const char *source, const char *file_name) return true; } -Graph *AsmTest::BuildGraph(const char *method_name, Graph *graph) +Graph *AsmTest::BuildGraph(const char *methodName, Graph *graph) { auto loader = GetClassLinker(); PandaString storage; @@ -136,7 +136,7 @@ Graph *AsmTest::BuildGraph(const char *method_name, Graph *graph) auto klass = extension->GetClass(ClassHelper::GetDescriptor(utf::CStringAsMutf8("_GLOBAL"), &storage)); thread->ManagedCodeEnd(); - auto method = klass->GetDirectMethod(utf::CStringAsMutf8(method_name)); + auto method = klass->GetDirectMethod(utf::CStringAsMutf8(methodName)); if (method == nullptr) { ADD_FAILURE(); return nullptr; @@ -167,8 +167,8 @@ CommonTest::~CommonTest() } delete builder_; delete allocator_; - delete object_allocator_; - delete local_allocator_; + delete objectAllocator_; + delete localAllocator_; PoolManager::Finalize(); panda::mem::MemConfig::Finalize(); @@ -180,6 +180,6 @@ int main(int argc, char **argv) ::testing::InitGoogleTest(&argc, argv); panda::compiler::PandaRuntimeTest::Initialize(argc, argv); - panda::compiler::OPTIONS.SetCompilerUseSafepoint(false); + panda::compiler::g_options.SetCompilerUseSafepoint(false); return RUN_ALL_TESTS(); } diff --git a/tests/compiler/vn_test_ecma.cpp b/tests/compiler/vn_test_ecma.cpp index 48c309d544be2dac7564e8ad8f253e3bba67f2dd..adf4a728858865c9036773c3902bef7db2c8be8f 100644 --- a/tests/compiler/vn_test_ecma.cpp +++ b/tests/compiler/vn_test_ecma.cpp @@ -55,8 +55,8 @@ TEST_F(VNTest, CompareAnyTypeVNTrue) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); @@ -78,7 +78,7 @@ TEST_F(VNTest, CompareAnyTypeVNTrue) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(VNTest, CompareAnyTypeVNFalse) @@ -107,13 +107,13 @@ TEST_F(VNTest, CompareAnyTypeVNFalse) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(VNTest, CastAnyTypeVNTrue) @@ -146,8 +146,8 @@ TEST_F(VNTest, CastAnyTypeVNTrue) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { PARAMETER(0, 0).any(); @@ -169,7 +169,7 @@ TEST_F(VNTest, CastAnyTypeVNTrue) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(VNTest, CastAnyTypeVNFalse) @@ -198,13 +198,13 @@ TEST_F(VNTest, CastAnyTypeVNFalse) } } - auto graph_opt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); + auto graphOpt = GraphCloner(graph, graph->GetAllocator(), graph->GetLocalAllocator()).CloneGraph(); ASSERT_FALSE(graph->RunPass()); ASSERT_FALSE(graph->RunPass()); GraphChecker(graph).Check(); - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } TEST_F(VNTest, CastValueToAnyType) @@ -228,8 +228,8 @@ TEST_F(VNTest, CastValueToAnyType) ASSERT_TRUE(graph->RunPass()); GraphChecker(graph).Check(); - auto graph_opt = CreateGraphDynWithDefaultRuntime(); - GRAPH(graph_opt) + auto graphOpt = CreateGraphDynWithDefaultRuntime(); + GRAPH(graphOpt) { CONSTANT(0, 0); BASIC_BLOCK(2, -1) @@ -242,7 +242,7 @@ TEST_F(VNTest, CastValueToAnyType) } } - EXPECT_TRUE(GraphComparator().Compare(graph, graph_opt)); + EXPECT_TRUE(GraphComparator().Compare(graph, graphOpt)); } } // namespace panda::compiler diff --git a/tests/disassembler/disasm_test_lit_ecma.cpp.in b/tests/disassembler/disasm_test_lit_ecma.cpp.in index 53527b4eb475fffe11cca6a7b7141a4e4a303bbb..5045aa88292b11397f74795ddfd4580440214ea4 100644 --- a/tests/disassembler/disasm_test_lit_ecma.cpp.in +++ b/tests/disassembler/disasm_test_lit_ecma.cpp.in @@ -43,10 +43,10 @@ TEST(InstructionsTest, TestLiteralArrayEcma) EXPECT_TRUE(ss.str().find(".language ECMAScript") != std::string::npos); - auto array_body = ExtractArrayBody(ss.str(), ".array array_0 {\n"); + auto arrayBody = ExtractArrayBody(ss.str(), ".array array_0 {\n"); std::string line; - std::stringstream arr {array_body}; + std::stringstream arr {arrayBody}; std::getline(arr, line); EXPECT_EQ("\tpanda.JSString \"1\"", line); std::getline(arr, line); diff --git a/tests/runtime/builtins/builtins_array_test.cpp b/tests/runtime/builtins/builtins_array_test.cpp index 02a4c5f4b885f242dc7076a1bf648448cd8fe471..ee7c54af60916babe5b876dc9e4976ba13849588 100644 --- a/tests/runtime/builtins/builtins_array_test.cpp +++ b/tests/runtime/builtins/builtins_array_test.cpp @@ -71,9 +71,9 @@ public: if (key->IsUndefined()) { return JSTaggedValue::Undefined(); } - JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); - int length = js_array->GetArrayLength() + 1; - js_array->SetArrayLength(argv->GetThread(), length); + JSArray *jsArray = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); + int length = jsArray->GetArrayLength() + 1; + jsArray->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); } @@ -151,7 +151,7 @@ public: // element = [x] JSTaggedValue element = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle key0(thread, JSTaggedValue(0)); // val = x @@ -174,16 +174,16 @@ private: EcmaHandleScope *scope_ {nullptr}; }; -JSTaggedValue CreateBuiltinsJSObject(JSThread *thread, const PandaString &key_c_str) +JSTaggedValue CreateBuiltinsJSObject(JSThread *thread, const PandaString &keyCStr) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); - JSHandle dynclass = global_env->GetObjectFunction(); + JSHandle dynclass = globalEnv->GetObjectFunction(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - JSHandle key(factory->NewFromCanBeCompressString(&key_c_str[0])); + JSHandle key(factory->NewFromCanBeCompressString(&keyCStr[0])); JSHandle value(thread, JSTaggedValue(1)); JSObject::SetProperty(thread, obj, key, value); return obj.GetTaggedValue(); @@ -191,44 +191,44 @@ JSTaggedValue CreateBuiltinsJSObject(JSThread *thread, const PandaString &key_c_ TEST_F(BuiltinsArrayTest, ArrayConstructor) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle array(env->GetArrayFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info1->SetFunction(array.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo1->SetFunction(array.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::ArrayConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::ArrayConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); JSHandle key0(thread_, JSTaggedValue(0)); JSHandle key1(thread_, JSTaggedValue(1)); JSHandle key2(thread_, JSTaggedValue(2)); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(1)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(1)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); } // 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) TEST_F(BuiltinsArrayTest, From) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))->GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -246,113 +246,113 @@ TEST_F(BuiltinsArrayTest, From) PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(5)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key4, desc4); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::From(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::From(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(1)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(2)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, value_handle, key3, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(4)); - JSObject::GetOwnProperty(thread_, value_handle, key4, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(1)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(2)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, valueHandle, key3, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(4)); + JSObject::GetOwnProperty(thread_, valueHandle, key4, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); } // 22.1.2.2 Array.isArray(arg) TEST_F(BuiltinsArrayTest, IsArray) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::IsArray(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::IsArray(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - result = array::IsArray(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + result = array::IsArray(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } TEST_F(BuiltinsArrayTest, Of) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle array(env->GetArrayFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info1->SetFunction(array.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo1->SetFunction(array.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::Of(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::Of(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); JSHandle key0(thread_, JSTaggedValue(0)); JSHandle key1(thread_, JSTaggedValue(1)); JSHandle key2(thread_, JSTaggedValue(2)); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(1)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(1)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); } TEST_F(BuiltinsArrayTest, Species) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle array(env->GetArrayFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(array.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(global_object.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(array.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(globalObject.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::GetSpecies(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::GetSpecies(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); } TEST_F(BuiltinsArrayTest, Concat) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); @@ -379,35 +379,34 @@ TEST_F(BuiltinsArrayTest, Concat) PropertyDescriptor desc6(thread_, JSHandle(thread_, JSTaggedValue(6)), true, true, true); JSArray::DefineOwnProperty(thread_, obj1, key6, desc6); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, obj1.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, obj1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Concat(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Concat(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); JSHandle key7(thread_, JSTaggedValue(5)); - EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue()->GetInt(), - 6); - JSObject::GetOwnProperty(thread_, value_handle, key7, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(6)); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue()->GetInt(), + 6); + JSObject::GetOwnProperty(thread_, valueHandle, key7, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(6)); } // 22.1.3.3 new Array(1,2,3,4,5).CopyWithin(0,3,5) TEST_F(BuiltinsArrayTest, CopyWithin) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -425,43 +424,43 @@ TEST_F(BuiltinsArrayTest, CopyWithin) PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(5)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key4, desc4); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(0))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(0))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::CopyWithin(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::CopyWithin(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(4)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, value_handle, key3, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(4)); - JSObject::GetOwnProperty(thread_, value_handle, key4, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(4)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, valueHandle, key3, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(4)); + JSObject::GetOwnProperty(thread_, valueHandle, key4, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); } TEST_F(BuiltinsArrayTest, Every) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(100)), true, true, true); @@ -474,17 +473,17 @@ TEST_F(BuiltinsArrayTest, Every) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(300)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - JSHandle js_array = factory->NewJSArray(); + JSHandle jsArray = factory->NewJSArray(); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestEveryFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = array::proto::Every(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = array::proto::Every(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -492,15 +491,15 @@ TEST_F(BuiltinsArrayTest, Every) TEST_F(BuiltinsArrayTest, Map) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(50)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -510,42 +509,41 @@ TEST_F(BuiltinsArrayTest, Map) JSHandle key2(thread_, JSTaggedValue(2)); PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - JSHandle js_array(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle jsArray(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestMapFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Map(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Map(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); - EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue()->GetInt(), - 3); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - - ASSERT_EQ(desc_res.GetValue()->GetInt(), 100); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue()->GetInt(), 400); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue()->GetInt(), 6); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue()->GetInt(), + 3); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + + ASSERT_EQ(descRes.GetValue()->GetInt(), 100); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue()->GetInt(), 400); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue()->GetInt(), 6); } TEST_F(BuiltinsArrayTest, Reverse) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(50)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -556,43 +554,42 @@ TEST_F(BuiltinsArrayTest, Reverse) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Reverse(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Reverse(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); - EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue()->GetInt(), - 3); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(200)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(50)); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 3); - JSObject::GetOwnProperty(thread_, obj, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, obj, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(200)); - JSObject::GetOwnProperty(thread_, obj, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(50)); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue()->GetInt(), + 3); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(200)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(50)); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 3); + JSObject::GetOwnProperty(thread_, obj, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, obj, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(200)); + JSObject::GetOwnProperty(thread_, obj, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(50)); } TEST_F(BuiltinsArrayTest, Slice) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -609,38 +606,37 @@ TEST_F(BuiltinsArrayTest, Slice) PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key4, desc4); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(4))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(4))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Slice(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Slice(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); - EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue()->GetInt(), - 3); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(2)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(4)); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue()->GetInt(), + 3); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(2)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(4)); } TEST_F(BuiltinsArrayTest, Splice) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -657,34 +653,33 @@ TEST_F(BuiltinsArrayTest, Splice) PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(5)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key4, desc4); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(2))); - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(100))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(2))); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(100))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Splice(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Splice(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 4); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 4); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); - EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue()->GetInt(), - 2); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(2)); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue()->GetInt(), + 2); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(2)); } // ES2019 22.1.3.10 Builtin Array.flat() TEST_F(BuiltinsArrayTest, Flat) { ASSERT_NE(thread_, nullptr); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); auto *arr1 = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); auto *arr2 = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); @@ -698,9 +693,9 @@ TEST_F(BuiltinsArrayTest, Flat) JSHandle obj2(thread_, arr2); JSHandle obj3(thread_, arr3); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj1), length_key_handle).GetValue()->GetInt(), 0); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj2), length_key_handle).GetValue()->GetInt(), 0); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj3), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj1), lengthKeyHandle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj2), lengthKeyHandle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj3), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); JSHandle key1(thread_, JSTaggedValue(1)); @@ -709,18 +704,18 @@ TEST_F(BuiltinsArrayTest, Flat) // arr1 = [0, 1, arr2] PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(0)), true, true, true); PropertyDescriptor desc1(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); - PropertyDescriptor desc_nested1(thread_, JSHandle(thread_, obj2.GetTaggedValue()), true, true, true); + PropertyDescriptor descNested1(thread_, JSHandle(thread_, obj2.GetTaggedValue()), true, true, true); JSArray::DefineOwnProperty(thread_, obj1, key0, desc0); JSArray::DefineOwnProperty(thread_, obj1, key1, desc1); - JSArray::DefineOwnProperty(thread_, obj1, key2, desc_nested1); + JSArray::DefineOwnProperty(thread_, obj1, key2, descNested1); // arr2 = [2, 3, arr3] PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(2)), true, true, true); PropertyDescriptor desc3(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); - PropertyDescriptor desc_nested2(thread_, JSHandle(thread_, obj3.GetTaggedValue()), true, true, true); + PropertyDescriptor descNested2(thread_, JSHandle(thread_, obj3.GetTaggedValue()), true, true, true); JSArray::DefineOwnProperty(thread_, obj2, key0, desc2); JSArray::DefineOwnProperty(thread_, obj2, key1, desc3); - JSArray::DefineOwnProperty(thread_, obj2, key2, desc_nested2); + JSArray::DefineOwnProperty(thread_, obj2, key2, descNested2); // arr3 = [4, 5] PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(4)), true, true, true); @@ -729,81 +724,78 @@ TEST_F(BuiltinsArrayTest, Flat) JSArray::DefineOwnProperty(thread_, obj3, key1, desc5); // [0, 1, [2, 3, [4, 5]]].flat(2) = [0, 1, 2, 3, 4, 5] - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj1.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj1.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Flat(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Flat(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - PropertyDescriptor desc_res(thread_); + PropertyDescriptor descRes(thread_); JSTaggedValue value(static_cast(result.GetRawData())); - JSHandle value_handle(thread_, value); + JSHandle valueHandle(thread_, value); - EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue()->GetInt(), - 6); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue()->GetInt(), + 6); JSHandle key3(thread_, JSTaggedValue(3)); JSHandle key4(thread_, JSTaggedValue(4)); JSHandle key5(thread_, JSTaggedValue(5)); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(0)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(1)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(2)); - JSObject::GetOwnProperty(thread_, value_handle, key3, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - JSObject::GetOwnProperty(thread_, value_handle, key4, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(4)); - JSObject::GetOwnProperty(thread_, value_handle, key5, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(0)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(1)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(2)); + JSObject::GetOwnProperty(thread_, valueHandle, key3, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + JSObject::GetOwnProperty(thread_, valueHandle, key4, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(4)); + JSObject::GetOwnProperty(thread_, valueHandle, key5, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); // [0, 1, [2, 3, [4, 5]]].flat() = [0, 1, 2, 3, [4, 5]] - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(obj1.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(obj1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - result = array::proto::Flat(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + result = array::proto::Flat(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value2(static_cast(result.GetRawData())); - JSHandle value_handle2(thread_, value2); + JSHandle valueHandle2(thread_, value2); EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle2), length_key_handle).GetValue()->GetInt(), - 5); - - JSObject::GetOwnProperty(thread_, value_handle2, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(0)); - JSObject::GetOwnProperty(thread_, value_handle2, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(1)); - JSObject::GetOwnProperty(thread_, value_handle2, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(2)); - JSObject::GetOwnProperty(thread_, value_handle2, key3, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(3)); - - JSObject::GetOwnProperty(thread_, value_handle2, key4, desc_res); - ASSERT_TRUE(desc_res.GetValue().GetTaggedValue().IsECMAObject()); - - JSTaggedValue inner_arr_value(desc_res.GetValue().GetTaggedValue()); - JSHandle inner_arr_handle(thread_, inner_arr_value); - - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(inner_arr_handle), length_key_handle) - .GetValue() - ->GetInt(), - 2); + JSArray::GetProperty(thread_, JSHandle(valueHandle2), lengthKeyHandle).GetValue()->GetInt(), 5); - JSObject::GetOwnProperty(thread_, inner_arr_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(4)); - JSObject::GetOwnProperty(thread_, inner_arr_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); + JSObject::GetOwnProperty(thread_, valueHandle2, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(0)); + JSObject::GetOwnProperty(thread_, valueHandle2, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(1)); + JSObject::GetOwnProperty(thread_, valueHandle2, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(2)); + JSObject::GetOwnProperty(thread_, valueHandle2, key3, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(3)); + + JSObject::GetOwnProperty(thread_, valueHandle2, key4, descRes); + ASSERT_TRUE(descRes.GetValue().GetTaggedValue().IsECMAObject()); + + JSTaggedValue innerArrValue(descRes.GetValue().GetTaggedValue()); + JSHandle innerArrHandle(thread_, innerArrValue); + + EXPECT_EQ( + JSArray::GetProperty(thread_, JSHandle(innerArrHandle), lengthKeyHandle).GetValue()->GetInt(), + 2); + + JSObject::GetOwnProperty(thread_, innerArrHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(4)); + JSObject::GetOwnProperty(thread_, innerArrHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); } // ES2019 22.1.3.11 Builtin Array.flatMap() @@ -811,11 +803,11 @@ TEST_F(BuiltinsArrayTest, FlatMap) { // [[1], [2], [4]].flatMap(x => [x*2]) = [2, 4, 8] ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); auto *arr = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); auto *arr1 = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); auto *arr2 = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); @@ -831,10 +823,10 @@ TEST_F(BuiltinsArrayTest, FlatMap) JSHandle obj2(thread_, arr2); JSHandle obj3(thread_, arr3); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj1), length_key_handle).GetValue()->GetInt(), 0); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj2), length_key_handle).GetValue()->GetInt(), 0); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj3), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj1), lengthKeyHandle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj2), lengthKeyHandle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj3), lengthKeyHandle).GetValue()->GetInt(), 0); // create [1], [2], [4] elements JSHandle key0(thread_, JSTaggedNumber(0)); @@ -848,53 +840,52 @@ TEST_F(BuiltinsArrayTest, FlatMap) JSObject::DefineOwnProperty(thread_, obj3, key0, desc4); // arr = [[1], [2], [4]] - PropertyDescriptor obj_desc1(thread_, JSHandle(thread_, obj1.GetTaggedValue()), true, true, true); - PropertyDescriptor obj_desc2(thread_, JSHandle(thread_, obj2.GetTaggedValue()), true, true, true); - PropertyDescriptor obj_desc4(thread_, JSHandle(thread_, obj3.GetTaggedValue()), true, true, true); - JSObject::DefineOwnProperty(thread_, obj, key0, obj_desc1); - JSObject::DefineOwnProperty(thread_, obj, key1, obj_desc2); - JSObject::DefineOwnProperty(thread_, obj, key2, obj_desc4); - - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj1), length_key_handle).GetValue()->GetInt(), 1); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj2), length_key_handle).GetValue()->GetInt(), 1); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj3), length_key_handle).GetValue()->GetInt(), 1); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 3); + PropertyDescriptor objDesc1(thread_, JSHandle(thread_, obj1.GetTaggedValue()), true, true, true); + PropertyDescriptor objDesc2(thread_, JSHandle(thread_, obj2.GetTaggedValue()), true, true, true); + PropertyDescriptor objDesc4(thread_, JSHandle(thread_, obj3.GetTaggedValue()), true, true, true); + JSObject::DefineOwnProperty(thread_, obj, key0, objDesc1); + JSObject::DefineOwnProperty(thread_, obj, key1, objDesc2); + JSObject::DefineOwnProperty(thread_, obj, key2, objDesc4); + + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj1), lengthKeyHandle).GetValue()->GetInt(), 1); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj2), lengthKeyHandle).GetValue()->GetInt(), 1); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj3), lengthKeyHandle).GetValue()->GetInt(), 1); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 3); JSHandle cb = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestFlatMapFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, cb.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, cb.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::FlatMap(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::FlatMap(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - PropertyDescriptor res_desc(thread_); + PropertyDescriptor resDesc(thread_); JSTaggedValue value(static_cast(result.GetRawData())); - JSHandle value_handle(thread_, value); + JSHandle valueHandle(thread_, value); - EXPECT_EQ( - JSArray::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue()->GetInt(), - 3); - - JSObject::GetOwnProperty(thread_, value_handle, key0, res_desc); - ASSERT_EQ(res_desc.GetValue().GetTaggedValue(), JSTaggedValue(2)); - JSObject::GetOwnProperty(thread_, value_handle, key1, res_desc); - ASSERT_EQ(res_desc.GetValue().GetTaggedValue(), JSTaggedValue(4)); - JSObject::GetOwnProperty(thread_, value_handle, key2, res_desc); - ASSERT_EQ(res_desc.GetValue().GetTaggedValue(), JSTaggedValue(8)); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue()->GetInt(), + 3); + + JSObject::GetOwnProperty(thread_, valueHandle, key0, resDesc); + ASSERT_EQ(resDesc.GetValue().GetTaggedValue(), JSTaggedValue(2)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, resDesc); + ASSERT_EQ(resDesc.GetValue().GetTaggedValue(), JSTaggedValue(4)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, resDesc); + ASSERT_EQ(resDesc.GetValue().GetTaggedValue(), JSTaggedValue(8)); } // 22.1.3.6 new Array(1,2,3,4,5).Fill(0,1,3) TEST_F(BuiltinsArrayTest, Fill) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -912,43 +903,43 @@ TEST_F(BuiltinsArrayTest, Fill) PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(5)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key4, desc4); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(0))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(0))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Fill(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Fill(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - PropertyDescriptor desc_res(thread_); - JSHandle value_handle(thread_, value); - JSObject::GetOwnProperty(thread_, value_handle, key0, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(1)); - JSObject::GetOwnProperty(thread_, value_handle, key1, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(0)); - JSObject::GetOwnProperty(thread_, value_handle, key2, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(0)); - JSObject::GetOwnProperty(thread_, value_handle, key3, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(4)); - JSObject::GetOwnProperty(thread_, value_handle, key4, desc_res); - ASSERT_EQ(desc_res.GetValue().GetTaggedValue(), JSTaggedValue(5)); + PropertyDescriptor descRes(thread_); + JSHandle valueHandle(thread_, value); + JSObject::GetOwnProperty(thread_, valueHandle, key0, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(1)); + JSObject::GetOwnProperty(thread_, valueHandle, key1, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(0)); + JSObject::GetOwnProperty(thread_, valueHandle, key2, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(0)); + JSObject::GetOwnProperty(thread_, valueHandle, key3, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(4)); + JSObject::GetOwnProperty(thread_, valueHandle, key4, descRes); + ASSERT_EQ(descRes.GetValue().GetTaggedValue(), JSTaggedValue(5)); } TEST_F(BuiltinsArrayTest, Find) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -958,17 +949,17 @@ TEST_F(BuiltinsArrayTest, Find) JSHandle key2(thread_, JSTaggedValue(2)); PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - JSHandle js_array(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle jsArray(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestFindFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = array::proto::Find(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = array::proto::Find(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue(102).GetRawData()); @@ -976,15 +967,15 @@ TEST_F(BuiltinsArrayTest, Find) TEST_F(BuiltinsArrayTest, FindIndex) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -997,17 +988,17 @@ TEST_F(BuiltinsArrayTest, FindIndex) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(30)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - JSHandle js_array(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle jsArray(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestFindIndexFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = array::proto::FindIndex(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = array::proto::FindIndex(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); @@ -1015,15 +1006,15 @@ TEST_F(BuiltinsArrayTest, FindIndex) TEST_F(BuiltinsArrayTest, ForEach) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1035,20 +1026,20 @@ TEST_F(BuiltinsArrayTest, ForEach) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - JSHandle js_array(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle jsArray(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForEachFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = array::proto::ForEach(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = array::proto::ForEach(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - EXPECT_EQ(js_array->GetArrayLength(), 3); + EXPECT_EQ(jsArray->GetArrayLength(), 3); } // ES2021 23.1.3.13 new Array(1,2,3,4,3).includes(searchElement [ , fromIndex ]) @@ -1056,11 +1047,11 @@ TEST_F(BuiltinsArrayTest, Includes1) { ASSERT_NE(thread_, nullptr); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetHeapObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1079,14 +1070,14 @@ TEST_F(BuiltinsArrayTest, Includes1) JSArray::DefineOwnProperty(thread_, obj, key4, desc4); // new Array(1,2,3,4,3).includes(1,0) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -1096,11 +1087,11 @@ TEST_F(BuiltinsArrayTest, Includes2) { ASSERT_NE(thread_, nullptr); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetHeapObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1119,14 +1110,14 @@ TEST_F(BuiltinsArrayTest, Includes2) JSArray::DefineOwnProperty(thread_, obj, key4, desc4); // new Array(1,2,3,4,3).includes(1,3) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -1136,11 +1127,11 @@ TEST_F(BuiltinsArrayTest, Includes3) { ASSERT_NE(thread_, nullptr); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetHeapObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1159,14 +1150,14 @@ TEST_F(BuiltinsArrayTest, Includes3) JSArray::DefineOwnProperty(thread_, obj, key4, desc4); // new Array(1,2,3,4,3).includes(5,0) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -1176,11 +1167,11 @@ TEST_F(BuiltinsArrayTest, Includes4) { ASSERT_NE(thread_, nullptr); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetHeapObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1199,13 +1190,13 @@ TEST_F(BuiltinsArrayTest, Includes4) JSArray::DefineOwnProperty(thread_, obj, key4, desc4); // new Array(1,2,3,4,3).includes(1) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -1215,11 +1206,11 @@ TEST_F(BuiltinsArrayTest, Includes5) { ASSERT_NE(thread_, nullptr); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetHeapObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1238,13 +1229,13 @@ TEST_F(BuiltinsArrayTest, Includes5) JSArray::DefineOwnProperty(thread_, obj, key4, desc4); // new Array(1,2,3,4,3).includes(5) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -1252,11 +1243,11 @@ TEST_F(BuiltinsArrayTest, Includes5) // 22.1.3.11 new Array(1,2,3,4,3).IndexOf(searchElement [ , fromIndex ]) TEST_F(BuiltinsArrayTest, IndexOf) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1274,46 +1265,46 @@ TEST_F(BuiltinsArrayTest, IndexOf) PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key4, desc4); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::IndexOf(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::IndexOf(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue(static_cast(3))); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - result = array::proto::IndexOf(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + result = array::proto::IndexOf(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); - auto ecma_runtime_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info3->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info3->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info3->SetCallArg(0, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info3->SetCallArg(1, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo3->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - result = array::proto::IndexOf(ecma_runtime_call_info3.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + result = array::proto::IndexOf(ecmaRuntimeCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info4->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info4->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo4->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo4->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(3))); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - result = array::proto::IndexOf(ecma_runtime_call_info4.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + result = array::proto::IndexOf(ecmaRuntimeCallInfo4.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -1321,11 +1312,11 @@ TEST_F(BuiltinsArrayTest, IndexOf) // 22.1.3.14 new Array(1,2,3,4,3).LastIndexOf(searchElement [ , fromIndex ]) TEST_F(BuiltinsArrayTest, LastIndexOf) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1344,49 +1335,49 @@ TEST_F(BuiltinsArrayTest, LastIndexOf) JSArray::DefineOwnProperty(thread_, obj, key4, desc4); // new Array(1,2,3,4,3).LastIndexOf(3,4) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(4))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::LastIndexOf(ecma_runtime_call_info1.get()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(4))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::LastIndexOf(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); // new Array(1,2,3,4,3).LastIndexOf(3,3) - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue(static_cast(3))); - - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - result = array::proto::LastIndexOf(ecma_runtime_call_info2.get()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue(static_cast(3))); + + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + result = array::proto::LastIndexOf(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); // new Array(1,2,3,4,3).LastIndexOf(5,4) - auto ecma_runtime_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info3->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info3->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info3->SetCallArg(0, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info3->SetCallArg(1, JSTaggedValue(static_cast(4))); - - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - result = array::proto::LastIndexOf(ecma_runtime_call_info3.get()); + auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo3->SetCallArg(1, JSTaggedValue(static_cast(4))); + + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + result = array::proto::LastIndexOf(ecmaRuntimeCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); // new Array(1,2,3,4,3).LastIndexOf(3) - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info4->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info4->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo4->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo4->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(3))); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - result = array::proto::LastIndexOf(ecma_runtime_call_info4.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + result = array::proto::LastIndexOf(ecmaRuntimeCallInfo4.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); } @@ -1394,18 +1385,18 @@ TEST_F(BuiltinsArrayTest, LastIndexOf) // 22.1.3.11 new Array().Pop() TEST_F(BuiltinsArrayTest, Pop) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Pop(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Pop(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -1420,12 +1411,12 @@ TEST_F(BuiltinsArrayTest, Pop) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - result = array::proto::Pop(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + result = array::proto::Pop(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); } @@ -1433,11 +1424,11 @@ TEST_F(BuiltinsArrayTest, Pop) // 22.1.3.11 new Array(1,2,3).Push(...items) TEST_F(BuiltinsArrayTest, Push) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1449,18 +1440,18 @@ TEST_F(BuiltinsArrayTest, Push) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(4))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(4))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Push(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Push(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetNumber(), 5); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 5); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 5); JSHandle key3(thread_, JSTaggedValue(3)); EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), key3).GetValue()->GetInt(), 4); JSHandle key4(thread_, JSTaggedValue(4)); @@ -1469,15 +1460,15 @@ TEST_F(BuiltinsArrayTest, Push) TEST_F(BuiltinsArrayTest, Reduce) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -1490,29 +1481,29 @@ TEST_F(BuiltinsArrayTest, Reduce) JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestReduceFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(10))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Reduce(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Reduce(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(16).GetRawData()); } TEST_F(BuiltinsArrayTest, ReduceRight) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -1525,25 +1516,25 @@ TEST_F(BuiltinsArrayTest, ReduceRight) JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestReduceRightFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(10))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::ReduceRight(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::ReduceRight(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(16).GetRawData()); } TEST_F(BuiltinsArrayTest, Shift) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1555,27 +1546,27 @@ TEST_F(BuiltinsArrayTest, Shift) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Shift(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Shift(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } TEST_F(BuiltinsArrayTest, Some) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1587,28 +1578,28 @@ TEST_F(BuiltinsArrayTest, Some) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - JSHandle js_array(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle jsArray(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestSomeFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = array::proto::Some(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = array::proto::Some(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); } TEST_F(BuiltinsArrayTest, Sort) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); @@ -1620,29 +1611,29 @@ TEST_F(BuiltinsArrayTest, Sort) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = array::proto::Sort(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = array::proto::Sort(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result2.IsECMAObject()); - JSHandle result_arr = + JSHandle resultArr = JSHandle(thread_, JSTaggedValue(static_cast(result2.GetRawData()))); - EXPECT_EQ(JSArray::GetProperty(thread_, result_arr, key0).GetValue()->GetInt(), 1); - EXPECT_EQ(JSArray::GetProperty(thread_, result_arr, key1).GetValue()->GetInt(), 2); - EXPECT_EQ(JSArray::GetProperty(thread_, result_arr, key2).GetValue()->GetInt(), 3); + EXPECT_EQ(JSArray::GetProperty(thread_, resultArr, key0).GetValue()->GetInt(), 1); + EXPECT_EQ(JSArray::GetProperty(thread_, resultArr, key1).GetValue()->GetInt(), 2); + EXPECT_EQ(JSArray::GetProperty(thread_, resultArr, key2).GetValue()->GetInt(), 3); } TEST_F(BuiltinsArrayTest, Unshift) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); @@ -1654,19 +1645,19 @@ TEST_F(BuiltinsArrayTest, Unshift) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(3)), true, true, true); JSArray::DefineOwnProperty(thread_, obj, key2, desc2); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(4))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(4))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Unshift(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Unshift(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 5); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 5); JSHandle key3(thread_, JSTaggedValue(0)); EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), key3).GetValue()->GetInt(), 4); JSHandle key4(thread_, JSTaggedValue(1)); @@ -1675,11 +1666,11 @@ TEST_F(BuiltinsArrayTest, Unshift) TEST_F(BuiltinsArrayTest, Join) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(2))); @@ -1692,26 +1683,26 @@ TEST_F(BuiltinsArrayTest, Join) JSArray::DefineOwnProperty(thread_, JSHandle(obj), key2, desc2); JSHandle str = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2,3,4"); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Join(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Join(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); - [[maybe_unused]] auto *res = EcmaString::Cast(result_handle.GetTaggedValue().GetTaggedObject()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto *res = EcmaString::Cast(resultHandle.GetTaggedValue().GetTaggedObject()); ASSERT_EQ(res->Compare(*str), 0); } TEST_F(BuiltinsArrayTest, ToString) { - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 0); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, JSHandle(thread_, JSTaggedValue(2))); @@ -1724,15 +1715,15 @@ TEST_F(BuiltinsArrayTest, ToString) JSArray::DefineOwnProperty(thread_, JSHandle(obj), key2, desc2); JSHandle str = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2,3,4"); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = array::proto::Join(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = array::proto::Join(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); - [[maybe_unused]] auto *res = EcmaString::Cast(result_handle.GetTaggedValue().GetTaggedObject()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto *res = EcmaString::Cast(resultHandle.GetTaggedValue().GetTaggedObject()); ASSERT_EQ(res->Compare(*str), 0); } diff --git a/tests/runtime/builtins/builtins_arraybuffer_test.cpp b/tests/runtime/builtins/builtins_arraybuffer_test.cpp index 0257e5e7d31b4603fe9c8869aa8c1681faa1e70b..1566a8ff46bfa6d9c38f72adc74a0aa3248b6db4 100644 --- a/tests/runtime/builtins/builtins_arraybuffer_test.cpp +++ b/tests/runtime/builtins/builtins_arraybuffer_test.cpp @@ -61,16 +61,16 @@ private: JSTaggedValue CreateBuiltinsArrayBuffer(JSThread *thread, int32_t length) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle array_buffer(thread, env->GetArrayBufferFunction().GetTaggedValue()); - JSHandle global_object(thread, env->GetGlobalObject()); + JSHandle arrayBuffer(thread, env->GetArrayBufferFunction().GetTaggedValue()); + JSHandle globalObject(thread, env->GetGlobalObject()); // 6 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, array_buffer.GetTaggedValue(), 6); - ecma_runtime_call_info->SetFunction(array_buffer.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(length)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, arrayBuffer.GetTaggedValue(), 6); + ecmaRuntimeCallInfo->SetFunction(arrayBuffer.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(length)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecmaRuntimeCallInfo.get()); return result; } @@ -78,15 +78,15 @@ JSTaggedValue CreateBuiltinsArrayBuffer(JSThread *thread, int32_t length) TEST_F(BuiltinsArrayBufferTest, Constructor1) { JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle array_buffer(thread_, env->GetArrayBufferFunction().GetTaggedValue()); - JSHandle global_object(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, array_buffer.GetTaggedValue(), 6); - ecma_runtime_call_info->SetFunction(array_buffer.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(8))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); + JSHandle arrayBuffer(thread_, env->GetArrayBufferFunction().GetTaggedValue()); + JSHandle globalObject(thread_, env->GetGlobalObject()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, arrayBuffer.GetTaggedValue(), 6); + ecmaRuntimeCallInfo->SetFunction(arrayBuffer.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(8))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -94,14 +94,13 @@ TEST_F(BuiltinsArrayBufferTest, Constructor1) TEST_F(BuiltinsArrayBufferTest, byteLength1) { JSTaggedValue tagged = CreateBuiltinsArrayBuffer(thread_, 5); - JSHandle arr_buf(thread_, - JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(arr_buf.GetTaggedValue()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = builtins::array_buffer::proto::GetByteLength(ecma_runtime_call_info.get()); + JSHandle arrBuf(thread_, JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(arrBuf.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = builtins::array_buffer::proto::GetByteLength(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(5).GetRawData()); } @@ -110,24 +109,23 @@ TEST_F(BuiltinsArrayBufferTest, slice1) { // NOLINTNEXTLINE(readability-magic-numbers) JSTaggedValue tagged = CreateBuiltinsArrayBuffer(thread_, 10); - JSHandle arr_buf(thread_, - JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(arr_buf.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(5))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = builtins::array_buffer::proto::Slice(ecma_runtime_call_info.get()); + JSHandle arrBuf(thread_, JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(arrBuf.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(5))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = builtins::array_buffer::proto::Slice(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle arr_buf1(thread_, - JSArrayBuffer::Cast(reinterpret_cast(result1.GetRawData()))); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(arr_buf1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = builtins::array_buffer::proto::GetByteLength(ecma_runtime_call_info1.get()); + JSHandle arrBuf1(thread_, + JSArrayBuffer::Cast(reinterpret_cast(result1.GetRawData()))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(arrBuf1.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = builtins::array_buffer::proto::GetByteLength(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(4).GetRawData()); } diff --git a/tests/runtime/builtins/builtins_bigint_test.cpp b/tests/runtime/builtins/builtins_bigint_test.cpp index 8ce0696da6ed6805c71f5132b8fbfef35493d1a9..0c6c358bb94b82d045024339c49150b2b4ac6a44 100644 --- a/tests/runtime/builtins/builtins_bigint_test.cpp +++ b/tests/runtime/builtins/builtins_bigint_test.cpp @@ -55,7 +55,7 @@ protected: JSThread *thread_ {nullptr}; private: - ecmascript::JSHandle method_function_; + ecmascript::JSHandle methodFunction_; PandaVM *instance_ {nullptr}; EcmaHandleScope *scope_ {nullptr}; }; @@ -63,14 +63,14 @@ private: // new BigInt(123) TEST_F(BuiltinsBigIntTest, BigIntConstructor1) { - JSHandle numeric_value(thread_, JSTaggedValue(123)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = big_int::BigIntConstructor(ecma_runtime_call_info.get()); + JSHandle numericValue(thread_, JSTaggedValue(123)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = big_int::BigIntConstructor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsBigInt()); @@ -80,15 +80,15 @@ TEST_F(BuiltinsBigIntTest, BigIntConstructor1) TEST_F(BuiltinsBigIntTest, BigIntConstructor2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("456"); + JSHandle numericValue = factory->NewFromCanBeCompressString("456"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = big_int::BigIntConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = big_int::BigIntConstructor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsBigInt()); @@ -98,130 +98,130 @@ TEST_F(BuiltinsBigIntTest, BigIntConstructor2) TEST_F(BuiltinsBigIntTest, AsIntN1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("9223372036854775807"); + JSHandle numericValue = factory->NewFromCanBeCompressString("9223372036854775807"); int bit = 64; // 64-bit - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(bit))); - ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); + ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = big_int::AsIntN(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = big_int::AsIntN(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsBigInt()); - JSHandle big_int_handle(thread_, result); - JSHandle result_str = BigInt::ToString(thread_, big_int_handle); + JSHandle bigIntHandle(thread_, result); + JSHandle resultStr = BigInt::ToString(thread_, bigIntHandle); JSHandle str = factory->NewFromCanBeCompressString("9223372036854775807"); - EXPECT_EQ(result_str->Compare(*str), 0); + EXPECT_EQ(resultStr->Compare(*str), 0); } // AsIntN(64, (2 ^ 63)) TEST_F(BuiltinsBigIntTest, AsIntN2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("9223372036854775808"); + JSHandle numericValue = factory->NewFromCanBeCompressString("9223372036854775808"); int bit = 64; // 64-bit - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(bit))); - ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); + ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = big_int::AsIntN(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = big_int::AsIntN(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsBigInt()); - JSHandle big_int_handle(thread_, result); - JSHandle result_str = BigInt::ToString(thread_, big_int_handle); + JSHandle bigIntHandle(thread_, result); + JSHandle resultStr = BigInt::ToString(thread_, bigIntHandle); JSHandle str = factory->NewFromCanBeCompressString("-9223372036854775808"); - EXPECT_EQ(result_str->Compare(*str), 0); + EXPECT_EQ(resultStr->Compare(*str), 0); } // AsUintN(64, (2 ^ 64 - 1)) TEST_F(BuiltinsBigIntTest, AsUintN1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("18446744073709551615"); + JSHandle numericValue = factory->NewFromCanBeCompressString("18446744073709551615"); int bit = 64; // 64-bit - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(bit))); - ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); + ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = big_int::AsUintN(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = big_int::AsUintN(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsBigInt()); - JSHandle big_int_handle(thread_, result); - JSHandle result_str = BigInt::ToString(thread_, big_int_handle); + JSHandle bigIntHandle(thread_, result); + JSHandle resultStr = BigInt::ToString(thread_, bigIntHandle); JSHandle str = factory->NewFromCanBeCompressString("18446744073709551615"); - EXPECT_EQ(result_str->Compare(*str), 0); + EXPECT_EQ(resultStr->Compare(*str), 0); } // AsUintN(64, (2 ^ 64)) TEST_F(BuiltinsBigIntTest, AsUintN2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("18446744073709551616"); + JSHandle numericValue = factory->NewFromCanBeCompressString("18446744073709551616"); int bit = 64; // 64-bit - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(bit))); - ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); + ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = big_int::AsUintN(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = big_int::AsUintN(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsBigInt()); - JSHandle big_int_handle(thread_, result); - JSHandle result_str = BigInt::ToString(thread_, big_int_handle); + JSHandle bigIntHandle(thread_, result); + JSHandle resultStr = BigInt::ToString(thread_, bigIntHandle); JSHandle str = factory->NewFromCanBeCompressString("0"); - EXPECT_EQ(result_str->Compare(*str), 0); + EXPECT_EQ(resultStr->Compare(*str), 0); } // using locale TEST_F(BuiltinsBigIntTest, ToLocaleString1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("123456789123456789"); + JSHandle numericValue = factory->NewFromCanBeCompressString("123456789123456789"); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); + JSHandle bigIntHandle(thread_, result1); JSHandle locale = factory->NewFromCanBeCompressString("de-DE"); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, locale.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, locale.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ToLocaleString(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ToLocaleString(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result2.IsString()); - JSHandle ecma_str_handle(thread_, result2); - JSHandle result_str = factory->NewFromCanBeCompressString("123.456.789.123.456.789"); - EXPECT_EQ(ecma_str_handle->Compare(*result_str), 0); + JSHandle ecmaStrHandle(thread_, result2); + JSHandle resultStr = factory->NewFromCanBeCompressString("123.456.789.123.456.789"); + EXPECT_EQ(ecmaStrHandle->Compare(*resultStr), 0); } // using locale and options @@ -229,186 +229,186 @@ TEST_F(BuiltinsBigIntTest, ToLocaleString2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle obj_fun = env->GetObjectFunction(); - JSHandle options_obj = factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle numeric_value = factory->NewFromCanBeCompressString("123456789123456789"); - JSHandle format_style = thread_->GlobalConstants()->GetHandledStyleString(); - JSHandle style_key(factory->NewFromCanBeCompressString("currency")); - JSHandle style_value(factory->NewFromCanBeCompressString("EUR")); - - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); + JSHandle objFun = env->GetObjectFunction(); + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle numericValue = factory->NewFromCanBeCompressString("123456789123456789"); + JSHandle formatStyle = thread_->GlobalConstants()->GetHandledStyleString(); + JSHandle styleKey(factory->NewFromCanBeCompressString("currency")); + JSHandle styleValue(factory->NewFromCanBeCompressString("EUR")); + + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); + JSHandle bigIntHandle(thread_, result1); JSHandle locale = factory->NewFromCanBeCompressString("de-DE"); - JSObject::SetProperty(thread_, options_obj, format_style, style_key); - JSObject::SetProperty(thread_, options_obj, style_key, style_value); + JSObject::SetProperty(thread_, optionsObj, formatStyle, styleKey); + JSObject::SetProperty(thread_, optionsObj, styleKey, styleValue); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, locale.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(1, options_obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, locale.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(1, optionsObj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ToLocaleString(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ToLocaleString(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result2.IsString()); - JSHandle ecma_str_handle(thread_, result2); - EXPECT_STREQ("123.456.789.123.456.789,00 €", PandaString(ecma_str_handle->GetCString().get()).c_str()); + JSHandle ecmaStrHandle(thread_, result2); + EXPECT_STREQ("123.456.789.123.456.789,00 €", PandaString(ecmaStrHandle->GetCString().get()).c_str()); } // 17.ToStirng() TEST_F(BuiltinsBigIntTest, ToString1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("17"); + JSHandle numericValue = factory->NewFromCanBeCompressString("17"); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue::Undefined()); + JSHandle bigIntHandle(thread_, result1); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result2.IsString()); - JSHandle ecma_str_handle(thread_, result2); - EXPECT_STREQ("17", PandaString(ecma_str_handle->GetCString().get()).c_str()); + JSHandle ecmaStrHandle(thread_, result2); + EXPECT_STREQ("17", PandaString(ecmaStrHandle->GetCString().get()).c_str()); } // -0.ToStirng() TEST_F(BuiltinsBigIntTest, ToString2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("-0"); + JSHandle numericValue = factory->NewFromCanBeCompressString("-0"); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue::Undefined()); + JSHandle bigIntHandle(thread_, result1); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result2.IsString()); - JSHandle ecma_str_handle(thread_, result2); - EXPECT_STREQ("0", PandaString(ecma_str_handle->GetCString().get()).c_str()); + JSHandle ecmaStrHandle(thread_, result2); + EXPECT_STREQ("0", PandaString(ecmaStrHandle->GetCString().get()).c_str()); } // -10.ToStirng(2) TEST_F(BuiltinsBigIntTest, ToString3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("-10"); + JSHandle numericValue = factory->NewFromCanBeCompressString("-10"); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); + JSHandle bigIntHandle(thread_, result1); JSHandle radix(thread_, JSTaggedValue(2)); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, radix.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, radix.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result2.IsString()); - JSHandle ecma_str_handle(thread_, result2); - EXPECT_STREQ("-1010", PandaString(ecma_str_handle->GetCString().get()).c_str()); + JSHandle ecmaStrHandle(thread_, result2); + EXPECT_STREQ("-1010", PandaString(ecmaStrHandle->GetCString().get()).c_str()); } // 254.ToStirng(16) TEST_F(BuiltinsBigIntTest, ToString4) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("254"); + JSHandle numericValue = factory->NewFromCanBeCompressString("254"); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); + JSHandle bigIntHandle(thread_, result1); JSHandle radix(thread_, JSTaggedValue(16)); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, radix.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, radix.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result2.IsString()); - JSHandle ecma_str_handle(thread_, result2); - EXPECT_STREQ("fe", PandaString(ecma_str_handle->GetCString().get()).c_str()); + JSHandle ecmaStrHandle(thread_, result2); + EXPECT_STREQ("fe", PandaString(ecmaStrHandle->GetCString().get()).c_str()); } // BigInt.ValueOf TEST_F(BuiltinsBigIntTest, ValueOf1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("-65536"); + JSHandle numericValue = factory->NewFromCanBeCompressString("-65536"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); + JSHandle bigIntHandle(thread_, result1); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ValueOf(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ValueOf(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_EQ(BigInt::SameValue(thread_, result1, result2), true); @@ -418,31 +418,30 @@ TEST_F(BuiltinsBigIntTest, ValueOf1) TEST_F(BuiltinsBigIntTest, ValueOf2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle numeric_value = factory->NewFromCanBeCompressString("65535"); + JSHandle numericValue = factory->NewFromCanBeCompressString("65535"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle big_int_handle(thread_, result1); - JSHandle big_int_obj(big_int_handle); + JSHandle bigIntHandle(thread_, result1); + JSHandle bigIntObj(bigIntHandle); - JSHandle js_primitive_ref = - factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_BIGINT, big_int_obj); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(js_primitive_ref.GetTaggedValue()); + JSHandle jsPrimitiveRef = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_BIGINT, bigIntObj); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(jsPrimitiveRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = big_int::proto::ValueOf(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = big_int::proto::ValueOf(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); - EXPECT_EQ(BigInt::SameValue(thread_, big_int_handle.GetTaggedValue(), result2), true); + EXPECT_EQ(BigInt::SameValue(thread_, bigIntHandle.GetTaggedValue(), result2), true); } // testcases of NumberToBigint() @@ -454,27 +453,27 @@ TEST_F(BuiltinsBigIntTest, NumberToBigint) number = JSHandle(thread_, JSTaggedValue(base::MAX_VALUE)); bigint = JSHandle(thread_, BigInt::NumberToBigInt(thread_, number)); ASSERT_TRUE(bigint->IsBigInt()); - bool compare_res = JSTaggedValue::Equal(thread_, number, bigint); - ASSERT_TRUE(compare_res); + bool compareRes = JSTaggedValue::Equal(thread_, number, bigint); + ASSERT_TRUE(compareRes); number = JSHandle(thread_, JSTaggedValue(-base::MAX_VALUE)); bigint = JSHandle(thread_, BigInt::NumberToBigInt(thread_, number)); ASSERT_TRUE(bigint->IsBigInt()); - compare_res = JSTaggedValue::Equal(thread_, number, bigint); + compareRes = JSTaggedValue::Equal(thread_, number, bigint); ASSERT_TRUE(JSHandle::Cast(bigint)->GetSign()); - ASSERT_TRUE(compare_res); + ASSERT_TRUE(compareRes); number = JSHandle(thread_, JSTaggedValue(-0xffffffff)); bigint = JSHandle(thread_, BigInt::NumberToBigInt(thread_, number)); ASSERT_TRUE(bigint->IsBigInt()); - compare_res = JSTaggedValue::Equal(thread_, number, bigint); - ASSERT_TRUE(compare_res); + compareRes = JSTaggedValue::Equal(thread_, number, bigint); + ASSERT_TRUE(compareRes); number = JSHandle(thread_, JSTaggedValue(0)); bigint = JSHandle(thread_, BigInt::NumberToBigInt(thread_, number)); ASSERT_TRUE(bigint->IsBigInt()); - compare_res = JSTaggedValue::Equal(thread_, number, bigint); - ASSERT_TRUE(compare_res); + compareRes = JSTaggedValue::Equal(thread_, number, bigint); + ASSERT_TRUE(compareRes); } // testcases of BigintToNumber() @@ -594,22 +593,22 @@ TEST_F(BuiltinsBigIntTest, StringToBigInt) bigint = JSHandle(thread_, base::NumberHelper::StringToBigInt(thread_, parma)); ASSERT_TRUE(bigint->IsBigInt()); JSHandle number(thread_, JSTaggedValue(static_cast(123))); - bool compare_res = JSTaggedValue::Equal(thread_, bigint, number); - ASSERT_TRUE(compare_res); + bool compareRes = JSTaggedValue::Equal(thread_, bigint, number); + ASSERT_TRUE(compareRes); parma = JSHandle(factory->NewFromCanBeCompressString("123 ")); bigint = JSHandle(thread_, base::NumberHelper::StringToBigInt(thread_, parma)); ASSERT_TRUE(bigint->IsBigInt()); number = JSHandle(thread_, JSTaggedValue(static_cast(123))); - compare_res = JSTaggedValue::Equal(thread_, bigint, number); - ASSERT_TRUE(compare_res); + compareRes = JSTaggedValue::Equal(thread_, bigint, number); + ASSERT_TRUE(compareRes); parma = JSHandle(factory->NewFromCanBeCompressString(" 123")); bigint = JSHandle(thread_, base::NumberHelper::StringToBigInt(thread_, parma)); ASSERT_TRUE(bigint->IsBigInt()); number = JSHandle(thread_, JSTaggedValue(static_cast(123))); - compare_res = JSTaggedValue::Equal(thread_, bigint, number); - ASSERT_TRUE(compare_res); + compareRes = JSTaggedValue::Equal(thread_, bigint, number); + ASSERT_TRUE(compareRes); parma = JSHandle(factory->NewFromCanBeCompressString("")); bigint = JSHandle(thread_, base::NumberHelper::StringToBigInt(thread_, parma)); diff --git a/tests/runtime/builtins/builtins_boolean_test.cpp b/tests/runtime/builtins/builtins_boolean_test.cpp index 4c20d1bd8b60f37cb3abeefd771de0f7f7407b74..144abf14e5886626b29a303422398a9620c4b943 100644 --- a/tests/runtime/builtins/builtins_boolean_test.cpp +++ b/tests/runtime/builtins/builtins_boolean_test.cpp @@ -67,16 +67,16 @@ TEST_F(BuiltinsBooleanTest, BooleanConstructor) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle boolean(env->GetBooleanFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*boolean), 6); - ecma_runtime_call_info->SetFunction(boolean.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*boolean), 6); + ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); // NOLINTNEXTLINE(readability-magic-numbers) - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(123))); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsTrue(), 1); @@ -88,15 +88,15 @@ TEST_F(BuiltinsBooleanTest, BooleanConstructor1) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle boolean(env->GetBooleanFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*boolean), 6); - ecma_runtime_call_info->SetFunction(boolean.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*boolean), 6); + ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsFalse(), 1); @@ -108,16 +108,16 @@ TEST_F(BuiltinsBooleanTest, BooleanConstructor2) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle boolean(env->GetBooleanFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); JSHandle str = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("helloworld"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(boolean.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); JSTaggedValue ruler = builtins_common::GetTaggedBoolean(true); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); @@ -126,12 +126,12 @@ TEST_F(BuiltinsBooleanTest, BooleanConstructor2) // false.toString() TEST_F(BuiltinsBooleanTest, BooleanPrototypeToString) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = boolean::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = boolean::proto::ToString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); auto ruler = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("false"); @@ -141,19 +141,19 @@ TEST_F(BuiltinsBooleanTest, BooleanPrototypeToString) // (new Boolean(true)).toString() TEST_F(BuiltinsBooleanTest, BooleanPrototypeToString1) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle boolean_object(env->GetBooleanFunction()); + JSHandle booleanObject(env->GetBooleanFunction()); JSHandle value(thread_, JSTaggedValue::True()); - JSHandle boolean = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(boolean_object, value); + JSHandle boolean = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(booleanObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(boolean.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(boolean.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = boolean::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = boolean::proto::ToString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); auto ruler = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("true"); @@ -163,12 +163,12 @@ TEST_F(BuiltinsBooleanTest, BooleanPrototypeToString1) // true.valueOf() TEST_F(BuiltinsBooleanTest, BooleanPrototypeValueOf) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = boolean::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = boolean::proto::ValueOf(ecmaRuntimeCallInfo.get()); JSTaggedValue ruler = builtins_common::GetTaggedBoolean(true); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); @@ -177,19 +177,19 @@ TEST_F(BuiltinsBooleanTest, BooleanPrototypeValueOf) // (new Boolean(false)).valueOf() TEST_F(BuiltinsBooleanTest, BooleanPrototypeValueOf1) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle boolean_object(env->GetBooleanFunction()); + JSHandle booleanObject(env->GetBooleanFunction()); JSHandle value(thread_, JSTaggedValue::False()); - JSHandle boolean = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(boolean_object, value); + JSHandle boolean = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(booleanObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(boolean.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(boolean.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = boolean::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = boolean::proto::ValueOf(ecmaRuntimeCallInfo.get()); JSTaggedValue ruler = builtins_common::GetTaggedBoolean(false); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); diff --git a/tests/runtime/builtins/builtins_dataview_test.cpp b/tests/runtime/builtins/builtins_dataview_test.cpp index b8577dfebb1f03b24e327be6e17d7d9627548b72..4a4d29bd9805bbcbe8444f1f382bd809b95b6e58 100644 --- a/tests/runtime/builtins/builtins_dataview_test.cpp +++ b/tests/runtime/builtins/builtins_dataview_test.cpp @@ -66,67 +66,66 @@ private: JSTaggedValue CreateBuiltinsArrayBuffer(JSThread *thread, int32_t length) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle array_buffer(thread, env->GetArrayBufferFunction().GetTaggedValue()); - JSHandle global_object(thread, env->GetGlobalObject()); + JSHandle arrayBuffer(thread, env->GetArrayBufferFunction().GetTaggedValue()); + JSHandle globalObject(thread, env->GetGlobalObject()); // 6 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*array_buffer), 6); - ecma_runtime_call_info->SetFunction(array_buffer.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(length)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*arrayBuffer), 6); + ecmaRuntimeCallInfo->SetFunction(arrayBuffer.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(length)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecmaRuntimeCallInfo.get()); return result; } -JSTaggedValue CreateBuiltinsDataView(JSThread *thread, int32_t length, int32_t byte_offset) +JSTaggedValue CreateBuiltinsDataView(JSThread *thread, int32_t length, int32_t byteOffset) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle data_view(thread, env->GetDataViewFunction().GetTaggedValue()); - JSHandle global_object(thread, env->GetGlobalObject()); + JSHandle dataView(thread, env->GetDataViewFunction().GetTaggedValue()); + JSHandle globalObject(thread, env->GetGlobalObject()); JSTaggedValue tagged = CreateBuiltinsArrayBuffer(thread, length); - JSHandle arr_buf(thread, JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); + JSHandle arrBuf(thread, JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); // 8 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*data_view), 8); - ecma_runtime_call_info->SetFunction(data_view.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, arr_buf.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(byte_offset)); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::DataViewConstructor(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*dataView), 8); + ecmaRuntimeCallInfo->SetFunction(dataView.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, arrBuf.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(byteOffset)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::DataViewConstructor(ecmaRuntimeCallInfo.get()); return result; } void SetUint8(JSThread *thread, const JSHandle &view, int32_t offset, JSTaggedValue value) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(offset)); - ecma_runtime_call_info->SetCallArg(1, value); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - data_view::proto::SetUint8(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(offset)); + ecmaRuntimeCallInfo->SetCallArg(1, value); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + data_view::proto::SetUint8(ecmaRuntimeCallInfo.get()); } // new DataView(new ArrayBuffer(10), 1) TEST_F(BuiltinsDataViewTest, Constructor) { JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle data_view(thread_, env->GetDataViewFunction().GetTaggedValue()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle dataView(thread_, env->GetDataViewFunction().GetTaggedValue()); + JSHandle globalObject(thread_, env->GetGlobalObject()); JSTaggedValue tagged = CreateBuiltinsArrayBuffer(thread_, 10); - JSHandle arr_buf(thread_, - JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*data_view), 8); - ecma_runtime_call_info->SetFunction(data_view.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, arr_buf.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(1)); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::DataViewConstructor(ecma_runtime_call_info.get()); + JSHandle arrBuf(thread_, JSArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*dataView), 8); + ecmaRuntimeCallInfo->SetFunction(dataView.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, arrBuf.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(1)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::DataViewConstructor(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -135,12 +134,12 @@ TEST_F(BuiltinsDataViewTest, byteOffset) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 10, 1); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetByteOffset(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetByteOffset(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -149,12 +148,12 @@ TEST_F(BuiltinsDataViewTest, byteLength) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 10, 2); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetByteLength(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetByteLength(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(8).GetRawData()); } @@ -163,12 +162,12 @@ TEST_F(BuiltinsDataViewTest, buffer) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 10, 1); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetBuffer(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetBuffer(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.IsArrayBuffer(), true); } @@ -177,24 +176,24 @@ TEST_F(BuiltinsDataViewTest, getUint16) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 8, 0); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-1870724872)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::False()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::SetUint16(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1870724872)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::False()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::SetUint16(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::True()); - JSTaggedValue result1 = data_view::proto::GetUint16(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetUint16(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(63488).GetRawData()); } @@ -203,24 +202,24 @@ TEST_F(BuiltinsDataViewTest, getInt16) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 8, 0); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-1870724872)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::False()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::SetInt16(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1870724872)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::False()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::SetInt16(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::True()); - JSTaggedValue result1 = data_view::proto::GetInt16(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetInt16(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(-2048).GetRawData()); } @@ -234,14 +233,14 @@ TEST_F(BuiltinsDataViewTest, GetUint32) SetUint8(thread_, view, 2, JSTaggedValue(255)); SetUint8(thread_, view, 3, JSTaggedValue(255)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetUint32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetUint32(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(2147483647).GetRawData()); } @@ -255,14 +254,14 @@ TEST_F(BuiltinsDataViewTest, GetInt32) SetUint8(thread_, view, 2, JSTaggedValue(255)); SetUint8(thread_, view, 3, JSTaggedValue(255)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetInt32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetInt32(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(2147483647).GetRawData()); } @@ -273,13 +272,13 @@ TEST_F(BuiltinsDataViewTest, GetInt8) JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); SetUint8(thread_, view, 0, JSTaggedValue(255)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetInt8(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetInt8(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -290,13 +289,13 @@ TEST_F(BuiltinsDataViewTest, GetUint8) JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); SetUint8(thread_, view, 0, JSTaggedValue(127)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetUint8(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetUint8(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(127).GetRawData()); } @@ -310,14 +309,14 @@ TEST_F(BuiltinsDataViewTest, GetFloat32) SetUint8(thread_, view, 6, JSTaggedValue(75)); SetUint8(thread_, view, 7, JSTaggedValue(75)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(4)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(4)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetFloat32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetFloat32(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(13323083)).GetRawData()); } @@ -335,14 +334,14 @@ TEST_F(BuiltinsDataViewTest, GetFloat64) SetUint8(thread_, view, 10, JSTaggedValue(68)); SetUint8(thread_, view, 11, JSTaggedValue(68)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(4)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(4)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::GetFloat64(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::GetFloat64(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(10846169068898440)).GetRawData()); } @@ -351,24 +350,24 @@ TEST_F(BuiltinsDataViewTest, SetUint32) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 8, 0); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(0x907f00f8)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::SetUint32(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(0x907f00f8)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::SetUint32(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = data_view::proto::GetUint32(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetUint32(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(0xf8007f90)).GetRawData()); } @@ -377,24 +376,24 @@ TEST_F(BuiltinsDataViewTest, SetInt32) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 8, 0); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-1870724872)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::SetInt32(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1870724872)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::SetInt32(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = data_view::proto::GetInt32(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetInt32(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(-134185072).GetRawData()); } @@ -403,20 +402,20 @@ TEST_F(BuiltinsDataViewTest, SetInt8) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 8, 0); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::SetInt8(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1)); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::SetInt8(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - JSTaggedValue result1 = data_view::proto::GetUint8(ecma_runtime_call_info1.get()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); + JSTaggedValue result1 = data_view::proto::GetUint8(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(255).GetRawData()); } @@ -425,24 +424,24 @@ TEST_F(BuiltinsDataViewTest, SetFloat32) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 4, 0); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(42)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::SetFloat32(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(42)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::SetFloat32(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = data_view::proto::GetFloat32(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetFloat32(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1.4441781973331565e-41)).GetRawData()); } @@ -451,24 +450,24 @@ TEST_F(BuiltinsDataViewTest, SetFloat64) { JSTaggedValue tagged = CreateBuiltinsDataView(thread_, 8, 0); JSHandle view(thread_, JSDataView::Cast(reinterpret_cast(tagged.GetRawData()))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(42)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = data_view::proto::SetFloat64(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(42)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = data_view::proto::SetFloat64(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = data_view::proto::GetFloat64(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetFloat64(ecmaRuntimeCallInfo1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(8.759e-320)).GetRawData()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_date_test.cpp b/tests/runtime/builtins/builtins_date_test.cpp index df02e021e23660c619a521e179b26ee016815a0a..6cb5fc3c5048e6adce0c0753c94bcc6c0bde4c6c 100644 --- a/tests/runtime/builtins/builtins_date_test.cpp +++ b/tests/runtime/builtins/builtins_date_test.cpp @@ -71,546 +71,545 @@ private: JSHandle JSDateCreateTest(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle date_function = global_env->GetDateFunction(); - JSHandle date_object = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(date_function), date_function)); - return date_object; + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle dateFunction = globalEnv->GetDateFunction(); + JSHandle dateObject = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(dateFunction), dateFunction)); + return dateObject; } -static std::unique_ptr CreateAndSetRuntimeCallInfo(JSThread *thread, ArraySizeT argv_length, - JSTaggedValue this_value) +static std::unique_ptr CreateAndSetRuntimeCallInfo(JSThread *thread, ArraySizeT argvLength, + JSTaggedValue thisValue) { - auto ecma_runtime_call_info = - TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), argv_length); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_value); - return ecma_runtime_call_info; + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), argvLength); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisValue); + return ecmaRuntimeCallInfo; } TEST_F(BuiltinsDateTest, SetGetDate) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 6, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 6, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - [[maybe_unused]] JSTaggedValue result1 = date::proto::SetDate(ecma_runtime_call_info.get()); - JSTaggedValue result2 = date::proto::GetDate(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] JSTaggedValue result1 = date::proto::SetDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = date::proto::GetDate(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetUTCDate) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 6, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 6, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - [[maybe_unused]] JSTaggedValue result3 = date::proto::SetUTCDate(ecma_runtime_call_info.get()); - JSTaggedValue result4 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] JSTaggedValue result3 = date::proto::SetUTCDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = date::proto::GetUTCDate(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMinusUTCDate) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 6, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-2))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 6, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - [[maybe_unused]] JSTaggedValue result3 = date::proto::SetUTCDate(ecma_runtime_call_info.get()); - JSTaggedValue result4 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] JSTaggedValue result3 = date::proto::SetUTCDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = date::proto::GetUTCDate(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(29)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetFullYear) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 10, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 10, jsDate.GetTaggedValue()); // 2018 : test case - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2018))); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2018))); // 10 : test case - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(10))); // 2, 6 : test case - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::GetFullYear(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetFullYear(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::GetFullYear(ecmaRuntimeCallInfo.get()); // 2018 : test case ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result2 = date::proto::GetMonth(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMonth(ecmaRuntimeCallInfo.get()); // 10 : test case ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result3 = date::proto::GetDate(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetDate(ecmaRuntimeCallInfo.get()); // 6 : test case ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetUTCFullYear) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 10, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 10, jsDate.GetTaggedValue()); // 2018 : test case - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2018))); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2018))); // 10 : test case - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(10))); // 2, 6 : test case - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetUTCFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result4 = date::proto::GetUTCFullYear(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetUTCFullYear(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = date::proto::GetUTCFullYear(ecmaRuntimeCallInfo.get()); // 2018 : test case ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result5 = date::proto::GetUTCMonth(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCMonth(ecmaRuntimeCallInfo.get()); // 10 : test case ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result6 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCDate(ecmaRuntimeCallInfo.get()); // 6 : test case ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMinusFullYear) { - JSHandle js_date = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 10, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-2018))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-10))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(-6))); + JSHandle jsDate = JSDateCreateTest(thread_); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 10, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-2018))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-10))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::GetFullYear(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetFullYear(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::GetFullYear(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-2019)).GetRawData()); - JSTaggedValue result2 = date::proto::GetMonth(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMonth(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(1)).GetRawData()); - JSTaggedValue result3 = date::proto::GetDate(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetDate(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(22)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMinusUTCFullYear) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 10, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-2018))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-10))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(-6))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 10, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-2018))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-10))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetUTCFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result4 = date::proto::GetUTCFullYear(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetUTCFullYear(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = date::proto::GetUTCFullYear(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(-2019)).GetRawData()); - JSTaggedValue result5 = date::proto::GetUTCMonth(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCMonth(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(1)).GetRawData()); - JSTaggedValue result6 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCDate(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(22)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetHours) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 12, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(18))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(10))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); - ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(111))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 12, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(18))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetHours(ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::GetHours(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetHours(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::GetHours(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(18)).GetRawData()); - JSTaggedValue result2 = date::proto::GetMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMinutes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result3 = date::proto::GetSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result4 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetUTCHours) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 12, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(18))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(10))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); - ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(111))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 12, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(18))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetUTCHours(ecma_runtime_call_info.get()); - JSTaggedValue result5 = date::proto::GetUTCHours(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetUTCHours(ecmaRuntimeCallInfo.get()); + JSTaggedValue result5 = date::proto::GetUTCHours(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(18)).GetRawData()); - JSTaggedValue result6 = date::proto::GetUTCMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCMinutes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result7 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result7 = date::proto::GetUTCSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result8 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result8 = date::proto::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result8.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMinusHours) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 12, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-18))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-10))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(-6))); - ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(-111))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 12, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-18))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-10))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); + ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(-111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetHours(ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::GetHours(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetHours(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::GetHours(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); - JSTaggedValue result2 = date::proto::GetMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMinutes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(49)).GetRawData()); - JSTaggedValue result3 = date::proto::GetSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(53)).GetRawData()); - JSTaggedValue result4 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(889)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMinusUTCHours) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 12, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-18))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-10))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(-6))); - ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(-111))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 12, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-18))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-10))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); + ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(-111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetUTCHours(ecma_runtime_call_info.get()); - JSTaggedValue result5 = date::proto::GetUTCHours(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetUTCHours(ecmaRuntimeCallInfo.get()); + JSTaggedValue result5 = date::proto::GetUTCHours(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); - JSTaggedValue result6 = date::proto::GetUTCMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCMinutes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(49)).GetRawData()); - JSTaggedValue result7 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result7 = date::proto::GetUTCSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(53)).GetRawData()); - JSTaggedValue result8 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result8 = date::proto::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result8.GetRawData(), JSTaggedValue(static_cast(889)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMilliseconds) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 6, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(100))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 6, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(100))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::SetMilliseconds(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::SetMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); - JSTaggedValue result2 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetUTCMilliseconds) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 6, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(100))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 6, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(100))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result3 = date::proto::SetUTCMilliseconds(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = date::proto::SetUTCMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); - JSTaggedValue result4 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMinutes) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 10, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(6))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(111))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 10, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetMinutes(ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::GetMinutes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetMinutes(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::GetMinutes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result2 = date::proto::GetSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result3 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetUTCMinutes) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 10, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(6))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(111))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 10, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetUTCMinutes(ecma_runtime_call_info.get()); - JSTaggedValue result4 = date::proto::GetUTCMinutes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetUTCMinutes(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = date::proto::GetUTCMinutes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result5 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result6 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetMonth) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 8, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(8))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 8, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(8))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetMonth(ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::GetMonth(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetMonth(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::GetMonth(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(8)).GetRawData()); - JSTaggedValue result2 = date::proto::GetDate(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetDate(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(3)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetUTCMonth) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 8, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(8))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 8, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(8))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetUTCMonth(ecma_runtime_call_info.get()); - JSTaggedValue result3 = date::proto::GetUTCMonth(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetUTCMonth(ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = date::proto::GetUTCMonth(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(8)).GetRawData()); - JSTaggedValue result4 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCDate(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(3)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetSeconds) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 8, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(59))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(123))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 8, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(59))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetSeconds(ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::GetSeconds(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::GetSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(59)).GetRawData()); - JSTaggedValue result2 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(123)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetUTCSeconds) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 8, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(59))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(123))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 8, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(59))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - date::proto::SetUTCSeconds(ecma_runtime_call_info.get()); - JSTaggedValue result3 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + date::proto::SetUTCSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = date::proto::GetUTCSeconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(59)).GetRawData()); - JSTaggedValue result4 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(123)).GetRawData()); } TEST_F(BuiltinsDateTest, SetGetTime) { - JSHandle js_date = JSDateCreateTest(thread_); + JSHandle jsDate = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 6, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 6, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::SetTime(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::SetTime(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); - JSTaggedValue result2 = date::proto::GetTime(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetTime(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } TEST_F(BuiltinsDateTest, UTC) { - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 12, JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(2020.982)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(10.23)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(4.32)); - ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(11.32)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 12, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(2020.982)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10.23)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(4.32)); + ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(11.32)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::UTC(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::UTC(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604487600000)).GetRawData()); - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread_, 18, JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(2020.982)); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(10.23)); - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(4.32)); - ecma_runtime_call_info1->SetCallArg(3, JSTaggedValue(11.32)); - ecma_runtime_call_info1->SetCallArg(4, JSTaggedValue(45.1)); - ecma_runtime_call_info1->SetCallArg(5, JSTaggedValue(34.321)); - ecma_runtime_call_info1->SetCallArg(6, JSTaggedValue(static_cast(231))); - - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - result1 = date::UTC(ecma_runtime_call_info1.get()); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread_, 18, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(2020.982)); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(10.23)); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(4.32)); + ecmaRuntimeCallInfo1->SetCallArg(3, JSTaggedValue(11.32)); + ecmaRuntimeCallInfo1->SetCallArg(4, JSTaggedValue(45.1)); + ecmaRuntimeCallInfo1->SetCallArg(5, JSTaggedValue(34.321)); + ecmaRuntimeCallInfo1->SetCallArg(6, JSTaggedValue(static_cast(231))); + + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + result1 = date::UTC(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604490334231)).GetRawData()); - auto ecma_runtime_call_info2 = CreateAndSetRuntimeCallInfo(thread_, 10, JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue(10.23)); - ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue(4.32)); - ecma_runtime_call_info2->SetCallArg(2, JSTaggedValue(11.32)); + auto ecmaRuntimeCallInfo2 = CreateAndSetRuntimeCallInfo(thread_, 10, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(10.23)); + ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue(4.32)); + ecmaRuntimeCallInfo2->SetCallArg(2, JSTaggedValue(11.32)); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - result1 = date::UTC(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + result1 = date::UTC(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-1882224000000)).GetRawData()); - auto ecma_runtime_call_info3 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info3->SetCallArg(0, JSTaggedValue(1994.982)); + auto ecmaRuntimeCallInfo3 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(1994.982)); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - result1 = date::UTC(ecma_runtime_call_info3.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + result1 = date::UTC(ecmaRuntimeCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(757382400000)).GetRawData()); - auto ecma_runtime_call_info4 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info4->SetCallArg(0, JSTaggedValue(19999944.982)); + auto ecmaRuntimeCallInfo4 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(19999944.982)); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - result1 = date::UTC(ecma_runtime_call_info4.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + result1 = date::UTC(ecmaRuntimeCallInfo4.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(base::NAN_VALUE)).GetRawData()); } -void SetAllYearAndHours(JSThread *thread, const JSHandle &js_date) +void SetAllYearAndHours(JSThread *thread, const JSHandle &jsDate) { - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 10, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread, 10, jsDate.GetTaggedValue()); // 2018 : test case - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2018))); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2018))); // 10 : test case - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(10))); // 2, 6 : test case - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - date::proto::SetFullYear(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + date::proto::SetFullYear(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread, prev); - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread, 12, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread, 12, jsDate.GetTaggedValue()); // 18 : test case - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(18))); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(18))); // 10 : test case - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(10))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(10))); // 2, 6 : test case - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(6))); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(6))); // 3, 111 : test case - ecma_runtime_call_info1->SetCallArg(3, JSTaggedValue(static_cast(111))); + ecmaRuntimeCallInfo1->SetCallArg(3, JSTaggedValue(static_cast(111))); - prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - date::proto::SetHours(ecma_runtime_call_info1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); + date::proto::SetHours(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread, prev); } -void SetAll1(JSThread *thread, const JSHandle &js_date) +void SetAll1(JSThread *thread, const JSHandle &jsDate) { - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 10, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread, 10, jsDate.GetTaggedValue()); // 1900 : test case - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1900))); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1900))); // 11 : test case - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(11))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(11))); // 2, 31 : test case - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(31))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(31))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - date::proto::SetFullYear(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + date::proto::SetFullYear(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread, prev); - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread, 12, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread, 12, jsDate.GetTaggedValue()); // 23 : test case - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(23))); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(23))); // 54 : test case - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(54))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(54))); // 2, 16 : test case - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(16))); + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(16))); // 3, 888 : test case - ecma_runtime_call_info1->SetCallArg(3, JSTaggedValue(static_cast(888))); + ecmaRuntimeCallInfo1->SetCallArg(3, JSTaggedValue(static_cast(888))); - prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - date::proto::SetHours(ecma_runtime_call_info1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); + date::proto::SetHours(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread, prev); } -void SetAll2(JSThread *thread, const JSHandle &js_date) +void SetAll2(JSThread *thread, const JSHandle &jsDate) { - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 10, js_date.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1901))); // 1901 : test case - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(1))); // 2 : test case + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread, 10, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1901))); // 1901 : test case + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(1))); // 2 : test case - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - date::proto::SetFullYear(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + date::proto::SetFullYear(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread, prev); // 12 : test case - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread, 12, js_date.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(0))); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(3))); // 3 : test case - ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(21))); // 2, 21 : test case - ecma_runtime_call_info1->SetCallArg(3, JSTaggedValue(static_cast(129))); // 3, 129 : test case - - prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - date::proto::SetHours(ecma_runtime_call_info1.get()); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread, 12, jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(0))); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(3))); // 3 : test case + ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(21))); // 2, 21 : test case + ecmaRuntimeCallInfo1->SetCallArg(3, JSTaggedValue(static_cast(129))); // 3, 129 : test case + + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); + date::proto::SetHours(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread, prev); } @@ -618,354 +617,354 @@ TEST_F(BuiltinsDateTest, parse) { JSHandle str = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2020-11-19T12:18:18.132Z"); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::Parse(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::Parse(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298132)).GetRawData()); JSHandle str1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2020-11-19Z"); - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, str1.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, str1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - result1 = date::Parse(ecma_runtime_call_info1.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + result1 = date::Parse(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605744000000)).GetRawData()); JSHandle str2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2020-11T12:18:17.231+08:00"); - auto ecma_runtime_call_info2 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetCallArg(0, str2.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetCallArg(0, str2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - result1 = date::Parse(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + result1 = date::Parse(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604204297231)).GetRawData()); JSHandle str3 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Thu Nov 19 2020 20:18:18 GMT+0800"); - auto ecma_runtime_call_info3 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info3->SetCallArg(0, str3.GetTaggedValue()); + auto ecmaRuntimeCallInfo3 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetCallArg(0, str3.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - result1 = date::Parse(ecma_runtime_call_info3.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + result1 = date::Parse(ecmaRuntimeCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298000)).GetRawData()); JSHandle str4 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Thu 03 Jun 2093 04:18 GMT"); - auto ecma_runtime_call_info4 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info4->SetCallArg(0, str4.GetTaggedValue()); + auto ecmaRuntimeCallInfo4 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo4->SetCallArg(0, str4.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - result1 = date::Parse(ecma_runtime_call_info4.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + result1 = date::Parse(ecmaRuntimeCallInfo4.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(3894841080000)).GetRawData()); - auto ecma_runtime_call_info5 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); - ecma_runtime_call_info5->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo5 = CreateAndSetRuntimeCallInfo(thread_, 6, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo5->SetCallArg(0, JSTaggedValue::Null()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info5.get()); - result1 = date::Parse(ecma_runtime_call_info5.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo5.get()); + result1 = date::Parse(ecmaRuntimeCallInfo5.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(base::NAN_VALUE)).GetRawData()); } TEST_F(BuiltinsDateTest, ToDateString) { - JSHandle expect_value = + JSHandle expectValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Tue Nov 06 2018"); - JSHandle js_date = JSDateCreateTest(thread_); - SetAllYearAndHours(thread_, js_date); + JSHandle jsDate = JSDateCreateTest(thread_); + SetAllYearAndHours(thread_, jsDate); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = date::proto::ToDateString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = date::proto::ToDateString(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expect_value)); + ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expectValue)); } TEST_F(BuiltinsDateTest, ToISOString) { - JSHandle expect_value = + JSHandle expectValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2020-11-19T12:18:18.132Z"); - JSHandle js_date = JSDateCreateTest(thread_); - JSDate::Cast(js_date.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ToISOString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ToISOString(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); + ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expectValue)); } TEST_F(BuiltinsDateTest, ToISOStringMinus) { - JSHandle expect_value = + JSHandle expectValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1831-12-02T21:47:18.382Z"); - JSHandle js_date = JSDateCreateTest(thread_); - JSDate::Cast(js_date.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); + JSHandle jsDate = JSDateCreateTest(thread_); + JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ToISOString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ToISOString(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); + ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expectValue)); } // test toJSON and toPrimitive TEST_F(BuiltinsDateTest, ToJSON) { - JSHandle expect_value = + JSHandle expectValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2020-11-19T12:18:18.132Z"); - JSHandle js_date = JSDateCreateTest(thread_); - js_date->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + jsDate->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ToJSON(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ToJSON(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); + ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expectValue)); } TEST_F(BuiltinsDateTest, ToJSONMinus) { - JSHandle expect_value = + JSHandle expectValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1831-12-02T21:47:18.382Z"); - JSHandle js_date = JSDateCreateTest(thread_); - js_date->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + jsDate->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ToJSON(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ToJSON(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); + ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expectValue)); } -static PandaString GetLocalTime(JSHandle js_date, int64_t local_min) +static PandaString GetLocalTime(JSHandle jsDate, int64_t localMin) { - PandaString local_time; - local_min = JSDate::GetLocalOffsetFromOS(local_min, true); - if (static_cast(JSDate::Cast(js_date.GetTaggedValue().GetTaggedObject())->GetTimeValue().GetDouble()) < + PandaString localTime; + localMin = JSDate::GetLocalOffsetFromOS(localMin, true); + if (static_cast(JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->GetTimeValue().GetDouble()) < CHINA_BEFORE_1900_MS && - local_min == CHINA_AFTER_1901_MIN) { - local_min = CHINA_BEFORE_1901_MIN; + localMin == CHINA_AFTER_1901_MIN) { + localMin = CHINA_BEFORE_1901_MIN; } - if (local_min >= 0) { - local_time += PLUS; - } else if (local_min < 0) { - local_time += NEG; - local_min = -local_min; + if (localMin >= 0) { + localTime += PLUS; + } else if (localMin < 0) { + localTime += NEG; + localMin = -localMin; } - local_time = local_time + JSDate::StrToTargetLength(ToPandaString(local_min / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - return local_time + JSDate::StrToTargetLength(ToPandaString(local_min % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + localTime = localTime + JSDate::StrToTargetLength(ToPandaString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); + return localTime + JSDate::StrToTargetLength(ToPandaString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); } TEST_F(BuiltinsDateTest, ToString) { - int local_min = 0; - PandaString local_time; + int localMin = 0; + PandaString localTime; - JSHandle js_date = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - SetAllYearAndHours(thread_, js_date); - local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result1 = date::proto::ToString(ecma_runtime_call_info.get()); + SetAllYearAndHours(thread_, jsDate); + localTime = GetLocalTime(jsDate, localMin); + JSTaggedValue result1 = date::proto::ToString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result1.IsString()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result1_val(thread_, reinterpret_cast(result1.GetRawData())); - PandaString str = "Tue Nov 06 2018 18:10:06 GMT" + local_time; - JSHandle str_handle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result1_val, *str_handle)); - - JSHandle js_date1 = JSDateCreateTest(thread_); - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread_, 4, js_date1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - - SetAll1(thread_, js_date1); - local_time = GetLocalTime(js_date1, local_min); - JSTaggedValue result2 = date::proto::ToString(ecma_runtime_call_info1.get()); + JSHandle result1Val(thread_, reinterpret_cast(result1.GetRawData())); + PandaString str = "Tue Nov 06 2018 18:10:06 GMT" + localTime; + JSHandle strHandle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); + ASSERT_TRUE(EcmaString::StringsAreEqual(*result1Val, *strHandle)); + + JSHandle jsDate1 = JSDateCreateTest(thread_); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate1.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + + SetAll1(thread_, jsDate1); + localTime = GetLocalTime(jsDate1, localMin); + JSTaggedValue result2 = date::proto::ToString(ecmaRuntimeCallInfo1.get()); ASSERT_TRUE(result2.IsString()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result2_val(thread_, reinterpret_cast(result2.GetRawData())); - str = "Mon Dec 31 1900 23:54:16 GMT" + local_time; - str_handle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result2_val, *str_handle)); - - JSHandle js_date2 = JSDateCreateTest(thread_); - auto ecma_runtime_call_info2 = CreateAndSetRuntimeCallInfo(thread_, 4, js_date2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - - SetAll2(thread_, js_date2); - local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result3 = date::proto::ToString(ecma_runtime_call_info2.get()); + JSHandle result2Val(thread_, reinterpret_cast(result2.GetRawData())); + str = "Mon Dec 31 1900 23:54:16 GMT" + localTime; + strHandle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); + ASSERT_TRUE(EcmaString::StringsAreEqual(*result2Val, *strHandle)); + + JSHandle jsDate2 = JSDateCreateTest(thread_); + auto ecmaRuntimeCallInfo2 = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate2.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + + SetAll2(thread_, jsDate2); + localTime = GetLocalTime(jsDate, localMin); + JSTaggedValue result3 = date::proto::ToString(ecmaRuntimeCallInfo2.get()); ASSERT_TRUE(result3.IsString()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result3_val(thread_, reinterpret_cast(result3.GetRawData())); - str = "Tue Jan 01 1901 00:03:21 GMT" + local_time; - str_handle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result3_val, *str_handle)); + JSHandle result3Val(thread_, reinterpret_cast(result3.GetRawData())); + str = "Tue Jan 01 1901 00:03:21 GMT" + localTime; + strHandle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); + ASSERT_TRUE(EcmaString::StringsAreEqual(*result3Val, *strHandle)); } TEST_F(BuiltinsDateTest, ToTimeString) { - int local_min = 0; - PandaString local_time; + int localMin = 0; + PandaString localTime; - JSHandle js_date = JSDateCreateTest(thread_); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - SetAllYearAndHours(thread_, js_date); - local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result1 = date::proto::ToTimeString(ecma_runtime_call_info.get()); + SetAllYearAndHours(thread_, jsDate); + localTime = GetLocalTime(jsDate, localMin); + JSTaggedValue result1 = date::proto::ToTimeString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result1.IsString()); - JSHandle result1_val(thread_, reinterpret_cast(result1.GetRawData())); - PandaString str = "18:10:06 GMT" + local_time; - JSHandle str_handle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result1_val, *str_handle)); - - JSHandle js_date1 = JSDateCreateTest(thread_); - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread_, 4, js_date1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - SetAll1(thread_, js_date1); - local_time = GetLocalTime(js_date1, local_min); - JSTaggedValue result2 = date::proto::ToTimeString(ecma_runtime_call_info1.get()); + JSHandle result1Val(thread_, reinterpret_cast(result1.GetRawData())); + PandaString str = "18:10:06 GMT" + localTime; + JSHandle strHandle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); + ASSERT_TRUE(EcmaString::StringsAreEqual(*result1Val, *strHandle)); + + JSHandle jsDate1 = JSDateCreateTest(thread_); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate1.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + SetAll1(thread_, jsDate1); + localTime = GetLocalTime(jsDate1, localMin); + JSTaggedValue result2 = date::proto::ToTimeString(ecmaRuntimeCallInfo1.get()); ASSERT_TRUE(result2.IsString()); - JSHandle result2_val(thread_, reinterpret_cast(result2.GetRawData())); - str = "23:54:16 GMT" + local_time; - str_handle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result2_val, *str_handle)); - JSHandle js_date2 = JSDateCreateTest(thread_); - auto ecma_runtime_call_info2 = CreateAndSetRuntimeCallInfo(thread_, 4, js_date2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - SetAll2(thread_, js_date2); - local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result3 = date::proto::ToTimeString(ecma_runtime_call_info2.get()); + JSHandle result2Val(thread_, reinterpret_cast(result2.GetRawData())); + str = "23:54:16 GMT" + localTime; + strHandle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); + ASSERT_TRUE(EcmaString::StringsAreEqual(*result2Val, *strHandle)); + JSHandle jsDate2 = JSDateCreateTest(thread_); + auto ecmaRuntimeCallInfo2 = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate2.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + SetAll2(thread_, jsDate2); + localTime = GetLocalTime(jsDate, localMin); + JSTaggedValue result3 = date::proto::ToTimeString(ecmaRuntimeCallInfo2.get()); ASSERT_TRUE(result3.IsString()); - JSHandle result3_val(thread_, reinterpret_cast(result3.GetRawData())); - str = "00:03:21 GMT" + local_time; - str_handle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result3_val, *str_handle)); + JSHandle result3Val(thread_, reinterpret_cast(result3.GetRawData())); + str = "00:03:21 GMT" + localTime; + strHandle = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str); + ASSERT_TRUE(EcmaString::StringsAreEqual(*result3Val, *strHandle)); } TEST_F(BuiltinsDateTest, ToUTCString) { - JSHandle expect_value = + JSHandle expectValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Thu, 19 Nov 2020 12:18:18 GMT"); - JSHandle js_date = JSDateCreateTest(thread_); - JSDate::Cast(js_date.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ToUTCString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ToUTCString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); + ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expectValue)); } TEST_F(BuiltinsDateTest, ToUTCStringMinus) { - JSHandle expect_value = + JSHandle expectValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Fri, 02 Dec 1831 21:47:18 GMT"); - JSHandle js_date = JSDateCreateTest(thread_); - JSDate::Cast(js_date.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ToUTCString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ToUTCString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); + ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expectValue)); } TEST_F(BuiltinsDateTest, ValueOf) { - JSHandle js_date = JSDateCreateTest(thread_); - JSDate::Cast(js_date.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(1605788298132.0)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ValueOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298132)).GetRawData()); } TEST_F(BuiltinsDateTest, ValueOfMinus) { - JSHandle js_date = JSDateCreateTest(thread_); - JSDate::Cast(js_date.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); - auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread_, 4, js_date.GetTaggedValue()); + JSHandle jsDate = JSDateCreateTest(thread_); + JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->SetTimeValue(thread_, JSTaggedValue(-4357419161618.0)); + auto ecmaRuntimeCallInfo = CreateAndSetRuntimeCallInfo(thread_, 4, jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = date::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = date::proto::ValueOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-4357419161618)).GetRawData()); } TEST_F(BuiltinsDateTest, DateConstructor) { // case1: test new target is undefined. - JSHandle js_date = JSDateCreateTest(thread_); - JSHandle global_env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle date_func(global_env->GetDateFunction()); - auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread_, 4, JSTaggedValue::Undefined()); + JSHandle jsDate = JSDateCreateTest(thread_); + JSHandle globalEnv = thread_->GetEcmaVM()->GetGlobalEnv(); + JSHandle dateFunc(globalEnv->GetDateFunction()); + auto ecmaRuntimeCallInfo1 = CreateAndSetRuntimeCallInfo(thread_, 4, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = date::DateConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = date::DateConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result1.IsString()); // case2: length == 0 - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, js_date.GetTaggedValue(), 4); - ecma_runtime_call_info2->SetFunction(date_func.GetTaggedValue()); - ecma_runtime_call_info2->SetThis(js_date.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, jsDate.GetTaggedValue(), 4); + ecmaRuntimeCallInfo2->SetFunction(dateFunc.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetThis(jsDate.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = date::DateConstructor(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = date::DateConstructor(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result2.IsObject()); // case3: length == 1 - auto ecma_runtime_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, js_date.GetTaggedValue(), 6); - ecma_runtime_call_info3->SetFunction(date_func.GetTaggedValue()); - ecma_runtime_call_info3->SetThis(js_date.GetTaggedValue()); - ecma_runtime_call_info3->SetCallArg(0, JSTaggedValue(static_cast(2018))); + auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, jsDate.GetTaggedValue(), 6); + ecmaRuntimeCallInfo3->SetFunction(dateFunc.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetThis(jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(2018))); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - JSTaggedValue result3 = date::DateConstructor(ecma_runtime_call_info3.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + JSTaggedValue result3 = date::DateConstructor(ecmaRuntimeCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result3.IsObject()); - date::proto::SetFullYear(ecma_runtime_call_info3.get()); - JSTaggedValue result4 = date::proto::GetFullYear(ecma_runtime_call_info3.get()); + date::proto::SetFullYear(ecmaRuntimeCallInfo3.get()); + JSTaggedValue result4 = date::proto::GetFullYear(ecmaRuntimeCallInfo3.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); // case3: length > 1 - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, js_date.GetTaggedValue(), 8); - ecma_runtime_call_info4->SetFunction(date_func.GetTaggedValue()); - ecma_runtime_call_info4->SetThis(js_date.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, JSTaggedValue(static_cast(2018))); - ecma_runtime_call_info4->SetCallArg(1, JSTaggedValue(static_cast(10))); - - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - JSTaggedValue result5 = date::DateConstructor(ecma_runtime_call_info4.get()); + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, jsDate.GetTaggedValue(), 8); + ecmaRuntimeCallInfo4->SetFunction(dateFunc.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetThis(jsDate.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(2018))); + ecmaRuntimeCallInfo4->SetCallArg(1, JSTaggedValue(static_cast(10))); + + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + JSTaggedValue result5 = date::DateConstructor(ecmaRuntimeCallInfo4.get()); ASSERT_TRUE(result5.IsObject()); - SetAllYearAndHours(thread_, js_date); - date::proto::SetFullYear(ecma_runtime_call_info4.get()); - JSTaggedValue result6 = date::proto::GetFullYear(ecma_runtime_call_info4.get()); + SetAllYearAndHours(thread_, jsDate); + date::proto::SetFullYear(ecmaRuntimeCallInfo4.get()); + JSTaggedValue result6 = date::proto::GetFullYear(ecmaRuntimeCallInfo4.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result7 = date::proto::GetMonth(ecma_runtime_call_info4.get()); + JSTaggedValue result7 = date::proto::GetMonth(ecmaRuntimeCallInfo4.get()); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_errors_test.cpp b/tests/runtime/builtins/builtins_errors_test.cpp index 7f8176887d005a36d1fc7b327b05d43eb8e8cab8..7f0612262d55f4e196d5dde4b83f5a4a1a852105 100644 --- a/tests/runtime/builtins/builtins_errors_test.cpp +++ b/tests/runtime/builtins/builtins_errors_test.cpp @@ -80,22 +80,22 @@ TEST_F(BuiltinsErrorsTest, GetJSErrorObject) /// @tc.steps: step1. Create JSError object ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); - JSHandle handle_obj = factory->GetJSError(ErrorType::TYPE_ERROR); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle handleObj = factory->GetJSError(ErrorType::TYPE_ERROR); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); /// @tc.steps: step2. obtain JSError object prototype chain name property and message property - JSHandle msg_value( - JSObject::GetProperty(thread_, JSHandle(handle_obj), msg_key).GetValue()); - EXPECT_EQ(reinterpret_cast(msg_value->GetRawData()) + JSHandle msgValue( + JSObject::GetProperty(thread_, JSHandle(handleObj), msgKey).GetValue()); + EXPECT_EQ(reinterpret_cast(msgValue->GetRawData()) ->Compare(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData())), 0); - JSHandle name_value( - JSObject::GetProperty(thread_, JSHandle(handle_obj), name_key).GetValue()); + JSHandle nameValue( + JSObject::GetProperty(thread_, JSHandle(handleObj), nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("TypeError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -108,20 +108,20 @@ TEST_F(BuiltinsErrorsTest, GetJSErrorWithMessage) { ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); - JSHandle handle_obj = factory->GetJSError(ErrorType::TYPE_ERROR, "I am type error"); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value( - JSObject::GetProperty(thread_, JSHandle(handle_obj), msg_key).GetValue()); + JSHandle handleObj = factory->GetJSError(ErrorType::TYPE_ERROR, "I am type error"); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle msgValue( + JSObject::GetProperty(thread_, JSHandle(handleObj), msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("I am type error")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value( - JSObject::GetProperty(thread_, JSHandle(handle_obj), name_key).GetValue()); + JSHandle nameValue( + JSObject::GetProperty(thread_, JSHandle(handleObj), nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("TypeError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -137,29 +137,29 @@ TEST_F(BuiltinsErrorsTest, ErrorNoParameterConstructor) JSHandle error(env->GetErrorFunction()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = error::ErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = error::ErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ( reinterpret_cast(ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Error")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -174,32 +174,32 @@ TEST_F(BuiltinsErrorsTest, ErrorParameterConstructor) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle error(env->GetErrorFunction()); - JSHandle param_msg(factory->NewFromCanBeCompressString("Hello Error!")); + JSHandle paramMsg(factory->NewFromCanBeCompressString("Hello Error!")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); - ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = error::ErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = error::ErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Hello Error!")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Error")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -213,21 +213,21 @@ TEST_F(BuiltinsErrorsTest, ErrorNoParameterToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = error::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = error::proto::ToString(ecmaRuntimeCallInfo.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Error")).GetRawData()) - ->Compare(reinterpret_cast(*result_handle)), + ->Compare(reinterpret_cast(*resultHandle)), 0); } @@ -241,26 +241,26 @@ TEST_F(BuiltinsErrorsTest, ErrorToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - JSHandle handle_msg_key(factory->NewFromCanBeCompressString("message")); + JSHandle handleMsgKey(factory->NewFromCanBeCompressString("message")); JSObject::SetProperty( - thread_, JSHandle(error), handle_msg_key, + thread_, JSHandle(error), handleMsgKey, JSHandle(thread_, factory->NewFromCanBeCompressString("This is Error!").GetTaggedValue())); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = error::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = error::proto::ToString(ecmaRuntimeCallInfo.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Error: This is Error!")).GetRawData()) - ->Compare(*result_handle), + ->Compare(*resultHandle), 0); } @@ -276,28 +276,28 @@ TEST_F(BuiltinsErrorsTest, RangeErrorNoParameterConstructor) JSHandle error(env->GetRangeErrorFunction()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = range_error::RangeErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = range_error::RangeErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ( reinterpret_cast(ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData()) - ->Compare(reinterpret_cast(JSTaggedValue(msg_value.GetTaggedValue()).GetRawData())), + ->Compare(reinterpret_cast(JSTaggedValue(msgValue.GetTaggedValue()).GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("RangeError")).GetRawData()) - ->Compare(reinterpret_cast(JSTaggedValue(name_value.GetTaggedValue()).GetRawData())), + ->Compare(reinterpret_cast(JSTaggedValue(nameValue.GetTaggedValue()).GetRawData())), 0); } @@ -312,32 +312,32 @@ TEST_F(BuiltinsErrorsTest, RangeErrorParameterConstructor) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle error(env->GetRangeErrorFunction()); - JSHandle param_msg(factory->NewFromCanBeCompressString("Hello RangeError!")); + JSHandle paramMsg(factory->NewFromCanBeCompressString("Hello RangeError!")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); - ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = range_error::RangeErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = range_error::RangeErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Hello RangeError!")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("RangeError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -351,22 +351,22 @@ TEST_F(BuiltinsErrorsTest, RangeErrorNoParameterToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetRangeErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetRangeErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = range_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, result); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = range_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, result); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("RangeError")).GetRawData()) - ->Compare(reinterpret_cast(result_handle->GetRawData())), + ->Compare(reinterpret_cast(resultHandle->GetRawData())), 0); } @@ -380,23 +380,23 @@ TEST_F(BuiltinsErrorsTest, RangeErrorToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetRangeErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetRangeErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - JSHandle handle_msg_key(factory->NewFromCanBeCompressString("message")); - JSObject::SetProperty(thread_, JSHandle(error), handle_msg_key, + JSHandle handleMsgKey(factory->NewFromCanBeCompressString("message")); + JSObject::SetProperty(thread_, JSHandle(error), handleMsgKey, JSHandle(factory->NewFromCanBeCompressString("This is RangeError!"))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = range_error::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = range_error::proto::ToString(ecmaRuntimeCallInfo.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); - EXPECT_EQ(factory->NewFromCanBeCompressString("RangeError: This is RangeError!")->Compare(*result_handle), 0); + EXPECT_EQ(factory->NewFromCanBeCompressString("RangeError: This is RangeError!")->Compare(*resultHandle), 0); } // new ReferenceError() @@ -412,28 +412,28 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorNoParameterConstructor) JSHandle error(env->GetReferenceErrorFunction()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reference_error::ReferenceErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reference_error::ReferenceErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ( reinterpret_cast(ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("ReferenceError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -448,30 +448,30 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorParameterConstructor) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle error(env->GetReferenceErrorFunction()); - JSHandle param_msg(factory->NewFromCanBeCompressString("Hello ReferenceError!")); + JSHandle paramMsg(factory->NewFromCanBeCompressString("Hello ReferenceError!")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); - ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reference_error::ReferenceErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reference_error::ReferenceErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Hello ReferenceError!")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("ReferenceError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -485,20 +485,20 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorNoParameterToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetReferenceErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetReferenceErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reference_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reference_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("ReferenceError")).GetRawData()) - ->Compare(*result_handle), + ->Compare(*resultHandle), 0); } @@ -512,22 +512,22 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetReferenceErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetReferenceErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - JSHandle handle_msg_key(factory->NewFromCanBeCompressString("message")); - JSObject::SetProperty(thread_, JSHandle(error), handle_msg_key, + JSHandle handleMsgKey(factory->NewFromCanBeCompressString("message")); + JSObject::SetProperty(thread_, JSHandle(error), handleMsgKey, JSHandle(factory->NewFromCanBeCompressString("This is ReferenceError!"))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reference_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reference_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); - EXPECT_EQ(factory->NewFromCanBeCompressString("ReferenceError: This is ReferenceError!")->Compare(*result_handle), + EXPECT_EQ(factory->NewFromCanBeCompressString("ReferenceError: This is ReferenceError!")->Compare(*resultHandle), 0); } @@ -543,27 +543,27 @@ TEST_F(BuiltinsErrorsTest, TypeErrorNoParameterConstructor) JSHandle error(env->GetTypeErrorFunction()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = type_error::TypeErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = type_error::TypeErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ( reinterpret_cast(ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); - EXPECT_EQ(reinterpret_cast(JSTaggedValue(name_value.GetTaggedValue()).GetRawData()) - ->Compare(reinterpret_cast(JSTaggedValue(name_value.GetTaggedValue()).GetRawData())), + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); + EXPECT_EQ(reinterpret_cast(JSTaggedValue(nameValue.GetTaggedValue()).GetRawData()) + ->Compare(reinterpret_cast(JSTaggedValue(nameValue.GetTaggedValue()).GetRawData())), 0); } @@ -578,31 +578,31 @@ TEST_F(BuiltinsErrorsTest, TypeErrorParameterConstructor) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle error(env->GetTypeErrorFunction()); - JSHandle param_msg(factory->NewFromCanBeCompressString("Hello TypeError!")); + JSHandle paramMsg(factory->NewFromCanBeCompressString("Hello TypeError!")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); - ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = type_error::TypeErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = type_error::TypeErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Hello TypeError!")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("TypeError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -616,20 +616,20 @@ TEST_F(BuiltinsErrorsTest, TypeErrorNoParameterToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetTypeErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetTypeErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = type_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = type_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("TypeError")).GetRawData()) - ->Compare(*result_handle), + ->Compare(*resultHandle), 0); } @@ -643,22 +643,22 @@ TEST_F(BuiltinsErrorsTest, TypeErrorToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetTypeErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetTypeErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); JSHandle value(factory->NewFromCanBeCompressString("This is TypeError!")); - JSHandle handle_msg_key(factory->NewFromCanBeCompressString("message")); - JSObject::SetProperty(thread_, JSHandle(error), handle_msg_key, value); + JSHandle handleMsgKey(factory->NewFromCanBeCompressString("message")); + JSObject::SetProperty(thread_, JSHandle(error), handleMsgKey, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = type_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = type_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); - EXPECT_EQ(factory->NewFromCanBeCompressString("TypeError: This is TypeError!")->Compare(*result_handle), 0); + EXPECT_EQ(factory->NewFromCanBeCompressString("TypeError: This is TypeError!")->Compare(*resultHandle), 0); } /* @@ -673,28 +673,28 @@ TEST_F(BuiltinsErrorsTest, URIErrorNoParameterConstructor) JSHandle error(env->GetURIErrorFunction()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = uri_error::URIErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = uri_error::URIErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ( reinterpret_cast(ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("URIError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -709,31 +709,31 @@ TEST_F(BuiltinsErrorsTest, URIErrorParameterConstructor) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle error(env->GetURIErrorFunction()); - JSHandle param_msg(factory->NewFromCanBeCompressString("Hello URIError!")); + JSHandle paramMsg(factory->NewFromCanBeCompressString("Hello URIError!")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); - ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = uri_error::URIErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = uri_error::URIErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Hello URIError!")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("URIError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -747,21 +747,21 @@ TEST_F(BuiltinsErrorsTest, URIErrorNoParameterToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetURIErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetURIErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = uri_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = uri_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("URIError")).GetRawData()) - ->Compare(*result_handle), + ->Compare(*resultHandle), 0); } @@ -775,27 +775,27 @@ TEST_F(BuiltinsErrorsTest, URIErrorToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetURIErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetURIErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - JSHandle handle_msg_key(factory->NewFromCanBeCompressString("message")); + JSHandle handleMsgKey(factory->NewFromCanBeCompressString("message")); JSObject::SetProperty( - thread_, JSHandle(error), handle_msg_key, + thread_, JSHandle(error), handleMsgKey, JSHandle(thread_, factory->NewFromCanBeCompressString("This is URIError!").GetTaggedValue())); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = uri_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = uri_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ( reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("URIError: This is URIError!")).GetRawData()) - ->Compare(*result_handle), + ->Compare(*resultHandle), 0); } @@ -811,28 +811,28 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorNoParameterConstructor) JSHandle error(env->GetSyntaxErrorFunction()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = syntax_error::SyntaxErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = syntax_error::SyntaxErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ( reinterpret_cast(ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("SyntaxError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -847,31 +847,31 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorParameterConstructor) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle error(env->GetSyntaxErrorFunction()); - JSHandle param_msg(factory->NewFromCanBeCompressString("Hello SyntaxError!")); + JSHandle paramMsg(factory->NewFromCanBeCompressString("Hello SyntaxError!")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); - ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = syntax_error::SyntaxErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = syntax_error::SyntaxErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Hello SyntaxError!")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("SyntaxError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -885,21 +885,21 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorNoParameterToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetSyntaxErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetSyntaxErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = syntax_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = syntax_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("SyntaxError")).GetRawData()) - ->Compare(*result_handle), + ->Compare(*resultHandle), 0); } @@ -913,23 +913,23 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetSyntaxErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetSyntaxErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - JSHandle handle_msg_key(factory->NewFromCanBeCompressString("message")); - JSObject::SetProperty(thread_, JSHandle(error), handle_msg_key, + JSHandle handleMsgKey(factory->NewFromCanBeCompressString("message")); + JSObject::SetProperty(thread_, JSHandle(error), handleMsgKey, JSHandle(factory->NewFromCanBeCompressString("This is SyntaxError!"))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = syntax_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = syntax_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); - EXPECT_EQ(factory->NewFromCanBeCompressString("SyntaxError: This is SyntaxError!")->Compare(*result_handle), 0); + EXPECT_EQ(factory->NewFromCanBeCompressString("SyntaxError: This is SyntaxError!")->Compare(*resultHandle), 0); } /* @@ -944,28 +944,28 @@ TEST_F(BuiltinsErrorsTest, EvalErrorNoParameterConstructor) JSHandle error(env->GetEvalErrorFunction()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 4); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = eval_error::EvalErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = eval_error::EvalErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ( reinterpret_cast(ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("EvalError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -980,31 +980,31 @@ TEST_F(BuiltinsErrorsTest, EvalErrorParameterConstructor) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle error(env->GetEvalErrorFunction()); - JSHandle param_msg(factory->NewFromCanBeCompressString("Hello EvalError!")); + JSHandle paramMsg(factory->NewFromCanBeCompressString("Hello EvalError!")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); - ecma_runtime_call_info->SetFunction(error.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); - ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*error), 6); + ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = eval_error::EvalErrorConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = eval_error::EvalErrorConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSHandle error_object(thread_, reinterpret_cast(result.GetRawData())); - JSHandle msg_key(factory->NewFromCanBeCompressString("message")); - JSHandle name_key = thread_->GlobalConstants()->GetHandledNameString(); + JSHandle errorObject(thread_, reinterpret_cast(result.GetRawData())); + JSHandle msgKey(factory->NewFromCanBeCompressString("message")); + JSHandle nameKey = thread_->GlobalConstants()->GetHandledNameString(); - JSHandle msg_value(JSObject::GetProperty(thread_, error_object, msg_key).GetValue()); + JSHandle msgValue(JSObject::GetProperty(thread_, errorObject, msgKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("Hello EvalError!")).GetRawData()) - ->Compare(reinterpret_cast(msg_value->GetRawData())), + ->Compare(reinterpret_cast(msgValue->GetRawData())), 0); - JSHandle name_value(JSObject::GetProperty(thread_, error_object, name_key).GetValue()); + JSHandle nameValue(JSObject::GetProperty(thread_, errorObject, nameKey).GetValue()); ASSERT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("EvalError")).GetRawData()) - ->Compare(reinterpret_cast(name_value->GetRawData())), + ->Compare(reinterpret_cast(nameValue->GetRawData())), 0); } @@ -1017,20 +1017,20 @@ TEST_F(BuiltinsErrorsTest, EvalErrorNoParameterToString) { ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetEvalErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetEvalErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = eval_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = eval_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( ecmascript::JSTaggedValue(*factory->NewFromCanBeCompressString("EvalError")).GetRawData()) - ->Compare(*result_handle), + ->Compare(*resultHandle), 0); } @@ -1044,22 +1044,22 @@ TEST_F(BuiltinsErrorsTest, EvalErrorToString) ObjectFactory *factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); - JSHandle error_object = env->GetEvalErrorFunction(); - JSHandle error = factory->NewJSObjectByConstructor(JSHandle(error_object), error_object); + JSHandle errorObject = env->GetEvalErrorFunction(); + JSHandle error = factory->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); - JSHandle handle_msg_key(factory->NewFromCanBeCompressString("message")); + JSHandle handleMsgKey(factory->NewFromCanBeCompressString("message")); JSObject::SetProperty( - thread_, JSHandle(error), handle_msg_key, + thread_, JSHandle(error), handleMsgKey, JSHandle(thread_, factory->NewFromCanBeCompressString("This is EvalError!").GetTaggedValue())); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = eval_error::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = eval_error::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); - EXPECT_EQ(factory->NewFromCanBeCompressString("EvalError: This is EvalError!")->Compare(*result_handle), 0); + EXPECT_EQ(factory->NewFromCanBeCompressString("EvalError: This is EvalError!")->Compare(*resultHandle), 0); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_function_test.cpp b/tests/runtime/builtins/builtins_function_test.cpp index 5e1380b64a2b7f5ea63a0b1686d0ea30ccf58bc3..b0edd43211cc6856a6dd93f502a507553a5ebcb2 100644 --- a/tests/runtime/builtins/builtins_function_test.cpp +++ b/tests/runtime/builtins/builtins_function_test.cpp @@ -70,27 +70,27 @@ private: JSTaggedValue TestFunctionApplyAndCall(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int result = 0; for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { result += builtins_common::GetCallArg(argv, index)->GetInt(); } - JSHandle this_value(builtins_common::GetThis(argv)); + JSHandle thisValue(builtins_common::GetThis(argv)); - JSTaggedValue test_a = - JSObject::GetProperty(thread, this_value, + JSTaggedValue testA = + JSObject::GetProperty(thread, thisValue, JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a"))) .GetValue() .GetTaggedValue(); - JSTaggedValue test_b = - JSObject::GetProperty(thread, this_value, + JSTaggedValue testB = + JSObject::GetProperty(thread, thisValue, JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b"))) .GetValue() .GetTaggedValue(); - result = result + test_a.GetInt() + test_b.GetInt(); + result = result + testA.GetInt() + testB.GetInt(); return builtins_common::GetTaggedInt(result); } @@ -104,27 +104,27 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeApply) JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestFunctionApplyAndCall)); // ecma 19.2.3.1: thisArg - JSHandle this_arg(thread_, env->GetGlobalObject()); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSHandle thisArg(thread_, env->GetGlobalObject()); + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a")), JSHandle(thread_, JSTaggedValue(1))); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b")), JSHandle(thread_, JSTaggedValue(2))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(func.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = function::proto::Apply(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = function::proto::Apply(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a"))); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b"))); } @@ -139,11 +139,11 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeApply1) JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestFunctionApplyAndCall)); // ecma 19.2.3.1: thisArg - JSHandle this_arg(thread_, env->GetGlobalObject()); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSHandle thisArg(thread_, env->GetGlobalObject()); + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a")), JSHandle(thread_, JSTaggedValue(10))); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b")), JSHandle(thread_, JSTaggedValue(20))); @@ -155,20 +155,20 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeApply1) PropertyDescriptor desc1(thread_, JSHandle(thread_, JSTaggedValue(40))); JSArray::DefineOwnProperty(thread_, array, JSHandle(thread_, JSTaggedValue(1)), desc1); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(func.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); - ecma_runtime_call_info->SetCallArg(1, array.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); + ecmaRuntimeCallInfo->SetCallArg(1, array.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = function::proto::Apply(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = function::proto::Apply(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(100).GetRawData()); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a"))); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b"))); } @@ -185,37 +185,37 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind) JSHandle(thread_, JSTaggedValue::Undefined())); JSFunction::SetFunctionLength(thread_, target, JSTaggedValue(2)); - JSHandle this_arg(thread_, env->GetGlobalObject()); + JSHandle thisArg(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = function::proto::Bind(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = function::proto::Bind(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_func(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultFunc(thread_, reinterpret_cast(result.GetRawData())); // test BoundTarget - ASSERT_EQ(result_func->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); // test BoundThis - ASSERT_EQ(result_func->GetBoundThis(), this_arg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); // test BoundArguments - JSHandle array(thread_, result_func->GetBoundArguments()); + JSHandle array(thread_, resultFunc->GetBoundArguments()); ASSERT_EQ(array->GetLength(), 0); // test name property - auto global_const = thread_->GlobalConstants(); - JSHandle name_key = global_const->GetHandledNameString(); - JSHandle result_func_handle(thread_, *result_func); - JSHandle result_name(JSObject::GetProperty(thread_, result_func_handle, name_key).GetValue()); - JSHandle bound_target = factory->NewFromCanBeCompressString("bound target"); - ASSERT_EQ(result_name->Compare(*bound_target), 0); + auto globalConst = thread_->GlobalConstants(); + JSHandle nameKey = globalConst->GetHandledNameString(); + JSHandle resultFuncHandle(thread_, *resultFunc); + JSHandle resultName(JSObject::GetProperty(thread_, resultFuncHandle, nameKey).GetValue()); + JSHandle boundTarget = factory->NewFromCanBeCompressString("bound target"); + ASSERT_EQ(resultName->Compare(*boundTarget), 0); // test length property - JSHandle length_key = global_const->GetHandledLengthString(); - JSHandle result_length(JSObject::GetProperty(thread_, result_func_handle, length_key).GetValue()); - ASSERT_EQ(JSTaggedValue::ToNumber(thread_, result_length).GetNumber(), 2.0); + JSHandle lengthKey = globalConst->GetHandledLengthString(); + JSHandle resultLength(JSObject::GetProperty(thread_, resultFuncHandle, lengthKey).GetValue()); + ASSERT_EQ(JSTaggedValue::ToNumber(thread_, resultLength).GetNumber(), 2.0); } // target.bind(thisArg, 123, "helloworld") @@ -231,28 +231,28 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind1) JSHandle(thread_, JSTaggedValue::Undefined())); JSFunction::SetFunctionLength(thread_, target, JSTaggedValue(5)); - JSHandle this_arg(thread_, env->GetGlobalObject()); + JSHandle thisArg(thread_, env->GetGlobalObject()); JSHandle str = factory->NewFromCanBeCompressString("helloworld"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, this_arg.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(123))); - ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, thisArg.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); + ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = function::proto::Bind(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = function::proto::Bind(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_func(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultFunc(thread_, reinterpret_cast(result.GetRawData())); // test BoundTarget - ASSERT_EQ(result_func->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); // test BoundThis - ASSERT_EQ(result_func->GetBoundThis(), this_arg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); // test BoundArguments - JSHandle array(thread_, result_func->GetBoundArguments()); + JSHandle array(thread_, resultFunc->GetBoundArguments()); ASSERT_EQ(array->GetLength(), 2); JSTaggedValue elem = array->Get(0); JSTaggedValue elem1 = array->Get(1); @@ -261,17 +261,17 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind1) ASSERT_EQ(elem1.GetRawData(), str.GetTaggedType()); ASSERT_TRUE(elem1.IsString()); // test name property - auto global_const = thread_->GlobalConstants(); - JSHandle name_key = global_const->GetHandledNameString(); - JSHandle result_func_handle(thread_, *result_func); - JSHandle result_name(JSObject::GetProperty(thread_, result_func_handle, name_key).GetValue()); - JSHandle ruler_name = factory->NewFromCanBeCompressString("bound target1"); - ASSERT_EQ(result_name->Compare(*ruler_name), 0); + auto globalConst = thread_->GlobalConstants(); + JSHandle nameKey = globalConst->GetHandledNameString(); + JSHandle resultFuncHandle(thread_, *resultFunc); + JSHandle resultName(JSObject::GetProperty(thread_, resultFuncHandle, nameKey).GetValue()); + JSHandle rulerName = factory->NewFromCanBeCompressString("bound target1"); + ASSERT_EQ(resultName->Compare(*rulerName), 0); // test length property - JSHandle length_key = global_const->GetHandledLengthString(); - JSHandle result_length(JSObject::GetProperty(thread_, result_func_handle, length_key).GetValue()); + JSHandle lengthKey = globalConst->GetHandledLengthString(); + JSHandle resultLength(JSObject::GetProperty(thread_, resultFuncHandle, lengthKey).GetValue()); // target.length is 5, (...args) length is 2 - ASSERT_EQ(JSTaggedValue::ToNumber(thread_, result_length).GetNumber(), 3.0); + ASSERT_EQ(JSTaggedValue::ToNumber(thread_, resultLength).GetNumber(), 3.0); } // target.bind(thisArg, 123, "helloworld") set target_name = EmptyString() @@ -282,33 +282,33 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind2) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle target = factory->NewJSFunction(env); - PropertyDescriptor name_desc(thread_, JSHandle(thread_, JSTaggedValue(123)), false, false, true); + PropertyDescriptor nameDesc(thread_, JSHandle(thread_, JSTaggedValue(123)), false, false, true); JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(target), - thread_->GlobalConstants()->GetHandledNameString(), name_desc); + thread_->GlobalConstants()->GetHandledNameString(), nameDesc); JSFunction::SetFunctionLength(thread_, target, JSTaggedValue(5)); - JSHandle this_arg(thread_, env->GetGlobalObject()); + JSHandle thisArg(thread_, env->GetGlobalObject()); JSHandle str = factory->NewFromCanBeCompressString("helloworld"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(123))); - ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); + ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = function::proto::Bind(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = function::proto::Bind(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_func(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultFunc(thread_, reinterpret_cast(result.GetRawData())); // test BoundTarget - ASSERT_EQ(result_func->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); // test BoundThis - ASSERT_EQ(result_func->GetBoundThis(), this_arg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); // test BoundArguments - JSHandle array(thread_, result_func->GetBoundArguments()); + JSHandle array(thread_, resultFunc->GetBoundArguments()); ASSERT_EQ(array->GetLength(), 2); JSTaggedValue elem = array->Get(0); JSTaggedValue elem1 = array->Get(1); @@ -317,17 +317,17 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind2) ASSERT_EQ(elem1.GetRawData(), str.GetTaggedType()); ASSERT_TRUE(elem1.IsString()); // test name property - auto global_const = thread_->GlobalConstants(); - JSHandle name_key = global_const->GetHandledNameString(); - JSHandle result_func_handle(result_func); - JSHandle result_name(JSObject::GetProperty(thread_, result_func_handle, name_key).GetValue()); - JSHandle ruler_name = factory->NewFromCanBeCompressString("bound "); - ASSERT_EQ(result_name->Compare(*ruler_name), 0); + auto globalConst = thread_->GlobalConstants(); + JSHandle nameKey = globalConst->GetHandledNameString(); + JSHandle resultFuncHandle(resultFunc); + JSHandle resultName(JSObject::GetProperty(thread_, resultFuncHandle, nameKey).GetValue()); + JSHandle rulerName = factory->NewFromCanBeCompressString("bound "); + ASSERT_EQ(resultName->Compare(*rulerName), 0); // test length property - JSHandle length_key = global_const->GetHandledLengthString(); - JSHandle result_length(JSObject::GetProperty(thread_, result_func_handle, length_key).GetValue()); + JSHandle lengthKey = globalConst->GetHandledLengthString(); + JSHandle resultLength(JSObject::GetProperty(thread_, resultFuncHandle, lengthKey).GetValue()); // target.length is 5, (...args) length is 2 - ASSERT_EQ(JSTaggedValue::ToNumber(thread_, result_length).GetNumber(), 3.0); + ASSERT_EQ(JSTaggedValue::ToNumber(thread_, resultLength).GetNumber(), 3.0); } // func.call(thisArg) @@ -341,27 +341,27 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeCall) JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestFunctionApplyAndCall)); // ecma 19.2.3.3: thisArg - JSHandle this_arg(thread_, env->GetGlobalObject()); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSHandle thisArg(thread_, env->GetGlobalObject()); + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a")), JSHandle(thread_, JSTaggedValue(1))); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b")), JSHandle(thread_, JSTaggedValue(2))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(func.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = function::proto::Call(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = function::proto::Call(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a"))); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b"))); } @@ -376,31 +376,31 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeCall1) JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestFunctionApplyAndCall)); // ecma 19.2.3.3: thisArg - JSHandle this_arg(thread_, env->GetGlobalObject()); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSHandle thisArg(thread_, env->GetGlobalObject()); + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a")), JSHandle(thread_, JSTaggedValue(1))); - JSObject::SetProperty(thread_, JSHandle(this_arg), + JSObject::SetProperty(thread_, JSHandle(thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b")), JSHandle(thread_, JSTaggedValue(2))); // func thisArg ...args - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 12); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(func.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(123))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(456))); - ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(789))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 12); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(456))); + ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(789))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = function::proto::Call(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = function::proto::Call(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1371).GetRawData()); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_a"))); - JSObject::DeleteProperty(thread_, (this_arg), + JSObject::DeleteProperty(thread_, (thisArg), JSHandle(factory->NewFromCanBeCompressString("test_builtins_function_b"))); } @@ -408,26 +408,26 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeHasInstance) { JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle boolean_ctor(env->GetBooleanFunction()); + JSHandle booleanCtor(env->GetBooleanFunction()); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*boolean_ctor), 6); - ecma_runtime_call_info1->SetFunction(boolean_ctor.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(123))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*booleanCtor), 6); + ecmaRuntimeCallInfo1->SetFunction(booleanCtor.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle boolean_instance(thread_, result); + JSHandle booleanInstance(thread_, result); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(boolean_ctor.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, boolean_instance.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(booleanCtor.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, booleanInstance.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - EXPECT_TRUE(function::proto::HasInstance(ecma_runtime_call_info2.get()).GetRawData()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + EXPECT_TRUE(function::proto::HasInstance(ecmaRuntimeCallInfo2.get()).GetRawData()); TestHelper::TearDownFrame(thread_, prev); } diff --git a/tests/runtime/builtins/builtins_global_test.cpp b/tests/runtime/builtins/builtins_global_test.cpp index af937149795e53b17be562a292e11513ae157276..ea12c44edf92d57877c31cbd48944e3071db676d 100644 --- a/tests/runtime/builtins/builtins_global_test.cpp +++ b/tests/runtime/builtins/builtins_global_test.cpp @@ -49,13 +49,13 @@ public: JSHandle str = factory->NewFromUtf16Literal(src, len); JSHandle expected = factory->NewFromString(dst); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = global::Escape(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = global::Escape(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_EQ(expected->Compare(reinterpret_cast(result.GetRawData())), 0); @@ -68,13 +68,13 @@ public: JSHandle str = factory->NewFromString(src); JSHandle expected = factory->NewFromString(res); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = global::Unescape(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = global::Unescape(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_EQ(expected->Compare(reinterpret_cast(result.GetRawData())), 0); @@ -137,21 +137,21 @@ TEST_F(BuiltinsGlobalTest, Escape1000) for (uint16_t i = 0; i < 1000; ++i) { JSHandle str = factory->NewFromUtf16Literal(&i, 1); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = global::Escape(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = global::Escape(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - bool is_equal = (str->Compare(reinterpret_cast(result.GetRawData())) == 0); + bool isEqual = (str->Compare(reinterpret_cast(result.GetRawData())) == 0); if (UNESCAPED.find(i) == std::string::npos) { - ASSERT_FALSE(is_equal); + ASSERT_FALSE(isEqual); } else { - ASSERT_TRUE(is_equal); + ASSERT_TRUE(isEqual); } } } @@ -175,21 +175,21 @@ TEST_F(BuiltinsGlobalTest, Unescape1000) static_cast(i + 8), static_cast(i + 9)}; JSHandle str = factory->NewFromUtf16Literal(c.data(), c.size()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result_escape = global::Escape(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue resultEscape = global::Escape(ecmaRuntimeCallInfo.get()); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetCallArg(0, result_escape); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetCallArg(0, resultEscape); - [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result = global::Unescape(ecma_runtime_call_info2.get()); + [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result = global::Unescape(ecmaRuntimeCallInfo2.get()); ASSERT_TRUE(result.IsString()); ASSERT_EQ(str->Compare(reinterpret_cast(result.GetRawData())), 0); diff --git a/tests/runtime/builtins/builtins_json_test.cpp b/tests/runtime/builtins/builtins_json_test.cpp index a9aa99a08b75bb6c604e43d6b89df95a9a70db4f..9bc62f298cb024e587025b10d95c453250178618 100644 --- a/tests/runtime/builtins/builtins_json_test.cpp +++ b/tests/runtime/builtins/builtins_json_test.cpp @@ -119,17 +119,17 @@ private: EcmaHandleScope *scope_ {nullptr}; }; -JSTaggedValue CreateBuiltinJSObject1(JSThread *thread, const PandaString &key_c_str) +JSTaggedValue CreateBuiltinJSObject1(JSThread *thread, const PandaString &keyCStr) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle object_func(global_env->GetObjectFunction()); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle objectFunc(globalEnv->GetObjectFunction()); - JSHandle jsobject(factory->NewJSObjectByConstructor(JSHandle(object_func), object_func)); + JSHandle jsobject(factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc)); EXPECT_TRUE(*jsobject != nullptr); - JSHandle key(factory->NewFromCanBeCompressString(&key_c_str[0])); + JSHandle key(factory->NewFromCanBeCompressString(&keyCStr[0])); JSHandle value(thread, JSTaggedValue(1)); JSObject::SetProperty(thread, JSHandle(jsobject), key, value); @@ -156,13 +156,13 @@ TEST_F(BuiltinsJsonTest, Parse10) "\n,\t\r \nnull\t\r \n,123.456\t\r \n] \t\r \n}\t\r \n")); JSHandle str(JSTaggedValue::ToString(thread_, msg)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Parse(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -173,41 +173,41 @@ TEST_F(BuiltinsJsonTest, Parse21) JSHandle msg(factory->NewFromCanBeCompressString("[100,2.5,\"abc\"]")); - JSHandle handle_func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForParse)); + JSHandle handleFunc = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForParse)); JSHandle str(JSTaggedValue::ToString(thread_, msg)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, handle_func.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Parse(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); } TEST_F(BuiltinsJsonTest, Parse) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle length_key_handle = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengthKeyHandle = thread_->GlobalConstants()->GetHandledLengthString(); JSHandle msg(factory->NewFromCanBeCompressString("[100,2.5,\"abc\"]")); JSHandle str(JSTaggedValue::ToString(thread_, msg)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Parse(ecmaRuntimeCallInfo.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - JSHandle value_handle(thread_, value); - JSHandle len_result = - JSObject::GetProperty(thread_, JSHandle(value_handle), length_key_handle).GetValue(); - uint32_t length = JSTaggedValue::ToLength(thread_, len_result).ToUint32(); + JSHandle valueHandle(thread_, value); + JSHandle lenResult = + JSObject::GetProperty(thread_, JSHandle(valueHandle), lengthKeyHandle).GetValue(); + uint32_t length = JSTaggedValue::ToLength(thread_, lenResult).ToUint32(); EXPECT_EQ(length, 3); } @@ -217,24 +217,24 @@ TEST_F(BuiltinsJsonTest, Parse2) JSHandle msg(factory->NewFromCanBeCompressString(R"({"epf":100,"key1":200})")); JSHandle str(JSTaggedValue::ToString(thread_, msg)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Parse(ecmaRuntimeCallInfo.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); - JSHandle value_handle(thread_, value); + JSHandle valueHandle(thread_, value); - JSHandle name_list(JSObject::EnumerableOwnNames(thread_, value_handle)); - JSHandle name_result = JSArray::CreateArrayFromList(thread_, name_list); + JSHandle nameList(JSObject::EnumerableOwnNames(thread_, valueHandle)); + JSHandle nameResult = JSArray::CreateArrayFromList(thread_, nameList); - JSHandle handle_key(name_result); - JSHandle length_key(factory->NewFromCanBeCompressString("length")); - JSHandle len_result = JSObject::GetProperty(thread_, handle_key, length_key).GetValue(); - uint32_t length = JSTaggedValue::ToLength(thread_, len_result).ToUint32(); + JSHandle handleKey(nameResult); + JSHandle lengthKey(factory->NewFromCanBeCompressString("length")); + JSHandle lenResult = JSObject::GetProperty(thread_, handleKey, lengthKey).GetValue(); + uint32_t length = JSTaggedValue::ToLength(thread_, lenResult).ToUint32(); ASSERT_EQ(length, 2); } @@ -243,17 +243,16 @@ TEST_F(BuiltinsJsonTest, Stringify11) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle obj = JSHandle(thread_, CreateBuiltinJSObject1(thread_, "x")); - JSHandle handle_func = - factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); + JSHandle handleFunc = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, handle_func.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Stringify(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); } @@ -262,18 +261,17 @@ TEST_F(BuiltinsJsonTest, Stringify12) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle obj = JSHandle(thread_, CreateBuiltinJSObject1(thread_, "x")); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle handle_func = - factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); - - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, handle_func.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(10))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); + JSHandle handleFunc = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(10))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Stringify(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); } @@ -282,20 +280,19 @@ TEST_F(BuiltinsJsonTest, Stringify13) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle obj = JSHandle(thread_, CreateBuiltinJSObject1(thread_, "x")); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle handle_func = - factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); + JSHandle handleFunc = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); JSHandle msg(factory->NewFromCanBeCompressString("tttt")); JSHandle str(JSTaggedValue::ToString(thread_, msg)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, handle_func.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Stringify(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); } @@ -316,36 +313,36 @@ TEST_F(BuiltinsJsonTest, Stringify14) JSHandle msg(factory->NewFromCanBeCompressString("tttt")); JSHandle str(JSTaggedValue::ToString(thread_, msg)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, obj1.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, obj1.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Stringify(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); } TEST_F(BuiltinsJsonTest, Stringify) { JSHandle obj = JSHandle(thread_, CreateBuiltinJSObject1(thread_, "x")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Stringify(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); } TEST_F(BuiltinsJsonTest, Stringify1) { - auto ecma_vm = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); @@ -364,27 +361,26 @@ TEST_F(BuiltinsJsonTest, Stringify1) JSHandle value2(factory->NewFromCanBeCompressString("abc")); JSObject::SetProperty(thread_, JSHandle(obj), key2, value2); - JSHandle handle_func = - factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); + JSHandle handleFunc = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForStringfy)); JSHandle msg(factory->NewFromCanBeCompressString("tttt")); JSHandle str(JSTaggedValue::ToString(thread_, msg)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, handle_func.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Stringify(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); } TEST_F(BuiltinsJsonTest, Stringify2) { - auto ecma_vm = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); EXPECT_TRUE(arr != nullptr); @@ -402,13 +398,13 @@ TEST_F(BuiltinsJsonTest, Stringify2) JSHandle value2(factory->NewFromCanBeCompressString("abc")); JSObject::SetProperty(thread_, JSHandle(obj), key2, value2); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = json::Stringify(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_map_test.cpp b/tests/runtime/builtins/builtins_map_test.cpp index ee1835a34fed3416b654867971d087310d71b6bf..57a88ad7ca6ad908a7afd8eae9bdd467de962d40 100644 --- a/tests/runtime/builtins/builtins_map_test.cpp +++ b/tests/runtime/builtins/builtins_map_test.cpp @@ -68,9 +68,9 @@ public: static JSTaggedValue TestFunc(EcmaRuntimeCallInfo *argv) { int num = builtins_common::GetCallArg(argv, 0)->GetInt(); - JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); - int length = js_array->GetArrayLength() + num; - js_array->SetArrayLength(argv->GetThread(), length); + JSArray *jsArray = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); + int length = jsArray->GetArrayLength() + num; + jsArray->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); } }; @@ -87,55 +87,55 @@ private: JSMap *CreateBuiltinsMap(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetMapFunction()); + JSHandle newTarget(env->GetMapFunction()); // 4 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*new_target), 4); - ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 4); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = map::MapConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = map::MapConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSMap *js_map = JSMap::Cast(reinterpret_cast(result.GetRawData())); - return js_map; + JSMap *jsMap = JSMap::Cast(reinterpret_cast(result.GetRawData())); + return jsMap; } // new Map("abrupt").toString() TEST_F(BuiltinsMapTest, CreateAndGetSize) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetMapFunction()); + JSHandle newTarget(env->GetMapFunction()); JSHandle map(thread_, CreateBuiltinsMap(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = map::proto::GetSize(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = map::proto::GetSize(ecmaRuntimeCallInfo.get()); EXPECT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } JSHandle array(factory->NewTaggedArray(5)); for (int i = 0; i < 5; i++) { - JSHandle internal_array(factory->NewTaggedArray(2)); - internal_array->Set(thread_, 0, JSTaggedValue(i)); - internal_array->Set(thread_, 1, JSTaggedValue(i)); - auto arr = JSArray::CreateArrayFromList(thread_, internal_array); + JSHandle internalArray(factory->NewTaggedArray(2)); + internalArray->Set(thread_, 0, JSTaggedValue(i)); + internalArray->Set(thread_, 1, JSTaggedValue(i)); + auto arr = JSArray::CreateArrayFromList(thread_, internalArray); array->Set(thread_, i, arr); } JSHandle values = JSArray::CreateArrayFromList(thread_, array); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, values.GetTaggedValue()); - ecma_runtime_call_info1->SetNewTarget(new_target.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, values.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetNewTarget(newTarget.GetTaggedValue()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = map::MapConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = map::MapConstructor(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(JSMap::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); } @@ -148,36 +148,36 @@ TEST_F(BuiltinsMapTest, SetAndHas) JSHandle map(thread_, CreateBuiltinsMap(thread_)); JSHandle key(factory->NewFromCanBeCompressString("key")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); - JSMap *js_map; + JSMap *jsMap; { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = map::proto::Has(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = map::proto::Has(ecmaRuntimeCallInfo.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Set() - JSTaggedValue result2 = map::proto::Set(ecma_runtime_call_info.get()); + JSTaggedValue result2 = map::proto::Set(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result2.IsECMAObject()); - js_map = JSMap::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(js_map->GetSize(), 1); + jsMap = JSMap::Cast(reinterpret_cast(result2.GetRawData())); + EXPECT_EQ(jsMap->GetSize(), 1); } // test Has() - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue(js_map)); - ecma_runtime_call_info1->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(jsMap)); + ecmaRuntimeCallInfo1->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(1))); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = map::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = map::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -189,37 +189,37 @@ TEST_F(BuiltinsMapTest, ForEach) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle map(thread_, CreateBuiltinsMap(thread_)); - char key_array[] = "key0"; + char keyArray[] = "key0"; for (int i = 0; i < 5; i++) { - key_array[3] = '1' + i; - JSHandle key(factory->NewFromCanBeCompressString(key_array)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(i))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = map::proto::Set(ecma_runtime_call_info.get()); + keyArray[3] = '1' + i; + JSHandle key(factory->NewFromCanBeCompressString(keyArray)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(i))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = map::proto::Set(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result1.IsECMAObject()); - JSMap *js_map = JSMap::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(js_map->GetSize(), i + 1); + JSMap *jsMap = JSMap::Cast(reinterpret_cast(result1.GetRawData())); + EXPECT_EQ(jsMap->GetSize(), i + 1); } // test foreach; - JSHandle js_array(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle jsArray(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = map::proto::ForEach(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = map::proto::ForEach(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - EXPECT_EQ(js_array->GetArrayLength(), 10); + EXPECT_EQ(jsArray->GetArrayLength(), 10); } TEST_F(BuiltinsMapTest, DeleteAndRemove) @@ -229,52 +229,52 @@ TEST_F(BuiltinsMapTest, DeleteAndRemove) JSHandle map(thread_, CreateBuiltinsMap(thread_)); // add 40 keys - char key_array[] = "key0"; + char keyArray[] = "key0"; for (int i = 0; i < 40; i++) { - key_array[3] = '1' + i; - JSHandle key(thread_, factory->NewFromCanBeCompressString(key_array).GetTaggedValue()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(i))); + keyArray[3] = '1' + i; + JSHandle key(thread_, factory->NewFromCanBeCompressString(keyArray).GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(i))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = map::proto::Set(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = map::proto::Set(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result1.IsECMAObject()); - JSMap *js_map = JSMap::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(js_map->GetSize(), i + 1); + JSMap *jsMap = JSMap::Cast(reinterpret_cast(result1.GetRawData())); + EXPECT_EQ(jsMap->GetSize(), i + 1); } // whether jsMap has delete key - key_array[3] = '1' + 8; - JSHandle delete_key(factory->NewFromCanBeCompressString(key_array)); + keyArray[3] = '1' + 8; + JSHandle deleteKey(factory->NewFromCanBeCompressString(keyArray)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, delete_key.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, deleteKey.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = map::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = map::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = map::proto::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = map::proto::Delete(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = map::proto::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = map::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); - JSTaggedValue result5 = map::proto::GetSize(ecma_runtime_call_info1.get()); + JSTaggedValue result5 = map::proto::GetSize(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result5.GetRawData(), JSTaggedValue(39).GetRawData()); // clear - JSTaggedValue result6 = map::proto::Clear(ecma_runtime_call_info1.get()); + JSTaggedValue result6 = map::proto::Clear(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(map->GetSize(), 0); } @@ -286,24 +286,24 @@ TEST_F(BuiltinsMapTest, Species) JSHandle map(thread_, CreateBuiltinsMap(thread_)); // test species - JSHandle species_symbol = env->GetSpeciesSymbol(); - EXPECT_TRUE(!species_symbol.GetTaggedValue().IsUndefined()); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + EXPECT_TRUE(!speciesSymbol.GetTaggedValue().IsUndefined()); - JSHandle new_target(env->GetMapFunction()); + JSHandle newTarget(env->GetMapFunction()); JSTaggedValue value = - JSObject::GetProperty(thread_, JSHandle(new_target), species_symbol).GetValue().GetTaggedValue(); - JSHandle value_handle(thread_, value); - EXPECT_EQ(value, new_target.GetTaggedValue()); + JSObject::GetProperty(thread_, JSHandle(newTarget), speciesSymbol).GetValue().GetTaggedValue(); + JSHandle valueHandle(thread_, value); + EXPECT_EQ(value, newTarget.GetTaggedValue()); // to string tag - JSHandle to_string_tag_symbol = env->GetToStringTagSymbol(); - JSHandle string_tag(JSObject::GetProperty(thread_, map, to_string_tag_symbol).GetValue()); + JSHandle toStringTagSymbol = env->GetToStringTagSymbol(); + JSHandle stringTag(JSObject::GetProperty(thread_, map, toStringTagSymbol).GetValue()); JSHandle str = factory->NewFromCanBeCompressString("Map"); - EXPECT_TRUE(!string_tag.GetTaggedValue().IsUndefined()); - EXPECT_TRUE(EcmaString::StringsAreEqual(*str, *string_tag)); + EXPECT_TRUE(!stringTag.GetTaggedValue().IsUndefined()); + EXPECT_TRUE(EcmaString::StringsAreEqual(*str, *stringTag)); - JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread_, value_handle)); + JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread_, valueHandle)); EXPECT_EQ(JSHandle(map)->GetPrototype(thread_), constructor->GetFunctionPrototype()); JSHandle key1(factory->NewFromCanBeCompressString("set")); @@ -338,26 +338,26 @@ TEST_F(BuiltinsMapTest, Species) TEST_F(BuiltinsMapTest, GetIterator) { JSHandle map(thread_, CreateBuiltinsMap(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(map.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // test Values() - JSTaggedValue result = map::proto::Values(ecma_runtime_call_info.get()); + JSTaggedValue result = map::proto::Values(ecmaRuntimeCallInfo.get()); JSHandle iter(thread_, result); EXPECT_TRUE(iter->IsJSMapIterator()); EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind().GetInt())); EXPECT_EQ(JSMap::Cast(map.GetTaggedValue().GetTaggedObject())->GetLinkedMap(), iter->GetIteratedMap()); // test Keys() - JSTaggedValue result1 = map::proto::Keys(ecma_runtime_call_info.get()); + JSTaggedValue result1 = map::proto::Keys(ecmaRuntimeCallInfo.get()); JSHandle iter1(thread_, result1); EXPECT_TRUE(iter1->IsJSMapIterator()); EXPECT_EQ(IterationKind::KEY, IterationKind(iter1->GetIterationKind().GetInt())); // test entries() - JSTaggedValue result2 = map::proto::Entries(ecma_runtime_call_info.get()); + JSTaggedValue result2 = map::proto::Entries(ecmaRuntimeCallInfo.get()); JSHandle iter2(thread_, result2); EXPECT_TRUE(iter2->IsJSMapIterator()); EXPECT_EQ(IterationKind::KEY_AND_VALUE, IterationKind(iter2->GetIterationKind().GetInt())); diff --git a/tests/runtime/builtins/builtins_math_test.cpp b/tests/runtime/builtins/builtins_math_test.cpp index a6de87eef413b31f8963fef50733797e93b253bf..122c0ca48fdfa7c7322fa2c873b0e466079bd2ca 100644 --- a/tests/runtime/builtins/builtins_math_test.cpp +++ b/tests/runtime/builtins/builtins_math_test.cpp @@ -55,13 +55,13 @@ JSThread *BuiltinsMathTest::thread_ = nullptr; // Math.abs(-10) TEST_F(BuiltinsMathTest, Abs) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-10))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -70,13 +70,13 @@ TEST_F(BuiltinsMathTest, Abs) // Math.abs(10) TEST_F(BuiltinsMathTest, Abs_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -85,13 +85,13 @@ TEST_F(BuiltinsMathTest, Abs_1) // Math.abs(0) TEST_F(BuiltinsMathTest, Abs_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -100,13 +100,13 @@ TEST_F(BuiltinsMathTest, Abs_2) // Math.abs(null) TEST_F(BuiltinsMathTest, Abs_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -117,13 +117,13 @@ TEST_F(BuiltinsMathTest, Abs_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("helloworld"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -132,14 +132,14 @@ TEST_F(BuiltinsMathTest, Abs_4) // Math.abs(Number.MAX_VALUE + 1) TEST_F(BuiltinsMathTest, Abs_5) { - const double test_value = base::MAX_VALUE + 1; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); + const double testValue = base::MAX_VALUE + 1; + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::MAX_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -148,14 +148,14 @@ TEST_F(BuiltinsMathTest, Abs_5) // Math.abs(Number.MIN_VALUE) TEST_F(BuiltinsMathTest, Abs_6) { - const double test_value = base::MIN_VALUE + 1; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); + const double testValue = base::MIN_VALUE + 1; + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -164,14 +164,14 @@ TEST_F(BuiltinsMathTest, Abs_6) // Math.abs(Number.POSITIVE_INFINITY + 1) TEST_F(BuiltinsMathTest, Abs_7) { - const double test_value = base::POSITIVE_INFINITY + 1; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); + const double testValue = base::POSITIVE_INFINITY + 1; + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -180,14 +180,14 @@ TEST_F(BuiltinsMathTest, Abs_7) // Math.abs(Number.NEGATIVE_INFINITY - 1) TEST_F(BuiltinsMathTest, Abs_8) { - const double test_value = -base::POSITIVE_INFINITY - 1; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); + const double testValue = -base::POSITIVE_INFINITY - 1; + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -196,14 +196,14 @@ TEST_F(BuiltinsMathTest, Abs_8) // Math.abs(Number.NAN_VALUE) TEST_F(BuiltinsMathTest, Abs_9) { - const double test_value = base::NAN_VALUE; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); + const double testValue = base::NAN_VALUE; + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -212,13 +212,13 @@ TEST_F(BuiltinsMathTest, Abs_9) // Math.abs(VALUE_UNDEFINED) TEST_F(BuiltinsMathTest, Abs_10) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -227,13 +227,13 @@ TEST_F(BuiltinsMathTest, Abs_10) // Math.abs(true) TEST_F(BuiltinsMathTest, Abs_11) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -242,13 +242,13 @@ TEST_F(BuiltinsMathTest, Abs_11) // Math.abs(false) TEST_F(BuiltinsMathTest, Abs_12) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -257,13 +257,13 @@ TEST_F(BuiltinsMathTest, Abs_12) // Math.abs(hole) TEST_F(BuiltinsMathTest, Abs_13) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Hole()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Hole()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -273,13 +273,13 @@ TEST_F(BuiltinsMathTest, Abs_13) TEST_F(BuiltinsMathTest, Abs_14) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("100.12"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Abs(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(100.12); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -288,13 +288,13 @@ TEST_F(BuiltinsMathTest, Abs_14) // Math.acos(-1) TEST_F(BuiltinsMathTest, Acos) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = math::GetPropPI(); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -303,13 +303,13 @@ TEST_F(BuiltinsMathTest, Acos) // Math.acos(1) TEST_F(BuiltinsMathTest, Acos_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -318,13 +318,13 @@ TEST_F(BuiltinsMathTest, Acos_1) // Math.acos(-1.5) TEST_F(BuiltinsMathTest, Acos_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-1.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -333,13 +333,13 @@ TEST_F(BuiltinsMathTest, Acos_2) // Math.acos(null) TEST_F(BuiltinsMathTest, Acos_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -348,13 +348,13 @@ TEST_F(BuiltinsMathTest, Acos_3) // Math.acos(UNDEFINED) TEST_F(BuiltinsMathTest, Acos_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -363,13 +363,13 @@ TEST_F(BuiltinsMathTest, Acos_4) // Math.acos(true) TEST_F(BuiltinsMathTest, Acos_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -378,13 +378,13 @@ TEST_F(BuiltinsMathTest, Acos_5) // Math.acos(false) TEST_F(BuiltinsMathTest, Acos_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -394,13 +394,13 @@ TEST_F(BuiltinsMathTest, Acos_6) TEST_F(BuiltinsMathTest, Acos_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.4706289056333368); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -410,13 +410,13 @@ TEST_F(BuiltinsMathTest, Acos_7) TEST_F(BuiltinsMathTest, Acos_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -425,13 +425,13 @@ TEST_F(BuiltinsMathTest, Acos_8) // Math.acos(-NaN) TEST_F(BuiltinsMathTest, Acos_9) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -440,13 +440,13 @@ TEST_F(BuiltinsMathTest, Acos_9) // Math.acosh(1.1) TEST_F(BuiltinsMathTest, Acosh) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.1)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.4435682543851154); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -455,13 +455,13 @@ TEST_F(BuiltinsMathTest, Acosh) // Math.acosh(0.5) TEST_F(BuiltinsMathTest, Acosh_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -470,13 +470,13 @@ TEST_F(BuiltinsMathTest, Acosh_1) // Math.acosh(base::POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Acosh_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -485,13 +485,13 @@ TEST_F(BuiltinsMathTest, Acosh_2) // Math.acosh(null) TEST_F(BuiltinsMathTest, Acosh_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -500,13 +500,13 @@ TEST_F(BuiltinsMathTest, Acosh_3) // Math.acosh(VALUE_UNDEFINED) TEST_F(BuiltinsMathTest, Acosh_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -515,13 +515,13 @@ TEST_F(BuiltinsMathTest, Acosh_4) // Math.acosh(true) TEST_F(BuiltinsMathTest, Acosh_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -530,13 +530,13 @@ TEST_F(BuiltinsMathTest, Acosh_5) // Math.acosh(false) TEST_F(BuiltinsMathTest, Acosh_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -545,13 +545,13 @@ TEST_F(BuiltinsMathTest, Acosh_6) // Math.acosh(hole) TEST_F(BuiltinsMathTest, Acosh_7) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Hole()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Hole()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -561,13 +561,13 @@ TEST_F(BuiltinsMathTest, Acosh_7) TEST_F(BuiltinsMathTest, Acosh_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -577,13 +577,13 @@ TEST_F(BuiltinsMathTest, Acosh_8) TEST_F(BuiltinsMathTest, Acosh_9) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -592,13 +592,13 @@ TEST_F(BuiltinsMathTest, Acosh_9) // Math.acosh(-NaN) TEST_F(BuiltinsMathTest, Acosh_10) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Acosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -607,13 +607,13 @@ TEST_F(BuiltinsMathTest, Acosh_10) // Math.asin(-1) TEST_F(BuiltinsMathTest, Asin) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -622,13 +622,13 @@ TEST_F(BuiltinsMathTest, Asin) // Math.asin(1) TEST_F(BuiltinsMathTest, Asin_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -637,13 +637,13 @@ TEST_F(BuiltinsMathTest, Asin_1) // Math.asin(-NaN) TEST_F(BuiltinsMathTest, Asin_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -652,13 +652,13 @@ TEST_F(BuiltinsMathTest, Asin_2) // Math.asin(null) TEST_F(BuiltinsMathTest, Asin_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -667,13 +667,13 @@ TEST_F(BuiltinsMathTest, Asin_3) // Math.asin(UNDEFINED) TEST_F(BuiltinsMathTest, Asin_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -682,13 +682,13 @@ TEST_F(BuiltinsMathTest, Asin_4) // Math.asin(true) TEST_F(BuiltinsMathTest, Asin_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -697,13 +697,13 @@ TEST_F(BuiltinsMathTest, Asin_5) // Math.asin(false) TEST_F(BuiltinsMathTest, Asin_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -713,13 +713,13 @@ TEST_F(BuiltinsMathTest, Asin_6) TEST_F(BuiltinsMathTest, Asin_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -729,13 +729,13 @@ TEST_F(BuiltinsMathTest, Asin_7) TEST_F(BuiltinsMathTest, Asin_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -744,13 +744,13 @@ TEST_F(BuiltinsMathTest, Asin_8) // Math.asinh(-1) TEST_F(BuiltinsMathTest, Asinh) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.881373587019543); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -759,13 +759,13 @@ TEST_F(BuiltinsMathTest, Asinh) // Math.asinh(1) TEST_F(BuiltinsMathTest, Asinh_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.881373587019543); @@ -775,13 +775,13 @@ TEST_F(BuiltinsMathTest, Asinh_1) // Math.asinh(null) TEST_F(BuiltinsMathTest, Asinh_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); @@ -791,13 +791,13 @@ TEST_F(BuiltinsMathTest, Asinh_2) // Math.asinh(-NaN) TEST_F(BuiltinsMathTest, Asinh_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -806,13 +806,13 @@ TEST_F(BuiltinsMathTest, Asinh_3) // Math.asinh(NEGATIVE_INFINITY) TEST_F(BuiltinsMathTest, Asinh_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -821,13 +821,13 @@ TEST_F(BuiltinsMathTest, Asinh_4) // Math.asinh(true) TEST_F(BuiltinsMathTest, Asinh_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.881373587019543); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -836,13 +836,13 @@ TEST_F(BuiltinsMathTest, Asinh_5) // Math.asinh(false) TEST_F(BuiltinsMathTest, Asinh_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -852,13 +852,13 @@ TEST_F(BuiltinsMathTest, Asinh_6) TEST_F(BuiltinsMathTest, Asinh_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -868,13 +868,13 @@ TEST_F(BuiltinsMathTest, Asinh_7) TEST_F(BuiltinsMathTest, Asinh_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-5.7"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Asinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-2.44122070725561); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -883,13 +883,13 @@ TEST_F(BuiltinsMathTest, Asinh_8) // Math.atan(-1) TEST_F(BuiltinsMathTest, Atan) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -898,13 +898,13 @@ TEST_F(BuiltinsMathTest, Atan) // Math.atan(1) TEST_F(BuiltinsMathTest, Atan_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -913,13 +913,13 @@ TEST_F(BuiltinsMathTest, Atan_1) // Math.atan(null) TEST_F(BuiltinsMathTest, Atan_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -928,13 +928,13 @@ TEST_F(BuiltinsMathTest, Atan_2) // Math.atan(-NaN) TEST_F(BuiltinsMathTest, Atan_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -943,13 +943,13 @@ TEST_F(BuiltinsMathTest, Atan_3) // Math.atan(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Atan_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(math::GetPropPI().GetDouble() / 2); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -958,13 +958,13 @@ TEST_F(BuiltinsMathTest, Atan_4) // Math.atan(true) TEST_F(BuiltinsMathTest, Atan_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -973,13 +973,13 @@ TEST_F(BuiltinsMathTest, Atan_5) // Math.atan(false) TEST_F(BuiltinsMathTest, Atan_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -989,13 +989,13 @@ TEST_F(BuiltinsMathTest, Atan_6) TEST_F(BuiltinsMathTest, Atan_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(" "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1005,13 +1005,13 @@ TEST_F(BuiltinsMathTest, Atan_7) TEST_F(BuiltinsMathTest, Atan_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1020,13 +1020,13 @@ TEST_F(BuiltinsMathTest, Atan_8) // Math.atanh(-1) TEST_F(BuiltinsMathTest, Atanh) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1035,13 +1035,13 @@ TEST_F(BuiltinsMathTest, Atanh) // Math.atanh(1) TEST_F(BuiltinsMathTest, Atanh_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1050,13 +1050,13 @@ TEST_F(BuiltinsMathTest, Atanh_1) // Math.atanh(null) TEST_F(BuiltinsMathTest, Atanh_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1065,13 +1065,13 @@ TEST_F(BuiltinsMathTest, Atanh_2) // Math.atanh(-NaN) TEST_F(BuiltinsMathTest, Atanh_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1080,13 +1080,13 @@ TEST_F(BuiltinsMathTest, Atanh_3) // Math.atanh(1.5) TEST_F(BuiltinsMathTest, Atanh_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1095,13 +1095,13 @@ TEST_F(BuiltinsMathTest, Atanh_4) // Math.atanh(true) TEST_F(BuiltinsMathTest, Atanh_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1110,13 +1110,13 @@ TEST_F(BuiltinsMathTest, Atanh_5) // Math.atanh(false) TEST_F(BuiltinsMathTest, Atanh_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1126,13 +1126,13 @@ TEST_F(BuiltinsMathTest, Atanh_6) TEST_F(BuiltinsMathTest, Atanh_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(" "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1142,13 +1142,13 @@ TEST_F(BuiltinsMathTest, Atanh_7) TEST_F(BuiltinsMathTest, Atanh_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1157,14 +1157,14 @@ TEST_F(BuiltinsMathTest, Atanh_8) // Math.atan2(NaN, 1.5) TEST_F(BuiltinsMathTest, Atan2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(1.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1173,14 +1173,14 @@ TEST_F(BuiltinsMathTest, Atan2) // Math.atan2(-1, 1.5) TEST_F(BuiltinsMathTest, Atan2_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(1.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.5880026035475675); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1189,14 +1189,14 @@ TEST_F(BuiltinsMathTest, Atan2_1) // Math.atan2(1, -0) TEST_F(BuiltinsMathTest, Atan2_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(math::GetPropPI().GetDouble() / 2); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1205,14 +1205,14 @@ TEST_F(BuiltinsMathTest, Atan2_2) // Math.atan2(0, 1) TEST_F(BuiltinsMathTest, Atan2_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1221,14 +1221,14 @@ TEST_F(BuiltinsMathTest, Atan2_3) // Math.atan2(0, -0) TEST_F(BuiltinsMathTest, Atan2_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = math::GetPropPI(); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1237,14 +1237,14 @@ TEST_F(BuiltinsMathTest, Atan2_4) // Math.atan2(-0, 0) TEST_F(BuiltinsMathTest, Atan2_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1253,14 +1253,14 @@ TEST_F(BuiltinsMathTest, Atan2_5) // Math.atan2(-0, -0) TEST_F(BuiltinsMathTest, Atan2_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-math::GetPropPI().GetDouble()); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1269,14 +1269,14 @@ TEST_F(BuiltinsMathTest, Atan2_6) // Math.atan2(true, false) TEST_F(BuiltinsMathTest, Atan2_7) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1285,14 +1285,14 @@ TEST_F(BuiltinsMathTest, Atan2_7) // Math.atan2(false, true) TEST_F(BuiltinsMathTest, Atan2_8) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1301,16 +1301,16 @@ TEST_F(BuiltinsMathTest, Atan2_8) // Math.atan2("-1","") TEST_F(BuiltinsMathTest, Atan2_9) { - JSHandle test_1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-1"); - JSHandle test_2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test_1.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, test_2.GetTaggedValue()); + JSHandle test1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-1"); + JSHandle test2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test1.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, test2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1319,16 +1319,16 @@ TEST_F(BuiltinsMathTest, Atan2_9) // Math.atan2("0.23","0.72") TEST_F(BuiltinsMathTest, Atan2_10) { - JSHandle test_1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.23"); - JSHandle test_2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.72"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test_1.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, test_2.GetTaggedValue()); + JSHandle test1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.23"); + JSHandle test2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.72"); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test1.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, test2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.3091989123270746); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1337,14 +1337,14 @@ TEST_F(BuiltinsMathTest, Atan2_10) // Math.atan2(-NaN, 1.5) TEST_F(BuiltinsMathTest, Atan2_11) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-1.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Atan2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1353,13 +1353,13 @@ TEST_F(BuiltinsMathTest, Atan2_11) // Math.cbrt(0) TEST_F(BuiltinsMathTest, Cbrt) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1368,13 +1368,13 @@ TEST_F(BuiltinsMathTest, Cbrt) // Math.cbrt(-0) TEST_F(BuiltinsMathTest, Cbrt_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1383,13 +1383,13 @@ TEST_F(BuiltinsMathTest, Cbrt_1) // Math.cbrt(NEGATIVE_INFINITY) TEST_F(BuiltinsMathTest, Cbrt_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1398,13 +1398,13 @@ TEST_F(BuiltinsMathTest, Cbrt_2) // Math.cbrt(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Cbrt_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1413,13 +1413,13 @@ TEST_F(BuiltinsMathTest, Cbrt_3) // Math.cbrt(VALUE_UNDEFINED) TEST_F(BuiltinsMathTest, Cbrt_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1428,13 +1428,13 @@ TEST_F(BuiltinsMathTest, Cbrt_4) // Math.cbrt(true) TEST_F(BuiltinsMathTest, Cbrt_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1443,13 +1443,13 @@ TEST_F(BuiltinsMathTest, Cbrt_5) // Math.cbrt(false) TEST_F(BuiltinsMathTest, Cbrt_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1459,13 +1459,13 @@ TEST_F(BuiltinsMathTest, Cbrt_6) TEST_F(BuiltinsMathTest, Cbrt_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(" "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1475,13 +1475,13 @@ TEST_F(BuiltinsMathTest, Cbrt_7) TEST_F(BuiltinsMathTest, Cbrt_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0714412696907731); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1490,13 +1490,13 @@ TEST_F(BuiltinsMathTest, Cbrt_8) // Math.cbrt(-NaN) TEST_F(BuiltinsMathTest, Cbrt_9) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cbrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1505,13 +1505,13 @@ TEST_F(BuiltinsMathTest, Cbrt_9) // Math.ceil(3.25) TEST_F(BuiltinsMathTest, Ceil) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(3.25)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(3.25)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1520,13 +1520,13 @@ TEST_F(BuiltinsMathTest, Ceil) // Math.ceil(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Ceil_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1535,13 +1535,13 @@ TEST_F(BuiltinsMathTest, Ceil_1) // Math.ceil(-0.0) TEST_F(BuiltinsMathTest, Ceil_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1550,13 +1550,13 @@ TEST_F(BuiltinsMathTest, Ceil_2) // Math.ceil(null) TEST_F(BuiltinsMathTest, Ceil_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1565,13 +1565,13 @@ TEST_F(BuiltinsMathTest, Ceil_3) // Math.ceil(0) TEST_F(BuiltinsMathTest, Ceil_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1580,13 +1580,13 @@ TEST_F(BuiltinsMathTest, Ceil_4) // Math.ceil(true) TEST_F(BuiltinsMathTest, Ceil_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1595,13 +1595,13 @@ TEST_F(BuiltinsMathTest, Ceil_5) // Math.ceil(false) TEST_F(BuiltinsMathTest, Ceil_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1611,13 +1611,13 @@ TEST_F(BuiltinsMathTest, Ceil_6) TEST_F(BuiltinsMathTest, Ceil_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1627,13 +1627,13 @@ TEST_F(BuiltinsMathTest, Ceil_7) TEST_F(BuiltinsMathTest, Ceil_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1642,13 +1642,13 @@ TEST_F(BuiltinsMathTest, Ceil_8) // Math.ceil(-NaN) TEST_F(BuiltinsMathTest, Ceil_9) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Ceil(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1657,13 +1657,13 @@ TEST_F(BuiltinsMathTest, Ceil_9) // Math.cos(0) TEST_F(BuiltinsMathTest, Cos) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1672,13 +1672,13 @@ TEST_F(BuiltinsMathTest, Cos) // Math.cos(-NAN) TEST_F(BuiltinsMathTest, Cos_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1687,13 +1687,13 @@ TEST_F(BuiltinsMathTest, Cos_1) // Math.cos(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Cos_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1702,13 +1702,13 @@ TEST_F(BuiltinsMathTest, Cos_2) // Math.cos(-POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Cos_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1717,13 +1717,13 @@ TEST_F(BuiltinsMathTest, Cos_3) // Math.cos(true) TEST_F(BuiltinsMathTest, Cos_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.5403023058681398); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1732,13 +1732,13 @@ TEST_F(BuiltinsMathTest, Cos_4) // Math.cos(false) TEST_F(BuiltinsMathTest, Cos_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1748,13 +1748,13 @@ TEST_F(BuiltinsMathTest, Cos_5) TEST_F(BuiltinsMathTest, Cos_6) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1764,13 +1764,13 @@ TEST_F(BuiltinsMathTest, Cos_6) TEST_F(BuiltinsMathTest, Cos_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cos(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9960946152060809); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1779,13 +1779,13 @@ TEST_F(BuiltinsMathTest, Cos_7) // Math.cosh(0) TEST_F(BuiltinsMathTest, Cosh) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1794,13 +1794,13 @@ TEST_F(BuiltinsMathTest, Cosh) // Math.cosh(-NAN) TEST_F(BuiltinsMathTest, Cosh_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1809,13 +1809,13 @@ TEST_F(BuiltinsMathTest, Cosh_1) // Math.cosh(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Cosh_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1824,13 +1824,13 @@ TEST_F(BuiltinsMathTest, Cosh_2) // Math.cosh(-POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Cosh_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1839,13 +1839,13 @@ TEST_F(BuiltinsMathTest, Cosh_3) // Math.cosh(true) TEST_F(BuiltinsMathTest, Cosh_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5430806348152437); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1854,13 +1854,13 @@ TEST_F(BuiltinsMathTest, Cosh_4) // Math.cosh(false) TEST_F(BuiltinsMathTest, Cosh_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1870,13 +1870,13 @@ TEST_F(BuiltinsMathTest, Cosh_5) TEST_F(BuiltinsMathTest, Cosh_6) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(" "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1886,13 +1886,13 @@ TEST_F(BuiltinsMathTest, Cosh_6) TEST_F(BuiltinsMathTest, Cosh_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Cosh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(12.659607234875645); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1901,13 +1901,13 @@ TEST_F(BuiltinsMathTest, Cosh_7) // Math.exp(0) TEST_F(BuiltinsMathTest, Exp) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1916,13 +1916,13 @@ TEST_F(BuiltinsMathTest, Exp) // Math.exp(-NAN) TEST_F(BuiltinsMathTest, Exp_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1931,13 +1931,13 @@ TEST_F(BuiltinsMathTest, Exp_1) // Math.exp(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Exp_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1946,13 +1946,13 @@ TEST_F(BuiltinsMathTest, Exp_2) // Math.exp(-POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Exp_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1961,13 +1961,13 @@ TEST_F(BuiltinsMathTest, Exp_3) // Math.exp(true) TEST_F(BuiltinsMathTest, Exp_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(2.718281828459045); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1976,13 +1976,13 @@ TEST_F(BuiltinsMathTest, Exp_4) // Math.exp(false) TEST_F(BuiltinsMathTest, Exp_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1992,13 +1992,13 @@ TEST_F(BuiltinsMathTest, Exp_5) TEST_F(BuiltinsMathTest, Exp_6) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2008,13 +2008,13 @@ TEST_F(BuiltinsMathTest, Exp_6) TEST_F(BuiltinsMathTest, Exp_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Exp(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.039557498788398725); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2023,13 +2023,13 @@ TEST_F(BuiltinsMathTest, Exp_7) // Math.Expm1(0) TEST_F(BuiltinsMathTest, Expm1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2038,13 +2038,13 @@ TEST_F(BuiltinsMathTest, Expm1) // Math.Expm1(-0.0) TEST_F(BuiltinsMathTest, Expm1_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2053,13 +2053,13 @@ TEST_F(BuiltinsMathTest, Expm1_1) // Math.Expm1(-NAN) TEST_F(BuiltinsMathTest, Expm1_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2068,13 +2068,13 @@ TEST_F(BuiltinsMathTest, Expm1_2) // Math.Expm1(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Expm1_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2083,13 +2083,13 @@ TEST_F(BuiltinsMathTest, Expm1_3) // Math.Expm1(-POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Expm1_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2098,13 +2098,13 @@ TEST_F(BuiltinsMathTest, Expm1_4) // Math.expm1(true) TEST_F(BuiltinsMathTest, Expm1_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); double expect = 1.718281828459045; ASSERT_TRUE(result.IsDouble()); @@ -2114,13 +2114,13 @@ TEST_F(BuiltinsMathTest, Expm1_5) // Math.expm1(false) TEST_F(BuiltinsMathTest, Expm1_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2130,13 +2130,13 @@ TEST_F(BuiltinsMathTest, Expm1_6) TEST_F(BuiltinsMathTest, Expm1_7) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(" "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2146,13 +2146,13 @@ TEST_F(BuiltinsMathTest, Expm1_7) TEST_F(BuiltinsMathTest, Expm1_8) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9604425012116012); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2162,13 +2162,13 @@ TEST_F(BuiltinsMathTest, Expm1_8) TEST_F(BuiltinsMathTest, Expm1_9) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0x12"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Expm1(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(65659968.13733051); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2177,13 +2177,13 @@ TEST_F(BuiltinsMathTest, Expm1_9) // Math.floor(-0.0) TEST_F(BuiltinsMathTest, Floor) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Floor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2192,13 +2192,13 @@ TEST_F(BuiltinsMathTest, Floor) // Math.floor(-NAN) TEST_F(BuiltinsMathTest, Floor_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Floor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2207,13 +2207,13 @@ TEST_F(BuiltinsMathTest, Floor_1) // Math.floor(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Floor_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Floor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2222,13 +2222,13 @@ TEST_F(BuiltinsMathTest, Floor_2) // Math.floor(true) TEST_F(BuiltinsMathTest, Floor_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Floor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2238,13 +2238,13 @@ TEST_F(BuiltinsMathTest, Floor_3) TEST_F(BuiltinsMathTest, Floor_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Floor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2253,13 +2253,13 @@ TEST_F(BuiltinsMathTest, Floor_4) // Math.log(-0.0) TEST_F(BuiltinsMathTest, Log) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2268,13 +2268,13 @@ TEST_F(BuiltinsMathTest, Log) // Math.log(-NAN) TEST_F(BuiltinsMathTest, Log_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2283,13 +2283,13 @@ TEST_F(BuiltinsMathTest, Log_1) // Math.log(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Log_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2298,13 +2298,13 @@ TEST_F(BuiltinsMathTest, Log_2) // Math.log(true) TEST_F(BuiltinsMathTest, Log_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2314,13 +2314,13 @@ TEST_F(BuiltinsMathTest, Log_3) TEST_F(BuiltinsMathTest, Log_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2329,13 +2329,13 @@ TEST_F(BuiltinsMathTest, Log_4) // Math.log(0.12) TEST_F(BuiltinsMathTest, Log_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.12)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.12)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-2.120263536200091); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2344,13 +2344,13 @@ TEST_F(BuiltinsMathTest, Log_5) // Math.log1p(-0.0) TEST_F(BuiltinsMathTest, Log1p) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log1p(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2359,13 +2359,13 @@ TEST_F(BuiltinsMathTest, Log1p) // Math.log1p(-NAN) TEST_F(BuiltinsMathTest, Log1p_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log1p(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2374,13 +2374,13 @@ TEST_F(BuiltinsMathTest, Log1p_1) // Math.log1p(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Log1p_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log1p(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2389,13 +2389,13 @@ TEST_F(BuiltinsMathTest, Log1p_2) // Math.log1p(true) TEST_F(BuiltinsMathTest, Log1p_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log1p(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.6931471805599453); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2405,13 +2405,13 @@ TEST_F(BuiltinsMathTest, Log1p_3) TEST_F(BuiltinsMathTest, Log1p_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-3.23"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log1p(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2420,13 +2420,13 @@ TEST_F(BuiltinsMathTest, Log1p_4) // Math.log1p(0.12) TEST_F(BuiltinsMathTest, Log1p_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.12)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.12)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log1p(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.11332868530700317); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2435,13 +2435,13 @@ TEST_F(BuiltinsMathTest, Log1p_5) // Math.log10(-0.0) TEST_F(BuiltinsMathTest, Log10) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log10(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2450,13 +2450,13 @@ TEST_F(BuiltinsMathTest, Log10) // Math.Log10(-NAN) TEST_F(BuiltinsMathTest, Log10_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log10(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2465,13 +2465,13 @@ TEST_F(BuiltinsMathTest, Log10_1) // Math.Log10(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Log10_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log10(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2480,13 +2480,13 @@ TEST_F(BuiltinsMathTest, Log10_2) // Math.Log10(true) TEST_F(BuiltinsMathTest, Log10_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log10(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2496,13 +2496,13 @@ TEST_F(BuiltinsMathTest, Log10_3) TEST_F(BuiltinsMathTest, Log10_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log10(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.3010299956639812); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2511,13 +2511,13 @@ TEST_F(BuiltinsMathTest, Log10_4) // Math.Log10(0.12) TEST_F(BuiltinsMathTest, Log10_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.12)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.12)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log10(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9208187539523752); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2526,13 +2526,13 @@ TEST_F(BuiltinsMathTest, Log10_5) // Math.log2(-0.0) TEST_F(BuiltinsMathTest, Log2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2541,13 +2541,13 @@ TEST_F(BuiltinsMathTest, Log2) // Math.log2(-NAN) TEST_F(BuiltinsMathTest, Log2_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2556,13 +2556,13 @@ TEST_F(BuiltinsMathTest, Log2_1) // Math.log2(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Log2_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2571,13 +2571,13 @@ TEST_F(BuiltinsMathTest, Log2_2) // Math.log2(true) TEST_F(BuiltinsMathTest, Log2_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2587,13 +2587,13 @@ TEST_F(BuiltinsMathTest, Log2_3) TEST_F(BuiltinsMathTest, Log2_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2602,13 +2602,13 @@ TEST_F(BuiltinsMathTest, Log2_4) // Math.log2(1) TEST_F(BuiltinsMathTest, Log2_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Log2(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2617,15 +2617,15 @@ TEST_F(BuiltinsMathTest, Log2_5) // Math.Max(NaN,1,POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Max) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Max(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2634,12 +2634,12 @@ TEST_F(BuiltinsMathTest, Max) // Math.Max() TEST_F(BuiltinsMathTest, Max_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Max(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2649,15 +2649,15 @@ TEST_F(BuiltinsMathTest, Max_1) TEST_F(BuiltinsMathTest, Max_2) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("3"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(100))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(2.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(100))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(2.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Max(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(100); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2667,15 +2667,15 @@ TEST_F(BuiltinsMathTest, Max_2) TEST_F(BuiltinsMathTest, Max_3) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("100"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info->SetCallArg(1, test.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(-101.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(-101.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Max(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(100.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2685,15 +2685,15 @@ TEST_F(BuiltinsMathTest, Max_3) TEST_F(BuiltinsMathTest, Max_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-100"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-3))); - ecma_runtime_call_info->SetCallArg(1, test.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-3))); + ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Max(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2702,15 +2702,15 @@ TEST_F(BuiltinsMathTest, Max_4) // Math.min(NaN,1,POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Min) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Min(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2719,12 +2719,12 @@ TEST_F(BuiltinsMathTest, Min) // Math.min() TEST_F(BuiltinsMathTest, Min_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Min(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2734,15 +2734,15 @@ TEST_F(BuiltinsMathTest, Min_1) TEST_F(BuiltinsMathTest, Min_2) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("3"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(100))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(2.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(100))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(2.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Min(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(2.5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2752,15 +2752,15 @@ TEST_F(BuiltinsMathTest, Min_2) TEST_F(BuiltinsMathTest, Min_3) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("100"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info->SetCallArg(1, test.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(-101.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(-101.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Min(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-101.5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2769,15 +2769,15 @@ TEST_F(BuiltinsMathTest, Min_3) // Math.min(3,100,false) TEST_F(BuiltinsMathTest, Min_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(100))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::False()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(100))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Min(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2787,14 +2787,14 @@ TEST_F(BuiltinsMathTest, Min_4) TEST_F(BuiltinsMathTest, Pow) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-2"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); - ecma_runtime_call_info->SetCallArg(1, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); + ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Pow(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.25); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2803,26 +2803,26 @@ TEST_F(BuiltinsMathTest, Pow) // Math.pow(-NaN,-2) TEST_F(BuiltinsMathTest, Pow_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-2))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Pow(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(std::isnan(result.GetDouble())); } // Math.pow() TEST_F(BuiltinsMathTest, Pow_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Pow(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2831,14 +2831,14 @@ TEST_F(BuiltinsMathTest, Pow_2) // Math.pow(false,-2) TEST_F(BuiltinsMathTest, Pow_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-2))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Pow(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2847,14 +2847,14 @@ TEST_F(BuiltinsMathTest, Pow_3) // Math.random() TEST_F(BuiltinsMathTest, Random) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = math::Random(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = math::Random(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue result2 = math::Random(ecma_runtime_call_info.get()); + JSTaggedValue result2 = math::Random(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_NE(result1.GetRawData(), result2.GetRawData()); } @@ -2862,14 +2862,14 @@ TEST_F(BuiltinsMathTest, Random) // Math.random() TEST_F(BuiltinsMathTest, Random_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = math::Random(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = math::Random(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue result2 = math::Random(ecma_runtime_call_info.get()); + JSTaggedValue result2 = math::Random(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); double value1 = JSTaggedValue(static_cast(result1.GetRawData())).GetDouble(); double value2 = JSTaggedValue(static_cast(result2.GetRawData())).GetDouble(); @@ -2882,13 +2882,13 @@ TEST_F(BuiltinsMathTest, Random_1) // Math.round(-NaN) TEST_F(BuiltinsMathTest, Round) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Round(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2897,13 +2897,13 @@ TEST_F(BuiltinsMathTest, Round) // Math.round(1.25) TEST_F(BuiltinsMathTest, Round_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.25)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.25)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Round(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2912,13 +2912,13 @@ TEST_F(BuiltinsMathTest, Round_1) // Math.round(-0.14) TEST_F(BuiltinsMathTest, Round_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.14)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.14)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Round(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2927,13 +2927,13 @@ TEST_F(BuiltinsMathTest, Round_2) // Math.round(-0.7) TEST_F(BuiltinsMathTest, Round_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.7)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.7)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Round(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2942,13 +2942,13 @@ TEST_F(BuiltinsMathTest, Round_3) // Math.round(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Round_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Round(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2957,13 +2957,13 @@ TEST_F(BuiltinsMathTest, Round_4) // Math.fround(POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Fround) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Fround(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2972,13 +2972,13 @@ TEST_F(BuiltinsMathTest, Fround) // Math.fround(-NaN) TEST_F(BuiltinsMathTest, Fround_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Fround(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2987,13 +2987,13 @@ TEST_F(BuiltinsMathTest, Fround_1) // Math.fround(-0) TEST_F(BuiltinsMathTest, Fround_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Fround(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3002,13 +3002,13 @@ TEST_F(BuiltinsMathTest, Fround_2) // Math.fround(1.337) TEST_F(BuiltinsMathTest, Fround_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.337)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.337)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Fround(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.3370000123977661); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3017,13 +3017,13 @@ TEST_F(BuiltinsMathTest, Fround_3) // Math.fround(-668523145.253485) TEST_F(BuiltinsMathTest, Fround_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-668523145.253485)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-668523145.253485)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Fround(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-668523136.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3032,13 +3032,13 @@ TEST_F(BuiltinsMathTest, Fround_4) // Math.clz32(NaN) TEST_F(BuiltinsMathTest, Clz32) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Clz32(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3047,13 +3047,13 @@ TEST_F(BuiltinsMathTest, Clz32) // Math.clz32(-0) TEST_F(BuiltinsMathTest, Clz32_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Clz32(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3062,13 +3062,13 @@ TEST_F(BuiltinsMathTest, Clz32_1) // Math.clz32(1) TEST_F(BuiltinsMathTest, Clz32_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Clz32(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(31); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3077,13 +3077,13 @@ TEST_F(BuiltinsMathTest, Clz32_2) // Math.clz32(568243) TEST_F(BuiltinsMathTest, Clz32_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(568243))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(568243))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Clz32(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(12); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3092,13 +3092,13 @@ TEST_F(BuiltinsMathTest, Clz32_3) // Math.clz32(4294967295) TEST_F(BuiltinsMathTest, Clz32_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(4294967295))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(4294967295))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Clz32(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3107,13 +3107,13 @@ TEST_F(BuiltinsMathTest, Clz32_4) // Math.clz32(10000000000.123) TEST_F(BuiltinsMathTest, Clz32_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(10000000000.123)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(10000000000.123)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Clz32(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3122,12 +3122,12 @@ TEST_F(BuiltinsMathTest, Clz32_5) // Math.clz32() TEST_F(BuiltinsMathTest, Clz32_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Clz32(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3136,12 +3136,12 @@ TEST_F(BuiltinsMathTest, Clz32_6) // Math.hypot() TEST_F(BuiltinsMathTest, Hypot) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Hypot(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3150,13 +3150,13 @@ TEST_F(BuiltinsMathTest, Hypot) // Math.hypot(-2.1) TEST_F(BuiltinsMathTest, Hypot_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-2.1)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-2.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Hypot(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(2.1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3165,13 +3165,13 @@ TEST_F(BuiltinsMathTest, Hypot_1) // Math.hypot(-NaN, 1) TEST_F(BuiltinsMathTest, Hypot_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Hypot(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsDouble()); ASSERT_TRUE(std::isnan(result.GetDouble())); @@ -3180,17 +3180,17 @@ TEST_F(BuiltinsMathTest, Hypot_2) // Math.hypot(true, 5, 8, -0.2, 90000) TEST_F(BuiltinsMathTest, Hypot_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 14); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(8))); - ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(-0.2)); - ecma_runtime_call_info->SetCallArg(4, JSTaggedValue(static_cast(90000))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 14); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(8))); + ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(-0.2)); + ecmaRuntimeCallInfo->SetCallArg(4, JSTaggedValue(static_cast(90000))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Hypot(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(90000.00050022222); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3199,12 +3199,12 @@ TEST_F(BuiltinsMathTest, Hypot_3) // Math.Imul() TEST_F(BuiltinsMathTest, Imul) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Imul(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3214,14 +3214,14 @@ TEST_F(BuiltinsMathTest, Imul) TEST_F(BuiltinsMathTest, Imul_1) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-2"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(9.256)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(9.256)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Imul(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(-18); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3230,14 +3230,14 @@ TEST_F(BuiltinsMathTest, Imul_1) // Math.Imul(5,0xffffffff) TEST_F(BuiltinsMathTest, Imul_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0xffffffff))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0xffffffff))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Imul(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(-5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3246,14 +3246,14 @@ TEST_F(BuiltinsMathTest, Imul_2) // Math.Imul(5,0xfffffffe) TEST_F(BuiltinsMathTest, Imul_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0xfffffffe))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0xfffffffe))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Imul(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedInt(-10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3262,13 +3262,13 @@ TEST_F(BuiltinsMathTest, Imul_3) // Math.sin(-1) TEST_F(BuiltinsMathTest, Sin) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.8414709848078965); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3277,13 +3277,13 @@ TEST_F(BuiltinsMathTest, Sin) // Math.sin(-1.5) TEST_F(BuiltinsMathTest, Sin_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-1.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9974949866040544); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3292,13 +3292,13 @@ TEST_F(BuiltinsMathTest, Sin_2) // Math.sin(null) TEST_F(BuiltinsMathTest, Sin_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3307,13 +3307,13 @@ TEST_F(BuiltinsMathTest, Sin_3) // Math.sin(UNDEFINED) TEST_F(BuiltinsMathTest, Sin_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3322,13 +3322,13 @@ TEST_F(BuiltinsMathTest, Sin_4) // Math.sin(true) TEST_F(BuiltinsMathTest, Sin_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.8414709848078965); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3338,13 +3338,13 @@ TEST_F(BuiltinsMathTest, Sin_5) TEST_F(BuiltinsMathTest, Sin_6) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.09983341664682815); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3353,13 +3353,13 @@ TEST_F(BuiltinsMathTest, Sin_6) // Math.sin(Number.POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Sin_7) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3368,13 +3368,13 @@ TEST_F(BuiltinsMathTest, Sin_7) // Math.sin(-NaN) TEST_F(BuiltinsMathTest, Sin_8) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sin(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3383,13 +3383,13 @@ TEST_F(BuiltinsMathTest, Sin_8) // Math.sinh(-1) TEST_F(BuiltinsMathTest, Sinh) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.1752011936438014); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3398,13 +3398,13 @@ TEST_F(BuiltinsMathTest, Sinh) // Math.sinh(-1.5) TEST_F(BuiltinsMathTest, Sinh_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-1.5)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-2.1292794550948173); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3413,13 +3413,13 @@ TEST_F(BuiltinsMathTest, Sinh_1) // Math.sinh(null) TEST_F(BuiltinsMathTest, Sinh_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3428,13 +3428,13 @@ TEST_F(BuiltinsMathTest, Sinh_2) // Math.sinh(UNDEFINED) TEST_F(BuiltinsMathTest, Sinh_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3443,13 +3443,13 @@ TEST_F(BuiltinsMathTest, Sinh_3) // Math.sinh(true) TEST_F(BuiltinsMathTest, Sinh_4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.1752011936438014); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3459,13 +3459,13 @@ TEST_F(BuiltinsMathTest, Sinh_4) TEST_F(BuiltinsMathTest, Sinh_5) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.10016675001984403); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3474,13 +3474,13 @@ TEST_F(BuiltinsMathTest, Sinh_5) // Math.sinh(-Number.POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Sinh_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3489,13 +3489,13 @@ TEST_F(BuiltinsMathTest, Sinh_6) // Math.sinh(-NaN) TEST_F(BuiltinsMathTest, Sinh_7) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sinh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3504,13 +3504,13 @@ TEST_F(BuiltinsMathTest, Sinh_7) // Math.sqrt(-1) TEST_F(BuiltinsMathTest, Sqrt) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sqrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3519,13 +3519,13 @@ TEST_F(BuiltinsMathTest, Sqrt) // Math.sqrt(-0) TEST_F(BuiltinsMathTest, Sqrt_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sqrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3534,13 +3534,13 @@ TEST_F(BuiltinsMathTest, Sqrt_1) // Math.sqrt(null) TEST_F(BuiltinsMathTest, Sqrt_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sqrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3549,13 +3549,13 @@ TEST_F(BuiltinsMathTest, Sqrt_2) // Math.sqrt(true) TEST_F(BuiltinsMathTest, Sqrt_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sqrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3565,13 +3565,13 @@ TEST_F(BuiltinsMathTest, Sqrt_3) TEST_F(BuiltinsMathTest, Sqrt_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sqrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.31622776601683794); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3580,13 +3580,13 @@ TEST_F(BuiltinsMathTest, Sqrt_4) // Math.sqrt(Number.POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Sqrt_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sqrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3595,13 +3595,13 @@ TEST_F(BuiltinsMathTest, Sqrt_5) // Math.sqrt(-NaN) TEST_F(BuiltinsMathTest, Sqrt_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Sqrt(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3610,13 +3610,13 @@ TEST_F(BuiltinsMathTest, Sqrt_6) // Math.tan(-1) TEST_F(BuiltinsMathTest, Tan) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.5574077246549023); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3625,13 +3625,13 @@ TEST_F(BuiltinsMathTest, Tan) // Math.tan(-0) TEST_F(BuiltinsMathTest, Tan_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3640,13 +3640,13 @@ TEST_F(BuiltinsMathTest, Tan_1) // Math.tan(null) TEST_F(BuiltinsMathTest, Tan_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3655,13 +3655,13 @@ TEST_F(BuiltinsMathTest, Tan_2) // Math.tan(true) TEST_F(BuiltinsMathTest, Tan_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5574077246549023); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3671,13 +3671,13 @@ TEST_F(BuiltinsMathTest, Tan_3) TEST_F(BuiltinsMathTest, Tan_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.10033467208545055); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3686,13 +3686,13 @@ TEST_F(BuiltinsMathTest, Tan_4) // Math.tan(Number.POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Tan_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3701,13 +3701,13 @@ TEST_F(BuiltinsMathTest, Tan_5) // Math.tan(-NaN) TEST_F(BuiltinsMathTest, Tan_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tan(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3716,13 +3716,13 @@ TEST_F(BuiltinsMathTest, Tan_6) // Math.tanh(-1) TEST_F(BuiltinsMathTest, Tanh) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.7615941559557649); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3731,13 +3731,13 @@ TEST_F(BuiltinsMathTest, Tanh) // Math.tanh(-0) TEST_F(BuiltinsMathTest, Tanh_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3746,13 +3746,13 @@ TEST_F(BuiltinsMathTest, Tanh_1) // Math.tanh(null) TEST_F(BuiltinsMathTest, Tanh_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3761,13 +3761,13 @@ TEST_F(BuiltinsMathTest, Tanh_2) // Math.tanh(true) TEST_F(BuiltinsMathTest, Tanh_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.7615941559557649); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3777,13 +3777,13 @@ TEST_F(BuiltinsMathTest, Tanh_3) TEST_F(BuiltinsMathTest, Tanh_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0.1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0.09966799462495582); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3792,13 +3792,13 @@ TEST_F(BuiltinsMathTest, Tanh_4) // Math.tanh(Number.POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Tanh_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3807,13 +3807,13 @@ TEST_F(BuiltinsMathTest, Tanh_5) // Math.tanh(-NaN) TEST_F(BuiltinsMathTest, Tanh_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Tanh(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3822,13 +3822,13 @@ TEST_F(BuiltinsMathTest, Tanh_6) // Math.trunc(-1) TEST_F(BuiltinsMathTest, Trunc) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Trunc(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3837,13 +3837,13 @@ TEST_F(BuiltinsMathTest, Trunc) // Math.trunc(-0) TEST_F(BuiltinsMathTest, Trunc_1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Trunc(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3852,13 +3852,13 @@ TEST_F(BuiltinsMathTest, Trunc_1) // Math.trunc(null) TEST_F(BuiltinsMathTest, Trunc_2) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Trunc(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3867,13 +3867,13 @@ TEST_F(BuiltinsMathTest, Trunc_2) // Math.trunc(true) TEST_F(BuiltinsMathTest, Trunc_3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Trunc(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3883,13 +3883,13 @@ TEST_F(BuiltinsMathTest, Trunc_3) TEST_F(BuiltinsMathTest, Trunc_4) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("-0.1"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Trunc(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3898,13 +3898,13 @@ TEST_F(BuiltinsMathTest, Trunc_4) // Math.trunc(Number.POSITIVE_INFINITY) TEST_F(BuiltinsMathTest, Trunc_5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Trunc(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3913,13 +3913,13 @@ TEST_F(BuiltinsMathTest, Trunc_5) // Math.trunc(-NaN) TEST_F(BuiltinsMathTest, Trunc_6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = math::Trunc(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); diff --git a/tests/runtime/builtins/builtins_number_test.cpp b/tests/runtime/builtins/builtins_number_test.cpp index a0e69aa23f7a82f73ceb396dad64b0e817a0b2a6..e96030687f020a791882a10fe70e21cfba4ed1b8 100644 --- a/tests/runtime/builtins/builtins_number_test.cpp +++ b/tests/runtime/builtins/builtins_number_test.cpp @@ -77,15 +77,15 @@ TEST_F(BuiltinsNumberTest, NumberConstructor) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle number(env->GetNumberFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*number), 6); - ecma_runtime_call_info->SetFunction(number.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*number), 6); + ecmaRuntimeCallInfo->SetFunction(number.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::NumberConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::NumberConstructor(ecmaRuntimeCallInfo.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSPrimitiveRef *ref = JSPrimitiveRef::Cast(value.GetTaggedObject()); @@ -96,26 +96,26 @@ TEST_F(BuiltinsNumberTest, NumberConstructor) TEST_F(BuiltinsNumberTest, IsFinite) { const double value = -10; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(value))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(value))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsFinite(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } // Number.isFinite(Number.MAX_VALUE) TEST_F(BuiltinsNumberTest, IsFinite1) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::MAX_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::MAX_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsFinite(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -123,91 +123,91 @@ TEST_F(BuiltinsNumberTest, IsFinite1) TEST_F(BuiltinsNumberTest, IsFinite2) { JSHandle test = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("helloworld"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsFinite(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } // Number.isFinite(NaN) TEST_F(BuiltinsNumberTest, IsFinite3) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsFinite(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } // Number.isFinite(Infinity) TEST_F(BuiltinsNumberTest, IsFinite4) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsFinite(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } // Number.isFinite(undefined) TEST_F(BuiltinsNumberTest, IsFinite5) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsFinite(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } // Number.isFinite(null) TEST_F(BuiltinsNumberTest, IsFinite6) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsFinite(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } // Number.isInteger(0.1) TEST_F(BuiltinsNumberTest, IsInteger) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.1)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsInteger(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsInteger(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } // Number.isNaN(0.1) TEST_F(BuiltinsNumberTest, IsNaN) { - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.1)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::IsNaN(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::IsNaN(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -215,164 +215,164 @@ TEST_F(BuiltinsNumberTest, IsNaN) TEST_F(BuiltinsNumberTest, ToString) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle number_object(env->GetNumberFunction()); + JSHandle numberObject(env->GetNumberFunction()); JSHandle value(thread_, JSTaggedValue(123.456)); - JSHandle number = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(number_object, value); + JSHandle number = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(numberObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(number.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(7.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(7.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::proto::ToString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); - JSHandle correct_result = factory->NewFromCanBeCompressString("234.312256641535441"); + JSHandle correctResult = factory->NewFromCanBeCompressString("234.312256641535441"); PandaVector test(res->GetLength() + 1); res->CopyDataUtf8(test.data(), res->GetLength()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correct_result)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); } // new Number(123.456).toExponential(5) TEST_F(BuiltinsNumberTest, IsExponential) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle number_object(env->GetNumberFunction()); + JSHandle numberObject(env->GetNumberFunction()); JSHandle value(thread_, JSTaggedValue(123.456)); - JSHandle number = factory->NewJSPrimitiveRef(number_object, value); + JSHandle number = factory->NewJSPrimitiveRef(numberObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(number.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(5.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(5.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::proto::ToExponential(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::proto::ToExponential(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); - JSHandle correct_result = factory->NewFromCanBeCompressString("1.23456e+2"); + JSHandle correctResult = factory->NewFromCanBeCompressString("1.23456e+2"); PandaVector test(res->GetLength() + 1); res->CopyDataUtf8(test.data(), res->GetLength()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correct_result)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); } // new Number(123.456).toFixed(10) TEST_F(BuiltinsNumberTest, ToFixed) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle number_object(env->GetNumberFunction()); + JSHandle numberObject(env->GetNumberFunction()); JSHandle value(thread_, JSTaggedValue(123.456)); - JSHandle number = factory->NewJSPrimitiveRef(number_object, value); + JSHandle number = factory->NewJSPrimitiveRef(numberObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(number.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(10.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(10.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::proto::ToFixed(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::proto::ToFixed(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); - JSHandle correct_result = factory->NewFromCanBeCompressString("123.4560000000"); - ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correct_result)); + JSHandle correctResult = factory->NewFromCanBeCompressString("123.4560000000"); + ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); } // new Number(123.456).toFixed(30) TEST_F(BuiltinsNumberTest, ToFixed1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle number_object(env->GetNumberFunction()); + JSHandle numberObject(env->GetNumberFunction()); JSHandle value(thread_, JSTaggedValue(123.456)); - JSHandle number = factory->NewJSPrimitiveRef(number_object, value); + JSHandle number = factory->NewJSPrimitiveRef(numberObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(number.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(30.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(30.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::proto::ToFixed(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::proto::ToFixed(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); - JSHandle correct_result = factory->NewFromCanBeCompressString("123.456000000000003069544618483633"); - ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correct_result)); + JSHandle correctResult = factory->NewFromCanBeCompressString("123.456000000000003069544618483633"); + ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); } // new Number(1e21).toFixed(20) TEST_F(BuiltinsNumberTest, ToFixed2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle number_object(env->GetNumberFunction()); + JSHandle numberObject(env->GetNumberFunction()); JSHandle value(thread_, JSTaggedValue(1e21)); - JSHandle number = factory->NewJSPrimitiveRef(number_object, value); + JSHandle number = factory->NewJSPrimitiveRef(numberObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(number.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(20.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(20.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::proto::ToFixed(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::proto::ToFixed(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); - JSHandle correct_result = factory->NewFromCanBeCompressString("1e+21"); + JSHandle correctResult = factory->NewFromCanBeCompressString("1e+21"); PandaVector test(res->GetLength() + 1); res->CopyDataUtf8(test.data(), res->GetLength()); std::cout << test.data(); - ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correct_result)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); } // new Number(123.456).toPrecision(8) TEST_F(BuiltinsNumberTest, ToPrecision) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle number_object(env->GetNumberFunction()); + JSHandle numberObject(env->GetNumberFunction()); JSHandle value(thread_, JSTaggedValue(123.456)); - JSHandle number = factory->NewJSPrimitiveRef(number_object, value); + JSHandle number = factory->NewJSPrimitiveRef(numberObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(number.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(8.0)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(8.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::proto::ToPrecision(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::proto::ToPrecision(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread_, reinterpret_cast(result.GetRawData())); - JSHandle correct_result = factory->NewFromCanBeCompressString("123.45600"); - ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correct_result)); + JSHandle correctResult = factory->NewFromCanBeCompressString("123.45600"); + ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); } // Number.parseFloat(0x123) TEST_F(BuiltinsNumberTest, parseFloat) { JSHandle param = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0x123"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, param.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, param.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::ParseFloat(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::ParseFloat(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(0)).GetRawData()); } @@ -380,13 +380,13 @@ TEST_F(BuiltinsNumberTest, parseFloat) TEST_F(BuiltinsNumberTest, parseFloat1) { JSHandle param = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0x123xx"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, param.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, param.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::ParseFloat(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::ParseFloat(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(0)).GetRawData()); } @@ -396,14 +396,14 @@ TEST_F(BuiltinsNumberTest, parseInt) const char *number = "0x123"; JSHandle param = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(number); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, param.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(16.0)); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = number::ParseInt(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, param.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(16.0)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = number::ParseInt(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(291)).GetRawData()); } diff --git a/tests/runtime/builtins/builtins_object_test.cpp b/tests/runtime/builtins/builtins_object_test.cpp index bf23711a3606c6c5868d217cd77da71623d1e591..5cdf267c2539ca6808700e5fd73e08f96a246817 100644 --- a/tests/runtime/builtins/builtins_object_test.cpp +++ b/tests/runtime/builtins/builtins_object_test.cpp @@ -68,15 +68,15 @@ private: EcmaHandleScope *scope_ {nullptr}; }; -JSTaggedValue CreateBuiltinJSObject(JSThread *thread, const PandaString &key_c_str) +JSTaggedValue CreateBuiltinJSObject(JSThread *thread, const PandaString &keyCStr) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle obj_fun = global_env->GetObjectFunction(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle objFun = globalEnv->GetObjectFunction(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun)); - JSHandle key(factory->NewFromCanBeCompressString(&key_c_str[0])); + JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(objFun), objFun)); + JSHandle key(factory->NewFromCanBeCompressString(&keyCStr[0])); JSHandle value(thread, JSTaggedValue(1)); JSObject::SetProperty(thread, obj, key, value); return obj.GetTaggedValue(); @@ -84,15 +84,15 @@ JSTaggedValue CreateBuiltinJSObject(JSThread *thread, const PandaString &key_c_s JSFunction *BuiltinsObjectTestCreate(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - return global_env->GetObjectFunction().GetObject(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + return globalEnv->GetObjectFunction().GetObject(); } -JSObject *TestNewJSObject(JSThread *thread, const JSHandle &dyn_class) +JSObject *TestNewJSObject(JSThread *thread, const JSHandle &dynClass) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSObject *obj = JSObject::Cast(factory->NewDynObject(dyn_class)); + JSObject *obj = JSObject::Cast(factory->NewDynObject(dynClass)); obj->SetElements(thread, factory->EmptyArray().GetTaggedValue(), SKIP_BARRIER); return obj; @@ -102,160 +102,160 @@ JSObject *TestNewJSObject(JSThread *thread, const JSHandle &dyn_class) TEST_F(BuiltinsObjectTest, ObjectConstructor) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle object_func(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle global_env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle obj_fun(global_env->GetObjectFunction()); + JSHandle objectFunc(thread_, BuiltinsObjectTestCreate(thread_)); + JSHandle globalEnv = thread_->GetEcmaVM()->GetGlobalEnv(); + JSHandle objFun(globalEnv->GetObjectFunction()); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::ObjectConstructor(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::ObjectConstructor(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); - JSHandle jt_handle(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); - JSTaggedValue result_proto = jt_handle->GetPrototype(thread_); - JSTaggedValue func_proto = object_func->GetFunctionPrototype(); - ASSERT_EQ(result_proto, func_proto); - ASSERT_TRUE(jt_handle->IsExtensible()); + JSHandle jtHandle(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); + JSTaggedValue resultProto = jtHandle->GetPrototype(thread_); + JSTaggedValue funcProto = objectFunc->GetFunctionPrototype(); + ASSERT_EQ(resultProto, funcProto); + ASSERT_TRUE(jtHandle->IsExtensible()); // num_args = 0 JSHandle object = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(function), function); - auto tg_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*object), 4); - tg_obj_call_info->SetFunction(JSTaggedValue(*obj_fun)); - tg_obj_call_info->SetThis(JSTaggedValue::Undefined()); - tg_obj_call_info->SetNewTarget(JSTaggedValue(*obj_fun)); + auto tgObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*object), 4); + tgObjCallInfo->SetFunction(JSTaggedValue(*objFun)); + tgObjCallInfo->SetThis(JSTaggedValue::Undefined()); + tgObjCallInfo->SetNewTarget(JSTaggedValue(*objFun)); - prev = TestHelper::SetupFrame(thread_, tg_obj_call_info.get()); - JSTaggedValue result_tg = object::ObjectConstructor(tg_obj_call_info.get()); + prev = TestHelper::SetupFrame(thread_, tgObjCallInfo.get()); + JSTaggedValue resultTg = object::ObjectConstructor(tgObjCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_tg.IsObject()); - JSHandle jt_handle_tg(thread_, JSTaggedValue(reinterpret_cast(result_tg.GetRawData()))); - JSTaggedValue result_proto_tg = jt_handle_tg->GetPrototype(thread_); - JSTaggedValue func_proto_tg = object_func->GetFunctionPrototype(); - ASSERT_EQ(result_proto_tg, func_proto_tg); - ASSERT_TRUE(jt_handle_tg->IsExtensible()); + ASSERT_TRUE(resultTg.IsObject()); + JSHandle jtHandleTg(thread_, JSTaggedValue(reinterpret_cast(resultTg.GetRawData()))); + JSTaggedValue resultProtoTg = jtHandleTg->GetPrototype(thread_); + JSTaggedValue funcProtoTg = objectFunc->GetFunctionPrototype(); + ASSERT_EQ(resultProtoTg, funcProtoTg); + ASSERT_TRUE(jtHandleTg->IsExtensible()); // value is null - JSHandle object_vn = + JSHandle objectVn = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(function), function); - auto vn_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*object_vn), 6); - vn_obj_call_info->SetFunction(JSTaggedValue(*obj_fun)); - vn_obj_call_info->SetThis(JSTaggedValue::Undefined()); - vn_obj_call_info->SetCallArg(0, JSTaggedValue::Null()); - vn_obj_call_info->SetNewTarget(JSTaggedValue(*obj_fun)); - - prev = TestHelper::SetupFrame(thread_, vn_obj_call_info.get()); - JSTaggedValue result_vn = object::ObjectConstructor(vn_obj_call_info.get()); + auto vnObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*objectVn), 6); + vnObjCallInfo->SetFunction(JSTaggedValue(*objFun)); + vnObjCallInfo->SetThis(JSTaggedValue::Undefined()); + vnObjCallInfo->SetCallArg(0, JSTaggedValue::Null()); + vnObjCallInfo->SetNewTarget(JSTaggedValue(*objFun)); + + prev = TestHelper::SetupFrame(thread_, vnObjCallInfo.get()); + JSTaggedValue resultVn = object::ObjectConstructor(vnObjCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_vn.IsObject()); - JSHandle jt_handle_vn(thread_, JSTaggedValue(reinterpret_cast(result_vn.GetRawData()))); - JSTaggedValue result_proto_vn = jt_handle_vn->GetPrototype(thread_); - JSTaggedValue func_proto_vn = object_func->GetFunctionPrototype(); - ASSERT_EQ(result_proto_vn, func_proto_vn); - ASSERT_TRUE(jt_handle_vn->IsExtensible()); + ASSERT_TRUE(resultVn.IsObject()); + JSHandle jtHandleVn(thread_, JSTaggedValue(reinterpret_cast(resultVn.GetRawData()))); + JSTaggedValue resultProtoVn = jtHandleVn->GetPrototype(thread_); + JSTaggedValue funcProtoVn = objectFunc->GetFunctionPrototype(); + ASSERT_EQ(resultProtoVn, funcProtoVn); + ASSERT_TRUE(jtHandleVn->IsExtensible()); } // 19.1.2.1Object.assign ( target, ...sources ) TEST_F(BuiltinsObjectTest, Assign) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle obj_handle1 = + JSHandle objHandle1 = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - JSHandle obj_handle2 = + JSHandle objHandle2 = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); JSHandle value1(thread_, JSTaggedValue(1)); - JSObject::SetProperty(thread_, JSHandle(obj_handle1), key1, value1); - EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj_handle1), key1).GetValue()->GetInt(), 1); + JSObject::SetProperty(thread_, JSHandle(objHandle1), key1, value1); + EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(objHandle1), key1).GetValue()->GetInt(), 1); JSHandle key2(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("y")); JSHandle value2(thread_, JSTaggedValue(2)); - JSObject::SetProperty(thread_, JSHandle(obj_handle2), key2, value2); - EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj_handle2), key2).GetValue()->GetInt(), 2); + JSObject::SetProperty(thread_, JSHandle(objHandle2), key2, value2); + EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(objHandle2), key2).GetValue()->GetInt(), 2); - auto assign_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - assign_obj_call_info->SetFunction(JSTaggedValue::Undefined()); - assign_obj_call_info->SetThis(JSTaggedValue::Undefined()); - assign_obj_call_info->SetCallArg(0, obj_handle1.GetTaggedValue()); - assign_obj_call_info->SetCallArg(1, obj_handle2.GetTaggedValue()); + auto assignObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + assignObjCallInfo->SetFunction(JSTaggedValue::Undefined()); + assignObjCallInfo->SetThis(JSTaggedValue::Undefined()); + assignObjCallInfo->SetCallArg(0, objHandle1.GetTaggedValue()); + assignObjCallInfo->SetCallArg(1, objHandle2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, assign_obj_call_info.get()); - JSTaggedValue result = object::Assign(assign_obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, assignObjCallInfo.get()); + JSTaggedValue result = object::Assign(assignObjCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); - JSHandle jt_handle(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); - EXPECT_EQ(JSObject::GetProperty(thread_, jt_handle, key1).GetValue()->GetInt(), 1); - EXPECT_EQ(JSObject::GetProperty(thread_, jt_handle, key2).GetValue()->GetInt(), 2); + JSHandle jtHandle(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); + EXPECT_EQ(JSObject::GetProperty(thread_, jtHandle, key1).GetValue()->GetInt(), 1); + EXPECT_EQ(JSObject::GetProperty(thread_, jtHandle, key2).GetValue()->GetInt(), 2); } // 19.1.2.2Object.create ( O [ , Properties ] ) TEST_F(BuiltinsObjectTest, Create) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle object_func(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle func_proto(thread_, object_func->GetFunctionPrototype()); + JSHandle objectFunc(thread_, BuiltinsObjectTestCreate(thread_)); + JSHandle funcProto(thread_, objectFunc->GetFunctionPrototype()); // no prop - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, func_proto.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, funcProto.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::Create(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::Create(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); - JSHandle jt_handle(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); - JSTaggedValue result_proto = jt_handle->GetPrototype(thread_); - ASSERT_EQ(result_proto, func_proto.GetTaggedValue()); + JSHandle jtHandle(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); + JSTaggedValue resultProto = jtHandle->GetPrototype(thread_); + ASSERT_EQ(resultProto, funcProto.GetTaggedValue()); // has prop JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("prop")); - JSHandle obj_handle = + JSHandle objHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(function), function); - EXPECT_TRUE(*obj_handle != nullptr); + EXPECT_TRUE(*objHandle != nullptr); PropertyDescriptor desc(thread_); desc.SetWritable(false); - JSHandle desc_handle(JSObject::FromPropertyDescriptor(thread_, desc)); + JSHandle descHandle(JSObject::FromPropertyDescriptor(thread_, desc)); - PropertyDescriptor desc_nw(thread_, JSHandle::Cast(desc_handle), true, true, true); - JSObject::DefineOwnProperty(thread_, obj_handle, key, desc_nw); + PropertyDescriptor descNw(thread_, JSHandle::Cast(descHandle), true, true, true); + JSObject::DefineOwnProperty(thread_, objHandle, key, descNw); - auto hp_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - hp_obj_call_info->SetFunction(JSTaggedValue::Undefined()); - hp_obj_call_info->SetThis(JSTaggedValue::Undefined()); - hp_obj_call_info->SetCallArg(0, func_proto.GetTaggedValue()); - hp_obj_call_info->SetCallArg(1, obj_handle.GetTaggedValue()); + auto hpObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + hpObjCallInfo->SetFunction(JSTaggedValue::Undefined()); + hpObjCallInfo->SetThis(JSTaggedValue::Undefined()); + hpObjCallInfo->SetCallArg(0, funcProto.GetTaggedValue()); + hpObjCallInfo->SetCallArg(1, objHandle.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, hp_obj_call_info.get()); - JSTaggedValue result_hp = object::Create(hp_obj_call_info.get()); + prev = TestHelper::SetupFrame(thread_, hpObjCallInfo.get()); + JSTaggedValue resultHp = object::Create(hpObjCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_hp.IsObject()); - PropertyDescriptor desc_res(thread_); - bool success = JSObject::GetOwnProperty(thread_, JSHandle(thread_, result_hp), key, desc_res); + ASSERT_TRUE(resultHp.IsObject()); + PropertyDescriptor descRes(thread_); + bool success = JSObject::GetOwnProperty(thread_, JSHandle(thread_, resultHp), key, descRes); EXPECT_TRUE(success); - EXPECT_TRUE(!desc_res.IsWritable()); + EXPECT_TRUE(!descRes.IsWritable()); // undefined - auto un_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - un_call_info->SetFunction(JSTaggedValue::Undefined()); - un_call_info->SetThis(JSTaggedValue::Undefined()); - un_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto unCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + unCallInfo->SetFunction(JSTaggedValue::Undefined()); + unCallInfo->SetThis(JSTaggedValue::Undefined()); + unCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread_, un_call_info.get()); - JSTaggedValue result_un = object::Create(un_call_info.get()); + prev = TestHelper::SetupFrame(thread_, unCallInfo.get()); + JSTaggedValue resultUn = object::Create(unCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(result_un.GetRawData(), JSTaggedValue::VALUE_EXCEPTION); + ASSERT_EQ(resultUn.GetRawData(), JSTaggedValue::VALUE_EXCEPTION); } // 19.1.2.3Object.defineProperties ( O, Properties ) @@ -263,35 +263,35 @@ TEST_F(BuiltinsObjectTest, DefineProperties) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle obj_func(env->GetObjectFunction()); - JSHandle obj_handle = + JSHandle objFunc(env->GetObjectFunction()); + JSHandle objHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("prop")); - JSHandle jsobj_handle = + JSHandle jsobjHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); PropertyDescriptor desc(thread_); desc.SetWritable(false); - JSHandle desc_handle(JSObject::FromPropertyDescriptor(thread_, desc)); + JSHandle descHandle(JSObject::FromPropertyDescriptor(thread_, desc)); - PropertyDescriptor desc_nw(thread_, JSHandle::Cast(desc_handle), true, true, true); - JSObject::DefineOwnProperty(thread_, jsobj_handle, key, desc_nw); + PropertyDescriptor descNw(thread_, JSHandle::Cast(descHandle), true, true, true); + JSObject::DefineOwnProperty(thread_, jsobjHandle, key, descNw); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); - obj_call_info->SetCallArg(1, jsobj_handle.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); + objCallInfo->SetCallArg(1, jsobjHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::DefineProperties(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::DefineProperties(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); JSTaggedValue res(reinterpret_cast(result.GetRawData())); - PropertyDescriptor desc_res(thread_); - JSObject::GetOwnProperty(thread_, JSHandle(thread_, res), key, desc_res); - EXPECT_TRUE(!desc_res.IsWritable()); + PropertyDescriptor descRes(thread_); + JSObject::GetOwnProperty(thread_, JSHandle(thread_, res), key, descRes); + EXPECT_TRUE(!descRes.IsWritable()); } // 19.1.2.4Object.defineProperty ( O, P, Attributes ) @@ -300,40 +300,40 @@ TEST_F(BuiltinsObjectTest, DefineProperty) JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle obj_func(env->GetObjectFunction()); - JSHandle att_handle = + JSHandle objFunc(env->GetObjectFunction()); + JSHandle attHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - JSHandle obj_handle = + JSHandle objHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); PropertyDescriptor desc(thread_); desc.SetWritable(true); - JSHandle writable_str = thread_->GlobalConstants()->GetHandledWritableString(); + JSHandle writableStr = thread_->GlobalConstants()->GetHandledWritableString(); JSHandle writable(thread_, JSTaggedValue(desc.IsWritable())); - JSObject::CreateDataProperty(thread_, att_handle, writable_str, writable); + JSObject::CreateDataProperty(thread_, attHandle, writableStr, writable); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); - PropertyDescriptor desc_nw(thread_); - JSObject::GetOwnProperty(thread_, obj_handle, key, desc_nw); - EXPECT_TRUE(!desc_nw.HasWritable()); + PropertyDescriptor descNw(thread_); + JSObject::GetOwnProperty(thread_, objHandle, key, descNw); + EXPECT_TRUE(!descNw.HasWritable()); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); - obj_call_info->SetCallArg(1, key.GetTaggedValue()); - obj_call_info->SetCallArg(2, att_handle.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); + objCallInfo->SetCallArg(1, key.GetTaggedValue()); + objCallInfo->SetCallArg(2, attHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::DefineProperty(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::DefineProperty(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); JSTaggedValue res(reinterpret_cast(result.GetRawData())); - PropertyDescriptor desc_res(thread_); - JSObject::GetOwnProperty(thread_, JSHandle(thread_, res), key, desc_res); - EXPECT_TRUE(desc_res.HasWritable()); + PropertyDescriptor descRes(thread_); + JSObject::GetOwnProperty(thread_, JSHandle(thread_, res), key, descRes); + EXPECT_TRUE(descRes.HasWritable()); } // B.2.2.2 Object.prototype.__defineGetter__ ( P, getter ) @@ -345,14 +345,14 @@ TEST_F(BuiltinsObjectTest, DefineGetter) JSHandle key(factory->NewFromString("prop")); JSHandle getter(factory->NewJSFunction(thread_->GetEcmaVM()->GetGlobalEnv())); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, getter.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, getter.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::__defineGetter__(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::__defineGetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -367,14 +367,14 @@ TEST_F(BuiltinsObjectTest, DefineSetter) JSHandle key(factory->NewFromString("prop")); JSHandle setter(factory->NewJSFunction(thread_->GetEcmaVM()->GetGlobalEnv())); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, setter.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, setter.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::__defineSetter__(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::__defineSetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -390,38 +390,38 @@ TEST_F(BuiltinsObjectTest, LookupGetter) JSHandle getter(factory->NewJSFunction(thread_->GetEcmaVM()->GetGlobalEnv())); // First - getter should not be defined. - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::__lookupGetter__(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::__lookupGetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); // Second - set a getter function. - ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, getter.GetTaggedValue()); - - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - result = object::proto::__defineGetter__(ecma_runtime_call_info.get()); + ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, getter.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + result = object::proto::__defineGetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); // Third - check the getter function if it really exists. - ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - result = object::proto::__lookupGetter__(ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + result = object::proto::__lookupGetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result, getter.GetTaggedValue()); @@ -437,38 +437,38 @@ TEST_F(BuiltinsObjectTest, LookupSetter) JSHandle setter(factory->NewJSFunction(thread_->GetEcmaVM()->GetGlobalEnv())); // First - setter should not be defined. - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::__lookupSetter__(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::__lookupSetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); // Second - set a setter function. - ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, setter.GetTaggedValue()); - - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - result = object::proto::__defineSetter__(ecma_runtime_call_info.get()); + ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, setter.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + result = object::proto::__defineSetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); // Third - check the setter function if it really exists. - ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - result = object::proto::__lookupSetter__(ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + result = object::proto::__lookupSetter__(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result, setter.GetTaggedValue()); @@ -479,23 +479,23 @@ TEST_F(BuiltinsObjectTest, Freeze) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); // An object is extensible by default, so it is also non-frozen. - JSHandle empty_obj = + JSHandle emptyObj = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - empty_obj->GetJSHClass()->SetExtensible(true); - auto nofreeze_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - nofreeze_obj_call_info->SetFunction(JSTaggedValue::Undefined()); - nofreeze_obj_call_info->SetThis(JSTaggedValue::Undefined()); - nofreeze_obj_call_info->SetCallArg(0, empty_obj.GetTaggedValue()); + emptyObj->GetJSHClass()->SetExtensible(true); + auto nofreezeObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + nofreezeObjCallInfo->SetFunction(JSTaggedValue::Undefined()); + nofreezeObjCallInfo->SetThis(JSTaggedValue::Undefined()); + nofreezeObjCallInfo->SetCallArg(0, emptyObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, nofreeze_obj_call_info.get()); - JSTaggedValue result = object::IsFrozen(nofreeze_obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, nofreezeObjCallInfo.get()); + JSTaggedValue result = object::IsFrozen(nofreezeObjCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); - object::Freeze(nofreeze_obj_call_info.get()); - JSTaggedValue result_is = object::IsFrozen(nofreeze_obj_call_info.get()); + object::Freeze(nofreezeObjCallInfo.get()); + JSTaggedValue resultIs = object::IsFrozen(nofreezeObjCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(result_is.GetRawData(), JSTaggedValue::True().GetRawData()); + ASSERT_EQ(resultIs.GetRawData(), JSTaggedValue::True().GetRawData()); } // ES2021 20.1.2.7 Object.fromEntries ( iterable ) @@ -512,11 +512,11 @@ TEST_F(BuiltinsObjectTest, FromEntries) JSHandle obj(thread_, arr1); JSHandle prop(thread_, arr2); - JSHandle foo_str = JSHandle(factory->NewFromString("foo")); - JSHandle bar_str = JSHandle(factory->NewFromString("bar")); + JSHandle fooStr = JSHandle(factory->NewFromString("foo")); + JSHandle barStr = JSHandle(factory->NewFromString("bar")); - PropertyDescriptor desc0(thread_, foo_str, true, true, true); - PropertyDescriptor desc1(thread_, bar_str, true, true, true); + PropertyDescriptor desc0(thread_, fooStr, true, true, true); + PropertyDescriptor desc1(thread_, barStr, true, true, true); JSHandle key0(thread_, JSTaggedValue(0)); JSHandle key1(thread_, JSTaggedValue(1)); @@ -524,55 +524,55 @@ TEST_F(BuiltinsObjectTest, FromEntries) JSArray::DefineOwnProperty(thread_, prop, key0, desc0); JSArray::DefineOwnProperty(thread_, prop, key1, desc1); - PropertyDescriptor desc_prop(thread_, JSHandle(prop), true, true, true); - JSArray::DefineOwnProperty(thread_, obj, key0, desc_prop); + PropertyDescriptor descProp(thread_, JSHandle(prop), true, true, true); + JSArray::DefineOwnProperty(thread_, obj, key0, descProp); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::FromEntries(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::FromEntries(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); PropertyDescriptor desc(thread_); - JSObject::GetOwnProperty(thread_, JSHandle(thread_, result), foo_str, desc); + JSObject::GetOwnProperty(thread_, JSHandle(thread_, result), fooStr, desc); - ASSERT_TRUE(JSTaggedValue::SameValue(desc.GetValue().GetTaggedValue(), bar_str.GetTaggedValue())); + ASSERT_TRUE(JSTaggedValue::SameValue(desc.GetValue().GetTaggedValue(), barStr.GetTaggedValue())); } // 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) TEST_F(BuiltinsObjectTest, GetOwnPropertyDescriptor) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle obj_handle = + JSHandle objHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); - PropertyDescriptor desc_enum(thread_); - desc_enum.SetWritable(true); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj_handle), key, desc_enum); + PropertyDescriptor descEnum(thread_); + descEnum.SetWritable(true); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(objHandle), key, descEnum); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); - obj_call_info->SetCallArg(1, key.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); + objCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::GetOwnPropertyDescriptor(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::GetOwnPropertyDescriptor(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); - JSHandle writable_str = thread_->GlobalConstants()->GetHandledWritableString(); + JSHandle writableStr = thread_->GlobalConstants()->GetHandledWritableString(); JSTaggedValue jt(reinterpret_cast(result.GetRawData())); PropertyDescriptor desc(thread_); - JSObject::GetOwnProperty(thread_, JSHandle(thread_, jt), writable_str, desc); + JSObject::GetOwnProperty(thread_, JSHandle(thread_, jt), writableStr, desc); ASSERT_TRUE(JSTaggedValue::SameValue(desc.GetValue().GetTaggedValue(), JSTaggedValue(true))); } @@ -580,60 +580,60 @@ TEST_F(BuiltinsObjectTest, GetOwnPropertyDescriptor) TEST_F(BuiltinsObjectTest, GetOwnPropertyDescriptors) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle obj_handle = + JSHandle objHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - JSHandle key_x(thread_->GetEcmaVM()->GetFactory()->NewFromString("x")); + JSHandle keyX(thread_->GetEcmaVM()->GetFactory()->NewFromString("x")); JSHandle value(thread_, JSTaggedValue(22)); - JSObject::SetProperty(thread_, obj_handle, key_x, value); + JSObject::SetProperty(thread_, objHandle, keyX, value); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::GetOwnPropertyDescriptors(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::GetOwnPropertyDescriptors(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); JSHandle handle(thread_, result); - JSHandle prop = JSObject::GetProperty(thread_, handle, key_x).GetValue(); + JSHandle prop = JSObject::GetProperty(thread_, handle, keyX).GetValue(); - JSHandle value_str = thread_->GlobalConstants()->GetHandledValueString(); - ASSERT_EQ(JSObject::GetProperty(thread_, prop, value_str).GetValue()->GetInt(), 22); + JSHandle valueStr = thread_->GlobalConstants()->GetHandledValueString(); + ASSERT_EQ(JSObject::GetProperty(thread_, prop, valueStr).GetValue()->GetInt(), 22); - JSHandle enumerable_str = thread_->GlobalConstants()->GetHandledEnumerableString(); - ASSERT_EQ(JSObject::GetProperty(thread_, prop, enumerable_str).GetValue().GetTaggedValue(), JSTaggedValue(true)); + JSHandle enumerableStr = thread_->GlobalConstants()->GetHandledEnumerableString(); + ASSERT_EQ(JSObject::GetProperty(thread_, prop, enumerableStr).GetValue().GetTaggedValue(), JSTaggedValue(true)); - JSHandle configurable_str = thread_->GlobalConstants()->GetHandledConfigurableString(); - ASSERT_EQ(JSObject::GetProperty(thread_, prop, configurable_str).GetValue().GetTaggedValue(), JSTaggedValue(true)); + JSHandle configurableStr = thread_->GlobalConstants()->GetHandledConfigurableString(); + ASSERT_EQ(JSObject::GetProperty(thread_, prop, configurableStr).GetValue().GetTaggedValue(), JSTaggedValue(true)); - JSHandle writable_str = thread_->GlobalConstants()->GetHandledWritableString(); - ASSERT_EQ(JSObject::GetProperty(thread_, prop, writable_str).GetValue().GetTaggedValue(), JSTaggedValue(true)); + JSHandle writableStr = thread_->GlobalConstants()->GetHandledWritableString(); + ASSERT_EQ(JSObject::GetProperty(thread_, prop, writableStr).GetValue().GetTaggedValue(), JSTaggedValue(true)); } // 19.1.2.7 Object.getOwnPropertyNames ( O ) TEST_F(BuiltinsObjectTest, GetOwnPropertyNames) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle obj_handle = + JSHandle objHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); JSHandle value(thread_, JSTaggedValue(1)); - JSObject::SetProperty(thread_, JSHandle(obj_handle), key, value); + JSObject::SetProperty(thread_, JSHandle(objHandle), key, value); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::GetOwnPropertyNames(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::GetOwnPropertyNames(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -643,21 +643,21 @@ TEST_F(BuiltinsObjectTest, GetOwnPropertyNames) TEST_F(BuiltinsObjectTest, GetOwnPropertySymbols) { JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); - JSHandle obj_handle = + JSHandle objHandle = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - JSHandle symbol_key = thread_->GetEcmaVM()->GetFactory()->NewJSSymbol(); - JSHandle key(symbol_key); + JSHandle symbolKey = thread_->GetEcmaVM()->GetFactory()->NewJSSymbol(); + JSHandle key(symbolKey); JSHandle value(thread_, JSTaggedValue(1)); - JSObject::SetProperty(thread_, JSHandle(obj_handle), key, value); + JSObject::SetProperty(thread_, JSHandle(objHandle), key, value); thread_->ClearException(); - auto obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - obj_call_info->SetFunction(JSTaggedValue::Undefined()); - obj_call_info->SetThis(JSTaggedValue::Undefined()); - obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info.get()); - JSTaggedValue result = object::GetOwnPropertySymbols(obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo.get()); + JSTaggedValue result = object::GetOwnPropertySymbols(objCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -674,88 +674,88 @@ TEST_F(BuiltinsObjectTest, Is) JSHandle obj2 = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - auto obj_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - obj_call_info1->SetFunction(JSTaggedValue::Undefined()); - obj_call_info1->SetThis(JSTaggedValue::Undefined()); - obj_call_info1->SetCallArg(0, obj1.GetTaggedValue()); - obj_call_info1->SetCallArg(1, obj2.GetTaggedValue()); + auto objCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + objCallInfo1->SetFunction(JSTaggedValue::Undefined()); + objCallInfo1->SetThis(JSTaggedValue::Undefined()); + objCallInfo1->SetCallArg(0, obj1.GetTaggedValue()); + objCallInfo1->SetCallArg(1, obj2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, obj_call_info1.get()); - JSTaggedValue obj_result1 = object::Is(obj_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo1.get()); + JSTaggedValue objResult1 = object::Is(objCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(obj_result1.GetRawData(), JSTaggedValue::False().GetRawData()); + ASSERT_EQ(objResult1.GetRawData(), JSTaggedValue::False().GetRawData()); - obj_call_info1->SetCallArg(1, obj1.GetTaggedValue()); - JSTaggedValue obj_result2 = object::Is(obj_call_info1.get()); - ASSERT_EQ(obj_result2.GetRawData(), JSTaggedValue::True().GetRawData()); + objCallInfo1->SetCallArg(1, obj1.GetTaggedValue()); + JSTaggedValue objResult2 = object::Is(objCallInfo1.get()); + ASSERT_EQ(objResult2.GetRawData(), JSTaggedValue::True().GetRawData()); // string compare - JSHandle test_str_value1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("helloworld"); - JSHandle test_str_value2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("helloworld"); + JSHandle testStrValue1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("helloworld"); + JSHandle testStrValue2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("helloworld"); - auto str_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - str_call_info->SetFunction(JSTaggedValue::Undefined()); - str_call_info->SetThis(JSTaggedValue::Undefined()); - str_call_info->SetCallArg(0, test_str_value1.GetTaggedValue()); - str_call_info->SetCallArg(1, test_str_value2.GetTaggedValue()); + auto strCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + strCallInfo->SetFunction(JSTaggedValue::Undefined()); + strCallInfo->SetThis(JSTaggedValue::Undefined()); + strCallInfo->SetCallArg(0, testStrValue1.GetTaggedValue()); + strCallInfo->SetCallArg(1, testStrValue2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, str_call_info.get()); - JSTaggedValue str_result = object::Is(str_call_info.get()); + prev = TestHelper::SetupFrame(thread_, strCallInfo.get()); + JSTaggedValue strResult = object::Is(strCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(str_result.GetRawData(), JSTaggedValue::True().GetRawData()); + ASSERT_EQ(strResult.GetRawData(), JSTaggedValue::True().GetRawData()); // bool compare - auto bool_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - bool_call_info->SetFunction(JSTaggedValue::Undefined()); - bool_call_info->SetThis(JSTaggedValue::Undefined()); - bool_call_info->SetCallArg(0, JSTaggedValue::True()); - bool_call_info->SetCallArg(1, JSTaggedValue::False()); - - prev = TestHelper::SetupFrame(thread_, bool_call_info.get()); - JSTaggedValue bool_result = object::Is(bool_call_info.get()); + auto boolCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + boolCallInfo->SetFunction(JSTaggedValue::Undefined()); + boolCallInfo->SetThis(JSTaggedValue::Undefined()); + boolCallInfo->SetCallArg(0, JSTaggedValue::True()); + boolCallInfo->SetCallArg(1, JSTaggedValue::False()); + + prev = TestHelper::SetupFrame(thread_, boolCallInfo.get()); + JSTaggedValue boolResult = object::Is(boolCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(bool_result.GetRawData(), JSTaggedValue::False().GetRawData()); + ASSERT_EQ(boolResult.GetRawData(), JSTaggedValue::False().GetRawData()); // number compare - auto num_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - num_call_info->SetFunction(JSTaggedValue::Undefined()); - num_call_info->SetThis(JSTaggedValue::Undefined()); - num_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); - num_call_info->SetCallArg(1, JSTaggedValue(-0.0)); - - prev = TestHelper::SetupFrame(thread_, num_call_info.get()); - JSTaggedValue num_result = object::Is(num_call_info.get()); + auto numCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + numCallInfo->SetFunction(JSTaggedValue::Undefined()); + numCallInfo->SetThis(JSTaggedValue::Undefined()); + numCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); + numCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); + + prev = TestHelper::SetupFrame(thread_, numCallInfo.get()); + JSTaggedValue numResult = object::Is(numCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(num_result.GetRawData(), JSTaggedValue::False().GetRawData()); + ASSERT_EQ(numResult.GetRawData(), JSTaggedValue::False().GetRawData()); // undefined or null compare - auto null_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - null_call_info->SetFunction(JSTaggedValue::Undefined()); - null_call_info->SetThis(JSTaggedValue::Undefined()); - null_call_info->SetCallArg(0, JSTaggedValue::Null()); - null_call_info->SetCallArg(1, JSTaggedValue::Null()); - - prev = TestHelper::SetupFrame(thread_, null_call_info.get()); - JSTaggedValue null_result = object::Is(null_call_info.get()); + auto nullCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + nullCallInfo->SetFunction(JSTaggedValue::Undefined()); + nullCallInfo->SetThis(JSTaggedValue::Undefined()); + nullCallInfo->SetCallArg(0, JSTaggedValue::Null()); + nullCallInfo->SetCallArg(1, JSTaggedValue::Null()); + + prev = TestHelper::SetupFrame(thread_, nullCallInfo.get()); + JSTaggedValue nullResult = object::Is(nullCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(null_result.GetRawData(), JSTaggedValue::True().GetRawData()); + ASSERT_EQ(nullResult.GetRawData(), JSTaggedValue::True().GetRawData()); - auto undefine_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - undefine_call_info->SetFunction(JSTaggedValue::Undefined()); - undefine_call_info->SetThis(JSTaggedValue::Undefined()); - undefine_call_info->SetCallArg(0, JSTaggedValue::Undefined()); - undefine_call_info->SetCallArg(1, JSTaggedValue::Undefined()); + auto undefineCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + undefineCallInfo->SetFunction(JSTaggedValue::Undefined()); + undefineCallInfo->SetThis(JSTaggedValue::Undefined()); + undefineCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); + undefineCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread_, undefine_call_info.get()); - JSTaggedValue undefine_result = object::Is(undefine_call_info.get()); + prev = TestHelper::SetupFrame(thread_, undefineCallInfo.get()); + JSTaggedValue undefineResult = object::Is(undefineCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(undefine_result.GetRawData(), JSTaggedValue::True().GetRawData()); + ASSERT_EQ(undefineResult.GetRawData(), JSTaggedValue::True().GetRawData()); } // 19.1.2.11 Object.isExtensible ( O ) @@ -764,22 +764,22 @@ TEST_F(BuiltinsObjectTest, IsExtensible) JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); // New objects can be extended by default. - JSHandle empty_obj = + JSHandle emptyObj = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - empty_obj->GetJSHClass()->SetExtensible(true); - auto empty_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - empty_obj_call_info->SetFunction(JSTaggedValue::Undefined()); - empty_obj_call_info->SetThis(JSTaggedValue::Undefined()); - empty_obj_call_info->SetCallArg(0, empty_obj.GetTaggedValue()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, empty_obj_call_info.get()); - JSTaggedValue result = object::IsExtensible(empty_obj_call_info.get()); + emptyObj->GetJSHClass()->SetExtensible(true); + auto emptyObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + emptyObjCallInfo->SetFunction(JSTaggedValue::Undefined()); + emptyObjCallInfo->SetThis(JSTaggedValue::Undefined()); + emptyObjCallInfo->SetCallArg(0, emptyObj.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, emptyObjCallInfo.get()); + JSTaggedValue result = object::IsExtensible(emptyObjCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); - empty_obj->GetJSHClass()->SetExtensible(false); - JSTaggedValue result2 = object::IsExtensible(empty_obj_call_info.get()); + emptyObj->GetJSHClass()->SetExtensible(false); + JSTaggedValue result2 = object::IsExtensible(emptyObjCallInfo.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -794,52 +794,52 @@ TEST_F(BuiltinsObjectTest, IsFrozen) JSHandle obj = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(function), function); obj->GetJSHClass()->SetExtensible(true); - auto empty_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - empty_obj_call_info->SetFunction(JSTaggedValue::Undefined()); - empty_obj_call_info->SetThis(JSTaggedValue::Undefined()); - empty_obj_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto emptyObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + emptyObjCallInfo->SetFunction(JSTaggedValue::Undefined()); + emptyObjCallInfo->SetThis(JSTaggedValue::Undefined()); + emptyObjCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, empty_obj_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, emptyObjCallInfo.get()); - JSTaggedValue result = object::IsFrozen(empty_obj_call_info.get()); + JSTaggedValue result = object::IsFrozen(emptyObjCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); obj->GetJSHClass()->SetExtensible(false); - JSTaggedValue result_nex = object::IsFrozen(empty_obj_call_info.get()); - ASSERT_EQ(result_nex.GetRawData(), JSTaggedValue::True().GetRawData()); + JSTaggedValue resultNex = object::IsFrozen(emptyObjCallInfo.get()); + ASSERT_EQ(resultNex.GetRawData(), JSTaggedValue::True().GetRawData()); TestHelper::TearDownFrame(thread_, prev); - PropertyDescriptor desc_enum(thread_); - desc_enum.SetConfigurable(true); - desc_enum.SetWritable(false); + PropertyDescriptor descEnum(thread_); + descEnum.SetConfigurable(true); + descEnum.SetWritable(false); obj->GetJSHClass()->SetExtensible(true); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc_enum); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, descEnum); obj->GetJSHClass()->SetExtensible(false); - auto empty_obj_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - empty_obj_call_info2->SetFunction(JSTaggedValue::Undefined()); - empty_obj_call_info2->SetThis(JSTaggedValue::Undefined()); - empty_obj_call_info2->SetCallArg(0, obj.GetTaggedValue()); + auto emptyObjCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + emptyObjCallInfo2->SetFunction(JSTaggedValue::Undefined()); + emptyObjCallInfo2->SetThis(JSTaggedValue::Undefined()); + emptyObjCallInfo2->SetCallArg(0, obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, empty_obj_call_info2.get()); - JSTaggedValue result_nw = object::IsFrozen(empty_obj_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, emptyObjCallInfo2.get()); + JSTaggedValue resultNw = object::IsFrozen(emptyObjCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(result_nw.GetRawData(), JSTaggedValue::False().GetRawData()); + ASSERT_EQ(resultNw.GetRawData(), JSTaggedValue::False().GetRawData()); - desc_enum.SetConfigurable(false); + descEnum.SetConfigurable(false); obj->GetJSHClass()->SetExtensible(true); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc_enum); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, descEnum); obj->GetJSHClass()->SetExtensible(false); - auto empty_obj_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - empty_obj_call_info3->SetFunction(JSTaggedValue::Undefined()); - empty_obj_call_info3->SetThis(JSTaggedValue::Undefined()); - empty_obj_call_info3->SetCallArg(0, obj.GetTaggedValue()); + auto emptyObjCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + emptyObjCallInfo3->SetFunction(JSTaggedValue::Undefined()); + emptyObjCallInfo3->SetThis(JSTaggedValue::Undefined()); + emptyObjCallInfo3->SetCallArg(0, obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, empty_obj_call_info3.get()); - JSTaggedValue result_nc = object::IsFrozen(empty_obj_call_info3.get()); + prev = TestHelper::SetupFrame(thread_, emptyObjCallInfo3.get()); + JSTaggedValue resultNc = object::IsFrozen(emptyObjCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(result_nc.GetRawData(), JSTaggedValue::True().GetRawData()); + ASSERT_EQ(resultNc.GetRawData(), JSTaggedValue::True().GetRawData()); } // 19.1.2.13 Object.isSealed ( O ) @@ -848,16 +848,16 @@ TEST_F(BuiltinsObjectTest, IsSealed) JSHandle function(thread_, BuiltinsObjectTestCreate(thread_)); // An object is extensible by default, so it is also non-frozen. - JSHandle empty_obj = + JSHandle emptyObj = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(function), function); - empty_obj->GetJSHClass()->SetExtensible(true); - auto empty_obj_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - empty_obj_call_info->SetFunction(JSTaggedValue::Undefined()); - empty_obj_call_info->SetThis(JSTaggedValue::Undefined()); - empty_obj_call_info->SetCallArg(0, empty_obj.GetTaggedValue()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, empty_obj_call_info.get()); - JSTaggedValue result = object::IsSealed(empty_obj_call_info.get()); + emptyObj->GetJSHClass()->SetExtensible(true); + auto emptyObjCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + emptyObjCallInfo->SetFunction(JSTaggedValue::Undefined()); + emptyObjCallInfo->SetThis(JSTaggedValue::Undefined()); + emptyObjCallInfo->SetCallArg(0, emptyObj.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, emptyObjCallInfo.get()); + JSTaggedValue result = object::IsSealed(emptyObjCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -867,13 +867,13 @@ TEST_F(BuiltinsObjectTest, IsSealed) TEST_F(BuiltinsObjectTest, Keys) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::Keys(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::Keys(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -884,38 +884,38 @@ TEST_F(BuiltinsObjectTest, PreventExtensions) { JSHandle obj = JSHandle(thread_, CreateBuiltinJSObject(thread_, "x")); obj->GetJSHClass()->SetExtensible(true); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::PreventExtensions(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::PreventExtensions(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); JSTaggedValue jt(reinterpret_cast(result.GetRawData())); - JSHandle jt_handle(thread_, jt); - ASSERT_TRUE(!jt_handle->IsExtensible()); + JSHandle jtHandle(thread_, jt); + ASSERT_TRUE(!jtHandle->IsExtensible()); } // Object.seal(obj) TEST_F(BuiltinsObjectTest, Seal) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::Seal(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::Seal(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(result.GetRawData(), obj->GetRawData()); // test isSealed(). - JSTaggedValue res = object::IsSealed(ecma_runtime_call_info.get()); + JSTaggedValue res = object::IsSealed(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(res.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -924,16 +924,16 @@ TEST_F(BuiltinsObjectTest, Seal) TEST_F(BuiltinsObjectTest, SetPrototypeOf) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - JSHandle obj_father(thread_, CreateBuiltinJSObject(thread_, "y")); + JSHandle objFather(thread_, CreateBuiltinJSObject(thread_, "y")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, obj_father.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, objFather.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::SetPrototypeOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::SetPrototypeOf(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -953,13 +953,13 @@ TEST_F(BuiltinsObjectTest, Values) JSObject::SetProperty(thread_, obj, key, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::Values(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::Values(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); @@ -975,17 +975,17 @@ TEST_F(BuiltinsObjectTest, Values) TEST_F(BuiltinsObjectTest, HasOwnProperty) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - PandaString key_c_str = "x"; - JSHandle key_string = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(&key_c_str[0]); - JSHandle key(key_string); + PandaString keyCStr = "x"; + JSHandle keyString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(&keyCStr[0]); + JSHandle key(keyString); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::HasOwnProperty(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::HasOwnProperty(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -995,15 +995,15 @@ TEST_F(BuiltinsObjectTest, HasOwnProperty) TEST_F(BuiltinsObjectTest, IsPrototypeOfFalse) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - JSHandle obj_father(thread_, CreateBuiltinJSObject(thread_, "y")); + JSHandle objFather(thread_, CreateBuiltinJSObject(thread_, "y")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj_father.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(objFather.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = object::proto::IsPrototypeOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = object::proto::IsPrototypeOf(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -1012,28 +1012,28 @@ TEST_F(BuiltinsObjectTest, IsPrototypeOfFalse) TEST_F(BuiltinsObjectTest, IsPrototypeOfTrue) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - JSHandle obj_father(thread_, CreateBuiltinJSObject(thread_, "y")); + JSHandle objFather(thread_, CreateBuiltinJSObject(thread_, "y")); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, obj.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, obj_father.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, objFather.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = object::SetPrototypeOf(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = object::SetPrototypeOf(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result1.IsObject()); ASSERT_EQ(result1.GetRawData(), obj->GetRawData()); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(obj_father.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(objFather.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = object::proto::IsPrototypeOf(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = object::proto::IsPrototypeOf(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -1045,13 +1045,13 @@ TEST_F(BuiltinsObjectTest, PropertyIsEnumerable) JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::PropertyIsEnumerable(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::PropertyIsEnumerable(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -1061,26 +1061,26 @@ TEST_F(BuiltinsObjectTest, PropertyIsEnumerable) TEST_F(BuiltinsObjectTest, ToLocaleString) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - JSHandle callee_func = thread_->GetEcmaVM()->GetFactory()->NewJSFunction( + JSHandle calleeFunc = thread_->GetEcmaVM()->GetFactory()->NewJSFunction( thread_->GetEcmaVM()->GetGlobalEnv(), reinterpret_cast(object::proto::ToString)); - JSHandle callee_value(callee_func); - JSHandle callee_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("toString")); - JSObject::SetProperty(thread_, obj, callee_key, callee_value); + JSHandle calleeValue(calleeFunc); + JSHandle calleeKey(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("toString")); + JSObject::SetProperty(thread_, obj, calleeKey, calleeValue); - JSHandle result_value = + JSHandle resultValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Object]"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::ToLocaleString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::ToLocaleString(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsString()); - ASSERT_EQ(result_value->Compare(reinterpret_cast(result.GetRawData())), 0); + ASSERT_EQ(resultValue->Compare(reinterpret_cast(result.GetRawData())), 0); } // obj.toString() @@ -1089,125 +1089,125 @@ TEST_F(BuiltinsObjectTest, ToString) JSHandle obj = JSHandle(thread_, CreateBuiltinJSObject(thread_, "x")); // object - JSHandle result_value = + JSHandle resultValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Object]"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::ToString(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsString()); - ASSERT_EQ(result_value->Compare(reinterpret_cast(result.GetRawData())), 0); + ASSERT_EQ(resultValue->Compare(reinterpret_cast(result.GetRawData())), 0); // array JSHandle arr = thread_->GetEcmaVM()->GetFactory()->NewJSArray(); - JSHandle result_arr_value = + JSHandle resultArrValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Array]"); - auto arr_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - arr_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - arr_ecma_runtime_call_info->SetThis(arr.GetTaggedValue()); + auto arrEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + arrEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + arrEcmaRuntimeCallInfo->SetThis(arr.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, arr_ecma_runtime_call_info.get()); - JSTaggedValue result_arr = object::proto::ToString(arr_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, arrEcmaRuntimeCallInfo.get()); + JSTaggedValue resultArr = object::proto::ToString(arrEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_arr.IsString()); - ASSERT_EQ(result_arr_value->Compare(reinterpret_cast(result_arr.GetRawData())), 0); + ASSERT_TRUE(resultArr.IsString()); + ASSERT_EQ(resultArrValue->Compare(reinterpret_cast(resultArr.GetRawData())), 0); // string JSHandle str = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("hello"); - JSHandle result_str_value = + JSHandle resultStrValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object String]"); - auto str_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - str_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - str_ecma_runtime_call_info->SetThis(str.GetTaggedValue()); + auto strEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + strEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + strEcmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, str_ecma_runtime_call_info.get()); - JSTaggedValue result_str = object::proto::ToString(str_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, strEcmaRuntimeCallInfo.get()); + JSTaggedValue resultStr = object::proto::ToString(strEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_str.IsString()); - ASSERT_EQ(result_str_value->Compare(reinterpret_cast(result_str.GetRawData())), 0); + ASSERT_TRUE(resultStr.IsString()); + ASSERT_EQ(resultStrValue->Compare(reinterpret_cast(resultStr.GetRawData())), 0); // function JSHandle func = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(thread_->GetEcmaVM()->GetGlobalEnv()); - JSHandle result_func_value = + JSHandle resultFuncValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Function]"); - auto func_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - func_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - func_ecma_runtime_call_info->SetThis(func.GetTaggedValue()); + auto funcEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + funcEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + funcEcmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, func_ecma_runtime_call_info.get()); - JSTaggedValue result_func = object::proto::ToString(func_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, funcEcmaRuntimeCallInfo.get()); + JSTaggedValue resultFunc = object::proto::ToString(funcEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_func.IsString()); - ASSERT_EQ(result_func_value->Compare(reinterpret_cast(result_func.GetRawData())), 0); + ASSERT_TRUE(resultFunc.IsString()); + ASSERT_EQ(resultFuncValue->Compare(reinterpret_cast(resultFunc.GetRawData())), 0); // error - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - JSHandle error_object = env->GetErrorFunction(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + JSHandle errorObject = env->GetErrorFunction(); JSHandle error = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(error_object), error_object); - JSHandle error_value = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Error]"); - auto error_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - error_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - error_ecma_runtime_call_info->SetThis(error.GetTaggedValue()); - - prev = TestHelper::SetupFrame(thread_, error_ecma_runtime_call_info.get()); - JSTaggedValue result_error = object::proto::ToString(error_ecma_runtime_call_info.get()); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(errorObject), errorObject); + JSHandle errorValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Error]"); + auto errorEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + errorEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + errorEcmaRuntimeCallInfo->SetThis(error.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread_, errorEcmaRuntimeCallInfo.get()); + JSTaggedValue resultError = object::proto::ToString(errorEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_error.IsString()); - ASSERT_EQ(error_value->Compare(reinterpret_cast(result_error.GetRawData())), 0); + ASSERT_TRUE(resultError.IsString()); + ASSERT_EQ(errorValue->Compare(reinterpret_cast(resultError.GetRawData())), 0); // boolean JSHandle value(thread_, JSTaggedValue::False()); - JSHandle boolean_object(env->GetBooleanFunction()); - JSHandle boolean = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(boolean_object, value); - JSHandle result_bool_value = + JSHandle booleanObject(env->GetBooleanFunction()); + JSHandle boolean = thread_->GetEcmaVM()->GetFactory()->NewJSPrimitiveRef(booleanObject, value); + JSHandle resultBoolValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Boolean]"); - auto bool_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - bool_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - bool_ecma_runtime_call_info->SetThis(boolean.GetTaggedValue()); + auto boolEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + boolEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + boolEcmaRuntimeCallInfo->SetThis(boolean.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, bool_ecma_runtime_call_info.get()); - JSTaggedValue result_bool = object::proto::ToString(bool_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, boolEcmaRuntimeCallInfo.get()); + JSTaggedValue resultBool = object::proto::ToString(boolEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_bool.IsString()); - ASSERT_EQ(result_bool_value->Compare(reinterpret_cast(result_bool.GetRawData())), 0); + ASSERT_TRUE(resultBool.IsString()); + ASSERT_EQ(resultBoolValue->Compare(reinterpret_cast(resultBool.GetRawData())), 0); // number - JSHandle result_num_value = + JSHandle resultNumValue = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("[object Number]"); - auto num_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - num_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - num_ecma_runtime_call_info->SetThis(JSTaggedValue(static_cast(0))); + auto numEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + numEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + numEcmaRuntimeCallInfo->SetThis(JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread_, num_ecma_runtime_call_info.get()); - JSTaggedValue result_num = object::proto::ToString(num_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, numEcmaRuntimeCallInfo.get()); + JSTaggedValue resultNum = object::proto::ToString(numEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(result_num.IsString()); - ASSERT_EQ(result_num_value->Compare(reinterpret_cast(result_num.GetRawData())), 0); + ASSERT_TRUE(resultNum.IsString()); + ASSERT_EQ(resultNumValue->Compare(reinterpret_cast(resultNum.GetRawData())), 0); } // object.valueOf() TEST_F(BuiltinsObjectTest, ValueOf) { JSHandle obj(thread_, CreateBuiltinJSObject(thread_, "x")); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = object::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = object::proto::ValueOf(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsECMAObject()); diff --git a/tests/runtime/builtins/builtins_promise_test.cpp b/tests/runtime/builtins/builtins_promise_test.cpp index 1089ae8f45c0ed0a580ecb83945f1e5045c72ec2..f6787f0e0f313c24abfe3938bf9b1d5d3ac348a2 100644 --- a/tests/runtime/builtins/builtins_promise_test.cpp +++ b/tests/runtime/builtins/builtins_promise_test.cpp @@ -81,18 +81,18 @@ JSTaggedValue TestPromiseRaceThenOnRejectd(EcmaRuntimeCallInfo *argv) // native function for all then_on_resolved() JSTaggedValue TestPromiseAllThenOnResolved(EcmaRuntimeCallInfo *argv) { - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); JSHandle array = builtins_common::GetCallArg(argv, 0); - JSHandle object_array = JSHandle::Cast(array); + JSHandle objectArray = JSHandle::Cast(array); [[maybe_unused]] PropertyDescriptor desc(argv->GetThread()); [[maybe_unused]] bool result1 = JSObject::GetOwnProperty( - argv->GetThread(), object_array, JSHandle(argv->GetThread(), JSTaggedValue(0)), desc); + argv->GetThread(), objectArray, JSHandle(argv->GetThread(), JSTaggedValue(0)), desc); EXPECT_TRUE(result1); JSHandle value1 = desc.GetValue(); // 111 : test case EXPECT_EQ(JSTaggedValue::SameValue(value1.GetTaggedValue(), JSTaggedValue(111)), true); [[maybe_unused]] bool result2 = JSObject::GetOwnProperty( - argv->GetThread(), object_array, JSHandle(argv->GetThread(), JSTaggedValue(1)), desc); + argv->GetThread(), objectArray, JSHandle(argv->GetThread(), JSTaggedValue(1)), desc); EXPECT_TRUE(result2); JSHandle value2 = desc.GetValue(); // 222 : test case @@ -112,7 +112,7 @@ JSTaggedValue TestPromiseCatch(EcmaRuntimeCallInfo *argv) // native function for then then_on_resolved() JSTaggedValue TestPromiseThenOnResolved(EcmaRuntimeCallInfo *argv) { - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); auto factory = argv->GetThread()->GetEcmaVM()->GetFactory(); JSHandle result = builtins_common::GetCallArg(argv, 0); auto expect = factory->NewFromCanBeCompressString("resolve"); @@ -123,7 +123,7 @@ JSTaggedValue TestPromiseThenOnResolved(EcmaRuntimeCallInfo *argv) // native function for then then_on_rejected() JSTaggedValue TestPromiseThenOnRejected(EcmaRuntimeCallInfo *argv) { - [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); auto factory = argv->GetThread()->GetEcmaVM()->GetFactory(); JSHandle result = builtins_common::GetCallArg(argv, 0); auto expect = factory->NewFromCanBeCompressString("reject"); @@ -141,21 +141,21 @@ TEST_F(BuiltinsPromiseTest, Reject1) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg(thread_, JSTaggedValue(3)); + JSHandle paramMsg(thread_, JSTaggedValue(3)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg.GetTaggedValue()); /// @tc.steps: var p1 = Promise.reject(3). - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = promise::Reject(ecma_runtime_call_info1.get()); - JSHandle reject_promise(thread_, result); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = promise::Reject(ecmaRuntimeCallInfo1.get()); + JSHandle rejectPromise(thread_, result); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseResult(), JSTaggedValue(3)), true); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); } /* @@ -170,31 +170,31 @@ TEST_F(BuiltinsPromiseTest, Reject2) // constructor promise1 JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg1 = + JSHandle paramMsg1 = JSHandle::Cast(factory->NewFromCanBeCompressString("Promise reject")); /// @tc.steps: step1. var p1 = Promise.reject("Promise reject") - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); - ecma_runtime_call_info->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, param_msg1.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); + ecmaRuntimeCallInfo->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = promise::Reject(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = promise::Reject(ecmaRuntimeCallInfo.get()); JSHandle promise1(thread_, result); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), param_msg1.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); /// @tc.steps: step2. var p2 = Promise.reject(p1) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, promise1.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, promise1.GetTaggedValue()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = promise::Reject(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = promise::Reject(ecmaRuntimeCallInfo1.get()); JSHandle promise2(thread_, result1); EXPECT_NE(*promise1, *promise2); EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseState(), @@ -215,21 +215,21 @@ TEST_F(BuiltinsPromiseTest, Resolve1) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg(thread_, JSTaggedValue(5)); + JSHandle paramMsg(thread_, JSTaggedValue(5)); /// @tc.steps: step1. var p1 = Promise.resolve(12345) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg.GetTaggedValue()); - - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = promise::Resolve(ecma_runtime_call_info1.get()); - JSHandle reject_promise(thread_, result); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg.GetTaggedValue()); + + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = promise::Resolve(ecmaRuntimeCallInfo1.get()); + JSHandle rejectPromise(thread_, result); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseResult(), JSTaggedValue(5)), true); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(5)), true); } /* @@ -244,38 +244,38 @@ TEST_F(BuiltinsPromiseTest, Resolve2) // constructor promise1 JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg1 = + JSHandle paramMsg1 = JSHandle::Cast(factory->NewFromCanBeCompressString("Promise reject")); /// @tc.steps: step1. var p1 = Promise.reject("Promise reject") - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); - ecma_runtime_call_info->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, param_msg1.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); + ecmaRuntimeCallInfo->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = promise::Reject(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = promise::Reject(ecmaRuntimeCallInfo.get()); JSHandle promise1(thread_, result); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), param_msg1.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); // promise1 Enter Reject() as a parameter. /// @tc.steps: step2. var p2 = Promise.resolve(p1) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, promise1.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, promise.GetTaggedValue(), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, promise1.GetTaggedValue()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = promise::Resolve(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = promise::Resolve(ecmaRuntimeCallInfo1.get()); JSHandle promise2(thread_, result1); EXPECT_EQ(*promise1, *promise2); EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseResult(), param_msg1.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); } /* @@ -288,58 +288,58 @@ TEST_F(BuiltinsPromiseTest, Race1) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg1(thread_, JSTaggedValue(12345)); - JSHandle param_msg2(thread_, JSTaggedValue(6789)); + JSHandle paramMsg1(thread_, JSTaggedValue(12345)); + JSHandle paramMsg2(thread_, JSTaggedValue(6789)); /// @tc.steps: step1. var p1 = Promise.reject(12345) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); - - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = promise::Reject(ecma_runtime_call_info1.get()); - JSHandle reject_promise(thread_, result1); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); + + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = promise::Reject(ecmaRuntimeCallInfo1.get()); + JSHandle rejectPromise(thread_, result1); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseResult(), JSTaggedValue(12345)), true); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); /// @tc.steps: step2. var p2 = Promise.resolve(6789) - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info2->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info2->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, param_msg2.GetTaggedValue()); - - [[maybe_unused]] auto prev_resolve = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = promise::Resolve(ecma_runtime_call_info2.get()); - JSHandle resolve_promise(thread_, result2); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo2->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, paramMsg2.GetTaggedValue()); + + [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = promise::Resolve(ecmaRuntimeCallInfo2.get()); + JSHandle resolvePromise(thread_, result2); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseResult(), JSTaggedValue(6789)), true); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); /// @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] JSHandle array(JSArray::ArrayCreate(thread_, JSTaggedNumber(2))); - PropertyDescriptor desc(thread_, JSHandle::Cast(reject_promise)); + PropertyDescriptor desc(thread_, JSHandle::Cast(rejectPromise)); JSArray::DefineOwnProperty(thread_, array, JSHandle(thread_, JSTaggedValue(0)), desc); - PropertyDescriptor desc1(thread_, JSHandle::Cast(resolve_promise)); + PropertyDescriptor desc1(thread_, JSHandle::Cast(resolvePromise)); JSArray::DefineOwnProperty(thread_, array, JSHandle(thread_, JSTaggedValue(1)), desc1); /// @tc.steps: step4. var p3 = Promise.race([p1,p2]); - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info4->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info4->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, array.GetTaggedValue()); - - [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = promise::Race(ecma_runtime_call_info4.get()); - JSHandle race_promise(thread_, result4); - EXPECT_EQ(JSTaggedValue::SameValue(race_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo4->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, array.GetTaggedValue()); + + [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + JSTaggedValue result4 = promise::Race(ecmaRuntimeCallInfo4.get()); + JSHandle racePromise(thread_, result4); + EXPECT_EQ(JSTaggedValue::SameValue(racePromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), true); - EXPECT_EQ(race_promise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); } /* @@ -354,80 +354,80 @@ TEST_F(BuiltinsPromiseTest, Race2) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg1(thread_, JSTaggedValue(12345)); - JSHandle param_msg2(thread_, JSTaggedValue(6789)); + JSHandle paramMsg1(thread_, JSTaggedValue(12345)); + JSHandle paramMsg2(thread_, JSTaggedValue(6789)); /// @tc.steps: step1. var p1 = Promise.reject(12345) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); - - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = promise::Reject(ecma_runtime_call_info1.get()); - JSHandle reject_promise(thread_, result1); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); + + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = promise::Reject(ecmaRuntimeCallInfo1.get()); + JSHandle rejectPromise(thread_, result1); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseResult(), JSTaggedValue(12345)), true); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); /// @tc.steps: step2. var p2 = Promise.resolve(6789) - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info2->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info2->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, param_msg2.GetTaggedValue()); - - [[maybe_unused]] auto prev_resolve = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = promise::Resolve(ecma_runtime_call_info2.get()); - JSHandle resolve_promise(thread_, result2); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo2->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, paramMsg2.GetTaggedValue()); + + [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = promise::Resolve(ecmaRuntimeCallInfo2.get()); + JSHandle resolvePromise(thread_, result2); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseResult(), JSTaggedValue(6789)), true); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); /// @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] JSHandle array(JSArray::ArrayCreate(thread_, JSTaggedNumber(2))); - PropertyDescriptor desc(thread_, JSHandle::Cast(reject_promise)); + PropertyDescriptor desc(thread_, JSHandle::Cast(rejectPromise)); JSArray::DefineOwnProperty(thread_, array, JSHandle(thread_, JSTaggedValue(0)), desc); - PropertyDescriptor desc1(thread_, JSHandle::Cast(resolve_promise)); + PropertyDescriptor desc1(thread_, JSHandle::Cast(resolvePromise)); JSArray::DefineOwnProperty(thread_, array, JSHandle(thread_, JSTaggedValue(1)), desc1); /// @tc.steps: step4. var p3 = Promise.race([p1,p2]); - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info4->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info4->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, array.GetTaggedValue()); - - [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = promise::Race(ecma_runtime_call_info4.get()); - JSHandle race_promise(thread_, result4); - EXPECT_EQ(JSTaggedValue::SameValue(race_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo4->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, array.GetTaggedValue()); + + [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + JSTaggedValue result4 = promise::Race(ecmaRuntimeCallInfo4.get()); + JSHandle racePromise(thread_, result4); + EXPECT_EQ(JSTaggedValue::SameValue(racePromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), true); - EXPECT_EQ(race_promise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); /// @tc.steps: step5. p3.then((resolve)=>{print(resolve)}, (reject)=>{print(reject)}) - JSHandle native_func_race_then_onrejected = + JSHandle nativeFuncRaceThenOnrejected = factory->NewJSFunction(env, reinterpret_cast(TestPromiseRaceThenOnRejectd)); - auto ecma_runtime_call_info5 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, race_promise.GetTaggedValue(), 8); - ecma_runtime_call_info5->SetFunction(race_promise.GetTaggedValue()); - ecma_runtime_call_info5->SetThis(race_promise.GetTaggedValue()); - ecma_runtime_call_info5->SetCallArg(0, JSTaggedValue::Undefined()); - ecma_runtime_call_info5->SetCallArg(1, native_func_race_then_onrejected.GetTaggedValue()); + auto ecmaRuntimeCallInfo5 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, racePromise.GetTaggedValue(), 8); + ecmaRuntimeCallInfo5->SetFunction(racePromise.GetTaggedValue()); + ecmaRuntimeCallInfo5->SetThis(racePromise.GetTaggedValue()); + ecmaRuntimeCallInfo5->SetCallArg(0, JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo5->SetCallArg(1, nativeFuncRaceThenOnrejected.GetTaggedValue()); - [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info5.get()); - JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info5.get()); - JSHandle then_promise(thread_, then_result); + [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo5.get()); + JSTaggedValue thenResult = promise::proto::Then(ecmaRuntimeCallInfo5.get()); + JSHandle thenPromise(thread_, thenResult); - EXPECT_TRUE(JSTaggedValue::SameValue(then_promise->GetPromiseState(), + EXPECT_TRUE(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING)))); - EXPECT_TRUE(then_promise->GetPromiseResult().IsUndefined()); + EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); /// @tc.steps: step6. execute promise queue - auto micro_job_queue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); + auto microJobQueue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); if (LIKELY(!thread_->HasPendingException())) { - job::MicroJobQueue::ExecutePendingJob(thread_, micro_job_queue); + job::MicroJobQueue::ExecutePendingJob(thread_, microJobQueue); } } @@ -443,80 +443,80 @@ TEST_F(BuiltinsPromiseTest, All) JSHandle env = EcmaVM::Cast(instance_)->GetGlobalEnv(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg1(thread_, JSTaggedValue(111)); - JSHandle param_msg2(thread_, JSTaggedValue(222)); + JSHandle paramMsg1(thread_, JSTaggedValue(111)); + JSHandle paramMsg2(thread_, JSTaggedValue(222)); /// @tc.steps: step1. var p1 = Promise.resolve(111) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); - - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = promise::Resolve(ecma_runtime_call_info1.get()); - JSHandle resolve_promise1(thread_, result1); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise1->GetPromiseState(), + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); + + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = promise::Resolve(ecmaRuntimeCallInfo1.get()); + JSHandle resolvePromise1(thread_, result1); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise1->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise1->GetPromiseResult(), JSTaggedValue(111)), true); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise1->GetPromiseResult(), JSTaggedValue(111)), true); /// @tc.steps: step2. var p2 = Promise.resolve(222) - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info2->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info2->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, param_msg2.GetTaggedValue()); - - [[maybe_unused]] auto prev_resolve = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = promise::Resolve(ecma_runtime_call_info2.get()); - JSHandle resolve_promise2(thread_, result2); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise2->GetPromiseState(), + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo2->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, paramMsg2.GetTaggedValue()); + + [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = promise::Resolve(ecmaRuntimeCallInfo2.get()); + JSHandle resolvePromise2(thread_, result2); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise2->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise2->GetPromiseResult(), JSTaggedValue(222)), true); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise2->GetPromiseResult(), JSTaggedValue(222)), true); /// @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] JSHandle array(JSArray::ArrayCreate(thread_, JSTaggedNumber(2))); - PropertyDescriptor desc(thread_, JSHandle::Cast(resolve_promise1)); + PropertyDescriptor desc(thread_, JSHandle::Cast(resolvePromise1)); JSArray::DefineOwnProperty(thread_, array, JSHandle(thread_, JSTaggedValue(0)), desc); - PropertyDescriptor desc1(thread_, JSHandle::Cast(resolve_promise2)); + PropertyDescriptor desc1(thread_, JSHandle::Cast(resolvePromise2)); JSArray::DefineOwnProperty(thread_, array, JSHandle(thread_, JSTaggedValue(1)), desc1); /// @tc.steps: step4. var p3 = Promise.all([p1,p2]); - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info4->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info4->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, array.GetTaggedValue()); - - [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = promise::All(ecma_runtime_call_info4.get()); - JSHandle all_promise(thread_, result4); - EXPECT_EQ(JSTaggedValue::SameValue(all_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo4->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, array.GetTaggedValue()); + + [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + JSTaggedValue result4 = promise::All(ecmaRuntimeCallInfo4.get()); + JSHandle allPromise(thread_, result4); + EXPECT_EQ(JSTaggedValue::SameValue(allPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), true); - EXPECT_EQ(all_promise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(allPromise->GetPromiseResult().IsUndefined(), true); /// @tc.steps: step5. p3.then((resolve)=>{print(resolve)}, (reject)=>{print(reject)}); - JSHandle native_func_race_then_on_resolved = + JSHandle nativeFuncRaceThenOnResolved = factory->NewJSFunction(env, reinterpret_cast(TestPromiseAllThenOnResolved)); - auto ecma_runtime_call_info5 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, all_promise.GetTaggedValue(), 8); - ecma_runtime_call_info5->SetFunction(all_promise.GetTaggedValue()); - ecma_runtime_call_info5->SetThis(all_promise.GetTaggedValue()); - ecma_runtime_call_info5->SetCallArg(0, native_func_race_then_on_resolved.GetTaggedValue()); - ecma_runtime_call_info5->SetCallArg(1, native_func_race_then_on_resolved.GetTaggedValue()); + auto ecmaRuntimeCallInfo5 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, allPromise.GetTaggedValue(), 8); + ecmaRuntimeCallInfo5->SetFunction(allPromise.GetTaggedValue()); + ecmaRuntimeCallInfo5->SetThis(allPromise.GetTaggedValue()); + ecmaRuntimeCallInfo5->SetCallArg(0, nativeFuncRaceThenOnResolved.GetTaggedValue()); + ecmaRuntimeCallInfo5->SetCallArg(1, nativeFuncRaceThenOnResolved.GetTaggedValue()); - [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info5.get()); - JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info5.get()); - JSHandle then_promise(thread_, then_result); + [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo5.get()); + JSTaggedValue thenResult = promise::proto::Then(ecmaRuntimeCallInfo5.get()); + JSHandle thenPromise(thread_, thenResult); - EXPECT_TRUE(JSTaggedValue::SameValue(then_promise->GetPromiseState(), + EXPECT_TRUE(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING)))); - EXPECT_TRUE(then_promise->GetPromiseResult().IsUndefined()); + EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); /// @tc.steps: step6. execute promise queue - auto micro_job_queue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); + auto microJobQueue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); if (LIKELY(!thread_->HasPendingException())) { - job::MicroJobQueue::ExecutePendingJob(thread_, micro_job_queue); + job::MicroJobQueue::ExecutePendingJob(thread_, microJobQueue); } } @@ -531,42 +531,42 @@ TEST_F(BuiltinsPromiseTest, Catch) auto factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg1(thread_, JSTaggedValue(3)); + JSHandle paramMsg1(thread_, JSTaggedValue(3)); /// @tc.steps: step1. var p1 = Promise.reject(3) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); - - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = promise::Reject(ecma_runtime_call_info1.get()); - JSHandle reject_promise(thread_, result); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); + + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = promise::Reject(ecmaRuntimeCallInfo1.get()); + JSHandle rejectPromise(thread_, result); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseResult(), JSTaggedValue(3)), true); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); /// @tc.steps: step2. p1 invokes catch() - JSHandle test_promise_catch = factory->NewJSFunction(env, reinterpret_cast(TestPromiseCatch)); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, reject_promise.GetTaggedValue(), 6); - ecma_runtime_call_info2->SetFunction(reject_promise.GetTaggedValue()); - ecma_runtime_call_info2->SetThis(reject_promise.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, test_promise_catch.GetTaggedValue()); + JSHandle testPromiseCatch = factory->NewJSFunction(env, reinterpret_cast(TestPromiseCatch)); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, rejectPromise.GetTaggedValue(), 6); + ecmaRuntimeCallInfo2->SetFunction(rejectPromise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetThis(rejectPromise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, testPromiseCatch.GetTaggedValue()); - [[maybe_unused]] auto prev_catch = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue catch_result = promise::proto::Catch(ecma_runtime_call_info2.get()); - JSHandle catch_promise(thread_, catch_result); + [[maybe_unused]] auto prevCatch = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue catchResult = promise::proto::Catch(ecmaRuntimeCallInfo2.get()); + JSHandle catchPromise(thread_, catchResult); - EXPECT_EQ(JSTaggedValue::SameValue(catch_promise->GetPromiseState(), + EXPECT_EQ(JSTaggedValue::SameValue(catchPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), true); - EXPECT_EQ(catch_promise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(catchPromise->GetPromiseResult().IsUndefined(), true); /// @tc.steps: step3. execute promise queue - auto micro_job_queue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); + auto microJobQueue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); if (LIKELY(!thread_->HasPendingException())) { - job::MicroJobQueue::ExecutePendingJob(thread_, micro_job_queue); + job::MicroJobQueue::ExecutePendingJob(thread_, microJobQueue); } } @@ -581,44 +581,44 @@ TEST_F(BuiltinsPromiseTest, ThenResolve) auto factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg = JSHandle::Cast(factory->NewFromCanBeCompressString("resolve")); + JSHandle paramMsg = JSHandle::Cast(factory->NewFromCanBeCompressString("resolve")); /// @tc.steps: step1. var p1 = Promise.resolve("resolve") - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg.GetTaggedValue()); - - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = promise::Resolve(ecma_runtime_call_info1.get()); - JSHandle resolve_promise(thread_, result); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg.GetTaggedValue()); + + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = promise::Resolve(ecmaRuntimeCallInfo1.get()); + JSHandle resolvePromise(thread_, result); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseResult(), param_msg.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); /// @tc.steps: step2. p1 invokes then() - JSHandle test_promise_then_on_resolved = + JSHandle testPromiseThenOnResolved = factory->NewJSFunction(env, reinterpret_cast(TestPromiseThenOnResolved)); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, resolve_promise.GetTaggedValue(), 8); - ecma_runtime_call_info2->SetFunction(resolve_promise.GetTaggedValue()); - ecma_runtime_call_info2->SetThis(resolve_promise.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, test_promise_then_on_resolved.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, resolvePromise.GetTaggedValue(), 8); + ecmaRuntimeCallInfo2->SetFunction(resolvePromise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetThis(resolvePromise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, testPromiseThenOnResolved.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev_then = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info2.get()); - JSHandle then_promise(thread_, then_result); + [[maybe_unused]] auto prevThen = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue thenResult = promise::proto::Then(ecmaRuntimeCallInfo2.get()); + JSHandle thenPromise(thread_, thenResult); - EXPECT_EQ(JSTaggedValue::SameValue(then_promise->GetPromiseState(), + EXPECT_EQ(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), true); - EXPECT_EQ(then_promise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); /// @tc.steps: step3. execute promise queue - auto micro_job_queue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); + auto microJobQueue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); if (LIKELY(!thread_->HasPendingException())) { - job::MicroJobQueue::ExecutePendingJob(thread_, micro_job_queue); + job::MicroJobQueue::ExecutePendingJob(thread_, microJobQueue); } } @@ -633,43 +633,43 @@ TEST_F(BuiltinsPromiseTest, ThenReject) auto factory = EcmaVM::Cast(instance_)->GetFactory(); JSHandle promise = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle param_msg = JSHandle::Cast(factory->NewFromCanBeCompressString("reject")); + JSHandle paramMsg = JSHandle::Cast(factory->NewFromCanBeCompressString("reject")); /// @tc.steps: step1. var p1 = Promise.Reject(5) - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); - ecma_runtime_call_info1->SetFunction(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(promise.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, param_msg.GetTaggedValue()); - - [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = promise::Reject(ecma_runtime_call_info1.get()); - JSHandle reject_promise(thread_, result); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*promise), 6); + ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg.GetTaggedValue()); + + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = promise::Reject(ecmaRuntimeCallInfo1.get()); + JSHandle rejectPromise(thread_, result); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), true); - EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseResult(), param_msg.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); /// @tc.steps: step1. p1 invokes then() - JSHandle test_promise_then_on_rejected = + JSHandle testPromiseThenOnRejected = factory->NewJSFunction(env, reinterpret_cast(TestPromiseThenOnRejected)); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, reject_promise.GetTaggedValue(), 8); - ecma_runtime_call_info2->SetFunction(reject_promise.GetTaggedValue()); - ecma_runtime_call_info2->SetThis(reject_promise.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, test_promise_then_on_rejected.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(1, test_promise_then_on_rejected.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, rejectPromise.GetTaggedValue(), 8); + ecmaRuntimeCallInfo2->SetFunction(rejectPromise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetThis(rejectPromise.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, testPromiseThenOnRejected.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(1, testPromiseThenOnRejected.GetTaggedValue()); - [[maybe_unused]] auto prev_then = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info2.get()); - JSHandle then_promise(thread_, then_result); + [[maybe_unused]] auto prevThen = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue thenResult = promise::proto::Then(ecmaRuntimeCallInfo2.get()); + JSHandle thenPromise(thread_, thenResult); - EXPECT_EQ(JSTaggedValue::SameValue(then_promise->GetPromiseState(), + EXPECT_EQ(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), true); - EXPECT_EQ(then_promise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); /// @tc.steps: step3. execute promise queue - auto micro_job_queue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); + auto microJobQueue = EcmaVM::Cast(instance_)->GetMicroJobQueue(); if (LIKELY(!thread_->HasPendingException())) { - job::MicroJobQueue::ExecutePendingJob(thread_, micro_job_queue); + job::MicroJobQueue::ExecutePendingJob(thread_, microJobQueue); } } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_proxy_test.cpp b/tests/runtime/builtins/builtins_proxy_test.cpp index 6fb7d0e345f67263a0156883c718c664a40f8f03..d9679011b963be10ca99c6c8cca1620934f6c8fd 100644 --- a/tests/runtime/builtins/builtins_proxy_test.cpp +++ b/tests/runtime/builtins/builtins_proxy_test.cpp @@ -66,12 +66,12 @@ private: JSHandle BuiltinsTestProxyCreate(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle obj_fun(global_env->GetObjectFunction()); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle objFun(globalEnv->GetObjectFunction()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); return obj; } @@ -81,17 +81,17 @@ TEST_F(BuiltinsProxyTest, ProxyConstructor) JSHandle target = BuiltinsTestProxyCreate(thread_); JSHandle handler = BuiltinsTestProxyCreate(thread_); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Null(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, handler.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Null(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, handler.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = proxy::ProxyConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = proxy::ProxyConstructor(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_handle(thread_, result); - EXPECT_TRUE(result_handle->IsJSProxy()); + JSHandle resultHandle(thread_, result); + EXPECT_TRUE(resultHandle->IsJSProxy()); } // 26.2.2.1 Proxy.revocable ( target, handler ) @@ -100,45 +100,45 @@ TEST_F(BuiltinsProxyTest, Revocable) JSHandle target = BuiltinsTestProxyCreate(thread_); JSHandle handler = BuiltinsTestProxyCreate(thread_); - JSHandle global_env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle proxy_fun(global_env->GetProxyFunction()); + JSHandle globalEnv = thread_->GetEcmaVM()->GetGlobalEnv(); + JSHandle proxyFun(globalEnv->GetProxyFunction()); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("prop")); PropertyDescriptor desc(thread_); desc.SetWritable(false); JSObject::DefineOwnProperty(thread_, handler, key, desc); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, handler.GetTaggedValue()); - ecma_runtime_call_info->SetNewTarget(JSTaggedValue(*proxy_fun)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, handler.GetTaggedValue()); + ecmaRuntimeCallInfo->SetNewTarget(JSTaggedValue(*proxyFun)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = proxy::Revocable(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = proxy::Revocable(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_handle(thread_, result); + JSHandle resultHandle(thread_, result); - auto global_const = thread_->GlobalConstants(); - JSHandle proxy_key = global_const->GetHandledProxyString(); - JSHandle revoke_key = global_const->GetHandledRevokeString(); + auto globalConst = thread_->GlobalConstants(); + JSHandle proxyKey = globalConst->GetHandledProxyString(); + JSHandle revokeKey = globalConst->GetHandledRevokeString(); - JSHandle keys = JSObject::GetOwnPropertyKeys(thread_, result_handle); + JSHandle keys = JSObject::GetOwnPropertyKeys(thread_, resultHandle); bool pflag = false; bool rflag = false; for (uint32_t i = 0; i < keys->GetLength(); i++) { - if (JSTaggedValue::SameValue(keys->Get(i), proxy_key.GetTaggedValue())) { + if (JSTaggedValue::SameValue(keys->Get(i), proxyKey.GetTaggedValue())) { pflag = true; } - if (JSTaggedValue::SameValue(keys->Get(i), revoke_key.GetTaggedValue())) { + if (JSTaggedValue::SameValue(keys->Get(i), revokeKey.GetTaggedValue())) { rflag = true; } } EXPECT_TRUE(pflag); EXPECT_TRUE(rflag); - PropertyDescriptor desc_res(thread_); - JSObject::GetOwnProperty(thread_, result_handle, revoke_key, desc_res); - EXPECT_TRUE(desc_res.GetValue()->IsProxyRevocFunction()); + PropertyDescriptor descRes(thread_); + JSObject::GetOwnProperty(thread_, resultHandle, revokeKey, descRes); + EXPECT_TRUE(descRes.GetValue()->IsProxyRevocFunction()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_reflect_test.cpp b/tests/runtime/builtins/builtins_reflect_test.cpp index 441649520e92f7c9c719dd794d4333f70fe1db17..3cbbaf1146aa2673812db4164eb7658d50bf2076 100644 --- a/tests/runtime/builtins/builtins_reflect_test.cpp +++ b/tests/runtime/builtins/builtins_reflect_test.cpp @@ -77,27 +77,27 @@ static JSHandle TestObjectCreate(JSThread *thread) JSTaggedValue TestReflectApply(EcmaRuntimeCallInfo *argv) { auto thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int result = 0; for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { result += builtins_common::GetCallArg(argv, index).GetTaggedValue().GetInt(); } - JSHandle this_value = builtins_common::GetThis(argv); + JSHandle thisValue = builtins_common::GetThis(argv); - JSTaggedValue test_a = - JSObject::GetProperty(thread, this_value, + JSTaggedValue testA = + JSObject::GetProperty(thread, thisValue, JSHandle(factory->NewFromCanBeCompressString("test_reflect_apply_a"))) .GetValue() .GetTaggedValue(); - JSTaggedValue test_b = - JSObject::GetProperty(thread, this_value, + JSTaggedValue testB = + JSObject::GetProperty(thread, thisValue, JSHandle(factory->NewFromCanBeCompressString("test_reflect_apply_b"))) .GetValue() .GetTaggedValue(); - result = result + test_a.GetInt() + test_b.GetInt(); + result = result + testA.GetInt() + testB.GetInt(); return builtins_common::GetTaggedInt(result); } @@ -111,36 +111,36 @@ TEST_F(BuiltinsReflectTest, ReflectApply) // target JSHandle target = factory->NewJSFunction(env, reinterpret_cast(TestReflectApply)); // thisArgument - JSHandle this_argument = factory->NewJSObjectByConstructor( + JSHandle thisArgument = factory->NewJSObjectByConstructor( TestObjectCreate(thread_), JSHandle(TestObjectCreate(thread_))); - JSObject::SetProperty(thread_, JSHandle(this_argument), + JSObject::SetProperty(thread_, JSHandle(thisArgument), JSHandle(factory->NewFromCanBeCompressString("test_reflect_apply_a")), JSHandle(thread_, JSTaggedValue(11))); - JSObject::SetProperty(thread_, JSHandle(this_argument), + JSObject::SetProperty(thread_, JSHandle(thisArgument), JSHandle(factory->NewFromCanBeCompressString("test_reflect_apply_b")), JSHandle(thread_, JSTaggedValue(22))); // argumentsList - JSHandle arguments_list(JSArray::ArrayCreate(thread_, JSTaggedNumber(2))); + JSHandle argumentsList(JSArray::ArrayCreate(thread_, JSTaggedNumber(2))); PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(33))); - JSArray::DefineOwnProperty(thread_, arguments_list, JSHandle(thread_, JSTaggedValue(0)), desc); + JSArray::DefineOwnProperty(thread_, argumentsList, JSHandle(thread_, JSTaggedValue(0)), desc); PropertyDescriptor desc1(thread_, JSHandle(thread_, JSTaggedValue(44))); - JSArray::DefineOwnProperty(thread_, arguments_list, JSHandle(thread_, JSTaggedValue(1)), desc1); + JSArray::DefineOwnProperty(thread_, argumentsList, JSHandle(thread_, JSTaggedValue(1)), desc1); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(*this_argument)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(*arguments_list)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(*thisArgument)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(*argumentsList)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::Apply(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::Apply(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(110).GetRawData()); - JSObject::DeleteProperty(thread_, (this_argument), + JSObject::DeleteProperty(thread_, (thisArgument), JSHandle(factory->NewFromCanBeCompressString("test_reflect_apply_a"))); - JSObject::DeleteProperty(thread_, (this_argument), + JSObject::DeleteProperty(thread_, (thisArgument), JSHandle(factory->NewFromCanBeCompressString("test_reflect_apply_b"))); } @@ -154,25 +154,25 @@ TEST_F(BuiltinsReflectTest, ReflectConstruct) // target JSHandle target = JSHandle::Cast(env->GetStringFunction()); // argumentsList - JSHandle arguments_list(JSArray::ArrayCreate(thread_, JSTaggedNumber(1))); + JSHandle argumentsList(JSArray::ArrayCreate(thread_, JSTaggedNumber(1))); PropertyDescriptor desc(thread_, JSHandle::Cast(factory->NewFromCanBeCompressString("ReflectConstruct"))); - JSArray::DefineOwnProperty(thread_, arguments_list, JSHandle(thread_, JSTaggedValue(0)), desc); + JSArray::DefineOwnProperty(thread_, argumentsList, JSHandle(thread_, JSTaggedValue(0)), desc); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(*arguments_list)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(*argumentsList)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::Construct(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::Construct(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle tagged_result(thread_, result); - JSHandle ref_result = JSHandle::Cast(tagged_result); + JSHandle taggedResult(thread_, result); + JSHandle refResult = JSHandle::Cast(taggedResult); JSHandle ruler = factory->NewFromCanBeCompressString("ReflectConstruct"); - ASSERT_EQ(EcmaString::Cast(ref_result->GetValue().GetTaggedObject())->Compare(*ruler), 0); + ASSERT_EQ(EcmaString::Cast(refResult->GetValue().GetTaggedObject())->Compare(*ruler), 0); } // Reflect.defineProperty (target, propertyKey, attributes) @@ -189,40 +189,40 @@ TEST_F(BuiltinsReflectTest, ReflectDefineProperty) JSHandle attributes = factory->NewJSObjectByConstructor( TestObjectCreate(thread_), JSHandle(TestObjectCreate(thread_))); // attributes value - auto global_const = thread_->GlobalConstants(); - JSHandle value_key = global_const->GetHandledValueString(); + auto globalConst = thread_->GlobalConstants(); + JSHandle valueKey = globalConst->GetHandledValueString(); JSHandle value(thread_, JSTaggedValue(100)); - JSObject::SetProperty(thread_, JSHandle(attributes), value_key, value); + JSObject::SetProperty(thread_, JSHandle(attributes), valueKey, value); // attributes writable - JSHandle writable_key = global_const->GetHandledWritableString(); + JSHandle writableKey = globalConst->GetHandledWritableString(); JSHandle writable(thread_, JSTaggedValue::True()); - JSObject::SetProperty(thread_, JSHandle(attributes), writable_key, writable); + JSObject::SetProperty(thread_, JSHandle(attributes), writableKey, writable); // attributes enumerable - JSHandle enumerable_key = global_const->GetHandledEnumerableString(); + JSHandle enumerableKey = globalConst->GetHandledEnumerableString(); JSHandle enumerable(thread_, JSTaggedValue::False()); - JSObject::SetProperty(thread_, JSHandle(attributes), enumerable_key, enumerable); + JSObject::SetProperty(thread_, JSHandle(attributes), enumerableKey, enumerable); // attributes configurable - JSHandle configurable_key = global_const->GetHandledConfigurableString(); + JSHandle configurableKey = globalConst->GetHandledConfigurableString(); JSHandle configurable(thread_, JSTaggedValue::True()); - JSObject::SetProperty(thread_, JSHandle(attributes), configurable_key, configurable); + JSObject::SetProperty(thread_, JSHandle(attributes), configurableKey, configurable); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(*attributes)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(*attributes)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::DefineProperty(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::DefineProperty(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); - PropertyDescriptor desc_ruler(thread_); - JSObject::GetOwnProperty(thread_, target, key, desc_ruler); - ASSERT_EQ(desc_ruler.GetValue()->GetInt(), 100); - ASSERT_EQ(desc_ruler.IsWritable(), true); - ASSERT_EQ(desc_ruler.IsEnumerable(), false); - ASSERT_EQ(desc_ruler.IsConfigurable(), true); + PropertyDescriptor descRuler(thread_); + JSObject::GetOwnProperty(thread_, target, key, descRuler); + ASSERT_EQ(descRuler.GetValue()->GetInt(), 100); + ASSERT_EQ(descRuler.IsWritable(), true); + ASSERT_EQ(descRuler.IsEnumerable(), false); + ASSERT_EQ(descRuler.IsConfigurable(), true); } // Reflect.deleteProperty (target, propertyKey) @@ -241,14 +241,14 @@ TEST_F(BuiltinsReflectTest, ReflectDeleteProperty) PropertyDescriptor desc(thread_); ASSERT_EQ(JSObject::GetOwnProperty(thread_, target, key, desc), true); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::DeleteProperty(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::DeleteProperty(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(JSObject::GetOwnProperty(thread_, target, key, desc), false); } @@ -267,17 +267,17 @@ TEST_F(BuiltinsReflectTest, ReflectGet) JSHandle value(thread_, JSTaggedValue(101.5)); JSObject::SetProperty(thread_, JSHandle(target), key, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::Get(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::Get(ecmaRuntimeCallInfo.get()); - JSHandle result_value(thread_, result); - ASSERT_EQ(result_value->GetDouble(), 101.5); + JSHandle resultValue(thread_, result); + ASSERT_EQ(resultValue->GetDouble(), 101.5); } // Reflect.getOwnPropertyDescriptor ( target, propertyKey ) @@ -293,36 +293,35 @@ TEST_F(BuiltinsReflectTest, ReflectGetOwnPropertyDescriptor) PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(102)), true, false, true); ASSERT_EQ(JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(target), key, desc), true); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::GetOwnPropertyDescriptor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::GetOwnPropertyDescriptor(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_obj(thread_, result); + JSHandle resultObj(thread_, result); // test value - auto global_const = thread_->GlobalConstants(); - JSHandle value_key = global_const->GetHandledValueString(); - JSHandle result_value = JSObject::GetProperty(thread_, result_obj, value_key).GetValue(); - ASSERT_EQ(result_value->GetInt(), 102); + auto globalConst = thread_->GlobalConstants(); + JSHandle valueKey = globalConst->GetHandledValueString(); + JSHandle resultValue = JSObject::GetProperty(thread_, resultObj, valueKey).GetValue(); + ASSERT_EQ(resultValue->GetInt(), 102); // test writable - JSHandle writable_key = global_const->GetHandledWritableString(); - JSHandle result_writable = JSObject::GetProperty(thread_, result_obj, writable_key).GetValue(); - ASSERT_EQ(result_writable->ToBoolean(), true); + JSHandle writableKey = globalConst->GetHandledWritableString(); + JSHandle resultWritable = JSObject::GetProperty(thread_, resultObj, writableKey).GetValue(); + ASSERT_EQ(resultWritable->ToBoolean(), true); // test enumerable - JSHandle enumerable_key = global_const->GetHandledEnumerableString(); - JSHandle result_enumerable = JSObject::GetProperty(thread_, result_obj, enumerable_key).GetValue(); - ASSERT_EQ(result_enumerable->ToBoolean(), false); + JSHandle enumerableKey = globalConst->GetHandledEnumerableString(); + JSHandle resultEnumerable = JSObject::GetProperty(thread_, resultObj, enumerableKey).GetValue(); + ASSERT_EQ(resultEnumerable->ToBoolean(), false); // test configurable - JSHandle configurable_key = global_const->GetHandledConfigurableString(); - JSHandle result_configurable = - JSObject::GetProperty(thread_, result_obj, configurable_key).GetValue(); - ASSERT_EQ(result_configurable->ToBoolean(), true); + JSHandle configurableKey = globalConst->GetHandledConfigurableString(); + JSHandle resultConfigurable = JSObject::GetProperty(thread_, resultObj, configurableKey).GetValue(); + ASSERT_EQ(resultConfigurable->ToBoolean(), true); } // Reflect.getPrototypeOf (target) @@ -337,16 +336,16 @@ TEST_F(BuiltinsReflectTest, ReflectGetPrototypeOf) ASSERT_EQ(JSObject::SetPrototype(thread_, target, JSHandle(proto)), true); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::GetPrototypeOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::GetPrototypeOf(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_obj(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); - ASSERT_EQ(JSTaggedValue::SameValue(result_obj.GetTaggedValue(), proto.GetTaggedValue()), true); + JSHandle resultObj(thread_, JSTaggedValue(reinterpret_cast(result.GetRawData()))); + ASSERT_EQ(JSTaggedValue::SameValue(resultObj.GetTaggedValue(), proto.GetTaggedValue()), true); } // Reflect.has (target, propertyKey) @@ -362,14 +361,14 @@ TEST_F(BuiltinsReflectTest, ReflectHas) JSHandle value(thread_, JSTaggedValue(103)); ASSERT_EQ(JSObject::SetProperty(thread_, JSHandle(target), key, value), true); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::Has(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::Has(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -384,13 +383,13 @@ TEST_F(BuiltinsReflectTest, ReflectIsExtensible) JSHandle(TestObjectCreate(thread_))); target->GetJSHClass()->SetExtensible(false); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::IsExtensible(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::IsExtensible(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -410,34 +409,34 @@ TEST_F(BuiltinsReflectTest, ReflectOwnKeys) JSHandle value1(thread_, JSTaggedValue(105)); ASSERT_EQ(JSObject::SetProperty(thread_, JSHandle(target), key1, value1), true); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::OwnKeys(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::OwnKeys(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_tagged_value(thread_, reinterpret_cast(result.GetRawData())); - JSHandle result_array = JSHandle::Cast(result_tagged_value); + JSHandle resultTaggedValue(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultArray = JSHandle::Cast(resultTaggedValue); // test length - JSHandle result_length_key = thread_->GlobalConstants()->GetHandledLengthString(); - JSHandle result_length = - JSObject::GetProperty(thread_, JSHandle(result_array), result_length_key).GetValue(); - ASSERT_EQ(result_length->GetInt(), 2); + JSHandle resultLengthKey = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle resultLength = + JSObject::GetProperty(thread_, JSHandle(resultArray), resultLengthKey).GetValue(); + ASSERT_EQ(resultLength->GetInt(), 2); // test array[0] - JSHandle result_key0(thread_, JSTaggedValue(0)); - JSHandle result_value0 = - JSObject::GetProperty(thread_, JSHandle(result_array), result_key0).GetValue(); - ASSERT_EQ(reinterpret_cast(result_value0.GetTaggedValue().GetTaggedObject()) + JSHandle resultKey0(thread_, JSTaggedValue(0)); + JSHandle resultValue0 = + JSObject::GetProperty(thread_, JSHandle(resultArray), resultKey0).GetValue(); + ASSERT_EQ(reinterpret_cast(resultValue0.GetTaggedValue().GetTaggedObject()) ->Compare(reinterpret_cast(key0.GetTaggedValue().GetTaggedObject())), 0); // test array[1] - JSHandle result_key1(thread_, JSTaggedValue(1)); - JSHandle result_value1 = - JSObject::GetProperty(thread_, JSHandle(result_array), result_key1).GetValue(); - ASSERT_EQ(reinterpret_cast(result_value1.GetTaggedValue().GetTaggedObject()) + JSHandle resultKey1(thread_, JSTaggedValue(1)); + JSHandle resultValue1 = + JSObject::GetProperty(thread_, JSHandle(resultArray), resultKey1).GetValue(); + ASSERT_EQ(reinterpret_cast(resultValue1.GetTaggedValue().GetTaggedObject()) ->Compare(reinterpret_cast(key1.GetTaggedValue().GetTaggedObject())), 0); } @@ -452,13 +451,13 @@ TEST_F(BuiltinsReflectTest, ReflectPreventExtensions) JSHandle(TestObjectCreate(thread_))); target->GetJSHClass()->SetExtensible(true); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::PreventExtensions(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::PreventExtensions(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(target->IsExtensible(), false); @@ -477,15 +476,15 @@ TEST_F(BuiltinsReflectTest, ReflectSet) // value JSHandle value(thread_, JSTaggedValue(106)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::Set(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::Set(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -503,18 +502,18 @@ TEST_F(BuiltinsReflectTest, ReflectSetPrototypeOf) JSHandle proto = factory->NewJSObjectByConstructor(TestObjectCreate(thread_), JSHandle(TestObjectCreate(thread_))); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, proto.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, proto.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = reflect::SetPrototypeOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reflect::SetPrototypeOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); - JSHandle result_obj(thread_, target->GetJSHClass()->GetPrototype()); - ASSERT_EQ(JSTaggedValue::SameValue(result_obj.GetTaggedValue(), proto.GetTaggedValue()), true); + JSHandle resultObj(thread_, target->GetJSHClass()->GetPrototype()); + ASSERT_EQ(JSTaggedValue::SameValue(resultObj.GetTaggedValue(), proto.GetTaggedValue()), true); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_regexp_test.cpp b/tests/runtime/builtins/builtins_regexp_test.cpp index 913b72147ebe8f552232b7f75b6afc18b4bec6b7..153e299c60b65554bf2492e93f962ce2f4227370 100644 --- a/tests/runtime/builtins/builtins_regexp_test.cpp +++ b/tests/runtime/builtins/builtins_regexp_test.cpp @@ -73,18 +73,18 @@ JSTaggedValue CreateBuiltinsRegExpObjByPatternAndFlags(JSThread *thread, const J { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle regexp(env->GetRegExpFunction()); - JSHandle global_object(thread, env->GetGlobalObject()); + JSHandle globalObject(thread, env->GetGlobalObject()); // make ecma_runtime_call_info // 8 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*regexp), 8); - ecma_runtime_call_info->SetFunction(regexp.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, pattern.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, flags.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*regexp), 8); + ecmaRuntimeCallInfo->SetFunction(regexp.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, pattern.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, flags.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); // invoke RegExpConstructor method - JSTaggedValue result = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = reg_exp::RegExpConstructor(ecmaRuntimeCallInfo.get()); return result; } @@ -96,15 +96,15 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor1) JSTaggedValue result = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern, flags); // ASSERT IsRegExp() - JSHandle regexp_object(thread_, result); - ASSERT_TRUE(JSObject::IsRegExp(thread_, regexp_object)); - - JSHandle js_regexp(thread_, JSRegExp::Cast(regexp_object->GetTaggedObject())); - JSHandle original_source(thread_, js_regexp->GetOriginalSource()); - uint8_t flags_bits = static_cast(js_regexp->GetOriginalFlags().GetInt()); - JSHandle original_flags(thread_, reg_exp::FlagsBitsToString(thread_, flags_bits)); - ASSERT_EQ(static_cast(original_source->GetTaggedObject())->Compare(*pattern), 0); - ASSERT_EQ(static_cast(original_flags->GetTaggedObject())->Compare(*flags), 0); + JSHandle regexpObject(thread_, result); + ASSERT_TRUE(JSObject::IsRegExp(thread_, regexpObject)); + + JSHandle jsRegexp(thread_, JSRegExp::Cast(regexpObject->GetTaggedObject())); + JSHandle originalSource(thread_, jsRegexp->GetOriginalSource()); + uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags().GetInt()); + JSHandle originalFlags(thread_, reg_exp::FlagsBitsToString(thread_, flagsBits)); + ASSERT_EQ(static_cast(originalSource->GetTaggedObject())->Compare(*pattern), 0); + ASSERT_EQ(static_cast(originalFlags->GetTaggedObject())->Compare(*flags), 0); } TEST_F(BuiltinsRegExpTest, RegExpConstructor2) @@ -117,29 +117,29 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor2) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle regexp(env->GetRegExpFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*regexp), 8); - ecma_runtime_call_info->SetFunction(regexp.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*regexp), 8); + ecmaRuntimeCallInfo->SetFunction(regexp.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke RegExpConstructor method - JSTaggedValue result2 = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result2 = reg_exp::RegExpConstructor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); // ASSERT IsRegExp() - JSHandle regexp_object(thread_, result2); - ASSERT_TRUE(JSObject::IsRegExp(thread_, regexp_object)); - - JSHandle js_regexp(thread_, JSRegExp::Cast(regexp_object->GetTaggedObject())); - JSHandle original_source(thread_, js_regexp->GetOriginalSource()); - uint8_t flags_bits = static_cast(js_regexp->GetOriginalFlags().GetInt()); - JSHandle original_flags(thread_, reg_exp::FlagsBitsToString(thread_, flags_bits)); - ASSERT_EQ(static_cast(original_source->GetTaggedObject())->Compare(*pattern), 0); - ASSERT_EQ(static_cast(original_flags->GetTaggedObject())->Compare(*flags), 0); + JSHandle regexpObject(thread_, result2); + ASSERT_TRUE(JSObject::IsRegExp(thread_, regexpObject)); + + JSHandle jsRegexp(thread_, JSRegExp::Cast(regexpObject->GetTaggedObject())); + JSHandle originalSource(thread_, jsRegexp->GetOriginalSource()); + uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags().GetInt()); + JSHandle originalFlags(thread_, reg_exp::FlagsBitsToString(thread_, flagsBits)); + ASSERT_EQ(static_cast(originalSource->GetTaggedObject())->Compare(*pattern), 0); + ASSERT_EQ(static_cast(originalFlags->GetTaggedObject())->Compare(*flags), 0); } TEST_F(BuiltinsRegExpTest, RegExpConstructor3) @@ -152,29 +152,29 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor3) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle regexp(env->GetRegExpFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); JSHandle flags2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("gi"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*regexp), 8); - ecma_runtime_call_info->SetFunction(regexp.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, flags2.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue(*regexp), 8); + ecmaRuntimeCallInfo->SetFunction(regexp.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, flags2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke RegExpConstructor method - JSTaggedValue result2 = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result2 = reg_exp::RegExpConstructor(ecmaRuntimeCallInfo.get()); // ASSERT IsRegExp() - JSHandle regexp_object(thread_, result2); - ASSERT_TRUE(JSObject::IsRegExp(thread_, regexp_object)); - - JSHandle js_regexp(thread_, JSRegExp::Cast(regexp_object->GetTaggedObject())); - JSHandle original_source(thread_, js_regexp->GetOriginalSource()); - uint8_t flags_bits = static_cast(js_regexp->GetOriginalFlags().GetInt()); - JSHandle original_flags(thread_, reg_exp::FlagsBitsToString(thread_, flags_bits)); - ASSERT_EQ(static_cast(original_source->GetTaggedObject())->Compare(*pattern1), 0); - ASSERT_EQ(static_cast(original_flags->GetTaggedObject())->Compare(*flags2), 0); + JSHandle regexpObject(thread_, result2); + ASSERT_TRUE(JSObject::IsRegExp(thread_, regexpObject)); + + JSHandle jsRegexp(thread_, JSRegExp::Cast(regexpObject->GetTaggedObject())); + JSHandle originalSource(thread_, jsRegexp->GetOriginalSource()); + uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags().GetInt()); + JSHandle originalFlags(thread_, reg_exp::FlagsBitsToString(thread_, flagsBits)); + ASSERT_EQ(static_cast(originalSource->GetTaggedObject())->Compare(*pattern1), 0); + ASSERT_EQ(static_cast(originalFlags->GetTaggedObject())->Compare(*flags2), 0); } TEST_F(BuiltinsRegExpTest, GetSource1) @@ -183,15 +183,15 @@ TEST_F(BuiltinsRegExpTest, GetSource1) JSHandle pattern1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); JSHandle flags1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("i"); JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); - JSHandle result1_handle(thread_, result1); + JSHandle result1Handle(thread_, result1); // invoke GetSource method JSHandle source( thread_, thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("source").GetTaggedValue()); - JSHandle source_result(JSObject::GetProperty(thread_, result1_handle, source).GetValue()); + JSHandle sourceResult(JSObject::GetProperty(thread_, result1Handle, source).GetValue()); JSHandle expect = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("(?:)"); - ASSERT_EQ(static_cast(source_result->GetTaggedObject())->Compare(*expect), 0); + ASSERT_EQ(static_cast(sourceResult->GetTaggedObject())->Compare(*expect), 0); } TEST_F(BuiltinsRegExpTest, GetSource2) @@ -200,14 +200,14 @@ TEST_F(BuiltinsRegExpTest, GetSource2) JSHandle pattern1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("/w+"); JSHandle flags1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("i"); JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); - JSHandle result1_handle(thread_, result1); + JSHandle result1Handle(thread_, result1); // invoke GetSource method JSHandle source(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("source")); - JSHandle source_result(JSObject::GetProperty(thread_, result1_handle, source).GetValue()); + JSHandle sourceResult(JSObject::GetProperty(thread_, result1Handle, source).GetValue()); JSHandle expect = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("\\/w+"); - ASSERT_EQ(static_cast(source_result->GetTaggedObject())->Compare(*expect), 0); + ASSERT_EQ(static_cast(sourceResult->GetTaggedObject())->Compare(*expect), 0); } TEST_F(BuiltinsRegExpTest, Get) @@ -216,32 +216,32 @@ TEST_F(BuiltinsRegExpTest, Get) JSHandle pattern1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("\\w+"); JSHandle flags1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("gimuy"); JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); - JSHandle result1_handle(thread_, result1); + JSHandle result1Handle(thread_, result1); JSHandle global(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("global")); - JSTaggedValue tagged_global_result = - JSTaggedValue(JSObject::GetProperty(thread_, result1_handle, global).GetValue().GetTaggedValue()); - ASSERT_EQ(tagged_global_result.GetRawData(), JSTaggedValue::True().GetRawData()); + JSTaggedValue taggedGlobalResult = + JSTaggedValue(JSObject::GetProperty(thread_, result1Handle, global).GetValue().GetTaggedValue()); + ASSERT_EQ(taggedGlobalResult.GetRawData(), JSTaggedValue::True().GetRawData()); - JSHandle ignore_case(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("ignoreCase")); - JSTaggedValue tagged_ignore_case_result = - JSTaggedValue(JSObject::GetProperty(thread_, result1_handle, ignore_case).GetValue().GetTaggedValue()); - ASSERT_EQ(tagged_ignore_case_result.GetRawData(), JSTaggedValue::True().GetRawData()); + JSHandle ignoreCase(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("ignoreCase")); + JSTaggedValue taggedIgnoreCaseResult = + JSTaggedValue(JSObject::GetProperty(thread_, result1Handle, ignoreCase).GetValue().GetTaggedValue()); + ASSERT_EQ(taggedIgnoreCaseResult.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle multiline(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("multiline")); - JSTaggedValue tagged_multiline_result = - JSTaggedValue(JSObject::GetProperty(thread_, result1_handle, multiline).GetValue().GetTaggedValue()); - ASSERT_EQ(tagged_multiline_result.GetRawData(), JSTaggedValue::True().GetRawData()); + JSTaggedValue taggedMultilineResult = + JSTaggedValue(JSObject::GetProperty(thread_, result1Handle, multiline).GetValue().GetTaggedValue()); + ASSERT_EQ(taggedMultilineResult.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle sticky(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("sticky")); - JSTaggedValue tagged_sticky_result = - JSTaggedValue(JSObject::GetProperty(thread_, result1_handle, sticky).GetValue().GetTaggedValue()); - ASSERT_EQ(tagged_sticky_result.GetRawData(), JSTaggedValue::True().GetRawData()); + JSTaggedValue taggedStickyResult = + JSTaggedValue(JSObject::GetProperty(thread_, result1Handle, sticky).GetValue().GetTaggedValue()); + ASSERT_EQ(taggedStickyResult.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle unicode(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("unicode")); - JSTaggedValue tagged_unicode_result = - JSTaggedValue(JSObject::GetProperty(thread_, result1_handle, unicode).GetValue().GetTaggedValue()); - ASSERT_EQ(tagged_unicode_result.GetRawData(), JSTaggedValue::True().GetRawData()); + JSTaggedValue taggedUnicodeResult = + JSTaggedValue(JSObject::GetProperty(thread_, result1Handle, unicode).GetValue().GetTaggedValue()); + ASSERT_EQ(taggedUnicodeResult.GetRawData(), JSTaggedValue::True().GetRawData()); } TEST_F(BuiltinsRegExpTest, GetFlags) @@ -250,14 +250,14 @@ TEST_F(BuiltinsRegExpTest, GetFlags) JSHandle pattern1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("\\w+"); JSHandle flags1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("imuyg"); JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); - JSHandle result1_handle(thread_, result1); + JSHandle result1Handle(thread_, result1); // invoke GetFlags method JSHandle flags(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("flags")); - JSHandle flags_result(JSObject::GetProperty(thread_, result1_handle, flags).GetValue()); + JSHandle flagsResult(JSObject::GetProperty(thread_, result1Handle, flags).GetValue()); - JSHandle expect_result = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("gimuy"); - ASSERT_EQ(static_cast(flags_result->GetTaggedObject())->Compare(*expect_result), 0); + JSHandle expectResult = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("gimuy"); + ASSERT_EQ(static_cast(flagsResult->GetTaggedObject())->Compare(*expectResult), 0); } TEST_F(BuiltinsRegExpTest, toString) @@ -268,17 +268,17 @@ TEST_F(BuiltinsRegExpTest, toString) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke ToString method - JSTaggedValue to_string_result = reg_exp::proto::ToString(ecma_runtime_call_info.get()); - ASSERT_TRUE(to_string_result.IsString()); - JSHandle to_string_result_handle(thread_, to_string_result); - JSHandle expect_result = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("/\\w+/gimuy"); - ASSERT_EQ(static_cast(to_string_result_handle->GetTaggedObject())->Compare(*expect_result), 0); + JSTaggedValue toStringResult = reg_exp::proto::ToString(ecmaRuntimeCallInfo.get()); + ASSERT_TRUE(toStringResult.IsString()); + JSHandle toStringResultHandle(thread_, toStringResult); + JSHandle expectResult = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("/\\w+/gimuy"); + ASSERT_EQ(static_cast(toStringResultHandle->GetTaggedObject())->Compare(*expectResult), 0); } TEST_F(BuiltinsRegExpTest, Exec1) @@ -290,55 +290,55 @@ TEST_F(BuiltinsRegExpTest, Exec1) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("The Quick Brown Fox Jumps Over The Lazy Dog"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke Exec method - JSTaggedValue results = reg_exp::proto::Exec(ecma_runtime_call_info.get()); + JSTaggedValue results = reg_exp::proto::Exec(ecmaRuntimeCallInfo.get()); - JSHandle exec_result(thread_, results); - JSHandle result_zero = + JSHandle execResult(thread_, results); + JSHandle resultZero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Quick Brown Fox Jumps"); - JSHandle result_one = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Brown"); - JSHandle result_two = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Jumps"); + JSHandle resultOne = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Brown"); + JSHandle resultTwo = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Jumps"); JSHandle index(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("index")); - JSHandle index_handle(JSObject::GetProperty(thread_, exec_result, index).GetValue()); - uint32_t result_index = JSTaggedValue::ToUint32(thread_, index_handle); - ASSERT_TRUE(result_index == 4U); + JSHandle indexHandle(JSObject::GetProperty(thread_, execResult, index).GetValue()); + uint32_t resultIndex = JSTaggedValue::ToUint32(thread_, indexHandle); + ASSERT_TRUE(resultIndex == 4U); JSHandle input(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("input")); - JSHandle input_handle(JSObject::GetProperty(thread_, exec_result, input).GetValue()); - JSHandle output_input = JSTaggedValue::ToString(thread_, input_handle); - ASSERT_EQ(output_input->Compare(*input_string), 0); + JSHandle inputHandle(JSObject::GetProperty(thread_, execResult, input).GetValue()); + JSHandle outputInput = JSTaggedValue::ToString(thread_, inputHandle); + ASSERT_EQ(outputInput->Compare(*inputString), 0); JSHandle zero(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0")); - JSHandle zero_handle(JSObject::GetProperty(thread_, exec_result, zero).GetValue()); - JSHandle output_zero = JSTaggedValue::ToString(thread_, zero_handle); - ASSERT_EQ(output_zero->Compare(*result_zero), 0); + JSHandle zeroHandle(JSObject::GetProperty(thread_, execResult, zero).GetValue()); + JSHandle outputZero = JSTaggedValue::ToString(thread_, zeroHandle); + ASSERT_EQ(outputZero->Compare(*resultZero), 0); JSHandle first(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1")); - JSHandle one_handle(JSObject::GetProperty(thread_, exec_result, first).GetValue()); - JSHandle output_one = JSTaggedValue::ToString(thread_, one_handle); - ASSERT_EQ(output_one->Compare(*result_one), 0); + JSHandle oneHandle(JSObject::GetProperty(thread_, execResult, first).GetValue()); + JSHandle outputOne = JSTaggedValue::ToString(thread_, oneHandle); + ASSERT_EQ(outputOne->Compare(*resultOne), 0); JSHandle second(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2")); - JSHandle two_handle(JSObject::GetProperty(thread_, exec_result, second).GetValue()); - JSHandle output_two = JSTaggedValue::ToString(thread_, two_handle); - ASSERT_EQ(output_two->Compare(*result_two), 0); + JSHandle twoHandle(JSObject::GetProperty(thread_, execResult, second).GetValue()); + JSHandle outputTwo = JSTaggedValue::ToString(thread_, twoHandle); + ASSERT_EQ(outputTwo->Compare(*resultTwo), 0); JSHandle regexp = JSHandle::Cast(value); - JSHandle last_index_handle( + JSHandle lastIndexHandle( thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("lastIndex")); - JSHandle last_index_obj(JSObject::GetProperty(thread_, regexp, last_index_handle).GetValue()); - int last_index = last_index_obj->GetInt(); - ASSERT_TRUE(last_index == 25); + JSHandle lastIndexObj(JSObject::GetProperty(thread_, regexp, lastIndexHandle).GetValue()); + int lastIndex = lastIndexObj->GetInt(); + ASSERT_TRUE(lastIndex == 25); } TEST_F(BuiltinsRegExpTest, Exec2) @@ -350,72 +350,72 @@ TEST_F(BuiltinsRegExpTest, Exec2) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("123"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("123"); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke Exec method - JSTaggedValue results = reg_exp::proto::Exec(ecma_runtime_call_info.get()); + JSTaggedValue results = reg_exp::proto::Exec(ecmaRuntimeCallInfo.get()); - JSHandle exec_result(thread_, results); - JSHandle result_zero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("123"); - JSHandle result_one = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1"); - JSHandle result_two = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1"); - JSHandle result_four = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("23"); - JSHandle result_six = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("23"); + JSHandle execResult(thread_, results); + JSHandle resultZero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("123"); + JSHandle resultOne = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1"); + JSHandle resultTwo = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1"); + JSHandle resultFour = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("23"); + JSHandle resultSix = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("23"); JSHandle index(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("index")); - JSHandle index_handle(JSObject::GetProperty(thread_, exec_result, index).GetValue()); - uint32_t result_index = JSTaggedValue::ToUint32(thread_, index_handle); - ASSERT_TRUE(result_index == 0U); + JSHandle indexHandle(JSObject::GetProperty(thread_, execResult, index).GetValue()); + uint32_t resultIndex = JSTaggedValue::ToUint32(thread_, indexHandle); + ASSERT_TRUE(resultIndex == 0U); JSHandle input(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("input")); - JSHandle input_handle(JSObject::GetProperty(thread_, exec_result, input).GetValue()); - JSHandle output_input = JSTaggedValue::ToString(thread_, input_handle); - ASSERT_EQ(output_input->Compare(*input_string), 0); + JSHandle inputHandle(JSObject::GetProperty(thread_, execResult, input).GetValue()); + JSHandle outputInput = JSTaggedValue::ToString(thread_, inputHandle); + ASSERT_EQ(outputInput->Compare(*inputString), 0); JSHandle zero(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0")); - JSHandle zero_handle(JSObject::GetProperty(thread_, exec_result, zero).GetValue()); - JSHandle output_zero = JSTaggedValue::ToString(thread_, zero_handle); - ASSERT_EQ(output_zero->Compare(*result_zero), 0); + JSHandle zeroHandle(JSObject::GetProperty(thread_, execResult, zero).GetValue()); + JSHandle outputZero = JSTaggedValue::ToString(thread_, zeroHandle); + ASSERT_EQ(outputZero->Compare(*resultZero), 0); JSHandle first(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1")); - JSHandle one_handle(JSObject::GetProperty(thread_, exec_result, first).GetValue()); - JSHandle output_one = JSTaggedValue::ToString(thread_, one_handle); - ASSERT_EQ(output_one->Compare(*result_one), 0); + JSHandle oneHandle(JSObject::GetProperty(thread_, execResult, first).GetValue()); + JSHandle outputOne = JSTaggedValue::ToString(thread_, oneHandle); + ASSERT_EQ(outputOne->Compare(*resultOne), 0); JSHandle second(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2")); - JSHandle two_handle(JSObject::GetProperty(thread_, exec_result, second).GetValue()); - JSHandle output_two = JSTaggedValue::ToString(thread_, two_handle); - ASSERT_EQ(output_two->Compare(*result_two), 0); + JSHandle twoHandle(JSObject::GetProperty(thread_, execResult, second).GetValue()); + JSHandle outputTwo = JSTaggedValue::ToString(thread_, twoHandle); + ASSERT_EQ(outputTwo->Compare(*resultTwo), 0); JSHandle regexp = JSHandle::Cast(value); - JSHandle last_index_handle( + JSHandle lastIndexHandle( thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("lastIndex")); - JSHandle last_index_obj(JSObject::GetProperty(thread_, regexp, last_index_handle).GetValue()); - int last_index = last_index_obj->GetInt(); - ASSERT_TRUE(last_index == 3); + JSHandle lastIndexObj(JSObject::GetProperty(thread_, regexp, lastIndexHandle).GetValue()); + int lastIndex = lastIndexObj->GetInt(); + ASSERT_TRUE(lastIndex == 3); JSHandle third(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("3")); - JSHandle third_handle(JSObject::GetProperty(thread_, exec_result, third).GetValue()); - ASSERT_TRUE(third_handle->IsUndefined()); + JSHandle thirdHandle(JSObject::GetProperty(thread_, execResult, third).GetValue()); + ASSERT_TRUE(thirdHandle->IsUndefined()); JSHandle four(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("4")); - JSHandle four_handle(JSObject::GetProperty(thread_, exec_result, four).GetValue()); - JSHandle output_four = JSTaggedValue::ToString(thread_, four_handle); - ASSERT_EQ(output_four->Compare(*result_four), 0); + JSHandle fourHandle(JSObject::GetProperty(thread_, execResult, four).GetValue()); + JSHandle outputFour = JSTaggedValue::ToString(thread_, fourHandle); + ASSERT_EQ(outputFour->Compare(*resultFour), 0); JSHandle five(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("5")); - JSHandle five_handle(JSObject::GetProperty(thread_, exec_result, five).GetValue()); - ASSERT_TRUE(five_handle->IsUndefined()); + JSHandle fiveHandle(JSObject::GetProperty(thread_, execResult, five).GetValue()); + ASSERT_TRUE(fiveHandle->IsUndefined()); JSHandle six(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("6")); - JSHandle six_handle(JSObject::GetProperty(thread_, exec_result, six).GetValue()); - JSHandle output_six = JSTaggedValue::ToString(thread_, six_handle); - ASSERT_EQ(output_six->Compare(*result_six), 0); + JSHandle sixHandle(JSObject::GetProperty(thread_, execResult, six).GetValue()); + JSHandle outputSix = JSTaggedValue::ToString(thread_, sixHandle); + ASSERT_EQ(outputSix->Compare(*resultSix), 0); } TEST_F(BuiltinsRegExpTest, Match1) @@ -427,24 +427,24 @@ TEST_F(BuiltinsRegExpTest, Match1) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("The Quick Brown Fox Jumps Over The Lazy Dog"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke Match method - JSTaggedValue match_results = reg_exp::proto::Match(ecma_runtime_call_info.get()); + JSTaggedValue matchResults = reg_exp::proto::Match(ecmaRuntimeCallInfo.get()); - JSHandle match_result(thread_, match_results); + JSHandle matchResult(thread_, matchResults); JSHandle zero(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0")); - JSHandle result_zero = + JSHandle resultZero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Quick Brown Fox Jumps"); - JSHandle zero_handle(JSObject::GetProperty(thread_, match_result, zero).GetValue()); - JSHandle output_zero = JSTaggedValue::ToString(thread_, zero_handle); - ASSERT_EQ(output_zero->Compare(*result_zero), 0); + JSHandle zeroHandle(JSObject::GetProperty(thread_, matchResult, zero).GetValue()); + JSHandle outputZero = JSTaggedValue::ToString(thread_, zeroHandle); + ASSERT_EQ(outputZero->Compare(*resultZero), 0); } TEST_F(BuiltinsRegExpTest, Test1) @@ -456,17 +456,17 @@ TEST_F(BuiltinsRegExpTest, Test1) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("The Quick Brown Fox Jumps Over The Lazy Dog"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke Test method - JSTaggedValue test_result = reg_exp::proto::Test(ecma_runtime_call_info.get()); - ASSERT_EQ(test_result.GetRawData(), JSTaggedValue::True().GetRawData()); + JSTaggedValue testResult = reg_exp::proto::Test(ecmaRuntimeCallInfo.get()); + ASSERT_EQ(testResult.GetRawData(), JSTaggedValue::True().GetRawData()); } TEST_F(BuiltinsRegExpTest, Search1) @@ -478,17 +478,17 @@ TEST_F(BuiltinsRegExpTest, Search1) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("The Quick Brown Fox Jumps Over The Lazy Dog"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke Search method - JSTaggedValue search_result = reg_exp::proto::Search(ecma_runtime_call_info.get()); - ASSERT_EQ(search_result.GetRawData(), JSTaggedValue(4).GetRawData()); + JSTaggedValue searchResult = reg_exp::proto::Search(ecmaRuntimeCallInfo.get()); + ASSERT_EQ(searchResult.GetRawData(), JSTaggedValue(4).GetRawData()); } TEST_F(BuiltinsRegExpTest, Split1) @@ -499,24 +499,24 @@ TEST_F(BuiltinsRegExpTest, Split1) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke Split method - JSTaggedValue split_results = reg_exp::proto::Split(ecma_runtime_call_info.get()); - JSHandle split_result(thread_, split_results); + JSTaggedValue splitResults = reg_exp::proto::Split(ecmaRuntimeCallInfo.get()); + JSHandle splitResult(thread_, splitResults); JSHandle zero(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0")); - JSHandle zero_handle(JSObject::GetProperty(thread_, split_result, zero).GetValue()); - JSHandle output_zero = JSTaggedValue::ToString(thread_, zero_handle); + JSHandle zeroHandle(JSObject::GetProperty(thread_, splitResult, zero).GetValue()); + JSHandle outputZero = JSTaggedValue::ToString(thread_, zeroHandle); - ASSERT_EQ(output_zero->Compare(*input_string), 0); + ASSERT_EQ(outputZero->Compare(*inputString), 0); } TEST_F(BuiltinsRegExpTest, Split2) @@ -527,50 +527,50 @@ TEST_F(BuiltinsRegExpTest, Split2) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("a-b-c"); + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("a-b-c"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke Split method - JSTaggedValue split_results = reg_exp::proto::Split(ecma_runtime_call_info.get()); - JSHandle split_result(thread_, split_results); - JSHandle result_zero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("a"); - JSHandle result_one = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("b"); - JSHandle result_two = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("c"); + JSTaggedValue splitResults = reg_exp::proto::Split(ecmaRuntimeCallInfo.get()); + JSHandle splitResult(thread_, splitResults); + JSHandle resultZero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("a"); + JSHandle resultOne = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("b"); + JSHandle resultTwo = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("c"); JSHandle zero(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0")); - JSHandle zero_handle(JSObject::GetProperty(thread_, split_result, zero).GetValue()); - JSHandle output_zero = JSTaggedValue::ToString(thread_, zero_handle); - ASSERT_EQ(output_zero->Compare(*result_zero), 0); + JSHandle zeroHandle(JSObject::GetProperty(thread_, splitResult, zero).GetValue()); + JSHandle outputZero = JSTaggedValue::ToString(thread_, zeroHandle); + ASSERT_EQ(outputZero->Compare(*resultZero), 0); JSHandle first(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("1")); - JSHandle one_handle(JSObject::GetProperty(thread_, split_result, first).GetValue()); - JSHandle output_one = JSTaggedValue::ToString(thread_, one_handle); - ASSERT_EQ(output_one->Compare(*result_one), 0); + JSHandle oneHandle(JSObject::GetProperty(thread_, splitResult, first).GetValue()); + JSHandle outputOne = JSTaggedValue::ToString(thread_, oneHandle); + ASSERT_EQ(outputOne->Compare(*resultOne), 0); JSHandle second(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2")); - JSHandle two_handle(JSObject::GetProperty(thread_, split_result, second).GetValue()); - JSHandle output_two = JSTaggedValue::ToString(thread_, two_handle); - ASSERT_EQ(output_two->Compare(*result_two), 0); + JSHandle twoHandle(JSObject::GetProperty(thread_, splitResult, second).GetValue()); + JSHandle outputTwo = JSTaggedValue::ToString(thread_, twoHandle); + ASSERT_EQ(outputTwo->Compare(*resultTwo), 0); } TEST_F(BuiltinsRegExpTest, GetSpecies) { // invoke RegExpConstructor method JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle species_symbol = env->GetSpeciesSymbol(); - EXPECT_TRUE(!species_symbol.GetTaggedValue().IsUndefined()); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + EXPECT_TRUE(!speciesSymbol.GetTaggedValue().IsUndefined()); - JSHandle new_target(env->GetRegExpFunction()); + JSHandle newTarget(env->GetRegExpFunction()); JSTaggedValue value = - JSObject::GetProperty(thread_, JSHandle(new_target), species_symbol).GetValue().GetTaggedValue(); - EXPECT_EQ(value, new_target.GetTaggedValue()); + JSObject::GetProperty(thread_, JSHandle(newTarget), speciesSymbol).GetValue().GetTaggedValue(); + EXPECT_EQ(value, newTarget.GetTaggedValue()); } TEST_F(BuiltinsRegExpTest, Replace1) @@ -582,23 +582,23 @@ TEST_F(BuiltinsRegExpTest, Replace1) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = + JSHandle inputString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("The Quick Brown Fox Jumps Over The Lazy Dog"); - JSHandle replace_string = + JSHandle replaceString = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("$&a $` $\' $2 $01 $$1 $21 $32 a"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke replace method - JSTaggedValue results = reg_exp::proto::Replace(ecma_runtime_call_info.get()); - JSHandle replace_result(thread_, results); - JSHandle result_zero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString( + JSTaggedValue results = reg_exp::proto::Replace(ecmaRuntimeCallInfo.get()); + JSHandle replaceResult(thread_, results); + JSHandle resultZero = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString( "The Quick Brown Fox Jumpsa The Over The Lazy Dog Jumps Brown $1 Jumps1 $32 a Over The Lazy Dog"); - ASSERT_EQ(static_cast(replace_result->GetTaggedObject())->Compare(*result_zero), 0); + ASSERT_EQ(static_cast(replaceResult->GetTaggedObject())->Compare(*resultZero), 0); } TEST_F(BuiltinsRegExpTest, Replace2) @@ -610,20 +610,20 @@ TEST_F(BuiltinsRegExpTest, Replace2) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = factory->NewFromCanBeCompressString("abcde"); - JSHandle replace_string = factory->NewFromCanBeCompressString("[$01$02$03$04$00]"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_string.GetTaggedValue()); + JSHandle inputString = factory->NewFromCanBeCompressString("abcde"); + JSHandle replaceString = factory->NewFromCanBeCompressString("[$01$02$03$04$00]"); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke replace method - JSTaggedValue results = reg_exp::proto::Replace(ecma_runtime_call_info.get()); - JSHandle replace_result(thread_, results); - JSHandle result_zero = factory->NewFromCanBeCompressString("a[cd$04$00]e"); - ASSERT_EQ(static_cast(replace_result->GetTaggedObject())->Compare(*result_zero), 0); + JSTaggedValue results = reg_exp::proto::Replace(ecmaRuntimeCallInfo.get()); + JSHandle replaceResult(thread_, results); + JSHandle resultZero = factory->NewFromCanBeCompressString("a[cd$04$00]e"); + ASSERT_EQ(static_cast(replaceResult->GetTaggedObject())->Compare(*resultZero), 0); } TEST_F(BuiltinsRegExpTest, Replace3) @@ -635,34 +635,34 @@ TEST_F(BuiltinsRegExpTest, Replace3) JSTaggedValue result1 = CreateBuiltinsRegExpObjByPatternAndFlags(thread_, pattern1, flags1); JSHandle value(thread_, reinterpret_cast(result1.GetRawData())); - JSHandle input_string = factory->NewFromCanBeCompressString("abcde"); - JSHandle replace_string = factory->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, input_string.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_string.GetTaggedValue()); + JSHandle inputString = factory->NewFromCanBeCompressString("abcde"); + JSHandle replaceString = factory->NewFromCanBeCompressString(""); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // invoke replace method - JSTaggedValue results = reg_exp::proto::Replace(ecma_runtime_call_info.get()); - JSHandle replace_result(thread_, results); - JSHandle result_zero = factory->NewFromCanBeCompressString("de"); - ASSERT_EQ(static_cast(replace_result->GetTaggedObject())->Compare(*result_zero), 0); + JSTaggedValue results = reg_exp::proto::Replace(ecmaRuntimeCallInfo.get()); + JSHandle replaceResult(thread_, results); + JSHandle resultZero = factory->NewFromCanBeCompressString("de"); + ASSERT_EQ(static_cast(replaceResult->GetTaggedObject())->Compare(*resultZero), 0); } TEST_F(BuiltinsRegExpTest, RegExpParseCache) { - RegExpParserCache *reg_exp_parser_cache = thread_->GetEcmaVM()->GetRegExpParserCache(); + RegExpParserCache *regExpParserCache = thread_->GetEcmaVM()->GetRegExpParserCache(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle string1 = factory->NewFromString("abc"); JSHandle string2 = factory->NewFromString("abcd"); PandaVector vec {}; - reg_exp_parser_cache->SetCache(*string1, 0, JSTaggedValue::True(), 2, std::move(vec)); - ASSERT_TRUE(reg_exp_parser_cache->GetCache(*string1, 0, vec).first == JSTaggedValue::True()); - ASSERT_TRUE(reg_exp_parser_cache->GetCache(*string1, 0, vec).second == 2U); - ASSERT_TRUE(reg_exp_parser_cache->GetCache(*string1, RegExpParserCache::CACHE_SIZE, vec).first == + regExpParserCache->SetCache(*string1, 0, JSTaggedValue::True(), 2, std::move(vec)); + ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0, vec).first == JSTaggedValue::True()); + ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0, vec).second == 2U); + ASSERT_TRUE(regExpParserCache->GetCache(*string1, RegExpParserCache::CACHE_SIZE, vec).first == JSTaggedValue::Hole()); - ASSERT_TRUE(reg_exp_parser_cache->GetCache(*string2, 0, vec).first == JSTaggedValue::Hole()); + ASSERT_TRUE(regExpParserCache->GetCache(*string2, 0, vec).first == JSTaggedValue::Hole()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_set_test.cpp b/tests/runtime/builtins/builtins_set_test.cpp index d84ea226bcda7258e73b80dab0b7e8ee81ffe068..5d4c8caed223e7b7e3f596938bcff85385b72e79 100644 --- a/tests/runtime/builtins/builtins_set_test.cpp +++ b/tests/runtime/builtins/builtins_set_test.cpp @@ -68,9 +68,9 @@ public: if (key.IsUndefined()) { return JSTaggedValue::Undefined(); } - JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); - int length = js_array->GetArrayLength() + 1; - js_array->SetArrayLength(argv->GetThread(), length); + JSArray *jsArray = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); + int length = jsArray->GetArrayLength() + 1; + jsArray->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); } }; @@ -87,14 +87,14 @@ private: JSSet *CreateBuiltinsSet(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetSetFunction()); + JSHandle newTarget(env->GetSetFunction()); // 4 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*new_target), 4); - ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 4); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = set::SetConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = set::SetConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); return JSSet::Cast(reinterpret_cast(result.GetRawData())); @@ -104,16 +104,16 @@ TEST_F(BuiltinsSetTest, CreateAndGetSize) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetSetFunction()); + JSHandle newTarget(env->GetSetFunction()); JSHandle set(thread_, CreateBuiltinsSet(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(set.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = set::proto::GetSize(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = set::proto::GetSize(ecmaRuntimeCallInfo.get()); EXPECT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -124,14 +124,14 @@ TEST_F(BuiltinsSetTest, CreateAndGetSize) } JSHandle values = JSArray::CreateArrayFromList(thread_, array); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(set.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, values.GetTaggedValue()); - ecma_runtime_call_info1->SetNewTarget(new_target.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(set.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, values.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetNewTarget(newTarget.GetTaggedValue()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = set::SetConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = set::SetConstructor(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(JSSet::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); } @@ -144,53 +144,53 @@ TEST_F(BuiltinsSetTest, AddAndHas) JSHandle set(thread_, CreateBuiltinsSet(thread_)); JSHandle key(thread_, factory->NewFromCanBeCompressString("key").GetTaggedValue()); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(set.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = set::proto::Has(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = set::proto::Has(ecmaRuntimeCallInfo.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Add() - JSTaggedValue result2 = set::proto::Add(ecma_runtime_call_info.get()); + JSTaggedValue result2 = set::proto::Add(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result2.IsECMAObject()); - JSSet *js_set = JSSet::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(js_set->GetSize(), 1); + JSSet *jsSet = JSSet::Cast(reinterpret_cast(result2.GetRawData())); + EXPECT_EQ(jsSet->GetSize(), 1); // test Has() - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue(js_set)); - ecma_runtime_call_info1->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(jsSet)); + ecmaRuntimeCallInfo1->SetCallArg(0, key.GetTaggedValue()); { - [[maybe_unused]] auto prev_local = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = set::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = set::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } // test -0.0 - JSHandle negative_zero(thread_, JSTaggedValue(-0.0)); - JSHandle positive_zero(thread_, JSTaggedValue(+0.0)); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(JSTaggedValue(js_set)); - ecma_runtime_call_info2->SetCallArg(0, negative_zero.GetTaggedValue()); + JSHandle negativeZero(thread_, JSTaggedValue(-0.0)); + JSHandle positiveZero(thread_, JSTaggedValue(+0.0)); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(JSTaggedValue(jsSet)); + ecmaRuntimeCallInfo2->SetCallArg(0, negativeZero.GetTaggedValue()); { - [[maybe_unused]] auto prev_local = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - set::proto::Add(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + set::proto::Add(ecmaRuntimeCallInfo.get()); } - auto ecma_runtime_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info3->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info3->SetThis(JSTaggedValue(js_set)); - ecma_runtime_call_info3->SetCallArg(0, positive_zero.GetTaggedValue()); + auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetThis(JSTaggedValue(jsSet)); + ecmaRuntimeCallInfo3->SetCallArg(0, positiveZero.GetTaggedValue()); { - [[maybe_unused]] auto prev_local = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - JSTaggedValue result4 = set::proto::Has(ecma_runtime_call_info3.get()); + [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + JSTaggedValue result4 = set::proto::Has(ecmaRuntimeCallInfo3.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -202,38 +202,38 @@ TEST_F(BuiltinsSetTest, ForEach) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle set(thread_, CreateBuiltinsSet(thread_)); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char key_array[] = "key0"; + char keyArray[] = "key0"; for (int i = 0; i < 5; i++) { - key_array[3] = '1' + i; - JSHandle key(factory->NewFromCanBeCompressString(key_array)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(set.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + keyArray[3] = '1' + i; + JSHandle key(factory->NewFromCanBeCompressString(keyArray)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = set::proto::Add(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = set::proto::Add(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result1.IsECMAObject()); - JSSet *js_set = JSSet::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(js_set->GetSize(), i + 1); + JSSet *jsSet = JSSet::Cast(reinterpret_cast(result1.GetRawData())); + EXPECT_EQ(jsSet->GetSize(), i + 1); } // test foreach; - JSHandle js_array(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle jsArray(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(thread_->GetEcmaVM()->GetGlobalEnv(), reinterpret_cast(TestClass::TestFunc)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(set.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, func.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(set.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = set::proto::ForEach(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = set::proto::ForEach(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - EXPECT_EQ(js_array->GetArrayLength(), 5); + EXPECT_EQ(jsArray->GetArrayLength(), 5); } TEST_F(BuiltinsSetTest, DeleteAndRemove) @@ -244,54 +244,54 @@ TEST_F(BuiltinsSetTest, DeleteAndRemove) // add 40 keys // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char key_array[] = "key0"; + char keyArray[] = "key0"; // NOLINTNEXTLINE(readability-magic-numbers) for (int i = 0; i < 40; i++) { - key_array[3] = '1' + i; - JSHandle key(factory->NewFromCanBeCompressString(key_array)); + keyArray[3] = '1' + i; + JSHandle key(factory->NewFromCanBeCompressString(keyArray)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(set.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = set::proto::Add(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = set::proto::Add(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result1.IsECMAObject()); - JSSet *js_set = JSSet::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(js_set->GetSize(), i + 1); + JSSet *jsSet = JSSet::Cast(reinterpret_cast(result1.GetRawData())); + EXPECT_EQ(jsSet->GetSize(), i + 1); } // whether jsSet has delete key - key_array[3] = '1' + 8; - JSHandle delete_key(factory->NewFromCanBeCompressString(key_array)); + keyArray[3] = '1' + 8; + JSHandle deleteKey(factory->NewFromCanBeCompressString(keyArray)); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(set.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, delete_key.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(set.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, deleteKey.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = set::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = set::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = set::proto::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = set::proto::Delete(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = set::proto::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = set::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); - JSTaggedValue result5 = set::proto::GetSize(ecma_runtime_call_info1.get()); + JSTaggedValue result5 = set::proto::GetSize(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result5.GetRawData(), JSTaggedValue(39).GetRawData()); // clear - JSTaggedValue result6 = set::proto::Clear(ecma_runtime_call_info1.get()); + JSTaggedValue result6 = set::proto::Clear(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(set->GetSize(), 0); } @@ -301,24 +301,24 @@ TEST_F(BuiltinsSetTest, Species) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle set(thread_, CreateBuiltinsSet(thread_)); - JSHandle species_symbol = env->GetSpeciesSymbol(); - EXPECT_TRUE(!species_symbol->IsUndefined()); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + EXPECT_TRUE(!speciesSymbol->IsUndefined()); - JSHandle new_target(env->GetSetFunction()); + JSHandle newTarget(env->GetSetFunction()); JSTaggedValue value = - JSObject::GetProperty(thread_, JSHandle(new_target), species_symbol).GetValue().GetTaggedValue(); - JSHandle value_handle(thread_, value); - EXPECT_EQ(value, new_target.GetTaggedValue()); + JSObject::GetProperty(thread_, JSHandle(newTarget), speciesSymbol).GetValue().GetTaggedValue(); + JSHandle valueHandle(thread_, value); + EXPECT_EQ(value, newTarget.GetTaggedValue()); // to string tag - JSHandle to_string_tag_symbol = env->GetToStringTagSymbol(); - JSHandle string_tag(JSObject::GetProperty(thread_, set, to_string_tag_symbol).GetValue()); + JSHandle toStringTagSymbol = env->GetToStringTagSymbol(); + JSHandle stringTag(JSObject::GetProperty(thread_, set, toStringTagSymbol).GetValue()); JSHandle str = factory->NewFromCanBeCompressString("Set"); - EXPECT_TRUE(!string_tag.GetTaggedValue().IsUndefined()); - EXPECT_TRUE(EcmaString::StringsAreEqual(*str, *string_tag)); + EXPECT_TRUE(!stringTag.GetTaggedValue().IsUndefined()); + EXPECT_TRUE(EcmaString::StringsAreEqual(*str, *stringTag)); - JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread_, value_handle)); + JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread_, valueHandle)); EXPECT_EQ(JSHandle(set)->GetPrototype(thread_), constructor->GetFunctionPrototype()); JSHandle key1(factory->NewFromCanBeCompressString("add")); @@ -350,20 +350,20 @@ TEST_F(BuiltinsSetTest, GetIterator) { JSHandle set(thread_, CreateBuiltinsSet(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(set.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); // test Values() - JSTaggedValue result = set::proto::Values(ecma_runtime_call_info.get()); + JSTaggedValue result = set::proto::Values(ecmaRuntimeCallInfo.get()); JSHandle iter(thread_, result); EXPECT_TRUE(iter->IsJSSetIterator()); EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind().GetInt())); EXPECT_EQ(JSSet::Cast(set.GetTaggedValue().GetTaggedObject())->GetLinkedSet(), iter->GetIteratedSet()); // test entrys() - JSTaggedValue result2 = set::proto::Entries(ecma_runtime_call_info.get()); + JSTaggedValue result2 = set::proto::Entries(ecmaRuntimeCallInfo.get()); JSHandle iter2(thread_, result2); EXPECT_TRUE(iter2->IsJSSetIterator()); EXPECT_EQ(IterationKind::KEY_AND_VALUE, IterationKind(iter2->GetIterationKind().GetInt())); diff --git a/tests/runtime/builtins/builtins_string_test.cpp b/tests/runtime/builtins/builtins_string_test.cpp index c4092b53f3711417d1ee4674d055fd4c0159e8a5..39481001feda08f8e9efdb97199e19f02128a884 100644 --- a/tests/runtime/builtins/builtins_string_test.cpp +++ b/tests/runtime/builtins/builtins_string_test.cpp @@ -71,17 +71,17 @@ JSTaggedValue CreateRegExpObjByPatternAndFlags(JSThread *thread, const JSHandle< { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle regexp(env->GetRegExpFunction()); - JSHandle global_object(thread, env->GetGlobalObject()); + JSHandle globalObject(thread, env->GetGlobalObject()); // 8 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, regexp.GetTaggedValue(), 8); - ecma_runtime_call_info->SetFunction(regexp.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, pattern.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, flags.GetTaggedValue()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, regexp.GetTaggedValue(), 8); + ecmaRuntimeCallInfo->SetFunction(regexp.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, pattern.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, flags.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = reg_exp::RegExpConstructor(ecmaRuntimeCallInfo.get()); return result; } @@ -91,16 +91,16 @@ TEST_F(BuiltinsStringTest, StringConstructor1) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle string(env->GetStringFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); JSHandle string2 = factory->NewFromCanBeCompressString("ABC"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, string.GetTaggedValue(), 6); - ecma_runtime_call_info->SetFunction(string.GetTaggedValue()); - ecma_runtime_call_info->SetThis(global_object.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, string2.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, string.GetTaggedValue(), 6); + ecmaRuntimeCallInfo->SetFunction(string.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, string2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::StringConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::StringConstructor(ecmaRuntimeCallInfo.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSHandle ref(thread_, JSPrimitiveRef::Cast(value.GetTaggedObject())); @@ -118,21 +118,21 @@ TEST_F(BuiltinsStringTest, fromCharCode1) const double arg2 = 66; const double arg3 = 67; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(arg1)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(arg2)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(arg3)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(arg1)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(arg2)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(arg3)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::FromCharCode(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::FromCharCode(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); JSTaggedValue value(static_cast(result.GetRawData())); - JSHandle value_handle(thread_, JSTaggedValue(value.GetTaggedObject())); + JSHandle valueHandle(thread_, JSTaggedValue(value.GetTaggedObject())); JSTaggedValue test = factory->NewFromCanBeCompressString("ABC").GetTaggedValue(); ASSERT_EQ( - EcmaString::Cast(value_handle->GetTaggedObject())->Compare(reinterpret_cast(test.GetRawData())), + EcmaString::Cast(valueHandle->GetTaggedObject())->Compare(reinterpret_cast(test.GetRawData())), 0); } @@ -144,91 +144,91 @@ TEST_F(BuiltinsStringTest, fromCodePoint1) const double arg2 = 66; const double arg3 = 67; - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(arg1)); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(arg2)); - ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(arg3)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(arg1)); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(arg2)); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(arg3)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::FromCodePoint(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::FromCodePoint(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("ABC").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "abcabcabc".charAt(5) TEST_F(BuiltinsStringTest, charAt1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_val = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisVal = factory->NewFromCanBeCompressString("abcabcabc"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::CharAt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::CharAt(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("c").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "一二三四".charAt(2) TEST_F(BuiltinsStringTest, charAt2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_val = factory->NewFromString("一二三四"); + JSHandle thisVal = factory->NewFromString("一二三四"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::CharAt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::CharAt(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("三").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "abcabcabc".charAt(-1) TEST_F(BuiltinsStringTest, charAt3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_val = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisVal = factory->NewFromCanBeCompressString("abcabcabc"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::CharAt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::CharAt(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->GetEmptyString().GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "ABC".charCodeAt(0) TEST_F(BuiltinsStringTest, charCodeAt1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_val = factory->NewFromCanBeCompressString("ABC"); + JSHandle thisVal = factory->NewFromCanBeCompressString("ABC"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::CharCodeAt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::CharCodeAt(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(65).GetRawData()); } @@ -237,15 +237,15 @@ TEST_F(BuiltinsStringTest, charCodeAt1) TEST_F(BuiltinsStringTest, charCodeAt2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_val = factory->NewFromCanBeCompressString("ABC"); + JSHandle thisVal = factory->NewFromCanBeCompressString("ABC"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::CharCodeAt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::CharCodeAt(ecmaRuntimeCallInfo.get()); JSTaggedValue test = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), test.GetRawData()); @@ -255,15 +255,15 @@ TEST_F(BuiltinsStringTest, charCodeAt2) TEST_F(BuiltinsStringTest, codePointAt1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_val = factory->NewFromCanBeCompressString("ABC"); + JSHandle thisVal = factory->NewFromCanBeCompressString("ABC"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::CodePointAt(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::CodePointAt(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(66).GetRawData()); } @@ -272,40 +272,40 @@ TEST_F(BuiltinsStringTest, codePointAt1) TEST_F(BuiltinsStringTest, concat1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("a"); + JSHandle thisStr = factory->NewFromCanBeCompressString("a"); JSHandle val1 = factory->NewFromCanBeCompressString("b"); JSHandle val2 = factory->NewFromCanBeCompressString("c"); JSHandle val3 = factory->NewFromCanBeCompressString("d"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val1.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, val2.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(2, val3.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val1.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, val2.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, val3.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Concat(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Concat(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("abcd").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "abcabcabc".indexof('b') TEST_F(BuiltinsStringTest, indexof1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); JSHandle val = factory->NewFromCanBeCompressString("b"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::IndexOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::IndexOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -314,17 +314,17 @@ TEST_F(BuiltinsStringTest, indexof1) TEST_F(BuiltinsStringTest, indexof2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); JSHandle val = factory->NewFromCanBeCompressString("b"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::IndexOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::IndexOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(4).GetRawData()); } @@ -333,16 +333,16 @@ TEST_F(BuiltinsStringTest, indexof2) TEST_F(BuiltinsStringTest, indexof3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); JSHandle val = factory->NewFromCanBeCompressString("d"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::IndexOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::IndexOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -351,16 +351,16 @@ TEST_F(BuiltinsStringTest, indexof3) TEST_F(BuiltinsStringTest, lastIndexOf1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); JSHandle val = factory->NewFromCanBeCompressString("b"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::LastIndexOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::LastIndexOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(7).GetRawData()); } @@ -368,17 +368,17 @@ TEST_F(BuiltinsStringTest, lastIndexOf1) TEST_F(BuiltinsStringTest, lastIndexOf2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); JSHandle val = factory->NewFromCanBeCompressString("b"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::LastIndexOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::LastIndexOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -387,16 +387,16 @@ TEST_F(BuiltinsStringTest, lastIndexOf2) TEST_F(BuiltinsStringTest, lastIndexOf3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); JSHandle val = factory->NewFromCanBeCompressString("d"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::LastIndexOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::LastIndexOf(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -405,16 +405,16 @@ TEST_F(BuiltinsStringTest, lastIndexOf3) TEST_F(BuiltinsStringTest, Includes2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); JSHandle val = factory->NewFromCanBeCompressString("b"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Includes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Includes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -423,17 +423,17 @@ TEST_F(BuiltinsStringTest, Includes2) TEST_F(BuiltinsStringTest, Includes3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abccccccc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abccccccc"); JSHandle val = factory->NewFromCanBeCompressString("b"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(2))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Includes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Includes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -442,16 +442,16 @@ TEST_F(BuiltinsStringTest, Includes3) TEST_F(BuiltinsStringTest, Includes4) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("一二三四"); + JSHandle thisStr = factory->NewFromString("一二三四"); JSHandle val = factory->NewFromString("二"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Includes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Includes(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -460,16 +460,16 @@ TEST_F(BuiltinsStringTest, Includes4) TEST_F(BuiltinsStringTest, startsWith1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); + JSHandle thisStr = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); JSHandle val = factory->NewFromCanBeCompressString("To be"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::StartsWith(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::StartsWith(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -478,16 +478,16 @@ TEST_F(BuiltinsStringTest, startsWith1) TEST_F(BuiltinsStringTest, startsWith2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); + JSHandle thisStr = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); JSHandle val = factory->NewFromCanBeCompressString("not to be"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::StartsWith(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::StartsWith(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -496,17 +496,17 @@ TEST_F(BuiltinsStringTest, startsWith2) TEST_F(BuiltinsStringTest, startsWith3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); + JSHandle thisStr = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); JSHandle val = factory->NewFromCanBeCompressString("not to be"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(10))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::StartsWith(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::StartsWith(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -515,16 +515,16 @@ TEST_F(BuiltinsStringTest, startsWith3) TEST_F(BuiltinsStringTest, endsWith1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); + JSHandle thisStr = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); JSHandle val = factory->NewFromCanBeCompressString("question."); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::EndsWith(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::EndsWith(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -533,16 +533,16 @@ TEST_F(BuiltinsStringTest, endsWith1) TEST_F(BuiltinsStringTest, endsWith2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); + JSHandle thisStr = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); JSHandle val = factory->NewFromCanBeCompressString("to be"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::EndsWith(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::EndsWith(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -551,17 +551,17 @@ TEST_F(BuiltinsStringTest, endsWith2) TEST_F(BuiltinsStringTest, endsWith3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); + JSHandle thisStr = factory->NewFromCanBeCompressString("To be, or not to be, that is the question."); JSHandle val = factory->NewFromCanBeCompressString("to be"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(19))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(19))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::EndsWith(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::EndsWith(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -571,70 +571,70 @@ TEST_F(BuiltinsStringTest, toLocaleLowerCase2) { ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("有ABC"); + JSHandle thisStr = factory->NewFromString("有ABC"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ToLocaleLowerCase(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ToLocaleLowerCase(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("有abc").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "ABC".toLowerCase() TEST_F(BuiltinsStringTest, toLowerCase1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("ABC"); + JSHandle thisStr = factory->NewFromCanBeCompressString("ABC"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ToLowerCase(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ToLowerCase(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSHandle test = factory->NewFromCanBeCompressString("abc"); - ASSERT_TRUE(JSTaggedValue::SameValue(result_handle.GetTaggedValue(), test.GetTaggedValue())); + ASSERT_TRUE(JSTaggedValue::SameValue(resultHandle.GetTaggedValue(), test.GetTaggedValue())); } // "abc".toUpperCase() TEST_F(BuiltinsStringTest, toUpperCase1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abc"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ToUpperCase(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ToUpperCase(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("ABC").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "abc".localecompare('b') TEST_F(BuiltinsStringTest, localecompare1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abc"); JSHandle val = factory->NewFromCanBeCompressString("b"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::LocaleCompare(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::LocaleCompare(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -643,16 +643,16 @@ TEST_F(BuiltinsStringTest, localecompare1) TEST_F(BuiltinsStringTest, localecompare2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abc"); JSHandle val = factory->NewFromCanBeCompressString("abc"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::LocaleCompare(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::LocaleCompare(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -661,16 +661,16 @@ TEST_F(BuiltinsStringTest, localecompare2) TEST_F(BuiltinsStringTest, localecompare3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abc"); JSHandle val = factory->NewFromCanBeCompressString("aa"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::LocaleCompare(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::LocaleCompare(ecmaRuntimeCallInfo.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -680,20 +680,20 @@ TEST_F(BuiltinsStringTest, normalize1) { ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("abc"); + JSHandle thisStr = factory->NewFromString("abc"); JSHandle val = factory->NewFromString("NFC"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Normalize(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Normalize(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("abc").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "hello".padEnd(10) @@ -702,19 +702,19 @@ TEST_F(BuiltinsStringTest, padEnd1) ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("hello"); + JSHandle thisStr = factory->NewFromString("hello"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::PadEnd(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::PadEnd(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("hello ").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "hello".padEnd(11, world) @@ -723,21 +723,21 @@ TEST_F(BuiltinsStringTest, padEnd2) ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("hello"); - JSHandle fill_string = factory->NewFromString("world"); + JSHandle thisStr = factory->NewFromString("hello"); + JSHandle fillString = factory->NewFromString("world"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(11))); - ecma_runtime_call_info->SetCallArg(1, fill_string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(11))); + ecmaRuntimeCallInfo->SetCallArg(1, fillString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::PadEnd(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::PadEnd(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("helloworldw").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "world".padStart(10) @@ -746,19 +746,19 @@ TEST_F(BuiltinsStringTest, padStart1) ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("world"); + JSHandle thisStr = factory->NewFromString("world"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::PadStart(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::PadStart(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString(" world").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "world".padStart(11, "hello") @@ -767,160 +767,160 @@ TEST_F(BuiltinsStringTest, padStart2) ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("world"); - JSHandle fill_string = factory->NewFromString("hello"); + JSHandle thisStr = factory->NewFromString("world"); + JSHandle fillString = factory->NewFromString("hello"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(11))); - ecma_runtime_call_info->SetCallArg(1, fill_string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(11))); + ecmaRuntimeCallInfo->SetCallArg(1, fillString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::PadStart(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::PadStart(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("hellohworld").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // "abc".repeat(5) TEST_F(BuiltinsStringTest, repeat1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abc"); + JSHandle thisStr = factory->NewFromCanBeCompressString("abc"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Repeat(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Repeat(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("abcabcabcabcabc").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // 'The morning is upon us.'.slice(4, -2) TEST_F(BuiltinsStringTest, slice1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("The morning is upon us."); + JSHandle thisStr = factory->NewFromCanBeCompressString("The morning is upon us."); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(4))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-2))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(4))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Slice(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Slice(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("morning is upon u").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // 'The morning is upon us.'.slice(12) TEST_F(BuiltinsStringTest, slice2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("The morning is upon us."); + JSHandle thisStr = factory->NewFromCanBeCompressString("The morning is upon us."); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(12))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(12))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Slice(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Slice(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("is upon us.").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // 'Mozilla'.substring(3, -3) TEST_F(BuiltinsStringTest, substring1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("Mozilla"); + JSHandle thisStr = factory->NewFromCanBeCompressString("Mozilla"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(3))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-3))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(3))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Substring(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Substring(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("Moz").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // 'Mozilla'.substring(7, 4) TEST_F(BuiltinsStringTest, substring2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("Mozilla"); + JSHandle thisStr = factory->NewFromCanBeCompressString("Mozilla"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(7))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(4))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(7))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(4))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Substring(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Substring(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("lla").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // " Hello world! ".trim() TEST_F(BuiltinsStringTest, trim1) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString(" Hello world! "); + JSHandle thisStr = factory->NewFromCanBeCompressString(" Hello world! "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Trim(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Trim(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("Hello world!").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } TEST_F(BuiltinsStringTest, trim2) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString(" Hello world! "); - JSHandle string_object(env->GetStringFunction()); - JSHandle value(thread_, JSTaggedValue(this_str.GetTaggedValue().GetTaggedObject())); - JSHandle str = factory->NewJSPrimitiveRef(string_object, value); + JSHandle thisStr = factory->NewFromCanBeCompressString(" Hello world! "); + JSHandle stringObject(env->GetStringFunction()); + JSHandle value(thread_, JSTaggedValue(thisStr.GetTaggedValue().GetTaggedObject())); + JSHandle str = factory->NewJSPrimitiveRef(stringObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Trim(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Trim(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("Hello world!").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // " Hello world! ".trimEnd() @@ -929,43 +929,43 @@ TEST_F(BuiltinsStringTest, trimEnd1) ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString(" Hello world! "); + JSHandle thisStr = factory->NewFromString(" Hello world! "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::TrimEnd(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::TrimEnd(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString(" Hello world!").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // new String(" Hello world! ").trimEnd() TEST_F(BuiltinsStringTest, trimEnd2) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString(" Hello world! "); - JSHandle string_object(env->GetStringFunction()); - JSHandle value(thread_, JSTaggedValue(this_str.GetTaggedValue().GetHeapObject())); - JSHandle str = factory->NewJSPrimitiveRef(string_object, value); + JSHandle thisStr = factory->NewFromString(" Hello world! "); + JSHandle stringObject(env->GetStringFunction()); + JSHandle value(thread_, JSTaggedValue(thisStr.GetTaggedValue().GetHeapObject())); + JSHandle str = factory->NewJSPrimitiveRef(stringObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::TrimEnd(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::TrimEnd(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString(" Hello world!").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // " Hello world! ".trimStart() @@ -974,97 +974,97 @@ TEST_F(BuiltinsStringTest, trimStart1) ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString(" Hello world! "); + JSHandle thisStr = factory->NewFromString(" Hello world! "); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::TrimStart(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::TrimStart(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("Hello world! ").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // new String(" Hello world! ").trimStart() TEST_F(BuiltinsStringTest, trimStart2) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString(" Hello world! "); - JSHandle string_object(env->GetStringFunction()); - JSHandle value(thread_, JSTaggedValue(this_str.GetTaggedValue().GetHeapObject())); - JSHandle str = factory->NewJSPrimitiveRef(string_object, value); + JSHandle thisStr = factory->NewFromString(" Hello world! "); + JSHandle stringObject(env->GetStringFunction()); + JSHandle value(thread_, JSTaggedValue(thisStr.GetTaggedValue().GetHeapObject())); + JSHandle str = factory->NewJSPrimitiveRef(stringObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::TrimStart(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::TrimStart(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("Hello world! ").GetTaggedValue(); - ASSERT_EQ(result_handle->Compare(reinterpret_cast(test.GetRawData())), 0); + ASSERT_EQ(resultHandle->Compare(reinterpret_cast(test.GetRawData())), 0); } // new String("abcabcabc").toString(); TEST_F(BuiltinsStringTest, ToString) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); - JSHandle string_object(env->GetStringFunction()); - JSHandle value(thread_, JSTaggedValue(this_str.GetTaggedValue().GetTaggedObject())); - JSHandle str = factory->NewJSPrimitiveRef(string_object, value); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle stringObject(env->GetStringFunction()); + JSHandle value(thread_, JSTaggedValue(thisStr.GetTaggedValue().GetTaggedObject())); + JSHandle str = factory->NewJSPrimitiveRef(stringObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ToString(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ToString(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); - auto test = JSTaggedValue(*this_str); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); + auto test = JSTaggedValue(*thisStr); ASSERT_EQ(result.GetRawData(), test.GetRawData()); } TEST_F(BuiltinsStringTest, ValueOf) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("abcabcabc"); - JSHandle string_object(env->GetStringFunction()); - JSHandle value(thread_, JSTaggedValue(this_str.GetTaggedValue().GetTaggedObject())); - JSHandle str = factory->NewJSPrimitiveRef(string_object, value); + JSHandle thisStr = factory->NewFromCanBeCompressString("abcabcabc"); + JSHandle stringObject(env->GetStringFunction()); + JSHandle value(thread_, JSTaggedValue(thisStr.GetTaggedValue().GetTaggedObject())); + JSHandle str = factory->NewJSPrimitiveRef(stringObject, value); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ValueOf(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); - auto test = JSTaggedValue(*this_str); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); + auto test = JSTaggedValue(*thisStr); ASSERT_EQ(result.GetRawData(), test.GetRawData()); } static inline JSFunction *BuiltinsStringTestCreate(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - return global_env->GetObjectFunction().GetObject(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + return globalEnv->GetObjectFunction().GetObject(); } TEST_F(BuiltinsStringTest, Raw) @@ -1073,8 +1073,8 @@ TEST_F(BuiltinsStringTest, Raw) JSHandle foo(factory->NewFromCanBeCompressString("foo")); JSHandle bar(factory->NewFromCanBeCompressString("bar")); JSHandle baz(factory->NewFromCanBeCompressString("baz")); - JSHandle raw_array = JSHandle::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); - JSHandle obj(raw_array); + JSHandle rawArray = JSHandle::Cast(JSArray::ArrayCreate(thread_, JSTaggedNumber(0))); + JSHandle obj(rawArray); JSHandle key0(thread_, JSTaggedValue(0)); PropertyDescriptor desc0(thread_, foo); JSArray::DefineOwnProperty(thread_, obj, key0, desc0); @@ -1086,23 +1086,23 @@ TEST_F(BuiltinsStringTest, Raw) JSArray::DefineOwnProperty(thread_, obj, key2, desc2); JSHandle constructor(thread_, BuiltinsStringTestCreate(thread_)); - JSHandle template_string( + JSHandle templateString( factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); - JSHandle raw_key(factory->NewFromCanBeCompressString("raw")); - JSObject::SetProperty(thread_, template_string, raw_key, raw_array); + JSHandle rawKey(factory->NewFromCanBeCompressString("raw")); + JSObject::SetProperty(thread_, templateString, rawKey, rawArray); JSHandle test = factory->NewFromCanBeCompressString("foo5barJavaScriptbaz"); JSHandle javascript = factory->NewFromCanBeCompressString("JavaScript"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(template_string.GetObject())); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info->SetCallArg(2, javascript.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(templateString.GetObject())); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo->SetCallArg(2, javascript.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::Raw(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::Raw(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *test)); } @@ -1110,187 +1110,187 @@ TEST_F(BuiltinsStringTest, Raw) TEST_F(BuiltinsStringTest, Replace) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("Twas the night before Xmas..."); - JSHandle search_str = factory->NewFromCanBeCompressString("Xmas"); - JSHandle replace_str = factory->NewFromCanBeCompressString("Christmas"); + JSHandle thisStr = factory->NewFromCanBeCompressString("Twas the night before Xmas..."); + JSHandle searchStr = factory->NewFromCanBeCompressString("Xmas"); + JSHandle replaceStr = factory->NewFromCanBeCompressString("Christmas"); JSHandle expected = factory->NewFromCanBeCompressString("Twas the night before Christmas..."); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Replace(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); - JSHandle replace_str1 = factory->NewFromCanBeCompressString("abc$$"); + JSHandle replaceStr1 = factory->NewFromCanBeCompressString("abc$$"); JSHandle expected1 = factory->NewFromCanBeCompressString("Twas the night before abc$..."); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, replace_str1.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, replaceStr1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = string::proto::Replace(ecma_runtime_call_info1.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = string::proto::Replace(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_string1(thread_, result1); + JSHandle resultString1(thread_, result1); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result_string1, *expected1)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*resultString1, *expected1)); - JSHandle replace_str2 = factory->NewFromCanBeCompressString("abc$$dd"); + JSHandle replaceStr2 = factory->NewFromCanBeCompressString("abc$$dd"); JSHandle expected2 = factory->NewFromCanBeCompressString("Twas the night before abc$dd..."); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(1, replace_str2.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(1, replaceStr2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = string::proto::Replace(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = string::proto::Replace(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_string2(thread_, result2); + JSHandle resultString2(thread_, result2); ASSERT_TRUE(result2.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result_string2, *expected2)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*resultString2, *expected2)); - JSHandle replace_str3 = factory->NewFromCanBeCompressString("abc$&dd"); + JSHandle replaceStr3 = factory->NewFromCanBeCompressString("abc$&dd"); JSHandle expected3 = factory->NewFromCanBeCompressString("Twas the night before abcXmasdd..."); - auto ecma_runtime_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info3->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info3->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info3->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info3->SetCallArg(1, replace_str3.GetTaggedValue()); + auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(1, replaceStr3.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - JSTaggedValue result3 = string::proto::Replace(ecma_runtime_call_info3.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + JSTaggedValue result3 = string::proto::Replace(ecmaRuntimeCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_string3(thread_, result3); + JSHandle resultString3(thread_, result3); ASSERT_TRUE(result3.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result_string3, *expected3)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*resultString3, *expected3)); - JSHandle replace_str4 = factory->NewFromCanBeCompressString("abc$`dd"); + JSHandle replaceStr4 = factory->NewFromCanBeCompressString("abc$`dd"); JSHandle expected4 = factory->NewFromCanBeCompressString("Twas the night before abcTwas the night before dd..."); - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info4->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info4->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(1, replace_str4.GetTaggedValue()); + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo4->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo4->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(1, replaceStr4.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = string::proto::Replace(ecma_runtime_call_info4.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + JSTaggedValue result4 = string::proto::Replace(ecmaRuntimeCallInfo4.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_string4(thread_, result4); + JSHandle resultString4(thread_, result4); ASSERT_TRUE(result4.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result_string4, *expected4)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*resultString4, *expected4)); } TEST_F(BuiltinsStringTest, Replace2) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("Twas the night before Xmas..."); - JSHandle search_str = factory->NewFromCanBeCompressString("Xmas"); - JSHandle replace_str = factory->NewFromCanBeCompressString("abc$\'dd"); + JSHandle thisStr = factory->NewFromCanBeCompressString("Twas the night before Xmas..."); + JSHandle searchStr = factory->NewFromCanBeCompressString("Xmas"); + JSHandle replaceStr = factory->NewFromCanBeCompressString("abc$\'dd"); JSHandle expected = factory->NewFromCanBeCompressString("Twas the night before abc...dd..."); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Replace(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); - JSHandle replace_str2 = factory->NewFromCanBeCompressString("abc$`dd$\'$ff"); + JSHandle replaceStr2 = factory->NewFromCanBeCompressString("abc$`dd$\'$ff"); JSHandle expected2 = factory->NewFromCanBeCompressString("Twas the night before abcTwas the night before dd...$ff..."); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info2->SetCallArg(1, replace_str2.GetTaggedValue()); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo2->SetCallArg(1, replaceStr2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = string::proto::Replace(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue result2 = string::proto::Replace(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_string2(thread_, result2); + JSHandle resultString2(thread_, result2); ASSERT_TRUE(result2.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result_string2, *expected2)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*resultString2, *expected2)); - JSHandle replace_str3 = factory->NewFromCanBeCompressString("abc$`dd$\'$"); + JSHandle replaceStr3 = factory->NewFromCanBeCompressString("abc$`dd$\'$"); JSHandle expected3 = factory->NewFromCanBeCompressString("Twas the night before abcTwas the night before dd...$..."); - auto ecma_runtime_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info3->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info3->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info3->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info3->SetCallArg(1, replace_str3.GetTaggedValue()); + auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(1, replaceStr3.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info3.get()); - JSTaggedValue result3 = string::proto::Replace(ecma_runtime_call_info3.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo3.get()); + JSTaggedValue result3 = string::proto::Replace(ecmaRuntimeCallInfo3.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_string3(thread_, result3); + JSHandle resultString3(thread_, result3); ASSERT_TRUE(result3.IsString()); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result_string3, *expected3)); + ASSERT_TRUE(EcmaString::StringsAreEqual(*resultString3, *expected3)); - JSHandle replace_str4 = factory->NewFromCanBeCompressString("abc$`dd$$"); + JSHandle replaceStr4 = factory->NewFromCanBeCompressString("abc$`dd$$"); JSHandle expected4 = factory->NewFromCanBeCompressString("Twas the night before abcTwas the night before dd$..."); - auto ecma_runtime_call_info4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info4->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info4->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info4->SetCallArg(1, replace_str4.GetTaggedValue()); + auto ecmaRuntimeCallInfo4 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo4->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo4->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo4->SetCallArg(1, replaceStr4.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = string::proto::Replace(ecma_runtime_call_info4.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo4.get()); + JSTaggedValue result4 = string::proto::Replace(ecmaRuntimeCallInfo4.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result4.IsString()); - JSHandle result_string4(thread_, result4); - ASSERT_TRUE(EcmaString::StringsAreEqual(*result_string4, *expected4)); + JSHandle resultString4(thread_, result4); + ASSERT_TRUE(EcmaString::StringsAreEqual(*resultString4, *expected4)); } TEST_F(BuiltinsStringTest, Replace3) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("Twas the night before Xmas..."); - JSHandle search_str = factory->NewFromCanBeCompressString("Xmas"); - JSHandle replace_str = factory->NewFromCanBeCompressString("$&a $` $\' $2 $01 $$1 $21 $32 a"); + JSHandle thisStr = factory->NewFromCanBeCompressString("Twas the night before Xmas..."); + JSHandle searchStr = factory->NewFromCanBeCompressString("Xmas"); + JSHandle replaceStr = factory->NewFromCanBeCompressString("$&a $` $\' $2 $01 $$1 $21 $32 a"); JSHandle expected = factory->NewFromCanBeCompressString( "Twas the night before Xmasa Twas the night before ... $2 $01 $1 $21 $32 a..."); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Replace(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1303,24 +1303,24 @@ TEST_F(BuiltinsStringTest, Replace4) thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("quick\\s(brown).+?(jumps)"); JSHandle flags1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("iug"); JSTaggedValue result1 = CreateRegExpObjByPatternAndFlags(thread_, pattern1, flags1); - JSHandle search_str(thread_, reinterpret_cast(result1.GetRawData())); + JSHandle searchStr(thread_, reinterpret_cast(result1.GetRawData())); JSHandle expected = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString( "The Quick Brown Fox Jumpsa The Over The Lazy Dog Jumps Brown $1 Jumps1 $32 a Over The Lazy Dog"); // make dyn_runtime_call_info2 - JSHandle this_str = + JSHandle thisStr = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("The Quick Brown Fox Jumps Over The Lazy Dog"); - JSHandle replace_str = + JSHandle replaceStr = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("$&a $` $\' $2 $01 $$1 $21 $32 a"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Replace(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1330,19 +1330,19 @@ TEST_F(BuiltinsStringTest, ReplaceAll1) { ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("The Quick Brown Fox Jumps Over The Lazy Dog"); - JSHandle search_str = factory->NewFromString("o"); - JSHandle replace_str = factory->NewFromString("a"); + JSHandle thisStr = factory->NewFromString("The Quick Brown Fox Jumps Over The Lazy Dog"); + JSHandle searchStr = factory->NewFromString("o"); + JSHandle replaceStr = factory->NewFromString("a"); JSHandle expected = factory->NewFromString("The Quick Brawn Fax Jumps Over The Lazy Dag"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ReplaceAll(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ReplaceAll(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1352,19 +1352,19 @@ TEST_F(BuiltinsStringTest, ReplaceAll2) { ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("xxx"); - JSHandle search_str = factory->NewFromString(""); - JSHandle replace_str = factory->NewFromString("_"); + JSHandle thisStr = factory->NewFromString("xxx"); + JSHandle searchStr = factory->NewFromString(""); + JSHandle replaceStr = factory->NewFromString("_"); JSHandle expected = factory->NewFromString("_x_x_x_"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ReplaceAll(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ReplaceAll(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1374,19 +1374,19 @@ TEST_F(BuiltinsStringTest, ReplaceAll3) { ASSERT_NE(thread_, nullptr); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromString("xxx"); - JSHandle search_str = factory->NewFromString("x"); - JSHandle replace_str = factory->NewFromString(""); + JSHandle thisStr = factory->NewFromString("xxx"); + JSHandle searchStr = factory->NewFromString("x"); + JSHandle replaceStr = factory->NewFromString(""); JSHandle expected = factory->NewFromString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, search_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::ReplaceAll(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::ReplaceAll(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1396,32 +1396,32 @@ TEST_F(BuiltinsStringTest, Split) { // invoke RegExpConstructor method ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("Hello World. How are you doing?"); - JSHandle separator_str = factory->NewFromCanBeCompressString(" "); + JSHandle thisStr = factory->NewFromCanBeCompressString("Hello World. How are you doing?"); + JSHandle separatorStr = factory->NewFromCanBeCompressString(" "); JSHandle limit(thread_, JSTaggedValue(3)); JSHandle expected1 = factory->NewFromCanBeCompressString("Hello"); JSHandle expected2 = factory->NewFromCanBeCompressString("World."); JSHandle expected3 = factory->NewFromCanBeCompressString("How"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, separator_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, separatorStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Split(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Split(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_array(thread_, reinterpret_cast(result.GetRawData())); - ASSERT_TRUE(result_array->IsJSArray()); - JSHandle result_obj(result_array); + JSHandle resultArray(thread_, reinterpret_cast(result.GetRawData())); + ASSERT_TRUE(resultArray->IsJSArray()); + JSHandle resultObj(resultArray); JSHandle string1( - JSObject::GetProperty(thread_, result_obj, JSHandle(thread_, JSTaggedValue(0))).GetValue()); + JSObject::GetProperty(thread_, resultObj, JSHandle(thread_, JSTaggedValue(0))).GetValue()); JSHandle string2( - JSObject::GetProperty(thread_, result_obj, JSHandle(thread_, JSTaggedValue(1))).GetValue()); + JSObject::GetProperty(thread_, resultObj, JSHandle(thread_, JSTaggedValue(1))).GetValue()); JSHandle string3( - JSObject::GetProperty(thread_, result_obj, JSHandle(thread_, JSTaggedValue(2))).GetValue()); + JSObject::GetProperty(thread_, resultObj, JSHandle(thread_, JSTaggedValue(2))).GetValue()); ASSERT_TRUE(EcmaString::StringsAreEqual(*string1, *expected1)); ASSERT_TRUE(EcmaString::StringsAreEqual(*string2, *expected2)); ASSERT_TRUE(EcmaString::StringsAreEqual(*string3, *expected3)); @@ -1431,36 +1431,36 @@ TEST_F(BuiltinsStringTest, Split2) { // invoke RegExpConstructor method ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle this_str = factory->NewFromCanBeCompressString("a-b-c"); + JSHandle thisStr = factory->NewFromCanBeCompressString("a-b-c"); JSHandle pattern1 = factory->NewFromCanBeCompressString("-"); JSHandle flags1 = factory->NewFromCanBeCompressString("iug"); JSTaggedValue result1 = CreateRegExpObjByPatternAndFlags(thread_, pattern1, flags1); - JSHandle separator_obj(thread_, result1); + JSHandle separatorObj(thread_, result1); JSHandle limit(thread_, JSTaggedValue(3)); JSHandle expected1 = factory->NewFromCanBeCompressString("a"); JSHandle expected2 = factory->NewFromCanBeCompressString("b"); JSHandle expected3 = factory->NewFromCanBeCompressString("c"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, separator_obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, separatorObj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = string::proto::Split(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = string::proto::Split(ecmaRuntimeCallInfo.get()); ASSERT_TRUE(result.IsECMAObject()); - JSHandle result_array(thread_, result); - ASSERT_TRUE(result_array->IsJSArray()); - JSHandle result_obj(result_array); + JSHandle resultArray(thread_, result); + ASSERT_TRUE(resultArray->IsJSArray()); + JSHandle resultObj(resultArray); JSHandle string1( - JSObject::GetProperty(thread_, result_obj, JSHandle(thread_, JSTaggedValue(0))).GetValue()); + JSObject::GetProperty(thread_, resultObj, JSHandle(thread_, JSTaggedValue(0))).GetValue()); JSHandle string2( - JSObject::GetProperty(thread_, result_obj, JSHandle(thread_, JSTaggedValue(1))).GetValue()); + JSObject::GetProperty(thread_, resultObj, JSHandle(thread_, JSTaggedValue(1))).GetValue()); JSHandle string3( - JSObject::GetProperty(thread_, result_obj, JSHandle(thread_, JSTaggedValue(2))).GetValue()); + JSObject::GetProperty(thread_, resultObj, JSHandle(thread_, JSTaggedValue(2))).GetValue()); ASSERT_TRUE(EcmaString::StringsAreEqual(*string1, *expected1)); ASSERT_TRUE(EcmaString::StringsAreEqual(*string2, *expected2)); ASSERT_TRUE(EcmaString::StringsAreEqual(*string3, *expected3)); diff --git a/tests/runtime/builtins/builtins_symbol_test.cpp b/tests/runtime/builtins/builtins_symbol_test.cpp index 3bf4233c492a7d6adc880fdb6f875816127f3fff..ad3209fd3707bcc537acf0a46b0ceedb28505d67 100644 --- a/tests/runtime/builtins/builtins_symbol_test.cpp +++ b/tests/runtime/builtins/builtins_symbol_test.cpp @@ -71,133 +71,133 @@ private: // new Symbol.toString() TEST_F(BuiltinsSymbolTest, SymbolNoParameterToString) { - auto ecma_vm = thread_->GetEcmaVM(); + auto ecmaVm = thread_->GetEcmaVM(); - JSHandle symbol = ecma_vm->GetFactory()->NewJSSymbol(); + JSHandle symbol = ecmaVm->GetFactory()->NewJSSymbol(); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); ASSERT_TRUE(result.IsString()); - auto symbol_value = ecmascript::builtins_common::GetTaggedString(thread_, "Symbol()"); - ASSERT_EQ(reinterpret_cast(symbol_value.GetRawData())->Compare(*result_handle), 0); + auto symbolValue = ecmascript::builtins_common::GetTaggedString(thread_, "Symbol()"); + ASSERT_EQ(reinterpret_cast(symbolValue.GetRawData())->Compare(*resultHandle), 0); } // new Symbol("aaa").toString() TEST_F(BuiltinsSymbolTest, SymbolWithParameterToString) { - auto ecma_vm = thread_->GetEcmaVM(); + auto ecmaVm = thread_->GetEcmaVM(); - JSHandle symbol = ecma_vm->GetFactory()->NewPublicSymbolWithChar("aaa"); + JSHandle symbol = ecmaVm->GetFactory()->NewPublicSymbolWithChar("aaa"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::proto::ToString(ecma_runtime_call_info.get()); - JSHandle result_handle(thread_, reinterpret_cast(result.GetRawData())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::proto::ToString(ecmaRuntimeCallInfo.get()); + JSHandle resultHandle(thread_, reinterpret_cast(result.GetRawData())); ASSERT_TRUE(result.IsString()); - auto symbol_value = ecmascript::builtins_common::GetTaggedString(thread_, "Symbol(aaa)"); - ASSERT_EQ(reinterpret_cast(symbol_value.GetRawData())->Compare(*result_handle), 0); + auto symbolValue = ecmascript::builtins_common::GetTaggedString(thread_, "Symbol(aaa)"); + ASSERT_EQ(reinterpret_cast(symbolValue.GetRawData())->Compare(*resultHandle), 0); } // new Symbol().valueOf() TEST_F(BuiltinsSymbolTest, SymbolNoParameterValueOf) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle symbol = ecma_vm->GetFactory()->NewJSSymbol(); + JSHandle symbol = ecmaVm->GetFactory()->NewJSSymbol(); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::proto::ValueOf(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); - JSHandle symbol_object(env->GetSymbolFunction()); - JSHandle symbol_value(symbol); - JSHandle symbol_ref = ecma_vm->GetFactory()->NewJSPrimitiveRef(symbol_object, symbol_value); + JSHandle symbolObject(env->GetSymbolFunction()); + JSHandle symbolValue(symbol); + JSHandle symbolRef = ecmaVm->GetFactory()->NewJSPrimitiveRef(symbolObject, symbolValue); - auto other_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - other_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - other_ecma_runtime_call_info->SetThis(symbol_ref.GetTaggedValue()); + auto otherEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + otherEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + otherEcmaRuntimeCallInfo->SetThis(symbolRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, other_ecma_runtime_call_info.get()); - JSTaggedValue other_result = symbol::proto::ValueOf(other_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, otherEcmaRuntimeCallInfo.get()); + JSTaggedValue otherResult = symbol::proto::ValueOf(otherEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - EXPECT_TRUE(other_result.IsSymbol()); - ASSERT_EQ(other_result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); + EXPECT_TRUE(otherResult.IsSymbol()); + ASSERT_EQ(otherResult.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); } // new Symbol("bbb").valueOf() TEST_F(BuiltinsSymbolTest, SymbolWithParameterValueOf) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle symbol = ecma_vm->GetFactory()->NewPublicSymbolWithChar("bbb"); + JSHandle symbol = ecmaVm->GetFactory()->NewPublicSymbolWithChar("bbb"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::proto::ValueOf(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::proto::ValueOf(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); - JSHandle symbol_object(env->GetSymbolFunction()); - JSHandle symbol_value(symbol); - JSHandle symbol_ref = ecma_vm->GetFactory()->NewJSPrimitiveRef(symbol_object, symbol_value); + JSHandle symbolObject(env->GetSymbolFunction()); + JSHandle symbolValue(symbol); + JSHandle symbolRef = ecmaVm->GetFactory()->NewJSPrimitiveRef(symbolObject, symbolValue); - auto other_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - other_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - other_ecma_runtime_call_info->SetThis(symbol_ref.GetTaggedValue()); + auto otherEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + otherEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + otherEcmaRuntimeCallInfo->SetThis(symbolRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, other_ecma_runtime_call_info.get()); - JSTaggedValue other_result = symbol::proto::ValueOf(other_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, otherEcmaRuntimeCallInfo.get()); + JSTaggedValue otherResult = symbol::proto::ValueOf(otherEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - EXPECT_TRUE(other_result.IsSymbol()); - ASSERT_EQ(other_result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); + EXPECT_TRUE(otherResult.IsSymbol()); + ASSERT_EQ(otherResult.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); } // new Symbol().for TEST_F(BuiltinsSymbolTest, SymbolWithParameterFor) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle table_handle(env->GetRegisterSymbols()); + JSHandle tableHandle(env->GetRegisterSymbols()); - JSHandle string = ecma_vm->GetFactory()->NewFromCanBeCompressString("ccc"); + JSHandle string = ecmaVm->GetFactory()->NewFromCanBeCompressString("ccc"); ASSERT_EQ(string->GetLength(), 3); - JSHandle string_handle(string); - ASSERT_EQ(table_handle->ContainsKey(thread_, string_handle.GetTaggedValue()), false); + JSHandle stringHandle(string); + ASSERT_EQ(tableHandle->ContainsKey(thread_, stringHandle.GetTaggedValue()), false); - JSHandle symbol = ecma_vm->GetFactory()->NewSymbolWithTableWithChar("ccc"); + JSHandle symbol = ecmaVm->GetFactory()->NewSymbolWithTableWithChar("ccc"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, string.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, string.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::For(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::For(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_EQ(table_handle->ContainsKey(thread_, string_handle.GetTaggedValue()), true); + ASSERT_EQ(tableHandle->ContainsKey(thread_, stringHandle.GetTaggedValue()), true); JSTaggedValue target(*symbol); ASSERT_EQ(result.GetRawData() == target.GetRawData(), true); @@ -206,131 +206,131 @@ TEST_F(BuiltinsSymbolTest, SymbolWithParameterFor) // Symbol.keyFor (sym) TEST_F(BuiltinsSymbolTest, SymbolKeyFor) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle symbol = ecma_vm->GetFactory()->NewPublicSymbolWithChar("bbb"); + JSHandle symbol = ecmaVm->GetFactory()->NewPublicSymbolWithChar("bbb"); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, symbol.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::KeyFor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::KeyFor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - JSHandle string = ecma_vm->GetFactory()->NewFromCanBeCompressString("ccc"); + JSHandle string = ecmaVm->GetFactory()->NewFromCanBeCompressString("ccc"); ASSERT_EQ(string->GetLength(), 3); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, string.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, string.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - symbol::For(ecma_runtime_call_info1.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + symbol::For(ecmaRuntimeCallInfo1.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle other_symbol = ecma_vm->GetFactory()->NewPublicSymbolWithChar("ccc"); - auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info2->SetCallArg(0, other_symbol.GetTaggedValue()); + JSHandle otherSymbol = ecmaVm->GetFactory()->NewPublicSymbolWithChar("ccc"); + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetCallArg(0, otherSymbol.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue other_result = symbol::KeyFor(ecma_runtime_call_info2.get()); + prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo2.get()); + JSTaggedValue otherResult = symbol::KeyFor(ecmaRuntimeCallInfo2.get()); TestHelper::TearDownFrame(thread_, prev); - ASSERT_TRUE(other_result.IsString()); - JSHandle table_handle(env->GetRegisterSymbols()); - JSTaggedValue string_value(*string); - ASSERT_EQ(table_handle->ContainsKey(thread_, string_value), true); + ASSERT_TRUE(otherResult.IsString()); + JSHandle tableHandle(env->GetRegisterSymbols()); + JSTaggedValue stringValue(*string); + ASSERT_EQ(tableHandle->ContainsKey(thread_, stringValue), true); } // Symbol.ToPrimitive() TEST_F(BuiltinsSymbolTest, SymbolToPrimitive) { - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle symbol = ecma_vm->GetFactory()->NewJSSymbol(); + JSHandle symbol = ecmaVm->GetFactory()->NewJSSymbol(); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::proto::ToPrimitive(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::proto::ToPrimitive(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); - JSHandle symbol_object(env->GetSymbolFunction()); - JSHandle symbol_value(symbol); - JSHandle symbol_ref = ecma_vm->GetFactory()->NewJSPrimitiveRef(symbol_object, symbol_value); + JSHandle symbolObject(env->GetSymbolFunction()); + JSHandle symbolValue(symbol); + JSHandle symbolRef = ecmaVm->GetFactory()->NewJSPrimitiveRef(symbolObject, symbolValue); - auto other_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - other_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - other_ecma_runtime_call_info->SetThis(symbol_ref.GetTaggedValue()); + auto otherEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + otherEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + otherEcmaRuntimeCallInfo->SetThis(symbolRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, other_ecma_runtime_call_info.get()); - JSTaggedValue other_result = symbol::proto::ToPrimitive(other_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, otherEcmaRuntimeCallInfo.get()); + JSTaggedValue otherResult = symbol::proto::ToPrimitive(otherEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - EXPECT_TRUE(other_result.IsSymbol()); - ASSERT_EQ(other_result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); + EXPECT_TRUE(otherResult.IsSymbol()); + ASSERT_EQ(otherResult.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); } // constructor TEST_F(BuiltinsSymbolTest, SymbolConstructor) { - auto ecma_vm = thread_->GetEcmaVM(); + auto ecmaVm = thread_->GetEcmaVM(); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::SymbolConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::SymbolConstructor(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); EXPECT_TRUE(result.IsSymbol()); auto *sym = reinterpret_cast(result.GetRawData()); ASSERT_EQ(sym->GetDescription().IsUndefined(), true); - JSHandle string = ecma_vm->GetFactory()->NewFromCanBeCompressString("ddd"); + JSHandle string = ecmaVm->GetFactory()->NewFromCanBeCompressString("ddd"); - auto other_ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - other_ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - other_ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - other_ecma_runtime_call_info->SetCallArg(0, string.GetTaggedValue()); + auto otherEcmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + otherEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + otherEcmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + otherEcmaRuntimeCallInfo->SetCallArg(0, string.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread_, other_ecma_runtime_call_info.get()); - JSTaggedValue result1 = symbol::SymbolConstructor(other_ecma_runtime_call_info.get()); + prev = TestHelper::SetupFrame(thread_, otherEcmaRuntimeCallInfo.get()); + JSTaggedValue result1 = symbol::SymbolConstructor(otherEcmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); - JSHandle result_string = JSTaggedValue::ToString( + JSHandle resultString = JSTaggedValue::ToString( thread_, JSHandle(thread_, reinterpret_cast(result1.GetRawData())->GetDescription())); - ASSERT_EQ(result_string->Compare(*string), 0); + ASSERT_EQ(resultString->Compare(*string), 0); } TEST_F(BuiltinsSymbolTest, SymbolGetter) { - auto ecma_vm = thread_->GetEcmaVM(); + auto ecmaVm = thread_->GetEcmaVM(); - JSHandle symbol = ecma_vm->GetFactory()->NewPublicSymbolWithChar(""); - JSHandle string = ecma_vm->GetFactory()->NewFromCanBeCompressString(""); + JSHandle symbol = ecmaVm->GetFactory()->NewPublicSymbolWithChar(""); + JSHandle string = ecmaVm->GetFactory()->NewFromCanBeCompressString(""); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = symbol::proto::GetDescription(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = symbol::proto::GetDescription(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsString()); - auto *res_string = reinterpret_cast(result.GetRawData()); - ASSERT_EQ(res_string->GetLength(), 0); - ASSERT_EQ(EcmaString::StringsAreEqual(res_string, *string), true); + auto *resString = reinterpret_cast(result.GetRawData()); + ASSERT_EQ(resString->GetLength(), 0); + ASSERT_EQ(EcmaString::StringsAreEqual(resString, *string), true); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_typedarray_test.cpp b/tests/runtime/builtins/builtins_typedarray_test.cpp index 1687b74661bee645f13709090ce37c13997e40b3..8fefb4dc8fa83267a866c057cd67dc8a4bca859e 100644 --- a/tests/runtime/builtins/builtins_typedarray_test.cpp +++ b/tests/runtime/builtins/builtins_typedarray_test.cpp @@ -79,9 +79,9 @@ protected: if (key->IsUndefined()) { return JSTaggedValue::Undefined(); } - JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); - int length = js_array->GetArrayLength() + 1; - js_array->SetArrayLength(argv->GetThread(), length); + JSArray *jsArray = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); + int length = jsArray->GetArrayLength() + 1; + jsArray->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); } @@ -174,15 +174,15 @@ private: EcmaHandleScope *scope_ {nullptr}; }; -JSTaggedValue CreateBuiltinsJSObject(JSThread *thread, const PandaString &key_c_str) +JSTaggedValue CreateBuiltinsJSObject(JSThread *thread, const PandaString &keyCStr) { - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle dynclass = env->GetObjectFunction(); - ObjectFactory *factory = ecma_vm->GetFactory(); + ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - JSHandle key(factory->NewFromCanBeCompressString(&key_c_str[0])); + JSHandle key(factory->NewFromCanBeCompressString(&keyCStr[0])); JSHandle value(thread, JSTaggedValue(1)); JSObject::SetProperty(thread, obj, key, value); return obj.GetTaggedValue(); @@ -190,20 +190,20 @@ JSTaggedValue CreateBuiltinsJSObject(JSThread *thread, const PandaString &key_c_ JSTypedArray *CreateTypedArrayFromList(JSThread *thread, const JSHandle &array) { - auto ecma_vm = thread->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle jsarray(JSArray::CreateArrayFromList(thread, array)); - JSHandle int8_array(env->GetInt8ArrayFunction()); - JSHandle global_object(thread, env->GetGlobalObject()); + JSHandle int8Array(env->GetInt8ArrayFunction()); + JSHandle globalObject(thread, env->GetGlobalObject()); // 6 : test case - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetNewTarget(JSTaggedValue(*int8_array)); - ecma_runtime_call_info1->SetThis(JSTaggedValue(*global_object)); - ecma_runtime_call_info1->SetCallArg(0, jsarray.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetNewTarget(JSTaggedValue(*int8Array)); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(*globalObject)); + ecmaRuntimeCallInfo1->SetCallArg(0, jsarray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = int8_array::Int8ArrayConstructor(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = int8_array::Int8ArrayConstructor(ecmaRuntimeCallInfo1.get()); EXPECT_TRUE(result.IsECMAObject()); JSTypedArray *int8arr = JSTypedArray::Cast(reinterpret_cast(result.GetRawData())); @@ -212,17 +212,17 @@ JSTypedArray *CreateTypedArrayFromList(JSThread *thread, const JSHandleGetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle array(env->GetArrayFunction()); - JSHandle global_object(thread_, env->GetGlobalObject()); + JSHandle globalObject(thread_, env->GetGlobalObject()); - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info1->SetFunction(array.GetTaggedValue()); - ecma_runtime_call_info1->SetThis(global_object.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo1->SetFunction(array.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(globalObject.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = typed_array::GetSpecies(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result = typed_array::GetSpecies(ecmaRuntimeCallInfo1.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -242,14 +242,14 @@ TEST_F(BuiltinsTypedArrayTest, Includes1) JSHandle obj(thread_, CreateTypedArrayFromList(thread_, array)); // new Array(1,2,3,4,3).includes(1,0) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = typed_array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -270,14 +270,14 @@ TEST_F(BuiltinsTypedArrayTest, Includes2) JSHandle obj(thread_, CreateTypedArrayFromList(thread_, array)); // new Array(1,2,3,4,3).includes(1,3) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = typed_array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -298,14 +298,14 @@ TEST_F(BuiltinsTypedArrayTest, Includes3) JSHandle obj(thread_, CreateTypedArrayFromList(thread_, array)); // new Array(1,2,3,4,3).includes(5,0) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = typed_array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -326,13 +326,13 @@ TEST_F(BuiltinsTypedArrayTest, Includes4) JSHandle obj(thread_, CreateTypedArrayFromList(thread_, array)); // new Array(1,2,3,4,3).includes(1) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = typed_array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -353,13 +353,13 @@ TEST_F(BuiltinsTypedArrayTest, Includes5) JSHandle obj(thread_, CreateTypedArrayFromList(thread_, array)); // new Array(1,2,3,4,3).includes(5) - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = typed_array::proto::Includes(ecmaRuntimeCallInfo.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } diff --git a/tests/runtime/builtins/builtins_weak_map_test.cpp b/tests/runtime/builtins/builtins_weak_map_test.cpp index 5001b168604436257ee8baad35a5f8081eda07f9..2bd3be4f3d4b27e36db45a157672abd3807813db 100644 --- a/tests/runtime/builtins/builtins_weak_map_test.cpp +++ b/tests/runtime/builtins/builtins_weak_map_test.cpp @@ -72,25 +72,25 @@ private: static JSObject *JSObjectTestCreate(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle js_func = global_env->GetObjectFunction(); - return *factory->NewJSObjectByConstructor(JSHandle(js_func), js_func); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle jsFunc = globalEnv->GetObjectFunction(); + return *factory->NewJSObjectByConstructor(JSHandle(jsFunc), jsFunc); } JSWeakMap *CreateBuiltinsWeakMap(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetWeakMapFunction()); + JSHandle newTarget(env->GetWeakMapFunction()); // 4 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, new_target.GetTaggedValue(), 4); - ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, newTarget.GetTaggedValue(), 4); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = weak_map::WeakMapConstructor(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = weak_map::WeakMapConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); return JSWeakMap::Cast(reinterpret_cast(result.GetRawData())); @@ -101,66 +101,66 @@ TEST_F(BuiltinsWeakMapTest, CreateAndGetSize) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetWeakMapFunction()); + JSHandle newTarget(env->GetWeakMapFunction()); JSHandle map(thread_, CreateBuiltinsWeakMap(thread_)); JSHandle array(factory->NewTaggedArray(1)); - JSHandle internal_array(factory->NewTaggedArray(2)); + JSHandle internalArray(factory->NewTaggedArray(2)); JSTaggedValue value(JSObjectTestCreate(thread_)); - internal_array->Set(thread_, 0, value); - internal_array->Set(thread_, 1, JSTaggedValue(0)); - auto result = JSArray::CreateArrayFromList(thread_, internal_array); + internalArray->Set(thread_, 0, value); + internalArray->Set(thread_, 1, JSTaggedValue(0)); + auto result = JSArray::CreateArrayFromList(thread_, internalArray); array->Set(thread_, 0, result); JSHandle values = JSArray::CreateArrayFromList(thread_, array); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info->SetThis(map.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, values.GetTaggedValue()); - ecma_runtime_call_info->SetNewTarget(new_target.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, values.GetTaggedValue()); + ecmaRuntimeCallInfo->SetNewTarget(newTarget.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = weak_map::WeakMapConstructor(ecma_runtime_call_info.get()); - JSHandle weak_map(thread_, JSWeakMap::Cast(reinterpret_cast(result1.GetRawData()))); - EXPECT_EQ(weak_map->GetSize(), 1); + JSTaggedValue result1 = weak_map::WeakMapConstructor(ecmaRuntimeCallInfo.get()); + JSHandle weakMap(thread_, JSWeakMap::Cast(reinterpret_cast(result1.GetRawData()))); + EXPECT_EQ(weakMap->GetSize(), 1); } TEST_F(BuiltinsWeakMapTest, SetAndHas) { // create jsWeakMap - JSHandle weak_map(thread_, CreateBuiltinsWeakMap(thread_)); + JSHandle weakMap(thread_, CreateBuiltinsWeakMap(thread_)); JSHandle key(thread_, JSObjectTestCreate(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(weak_map.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(1))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(weakMap.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = weak_map::proto::Has(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = weak_map::proto::Has(ecmaRuntimeCallInfo.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); } // test Set() - JSTaggedValue result2 = weak_map::proto::Set(ecma_runtime_call_info.get()); + JSTaggedValue result2 = weak_map::proto::Set(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result2.IsECMAObject()); - JSWeakMap *js_weak_map = JSWeakMap::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(js_weak_map->GetSize(), 1); + JSWeakMap *jsWeakMap = JSWeakMap::Cast(reinterpret_cast(result2.GetRawData())); + EXPECT_EQ(jsWeakMap->GetSize(), 1); // test Has() - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(1))); - ecma_runtime_call_info1->SetThis(JSTaggedValue(js_weak_map)); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(1))); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(jsWeakMap)); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = weak_map::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = weak_map::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -169,47 +169,47 @@ TEST_F(BuiltinsWeakMapTest, SetAndHas) TEST_F(BuiltinsWeakMapTest, DeleteAndRemove) { // create jsWeakMap - JSHandle weak_map(thread_, CreateBuiltinsWeakMap(thread_)); + JSHandle weakMap(thread_, CreateBuiltinsWeakMap(thread_)); // add 40 keys - JSTaggedValue last_key(JSTaggedValue::Undefined()); + JSTaggedValue lastKey(JSTaggedValue::Undefined()); // NOLINTNEXTLINE(readability-magic-numbers) for (int i = 0; i < 40; i++) { JSHandle key(thread_, JSObjectTestCreate(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(weak_map.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(i))); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 8); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(weakMap.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(i))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = weak_map::proto::Set(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = weak_map::proto::Set(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result1.IsECMAObject()); - JSWeakMap *js_weak_map = JSWeakMap::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(js_weak_map->GetSize(), i + 1); - last_key = key.GetTaggedValue(); + JSWeakMap *jsWeakMap = JSWeakMap::Cast(reinterpret_cast(result1.GetRawData())); + EXPECT_EQ(jsWeakMap->GetSize(), i + 1); + lastKey = key.GetTaggedValue(); } // whether jsWeakMap has delete lastKey - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(weak_map.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, last_key); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(weakMap.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, lastKey); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = weak_map::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = weak_map::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = weak_map::proto::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = weak_map::proto::Delete(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = weak_map::proto::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = weak_map::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } diff --git a/tests/runtime/builtins/builtins_weak_set_test.cpp b/tests/runtime/builtins/builtins_weak_set_test.cpp index 514cddab96f10cdba59154c741177dcccade7a90..a055cc0e982994caa73803c7781ffb408f607214 100644 --- a/tests/runtime/builtins/builtins_weak_set_test.cpp +++ b/tests/runtime/builtins/builtins_weak_set_test.cpp @@ -73,37 +73,37 @@ private: static JSObject *JSObjectTestCreate(JSThread *thread) { [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle js_func = global_env->GetObjectFunction(); - JSHandle new_obj = - thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(js_func), js_func); - return *new_obj; + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle jsFunc = globalEnv->GetObjectFunction(); + JSHandle newObj = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(jsFunc), jsFunc); + return *newObj; } JSWeakSet *CreateBuiltinsWeakSet(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetWeakSetFunction()); + JSHandle newTarget(env->GetWeakSetFunction()); // 4 : test case - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*new_target), 4); - ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = weak_set::WeakSetConstructor(ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 4); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + JSTaggedValue result = weak_set::WeakSetConstructor(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result.IsECMAObject()); - JSWeakSet *js_weak_set = JSWeakSet::Cast(reinterpret_cast(result.GetRawData())); - return js_weak_set; + JSWeakSet *jsWeakSet = JSWeakSet::Cast(reinterpret_cast(result.GetRawData())); + return jsWeakSet; } TEST_F(BuiltinsWeakSetTest, CreateAndGetSize) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetWeakSetFunction()); - JSHandle weak_set(thread_, CreateBuiltinsWeakSet(thread_)); + JSHandle newTarget(env->GetWeakSetFunction()); + JSHandle weakSet(thread_, CreateBuiltinsWeakSet(thread_)); JSHandle array(factory->NewTaggedArray(5)); for (int i = 0; i < 5; i++) { @@ -112,52 +112,51 @@ TEST_F(BuiltinsWeakSetTest, CreateAndGetSize) } JSHandle values = JSArray::CreateArrayFromList(thread_, array); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); - ecma_runtime_call_info->SetThis(weak_set.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, values.GetTaggedValue()); - ecma_runtime_call_info->SetNewTarget(new_target.GetTaggedValue()); - - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - - JSTaggedValue result1 = weak_set::WeakSetConstructor(ecma_runtime_call_info.get()); - JSHandle weak_set_result(thread_, - JSWeakSet::Cast(reinterpret_cast(result1.GetRawData()))); - EXPECT_EQ(weak_set_result->GetSize(), 5); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(weakSet.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, values.GetTaggedValue()); + ecmaRuntimeCallInfo->SetNewTarget(newTarget.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + + JSTaggedValue result1 = weak_set::WeakSetConstructor(ecmaRuntimeCallInfo.get()); + JSHandle weakSetResult(thread_, JSWeakSet::Cast(reinterpret_cast(result1.GetRawData()))); + EXPECT_EQ(weakSetResult->GetSize(), 5); } TEST_F(BuiltinsWeakSetTest, AddAndHas) { // create jsWeakSet - JSHandle weak_set(thread_, CreateBuiltinsWeakSet(thread_)); + JSHandle weakSet(thread_, CreateBuiltinsWeakSet(thread_)); JSHandle key(thread_, JSObjectTestCreate(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(weak_set.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(weakSet.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - JSWeakSet *js_weak_set; + JSWeakSet *jsWeakSet; { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = weak_set::proto::Has(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = weak_set::proto::Has(ecmaRuntimeCallInfo.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Add() - JSTaggedValue result2 = weak_set::proto::Add(ecma_runtime_call_info.get()); + JSTaggedValue result2 = weak_set::proto::Add(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result2.IsECMAObject()); - js_weak_set = JSWeakSet::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(js_weak_set->GetSize(), 1); + jsWeakSet = JSWeakSet::Cast(reinterpret_cast(result2.GetRawData())); + EXPECT_EQ(jsWeakSet->GetSize(), 1); } // test Has() - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(JSTaggedValue(js_weak_set)); - ecma_runtime_call_info1->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(jsWeakSet)); + ecmaRuntimeCallInfo1->SetCallArg(0, key.GetTaggedValue()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = weak_set::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = weak_set::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -166,46 +165,46 @@ TEST_F(BuiltinsWeakSetTest, AddAndHas) TEST_F(BuiltinsWeakSetTest, DeleteAndRemove) { // create jsSet - JSHandle weak_set(thread_, CreateBuiltinsWeakSet(thread_)); + JSHandle weakSet(thread_, CreateBuiltinsWeakSet(thread_)); // add 40 keys - JSTaggedValue last_key(JSTaggedValue::Undefined()); + JSTaggedValue lastKey(JSTaggedValue::Undefined()); // NOLINTNEXTLINE(readability-magic-numbers) for (int i = 0; i < 40; i++) { JSHandle key(thread_, JSObjectTestCreate(thread_)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(weak_set.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(weakSet.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = weak_set::proto::Add(ecma_runtime_call_info.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = weak_set::proto::Add(ecmaRuntimeCallInfo.get()); EXPECT_TRUE(result1.IsECMAObject()); - JSWeakSet *js_weak_set = JSWeakSet::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(js_weak_set->GetSize(), i + 1); - last_key = key.GetTaggedValue(); + JSWeakSet *jsWeakSet = JSWeakSet::Cast(reinterpret_cast(result1.GetRawData())); + EXPECT_EQ(jsWeakSet->GetSize(), i + 1); + lastKey = key.GetTaggedValue(); } // whether jsWeakSet has delete lastKey - auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info1->SetThis(weak_set.GetTaggedValue()); - ecma_runtime_call_info1->SetCallArg(0, last_key); + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(weakSet.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(0, lastKey); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = weak_set::proto::Has(ecma_runtime_call_info1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = weak_set::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = weak_set::proto::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = weak_set::proto::Delete(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = weak_set::proto::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = weak_set::proto::Has(ecmaRuntimeCallInfo1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } diff --git a/tests/runtime/common/builtins_test.cpp b/tests/runtime/common/builtins_test.cpp index 871d00372985da3b76361bdbc295f145f15da020..ccfa8a2fd4a0fa0b05ec91673243725333a108ff 100644 --- a/tests/runtime/common/builtins_test.cpp +++ b/tests/runtime/common/builtins_test.cpp @@ -56,69 +56,69 @@ private: TEST_F(BuiltinsTest, ObjectInit) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle object_function(env->GetObjectFunction()); - ASSERT_NE(*object_function, nullptr); + JSHandle objectFunction(env->GetObjectFunction()); + ASSERT_NE(*objectFunction, nullptr); } TEST_F(BuiltinsTest, FunctionInit) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle function_function(env->GetFunctionFunction()); - ASSERT_NE(*function_function, nullptr); + JSHandle functionFunction(env->GetFunctionFunction()); + ASSERT_NE(*functionFunction, nullptr); } TEST_F(BuiltinsTest, NumberInit) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle number_function(env->GetNumberFunction()); - ASSERT_NE(*number_function, nullptr); + JSHandle numberFunction(env->GetNumberFunction()); + ASSERT_NE(*numberFunction, nullptr); } TEST_F(BuiltinsTest, SetInit) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle set_function(env->GetSetFunction()); - ASSERT_NE(*set_function, nullptr); + JSHandle setFunction(env->GetSetFunction()); + ASSERT_NE(*setFunction, nullptr); } TEST_F(BuiltinsTest, MapInit) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle map_function(env->GetMapFunction()); - ASSERT_NE(*map_function, nullptr); + JSHandle mapFunction(env->GetMapFunction()); + ASSERT_NE(*mapFunction, nullptr); } TEST_F(BuiltinsTest, StrictModeForbiddenAccess) { ASSERT_NE(thread_, nullptr); - auto ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + auto ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle function = factory->NewJSFunction(env, static_cast(nullptr)); - JSHandle caller_key(factory->NewFromString("caller")); - JSHandle arguments_key(factory->NewFromString("arguments")); + JSHandle callerKey(factory->NewFromString("caller")); + JSHandle argumentsKey(factory->NewFromString("arguments")); - JSObject::GetProperty(thread_, JSHandle(function), caller_key); + JSObject::GetProperty(thread_, JSHandle(function), callerKey); ASSERT_EQ(thread_->HasPendingException(), true); - JSObject::GetProperty(thread_, JSHandle(function), arguments_key); + JSObject::GetProperty(thread_, JSHandle(function), argumentsKey); ASSERT_EQ(thread_->HasPendingException(), true); } diff --git a/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp b/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp index 2764953c653ceea019f768cce914a4a0004d6c2d..e78b9c2940e8d974776582cd49676a3e99dca867 100644 --- a/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp +++ b/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp @@ -23,29 +23,29 @@ class EcmaEmptyClassCheck : public testing::Test { public: std::string GetJSAbcFile() { - auto exec_path = panda::os::file::File::GetExecutablePath(); - return exec_path.Value() + + auto execPath = panda::os::file::File::GetExecutablePath(); + return execPath.Value() + "/../plugins/ecmascript/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.abc"; } }; static void CheckNames(const panda_file::File &pf) { - Span class_indexes = pf.GetClasses(); + Span classIndexes = pf.GetClasses(); - for (const uint32_t index : class_indexes) { - panda_file::File::EntityId class_id(index); - if (pf.IsExternal(class_id)) { + for (const uint32_t index : classIndexes) { + panda_file::File::EntityId classId(index); + if (pf.IsExternal(classId)) { continue; } - panda_file::ClassDataAccessor cda(pf, class_id); + panda_file::ClassDataAccessor cda(pf, classId); cda.EnumerateMethods([&pf](panda_file::MethodDataAccessor &mda) { - auto sd_mname = mda.GetName(); - std::string mname(reinterpret_cast(sd_mname.data), sd_mname.utf16_length); + auto sdMname = mda.GetName(); + std::string mname(reinterpret_cast(sdMname.data), sdMname.utf16Length); ASSERT(!mname.empty()); - auto sd_cname = pf.GetStringData(mda.GetClassId()); - std::string cname(reinterpret_cast(sd_cname.data), sd_cname.utf16_length); + auto sdCname = pf.GetStringData(mda.GetClassId()); + std::string cname(reinterpret_cast(sdCname.data), sdCname.utf16Length); ASSERT(!cname.empty()); }); } @@ -62,9 +62,9 @@ TEST_F(EcmaEmptyClassCheck, TestJSABC) ASSERT_TRUE(Runtime::Create(options)); - auto *ecma_vm = reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); + auto *ecmaVm = reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); - ASSERT_TRUE(ecma_vm); + ASSERT_TRUE(ecmaVm); std::unique_ptr pf = panda_file::OpenPandaFile(GetJSAbcFile(), "", panda_file::File::OpenMode::READ_WRITE); @@ -72,7 +72,7 @@ TEST_F(EcmaEmptyClassCheck, TestJSABC) ASSERT_TRUE(pf); CheckNames(*pf); - ASSERT_TRUE(ecma_vm->ExecuteFromBuffer(pf->GetBase(), pf->GetPtr().GetSize(), "_GLOBAL::func_main_0", {})); + ASSERT_TRUE(ecmaVm->ExecuteFromBuffer(pf->GetBase(), pf->GetPtr().GetSize(), "_GLOBAL::func_main_0", {})); Runtime::Destroy(); } diff --git a/tests/runtime/common/ecma_module_test.cpp b/tests/runtime/common/ecma_module_test.cpp index d32002514ce29319ce94184c8a8ffdcf70b96f20..b0076341e382acae8ea62d152d3afbc93b9f8ddd 100644 --- a/tests/runtime/common/ecma_module_test.cpp +++ b/tests/runtime/common/ecma_module_test.cpp @@ -63,9 +63,9 @@ private: EcmaModule *EcmaModuleCreate(JSThread *thread) { - ObjectFactory *object_factory = thread->GetEcmaVM()->GetFactory(); - JSHandle handle_ecma_module = object_factory->NewEmptyEcmaModule(); - return *handle_ecma_module; + ObjectFactory *objectFactory = thread->GetEcmaVM()->GetFactory(); + JSHandle handleEcmaModule = objectFactory->NewEmptyEcmaModule(); + return *handleEcmaModule; } /* @@ -78,18 +78,18 @@ EcmaModule *EcmaModuleCreate(JSThread *thread) */ TEST_F(EcmaModuleTest, AddItem_001) { - int num_of_elements_dict = 4; - PandaString c_str_item_name = "key1"; - int int_item_value = 1; - JSHandle handle_ecma_module(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_name_dict(NameDictionary::Create(thread_, num_of_elements_dict)); - JSHandle handle_tag_val_item_name( - thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(c_str_item_name)); - JSHandle handle_tag_val_item_value(thread_, JSTaggedValue(int_item_value)); - - handle_ecma_module->SetNameDictionary(thread_, handle_name_dict); // Call SetNameDictionary in TEST_F - EcmaModule::AddItem(thread_, handle_ecma_module, handle_tag_val_item_name, handle_tag_val_item_value); - EXPECT_EQ(handle_ecma_module->GetItem(thread_, handle_tag_val_item_name)->GetNumber(), int_item_value); + int numOfElementsDict = 4; + PandaString cStrItemName = "key1"; + int intItemValue = 1; + JSHandle handleEcmaModule(thread_, EcmaModuleCreate(thread_)); + JSHandle handleNameDict(NameDictionary::Create(thread_, numOfElementsDict)); + JSHandle handleTagValItemName( + thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(cStrItemName)); + JSHandle handleTagValItemValue(thread_, JSTaggedValue(intItemValue)); + + handleEcmaModule->SetNameDictionary(thread_, handleNameDict); // Call SetNameDictionary in TEST_F + EcmaModule::AddItem(thread_, handleEcmaModule, handleTagValItemName, handleTagValItemValue); + EXPECT_EQ(handleEcmaModule->GetItem(thread_, handleTagValItemName)->GetNumber(), intItemValue); } /* @@ -102,16 +102,16 @@ TEST_F(EcmaModuleTest, AddItem_001) */ TEST_F(EcmaModuleTest, AddItem_002) { - PandaString c_str_item_name = "cStrItemName"; - int int_item_value = 1; - JSHandle handle_ecma_module(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_tag_val_item_name( - thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(c_str_item_name)); - JSHandle handle_tag_val_item_value(thread_, JSTaggedValue(int_item_value)); + PandaString cStrItemName = "cStrItemName"; + int intItemValue = 1; + JSHandle handleEcmaModule(thread_, EcmaModuleCreate(thread_)); + JSHandle handleTagValItemName( + thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(cStrItemName)); + JSHandle handleTagValItemValue(thread_, JSTaggedValue(intItemValue)); // This EcmaModule calls 'SetNameDictionary' function through 'AddItem' function of "ecma_module.cpp". - EcmaModule::AddItem(thread_, handle_ecma_module, handle_tag_val_item_name, handle_tag_val_item_value); - EXPECT_EQ(handle_ecma_module->GetItem(thread_, handle_tag_val_item_name)->GetNumber(), int_item_value); + EcmaModule::AddItem(thread_, handleEcmaModule, handleTagValItemName, handleTagValItemValue); + EXPECT_EQ(handleEcmaModule->GetItem(thread_, handleTagValItemName)->GetNumber(), intItemValue); } /* @@ -125,17 +125,17 @@ TEST_F(EcmaModuleTest, AddItem_002) */ TEST_F(EcmaModuleTest, RemoveItem) { - ObjectFactory *obj_factory = thread_->GetEcmaVM()->GetFactory(); + ObjectFactory *objFactory = thread_->GetEcmaVM()->GetFactory(); - PandaString c_str_item_name = "cStrItemName"; - int int_item_value = 1; - JSHandle handle_ecma_module(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_tag_val_item_name(obj_factory->NewFromCanBeCompressString(c_str_item_name)); - JSHandle handle_tag_val_item_value(thread_, JSTaggedValue(int_item_value)); + PandaString cStrItemName = "cStrItemName"; + int intItemValue = 1; + JSHandle handleEcmaModule(thread_, EcmaModuleCreate(thread_)); + JSHandle handleTagValItemName(objFactory->NewFromCanBeCompressString(cStrItemName)); + JSHandle handleTagValItemValue(thread_, JSTaggedValue(intItemValue)); - EcmaModule::AddItem(thread_, handle_ecma_module, handle_tag_val_item_name, handle_tag_val_item_value); - EcmaModule::RemoveItem(thread_, handle_ecma_module, handle_tag_val_item_name); - EXPECT_TRUE(handle_ecma_module->GetItem(thread_, handle_tag_val_item_name)->IsUndefined()); + EcmaModule::AddItem(thread_, handleEcmaModule, handleTagValItemName, handleTagValItemValue); + EcmaModule::RemoveItem(thread_, handleEcmaModule, handleTagValItemName); + EXPECT_TRUE(handleEcmaModule->GetItem(thread_, handleTagValItemName)->IsUndefined()); } /* @@ -151,27 +151,27 @@ TEST_F(EcmaModuleTest, RemoveItem) */ TEST_F(EcmaModuleTest, SetNameDictionary) { - ObjectFactory *obj_factory = thread_->GetEcmaVM()->GetFactory(); - - int num_of_elements_dict = 4; - JSHandle handle_name_dict(NameDictionary::Create(thread_, num_of_elements_dict)); - JSHandle handle_obj_func = thread_->GetEcmaVM()->GetGlobalEnv()->GetObjectFunction(); - PandaString key_array1 = "hello1"; - JSHandle string_key1 = obj_factory->NewFromCanBeCompressString(key_array1); - JSHandle key1(string_key1); + ObjectFactory *objFactory = thread_->GetEcmaVM()->GetFactory(); + + int numOfElementsDict = 4; + JSHandle handleNameDict(NameDictionary::Create(thread_, numOfElementsDict)); + JSHandle handleObjFunc = thread_->GetEcmaVM()->GetGlobalEnv()->GetObjectFunction(); + PandaString keyArray1 = "hello1"; + JSHandle stringKey1 = objFactory->NewFromCanBeCompressString(keyArray1); + JSHandle key1(stringKey1); JSHandle value1( - obj_factory->NewJSObjectByConstructor(JSHandle(handle_obj_func), handle_obj_func)); - JSHandle handle_name_dictionary_from( - NameDictionary::Put(thread_, handle_name_dict, key1, value1, PropertyAttributes::Default())); - JSHandle handle_ecma_module(thread_, EcmaModuleCreate(thread_)); - - handle_ecma_module->SetNameDictionary(thread_, handle_name_dictionary_from); - JSHandle handle_name_dictionary_to( - thread_, NameDictionary::Cast(handle_ecma_module->GetNameDictionary().GetTaggedObject())); - EXPECT_EQ(handle_name_dictionary_to->EntriesCount(), 1); - int entry1 = handle_name_dictionary_to->FindEntry(key1.GetTaggedValue()); - EXPECT_TRUE(key1.GetTaggedValue() == handle_name_dictionary_to->GetKey(entry1)); - EXPECT_TRUE(value1.GetTaggedValue() == handle_name_dictionary_to->GetValue(entry1)); + objFactory->NewJSObjectByConstructor(JSHandle(handleObjFunc), handleObjFunc)); + JSHandle handleNameDictionaryFrom( + NameDictionary::Put(thread_, handleNameDict, key1, value1, PropertyAttributes::Default())); + JSHandle handleEcmaModule(thread_, EcmaModuleCreate(thread_)); + + handleEcmaModule->SetNameDictionary(thread_, handleNameDictionaryFrom); + JSHandle handleNameDictionaryTo( + thread_, NameDictionary::Cast(handleEcmaModule->GetNameDictionary().GetTaggedObject())); + EXPECT_EQ(handleNameDictionaryTo->EntriesCount(), 1); + int entry1 = handleNameDictionaryTo->FindEntry(key1.GetTaggedValue()); + EXPECT_TRUE(key1.GetTaggedValue() == handleNameDictionaryTo->GetKey(entry1)); + EXPECT_TRUE(value1.GetTaggedValue() == handleNameDictionaryTo->GetValue(entry1)); } /* @@ -185,53 +185,47 @@ TEST_F(EcmaModuleTest, SetNameDictionary) */ TEST_F(EcmaModuleTest, ModuleManager_AddModule) { - ObjectFactory *obj_factory = thread_->GetEcmaVM()->GetFactory(); - ModuleManager *module_manager = thread_->GetEcmaVM()->GetModuleManager(); - - int num_of_elements_dict1 = 4; - int num_of_elements_dict2 = 4; - PandaString c_str_item_name1 = "cStrItemName1"; - PandaString c_str_item_name2 = "cStrItemName2"; - int int_item_value1 = 1; - int int_item_value2 = 2; - JSHandle handle_name_dict1(NameDictionary::Create(thread_, num_of_elements_dict1)); - JSHandle handle_name_dict2(NameDictionary::Create(thread_, num_of_elements_dict2)); - JSHandle handle_item_name1( - thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(c_str_item_name1)); - JSHandle handle_item_name2( - thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(c_str_item_name2)); - JSHandle handle_item_value1(thread_, JSTaggedValue(int_item_value1)); - JSHandle handle_item_value2(thread_, JSTaggedValue(int_item_value2)); - JSHandle handle_ecma_module_add_from1(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_ecma_module_add_from2(thread_, EcmaModuleCreate(thread_)); - handle_ecma_module_add_from1->SetNameDictionary(thread_, handle_name_dict1); - handle_ecma_module_add_from2->SetNameDictionary(thread_, handle_name_dict2); - - EcmaModule::AddItem(thread_, handle_ecma_module_add_from1, handle_item_name1, handle_item_value1); - JSHandle handle_tag_val_ecma_module_add_from1(thread_, - handle_ecma_module_add_from1.GetTaggedValue()); - std::string std_str_name_ecma_module_add1 = "NameEcmaModule1"; - JSHandle handle_tag_val_name_ecma_module_add1( - obj_factory->NewFromStdString(std_str_name_ecma_module_add1)); - EcmaModule::AddItem(thread_, handle_ecma_module_add_from2, handle_item_name2, handle_item_value2); - JSHandle handle_tag_val_ecma_module_add_from2(thread_, - handle_ecma_module_add_from2.GetTaggedValue()); - std::string std_str_name_ecma_module_add2 = "NameEcmaModule2"; - JSHandle handle_tag_val_name_ecma_module_add2( - obj_factory->NewFromStdString(std_str_name_ecma_module_add2)); - - module_manager->AddModule(handle_tag_val_name_ecma_module_add1, handle_tag_val_ecma_module_add_from1); - module_manager->AddModule(handle_tag_val_name_ecma_module_add2, handle_tag_val_ecma_module_add_from2); - JSHandle handle_tag_val_ecma_module_get1 = - module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add1); - JSHandle handle_tag_val_ecma_module_get2 = - module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add2); - EXPECT_EQ( - JSHandle::Cast(handle_tag_val_ecma_module_get1)->GetItem(thread_, handle_item_name1)->GetNumber(), - int_item_value1); - EXPECT_EQ( - JSHandle::Cast(handle_tag_val_ecma_module_get2)->GetItem(thread_, handle_item_name2)->GetNumber(), - int_item_value2); + ObjectFactory *objFactory = thread_->GetEcmaVM()->GetFactory(); + ModuleManager *moduleManager = thread_->GetEcmaVM()->GetModuleManager(); + + int numOfElementsDict1 = 4; + int numOfElementsDict2 = 4; + PandaString cStrItemName1 = "cStrItemName1"; + PandaString cStrItemName2 = "cStrItemName2"; + int intItemValue1 = 1; + int intItemValue2 = 2; + JSHandle handleNameDict1(NameDictionary::Create(thread_, numOfElementsDict1)); + JSHandle handleNameDict2(NameDictionary::Create(thread_, numOfElementsDict2)); + JSHandle handleItemName1( + thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(cStrItemName1)); + JSHandle handleItemName2( + thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(cStrItemName2)); + JSHandle handleItemValue1(thread_, JSTaggedValue(intItemValue1)); + JSHandle handleItemValue2(thread_, JSTaggedValue(intItemValue2)); + JSHandle handleEcmaModuleAddFrom1(thread_, EcmaModuleCreate(thread_)); + JSHandle handleEcmaModuleAddFrom2(thread_, EcmaModuleCreate(thread_)); + handleEcmaModuleAddFrom1->SetNameDictionary(thread_, handleNameDict1); + handleEcmaModuleAddFrom2->SetNameDictionary(thread_, handleNameDict2); + + EcmaModule::AddItem(thread_, handleEcmaModuleAddFrom1, handleItemName1, handleItemValue1); + JSHandle handleTagValEcmaModuleAddFrom1(thread_, handleEcmaModuleAddFrom1.GetTaggedValue()); + std::string stdStrNameEcmaModuleAdd1 = "NameEcmaModule1"; + JSHandle handleTagValNameEcmaModuleAdd1(objFactory->NewFromStdString(stdStrNameEcmaModuleAdd1)); + EcmaModule::AddItem(thread_, handleEcmaModuleAddFrom2, handleItemName2, handleItemValue2); + JSHandle handleTagValEcmaModuleAddFrom2(thread_, handleEcmaModuleAddFrom2.GetTaggedValue()); + std::string stdStrNameEcmaModuleAdd2 = "NameEcmaModule2"; + JSHandle handleTagValNameEcmaModuleAdd2(objFactory->NewFromStdString(stdStrNameEcmaModuleAdd2)); + + moduleManager->AddModule(handleTagValNameEcmaModuleAdd1, handleTagValEcmaModuleAddFrom1); + moduleManager->AddModule(handleTagValNameEcmaModuleAdd2, handleTagValEcmaModuleAddFrom2); + JSHandle handleTagValEcmaModuleGet1 = + moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd1); + JSHandle handleTagValEcmaModuleGet2 = + moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd2); + EXPECT_EQ(JSHandle::Cast(handleTagValEcmaModuleGet1)->GetItem(thread_, handleItemName1)->GetNumber(), + intItemValue1); + EXPECT_EQ(JSHandle::Cast(handleTagValEcmaModuleGet2)->GetItem(thread_, handleItemName2)->GetNumber(), + intItemValue2); } /* @@ -246,57 +240,53 @@ TEST_F(EcmaModuleTest, ModuleManager_AddModule) */ TEST_F(EcmaModuleTest, ModuleManager_RemoveModule) { - ObjectFactory *obj_factory = thread_->GetEcmaVM()->GetFactory(); - ModuleManager *module_manager = thread_->GetEcmaVM()->GetModuleManager(); - - std::string std_str_name_ecma_module_add1 = "NameEcmaModule1"; - std::string std_str_name_ecma_module_add2 = "NameEcmaModule2"; - int int_item_value1 = 1; - int int_item_value2 = 2; - int num_of_elements_dict1 = 4; - int num_of_elements_dict2 = 4; - JSHandle handle_tag_val_name_ecma_module_add1( - obj_factory->NewFromStdString(std_str_name_ecma_module_add1)); - JSHandle handle_tag_val_name_ecma_module_add2( - obj_factory->NewFromStdString(std_str_name_ecma_module_add2)); - JSHandle handle_tag_val_item_name1(obj_factory->NewFromCanBeCompressString("name1")); - JSHandle handle_tag_val_item_name2(obj_factory->NewFromCanBeCompressString("name2")); - JSHandle handle_tag_val_item_value1(thread_, JSTaggedValue(int_item_value1)); - JSHandle handle_tag_val_item_value2(thread_, JSTaggedValue(int_item_value2)); - JSHandle handle_ecma_module_add_from1(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_ecma_module_add_from2(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_name_dict1(NameDictionary::Create(thread_, num_of_elements_dict1)); - JSHandle handle_name_dict2(NameDictionary::Create(thread_, num_of_elements_dict2)); - handle_ecma_module_add_from1->SetNameDictionary(thread_, handle_name_dict1); - handle_ecma_module_add_from2->SetNameDictionary(thread_, handle_name_dict2); - EcmaModule::AddItem(thread_, handle_ecma_module_add_from1, handle_tag_val_item_name1, handle_tag_val_item_value1); - EcmaModule::AddItem(thread_, handle_ecma_module_add_from2, handle_tag_val_item_name2, handle_tag_val_item_value2); - JSHandle handle_tagged_value_ecma_module_add_from1(thread_, - handle_ecma_module_add_from1.GetTaggedValue()); - JSHandle handle_tagged_value_ecma_module_add_from2(thread_, - handle_ecma_module_add_from2.GetTaggedValue()); - - module_manager->AddModule(handle_tag_val_name_ecma_module_add1, handle_tagged_value_ecma_module_add_from1); - module_manager->AddModule(handle_tag_val_name_ecma_module_add2, handle_tagged_value_ecma_module_add_from2); - EXPECT_EQ(JSHandle::Cast(module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add1)) - ->GetItem(thread_, handle_tag_val_item_name1) + ObjectFactory *objFactory = thread_->GetEcmaVM()->GetFactory(); + ModuleManager *moduleManager = thread_->GetEcmaVM()->GetModuleManager(); + + std::string stdStrNameEcmaModuleAdd1 = "NameEcmaModule1"; + std::string stdStrNameEcmaModuleAdd2 = "NameEcmaModule2"; + int intItemValue1 = 1; + int intItemValue2 = 2; + int numOfElementsDict1 = 4; + int numOfElementsDict2 = 4; + JSHandle handleTagValNameEcmaModuleAdd1(objFactory->NewFromStdString(stdStrNameEcmaModuleAdd1)); + JSHandle handleTagValNameEcmaModuleAdd2(objFactory->NewFromStdString(stdStrNameEcmaModuleAdd2)); + JSHandle handleTagValItemName1(objFactory->NewFromCanBeCompressString("name1")); + JSHandle handleTagValItemName2(objFactory->NewFromCanBeCompressString("name2")); + JSHandle handleTagValItemValue1(thread_, JSTaggedValue(intItemValue1)); + JSHandle handleTagValItemValue2(thread_, JSTaggedValue(intItemValue2)); + JSHandle handleEcmaModuleAddFrom1(thread_, EcmaModuleCreate(thread_)); + JSHandle handleEcmaModuleAddFrom2(thread_, EcmaModuleCreate(thread_)); + JSHandle handleNameDict1(NameDictionary::Create(thread_, numOfElementsDict1)); + JSHandle handleNameDict2(NameDictionary::Create(thread_, numOfElementsDict2)); + handleEcmaModuleAddFrom1->SetNameDictionary(thread_, handleNameDict1); + handleEcmaModuleAddFrom2->SetNameDictionary(thread_, handleNameDict2); + EcmaModule::AddItem(thread_, handleEcmaModuleAddFrom1, handleTagValItemName1, handleTagValItemValue1); + EcmaModule::AddItem(thread_, handleEcmaModuleAddFrom2, handleTagValItemName2, handleTagValItemValue2); + JSHandle handleTaggedValueEcmaModuleAddFrom1(thread_, handleEcmaModuleAddFrom1.GetTaggedValue()); + JSHandle handleTaggedValueEcmaModuleAddFrom2(thread_, handleEcmaModuleAddFrom2.GetTaggedValue()); + + moduleManager->AddModule(handleTagValNameEcmaModuleAdd1, handleTaggedValueEcmaModuleAddFrom1); + moduleManager->AddModule(handleTagValNameEcmaModuleAdd2, handleTaggedValueEcmaModuleAddFrom2); + EXPECT_EQ(JSHandle::Cast(moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd1)) + ->GetItem(thread_, handleTagValItemName1) ->GetNumber(), - int_item_value1); - EXPECT_EQ(JSHandle::Cast(module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add2)) - ->GetItem(thread_, handle_tag_val_item_name2) + intItemValue1); + EXPECT_EQ(JSHandle::Cast(moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd2)) + ->GetItem(thread_, handleTagValItemName2) ->GetNumber(), - int_item_value2); + intItemValue2); - module_manager->RemoveModule(handle_tag_val_name_ecma_module_add1); - EXPECT_TRUE(module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add1)->IsUndefined()); - EXPECT_EQ(JSHandle::Cast(module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add2)) - ->GetItem(thread_, handle_tag_val_item_name2) + moduleManager->RemoveModule(handleTagValNameEcmaModuleAdd1); + EXPECT_TRUE(moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd1)->IsUndefined()); + EXPECT_EQ(JSHandle::Cast(moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd2)) + ->GetItem(thread_, handleTagValItemName2) ->GetNumber(), - int_item_value2); + intItemValue2); - module_manager->RemoveModule(handle_tag_val_name_ecma_module_add2); - EXPECT_TRUE(module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add1)->IsUndefined()); - EXPECT_TRUE(module_manager->GetModule(thread_, handle_tag_val_name_ecma_module_add2)->IsUndefined()); + moduleManager->RemoveModule(handleTagValNameEcmaModuleAdd2); + EXPECT_TRUE(moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd1)->IsUndefined()); + EXPECT_TRUE(moduleManager->GetModule(thread_, handleTagValNameEcmaModuleAdd2)->IsUndefined()); } /* @@ -310,14 +300,14 @@ TEST_F(EcmaModuleTest, ModuleManager_RemoveModule) */ TEST_F(EcmaModuleTest, ModuleManager_SetCurrentExportModuleName) { - ModuleManager *module_manager = thread_->GetEcmaVM()->GetModuleManager(); - - std::string_view str_view_name_ecma_module1 = "NameEcmaModule1"; - std::string_view str_view_name_ecma_module2 = "NameEcmaModule2"; - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module1); - EXPECT_STREQ(module_manager->GetCurrentExportModuleName().c_str(), PandaString(str_view_name_ecma_module1).c_str()); - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module2); - EXPECT_STREQ(module_manager->GetCurrentExportModuleName().c_str(), PandaString(str_view_name_ecma_module2).c_str()); + ModuleManager *moduleManager = thread_->GetEcmaVM()->GetModuleManager(); + + std::string_view strViewNameEcmaModule1 = "NameEcmaModule1"; + std::string_view strViewNameEcmaModule2 = "NameEcmaModule2"; + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule1); + EXPECT_STREQ(moduleManager->GetCurrentExportModuleName().c_str(), PandaString(strViewNameEcmaModule1).c_str()); + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule2); + EXPECT_STREQ(moduleManager->GetCurrentExportModuleName().c_str(), PandaString(strViewNameEcmaModule2).c_str()); } /* @@ -331,16 +321,16 @@ TEST_F(EcmaModuleTest, ModuleManager_SetCurrentExportModuleName) */ TEST_F(EcmaModuleTest, ModuleManager_GetPrevExportModuleName) { - ModuleManager *module_manager = thread_->GetEcmaVM()->GetModuleManager(); - - std::string_view str_view_name_ecma_module1 = "NameEcmaModule1"; - std::string_view str_view_name_ecma_module2 = "NameEcmaModule2"; - std::string_view str_view_name_ecma_module3 = "NameEcmaModule3"; - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module1); - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module2); - EXPECT_STREQ(module_manager->GetPrevExportModuleName().c_str(), PandaString(str_view_name_ecma_module1).c_str()); - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module3); - EXPECT_STREQ(module_manager->GetPrevExportModuleName().c_str(), PandaString(str_view_name_ecma_module2).c_str()); + ModuleManager *moduleManager = thread_->GetEcmaVM()->GetModuleManager(); + + std::string_view strViewNameEcmaModule1 = "NameEcmaModule1"; + std::string_view strViewNameEcmaModule2 = "NameEcmaModule2"; + std::string_view strViewNameEcmaModule3 = "NameEcmaModule3"; + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule1); + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule2); + EXPECT_STREQ(moduleManager->GetPrevExportModuleName().c_str(), PandaString(strViewNameEcmaModule1).c_str()); + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule3); + EXPECT_STREQ(moduleManager->GetPrevExportModuleName().c_str(), PandaString(strViewNameEcmaModule2).c_str()); } /* @@ -355,19 +345,19 @@ TEST_F(EcmaModuleTest, ModuleManager_GetPrevExportModuleName) */ TEST_F(EcmaModuleTest, ModuleManager_RestoreCurrentExportModuleName) { - ModuleManager *module_manager = thread_->GetEcmaVM()->GetModuleManager(); - - std::string_view str_view_name_ecma_module1 = "NameEcmaModule1"; - std::string_view str_view_name_ecma_module2 = "NameEcmaModule2"; - std::string_view str_view_name_ecma_module3 = "NameEcmaModule3"; - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module1); - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module2); - module_manager->SetCurrentExportModuleName(str_view_name_ecma_module3); - EXPECT_STREQ(module_manager->GetCurrentExportModuleName().c_str(), PandaString(str_view_name_ecma_module3).c_str()); - module_manager->RestoreCurrentExportModuleName(); - EXPECT_STREQ(module_manager->GetCurrentExportModuleName().c_str(), PandaString(str_view_name_ecma_module2).c_str()); - module_manager->RestoreCurrentExportModuleName(); - EXPECT_STREQ(module_manager->GetCurrentExportModuleName().c_str(), PandaString(str_view_name_ecma_module1).c_str()); + ModuleManager *moduleManager = thread_->GetEcmaVM()->GetModuleManager(); + + std::string_view strViewNameEcmaModule1 = "NameEcmaModule1"; + std::string_view strViewNameEcmaModule2 = "NameEcmaModule2"; + std::string_view strViewNameEcmaModule3 = "NameEcmaModule3"; + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule1); + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule2); + moduleManager->SetCurrentExportModuleName(strViewNameEcmaModule3); + EXPECT_STREQ(moduleManager->GetCurrentExportModuleName().c_str(), PandaString(strViewNameEcmaModule3).c_str()); + moduleManager->RestoreCurrentExportModuleName(); + EXPECT_STREQ(moduleManager->GetCurrentExportModuleName().c_str(), PandaString(strViewNameEcmaModule2).c_str()); + moduleManager->RestoreCurrentExportModuleName(); + EXPECT_STREQ(moduleManager->GetCurrentExportModuleName().c_str(), PandaString(strViewNameEcmaModule1).c_str()); } /* @@ -382,62 +372,55 @@ TEST_F(EcmaModuleTest, ModuleManager_RestoreCurrentExportModuleName) */ TEST_F(EcmaModuleTest, ModuleManager_AddModuleItem) { - ObjectFactory *obj_factory = thread_->GetEcmaVM()->GetFactory(); - ModuleManager *module_manager = thread_->GetEcmaVM()->GetModuleManager(); + ObjectFactory *objFactory = thread_->GetEcmaVM()->GetFactory(); + ModuleManager *moduleManager = thread_->GetEcmaVM()->GetModuleManager(); constexpr int INT_ITEM_VALUE_11 = 11; constexpr int INT_ITEM_VALUE_12 = 12; constexpr int INT_ITEM_VALUE_21 = 21; constexpr int INT_ITEM_VALUE_22 = 22; - JSHandle handle_tag_val_item_name11(obj_factory->NewFromCanBeCompressString("cStrItemName11")); - JSHandle handle_tag_val_item_name12(obj_factory->NewFromCanBeCompressString("cStrItemName12")); - JSHandle handle_tag_val_item_name21(obj_factory->NewFromCanBeCompressString("cStrItemName21")); - JSHandle handle_tag_val_item_name22(obj_factory->NewFromCanBeCompressString("cStrItemName22")); - JSHandle handle_tag_val_item_value11(thread_, JSTaggedValue(INT_ITEM_VALUE_11)); - JSHandle handle_tag_val_item_value12(thread_, JSTaggedValue(INT_ITEM_VALUE_12)); - JSHandle handle_tag_val_item_value21(thread_, JSTaggedValue(INT_ITEM_VALUE_21)); - JSHandle handle_tag_val_item_value22(thread_, JSTaggedValue(INT_ITEM_VALUE_22)); - JSHandle handle_ecma_str_name_ecma_module1 = obj_factory->NewFromString("cStrNameEcmaModule1"); - JSHandle handle_ecma_str_name_ecma_module2 = obj_factory->NewFromString("cStrNameEcmaModule2"); - std::string std_str_module_file_name1 = JSLocale::ConvertToStdString(handle_ecma_str_name_ecma_module1); - std::string std_str_module_file_name2 = JSLocale::ConvertToStdString(handle_ecma_str_name_ecma_module2); - JSHandle handle_tag_val_ecma_module_name1(handle_ecma_str_name_ecma_module1); - JSHandle handle_tag_val_ecma_module_name2(handle_ecma_str_name_ecma_module2); + JSHandle handleTagValItemName11(objFactory->NewFromCanBeCompressString("cStrItemName11")); + JSHandle handleTagValItemName12(objFactory->NewFromCanBeCompressString("cStrItemName12")); + JSHandle handleTagValItemName21(objFactory->NewFromCanBeCompressString("cStrItemName21")); + JSHandle handleTagValItemName22(objFactory->NewFromCanBeCompressString("cStrItemName22")); + JSHandle handleTagValItemValue11(thread_, JSTaggedValue(INT_ITEM_VALUE_11)); + JSHandle handleTagValItemValue12(thread_, JSTaggedValue(INT_ITEM_VALUE_12)); + JSHandle handleTagValItemValue21(thread_, JSTaggedValue(INT_ITEM_VALUE_21)); + JSHandle handleTagValItemValue22(thread_, JSTaggedValue(INT_ITEM_VALUE_22)); + JSHandle handleEcmaStrNameEcmaModule1 = objFactory->NewFromString("cStrNameEcmaModule1"); + JSHandle handleEcmaStrNameEcmaModule2 = objFactory->NewFromString("cStrNameEcmaModule2"); + std::string stdStrModuleFileName1 = JSLocale::ConvertToStdString(handleEcmaStrNameEcmaModule1); + std::string stdStrModuleFileName2 = JSLocale::ConvertToStdString(handleEcmaStrNameEcmaModule2); + JSHandle handleTagValEcmaModuleName1(handleEcmaStrNameEcmaModule1); + JSHandle handleTagValEcmaModuleName2(handleEcmaStrNameEcmaModule2); // Test when the module is created through 'NewEmptyEcmaModule' function called at TEST_F. - JSHandle handle_ecma_module1(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_tag_val_ecma_module1(thread_, handle_ecma_module1.GetTaggedValue()); - module_manager->AddModule(handle_tag_val_ecma_module_name1, handle_tag_val_ecma_module1); - module_manager->SetCurrentExportModuleName(std_str_module_file_name1); - module_manager->AddModuleItem(thread_, handle_tag_val_item_name11, handle_tag_val_item_value11); - module_manager->AddModuleItem(thread_, handle_tag_val_item_name12, handle_tag_val_item_value12); - - EXPECT_EQ( - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module1, handle_tag_val_item_name11)->GetNumber(), - INT_ITEM_VALUE_11); - EXPECT_EQ( - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module1, handle_tag_val_item_name12)->GetNumber(), - INT_ITEM_VALUE_12); + JSHandle handleEcmaModule1(thread_, EcmaModuleCreate(thread_)); + JSHandle handleTagValEcmaModule1(thread_, handleEcmaModule1.GetTaggedValue()); + moduleManager->AddModule(handleTagValEcmaModuleName1, handleTagValEcmaModule1); + moduleManager->SetCurrentExportModuleName(stdStrModuleFileName1); + moduleManager->AddModuleItem(thread_, handleTagValItemName11, handleTagValItemValue11); + moduleManager->AddModuleItem(thread_, handleTagValItemName12, handleTagValItemValue12); + + EXPECT_EQ(moduleManager->GetModuleItem(thread_, handleTagValEcmaModule1, handleTagValItemName11)->GetNumber(), + INT_ITEM_VALUE_11); + EXPECT_EQ(moduleManager->GetModuleItem(thread_, handleTagValEcmaModule1, handleTagValItemName12)->GetNumber(), + INT_ITEM_VALUE_12); // Test when the module is created through 'NewEmptyEcmaModule' function called at "ecma_module.cpp". - module_manager->SetCurrentExportModuleName(std_str_module_file_name2); - module_manager->AddModuleItem(thread_, handle_tag_val_item_name21, handle_tag_val_item_value21); - module_manager->AddModuleItem(thread_, handle_tag_val_item_name22, handle_tag_val_item_value22); - - JSHandle handle_tag_val_ecma_module2 = - module_manager->GetModule(thread_, handle_tag_val_ecma_module_name2); - EXPECT_EQ( - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module1, handle_tag_val_item_name11)->GetNumber(), - INT_ITEM_VALUE_11); - EXPECT_EQ( - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module1, handle_tag_val_item_name12)->GetNumber(), - INT_ITEM_VALUE_12); - EXPECT_EQ( - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module2, handle_tag_val_item_name21)->GetNumber(), - INT_ITEM_VALUE_21); - EXPECT_EQ( - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module2, handle_tag_val_item_name22)->GetNumber(), - INT_ITEM_VALUE_22); + moduleManager->SetCurrentExportModuleName(stdStrModuleFileName2); + moduleManager->AddModuleItem(thread_, handleTagValItemName21, handleTagValItemValue21); + moduleManager->AddModuleItem(thread_, handleTagValItemName22, handleTagValItemValue22); + + JSHandle handleTagValEcmaModule2 = moduleManager->GetModule(thread_, handleTagValEcmaModuleName2); + EXPECT_EQ(moduleManager->GetModuleItem(thread_, handleTagValEcmaModule1, handleTagValItemName11)->GetNumber(), + INT_ITEM_VALUE_11); + EXPECT_EQ(moduleManager->GetModuleItem(thread_, handleTagValEcmaModule1, handleTagValItemName12)->GetNumber(), + INT_ITEM_VALUE_12); + EXPECT_EQ(moduleManager->GetModuleItem(thread_, handleTagValEcmaModule2, handleTagValItemName21)->GetNumber(), + INT_ITEM_VALUE_21); + EXPECT_EQ(moduleManager->GetModuleItem(thread_, handleTagValEcmaModule2, handleTagValItemName22)->GetNumber(), + INT_ITEM_VALUE_22); } /* @@ -452,66 +435,58 @@ TEST_F(EcmaModuleTest, ModuleManager_AddModuleItem) */ TEST_F(EcmaModuleTest, ModuleManager_CopyModule) { - ObjectFactory *obj_factory = thread_->GetEcmaVM()->GetFactory(); - ModuleManager *module_manager = thread_->GetEcmaVM()->GetModuleManager(); + ObjectFactory *objFactory = thread_->GetEcmaVM()->GetFactory(); + ModuleManager *moduleManager = thread_->GetEcmaVM()->GetModuleManager(); constexpr int INT_ITEM_VALUE_11 = 11; constexpr int INT_ITEM_VALUE_12 = 12; constexpr int INT_ITEM_VALUE_21 = 21; constexpr int INT_ITEM_VALUE_22 = 22; - std::string_view file_name_ecma_module_copy_to1 = "fileNameEcmaModuleCopyTo1"; - std::string_view file_name_ecma_module_copy_to2 = "fileNameEcmaModuleCopyTo2"; - JSHandle handle_tag_val_item_name11(obj_factory->NewFromCanBeCompressString("ItemName11")); - JSHandle handle_tag_val_item_name12(obj_factory->NewFromCanBeCompressString("ItemName12")); - JSHandle handle_tag_val_item_name21(obj_factory->NewFromCanBeCompressString("ItemName21")); - JSHandle handle_tag_val_item_name22(obj_factory->NewFromCanBeCompressString("ItemName22")); - JSHandle handle_tag_val_item_value11(thread_, JSTaggedValue(INT_ITEM_VALUE_11)); - JSHandle handle_tag_val_item_value12(thread_, JSTaggedValue(INT_ITEM_VALUE_12)); - JSHandle handle_tag_val_item_value21(thread_, JSTaggedValue(INT_ITEM_VALUE_21)); - JSHandle handle_tag_val_item_value22(thread_, JSTaggedValue(INT_ITEM_VALUE_22)); - JSHandle handle_ecma_module_copy_from1(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_ecma_module_copy_from2(thread_, EcmaModuleCreate(thread_)); - JSHandle handle_tag_val_ecma_module_copy_from1(thread_, - handle_ecma_module_copy_from1.GetTaggedValue()); - JSHandle handle_tag_val_ecma_module_copy_from2(thread_, - handle_ecma_module_copy_from2.GetTaggedValue()); - EcmaModule::AddItem(thread_, handle_ecma_module_copy_from1, handle_tag_val_item_name11, - handle_tag_val_item_value11); - EcmaModule::AddItem(thread_, handle_ecma_module_copy_from1, handle_tag_val_item_name12, - handle_tag_val_item_value12); - EcmaModule::AddItem(thread_, handle_ecma_module_copy_from2, handle_tag_val_item_name21, - handle_tag_val_item_value21); - EcmaModule::AddItem(thread_, handle_ecma_module_copy_from2, handle_tag_val_item_name22, - handle_tag_val_item_value22); - - module_manager->SetCurrentExportModuleName(file_name_ecma_module_copy_to1); - module_manager->CopyModule(thread_, handle_tag_val_ecma_module_copy_from1); - JSHandle handle_tag_val_ecma_module_copy_to1 = module_manager->GetModule( - thread_, - JSHandle::Cast(obj_factory->NewFromString(PandaString(file_name_ecma_module_copy_to1)))); - EXPECT_EQ(INT_ITEM_VALUE_11, - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name11) - ->GetNumber()); - EXPECT_EQ(INT_ITEM_VALUE_12, - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name12) - ->GetNumber()); - - module_manager->SetCurrentExportModuleName(file_name_ecma_module_copy_to2); - module_manager->CopyModule(thread_, handle_tag_val_ecma_module_copy_from2); - JSHandle handle_tag_val_ecma_module_copy_to2 = module_manager->GetModule( - thread_, - JSHandle::Cast(obj_factory->NewFromString(PandaString(file_name_ecma_module_copy_to2)))); - EXPECT_EQ(INT_ITEM_VALUE_11, - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name11) - ->GetNumber()); - EXPECT_EQ(INT_ITEM_VALUE_12, - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name12) - ->GetNumber()); - EXPECT_EQ(INT_ITEM_VALUE_21, - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module_copy_to2, handle_tag_val_item_name21) - ->GetNumber()); - EXPECT_EQ(INT_ITEM_VALUE_22, - module_manager->GetModuleItem(thread_, handle_tag_val_ecma_module_copy_to2, handle_tag_val_item_name22) - ->GetNumber()); + std::string_view fileNameEcmaModuleCopyTo1 = "fileNameEcmaModuleCopyTo1"; + std::string_view fileNameEcmaModuleCopyTo2 = "fileNameEcmaModuleCopyTo2"; + JSHandle handleTagValItemName11(objFactory->NewFromCanBeCompressString("ItemName11")); + JSHandle handleTagValItemName12(objFactory->NewFromCanBeCompressString("ItemName12")); + JSHandle handleTagValItemName21(objFactory->NewFromCanBeCompressString("ItemName21")); + JSHandle handleTagValItemName22(objFactory->NewFromCanBeCompressString("ItemName22")); + JSHandle handleTagValItemValue11(thread_, JSTaggedValue(INT_ITEM_VALUE_11)); + JSHandle handleTagValItemValue12(thread_, JSTaggedValue(INT_ITEM_VALUE_12)); + JSHandle handleTagValItemValue21(thread_, JSTaggedValue(INT_ITEM_VALUE_21)); + JSHandle handleTagValItemValue22(thread_, JSTaggedValue(INT_ITEM_VALUE_22)); + JSHandle handleEcmaModuleCopyFrom1(thread_, EcmaModuleCreate(thread_)); + JSHandle handleEcmaModuleCopyFrom2(thread_, EcmaModuleCreate(thread_)); + JSHandle handleTagValEcmaModuleCopyFrom1(thread_, handleEcmaModuleCopyFrom1.GetTaggedValue()); + JSHandle handleTagValEcmaModuleCopyFrom2(thread_, handleEcmaModuleCopyFrom2.GetTaggedValue()); + EcmaModule::AddItem(thread_, handleEcmaModuleCopyFrom1, handleTagValItemName11, handleTagValItemValue11); + EcmaModule::AddItem(thread_, handleEcmaModuleCopyFrom1, handleTagValItemName12, handleTagValItemValue12); + EcmaModule::AddItem(thread_, handleEcmaModuleCopyFrom2, handleTagValItemName21, handleTagValItemValue21); + EcmaModule::AddItem(thread_, handleEcmaModuleCopyFrom2, handleTagValItemName22, handleTagValItemValue22); + + moduleManager->SetCurrentExportModuleName(fileNameEcmaModuleCopyTo1); + moduleManager->CopyModule(thread_, handleTagValEcmaModuleCopyFrom1); + JSHandle handleTagValEcmaModuleCopyTo1 = moduleManager->GetModule( + thread_, JSHandle::Cast(objFactory->NewFromString(PandaString(fileNameEcmaModuleCopyTo1)))); + EXPECT_EQ( + INT_ITEM_VALUE_11, + moduleManager->GetModuleItem(thread_, handleTagValEcmaModuleCopyTo1, handleTagValItemName11)->GetNumber()); + EXPECT_EQ( + INT_ITEM_VALUE_12, + moduleManager->GetModuleItem(thread_, handleTagValEcmaModuleCopyTo1, handleTagValItemName12)->GetNumber()); + + moduleManager->SetCurrentExportModuleName(fileNameEcmaModuleCopyTo2); + moduleManager->CopyModule(thread_, handleTagValEcmaModuleCopyFrom2); + JSHandle handleTagValEcmaModuleCopyTo2 = moduleManager->GetModule( + thread_, JSHandle::Cast(objFactory->NewFromString(PandaString(fileNameEcmaModuleCopyTo2)))); + EXPECT_EQ( + INT_ITEM_VALUE_11, + moduleManager->GetModuleItem(thread_, handleTagValEcmaModuleCopyTo1, handleTagValItemName11)->GetNumber()); + EXPECT_EQ( + INT_ITEM_VALUE_12, + moduleManager->GetModuleItem(thread_, handleTagValEcmaModuleCopyTo1, handleTagValItemName12)->GetNumber()); + EXPECT_EQ( + INT_ITEM_VALUE_21, + moduleManager->GetModuleItem(thread_, handleTagValEcmaModuleCopyTo2, handleTagValItemName21)->GetNumber()); + EXPECT_EQ( + INT_ITEM_VALUE_22, + moduleManager->GetModuleItem(thread_, handleTagValEcmaModuleCopyTo2, handleTagValItemName22)->GetNumber()); } } // namespace panda::test diff --git a/tests/runtime/common/ecma_string_test.cpp b/tests/runtime/common/ecma_string_test.cpp index c06984c1113c28853d5bd8d9e31d403a4f2bd5fd..b45d1b26ea57b15fba69ea6c227adc52f5db3192 100644 --- a/tests/runtime/common/ecma_string_test.cpp +++ b/tests/runtime/common/ecma_string_test.cpp @@ -79,15 +79,15 @@ TEST_F(EcmaStringTest, SetCompressedStringsEnabled) */ TEST_F(EcmaStringTest, CanBeCompressed) { - uint8_t array_u8[] = {12, 34, 77, 127, 99, 1}; - uint16_t array_u16_comp[] = {1, 4, 37, 91, 127, 1}; - uint16_t array_u16_not_comp[] = {72, 43, 337, 961, 1317, 65535}; - EXPECT_TRUE(EcmaString::CanBeCompressed(array_u8, sizeof(array_u8) / sizeof(array_u8[0]))); - EXPECT_TRUE(EcmaString::CanBeCompressed(array_u16_comp, sizeof(array_u16_comp) / sizeof(array_u16_comp[0]))); - EXPECT_FALSE(EcmaString::CanBeCompressed(array_u16_not_comp, sizeof(array_u16_comp) / sizeof(array_u16_comp[0]))); + uint8_t arrayU8[] = {12, 34, 77, 127, 99, 1}; + uint16_t arrayU16Comp[] = {1, 4, 37, 91, 127, 1}; + uint16_t arrayU16NotComp[] = {72, 43, 337, 961, 1317, 65535}; + EXPECT_TRUE(EcmaString::CanBeCompressed(arrayU8, sizeof(arrayU8) / sizeof(arrayU8[0]))); + EXPECT_TRUE(EcmaString::CanBeCompressed(arrayU16Comp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]))); + EXPECT_FALSE(EcmaString::CanBeCompressed(arrayU16NotComp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]))); EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - EXPECT_FALSE(EcmaString::CanBeCompressed(array_u16_not_comp, sizeof(array_u16_comp) / sizeof(array_u16_comp[0]))); + EXPECT_FALSE(EcmaString::CanBeCompressed(arrayU16NotComp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]))); /* Set compressed_strings_enabled_ default, because it is a static boolean that some other functions rely on.The * foll- owing TEST_F will come to an unexpected result if we do not set it default in the end of this TEST_F. */ @@ -103,17 +103,17 @@ TEST_F(EcmaStringTest, CanBeCompressed) */ TEST_F(EcmaStringTest, CreateEmptyString) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); - JSHandle handle_ecma_str_empty(thread_, EcmaString::CreateEmptyString(ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_empty->GetLength(), 0); - EXPECT_TRUE(handle_ecma_str_empty->IsUtf8()); - EXPECT_FALSE(handle_ecma_str_empty->IsUtf16()); + JSHandle handleEcmaStrEmpty(thread_, EcmaString::CreateEmptyString(ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrEmpty->GetLength(), 0); + EXPECT_TRUE(handleEcmaStrEmpty->IsUtf8()); + EXPECT_FALSE(handleEcmaStrEmpty->IsUtf16()); EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - JSHandle handle_ecma_str_empty_disable_comp(thread_, EcmaString::CreateEmptyString(ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_empty_disable_comp->GetLength(), 0); - EXPECT_TRUE(handle_ecma_str_empty_disable_comp->IsUtf16()); + JSHandle handleEcmaStrEmptyDisableComp(thread_, EcmaString::CreateEmptyString(ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrEmptyDisableComp->GetLength(), 0); + EXPECT_TRUE(handleEcmaStrEmptyDisableComp->IsUtf16()); EcmaString::SetCompressedStringsEnabled(true); // Set compressed_strings_enabled_ true(default). } @@ -126,33 +126,32 @@ TEST_F(EcmaStringTest, CreateEmptyString) */ TEST_F(EcmaStringTest, AllocStringObject) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // AllocStringObject( , true, ). - size_t size_alloc_comp = 5; - JSHandle handle_ecma_str_alloc_comp(thread_, - EcmaString::AllocStringObject(size_alloc_comp, true, ecma_vm_ptr)); - for (size_t i = 0; i < size_alloc_comp; i++) { - EXPECT_EQ(handle_ecma_str_alloc_comp->At(i), 0); + size_t sizeAllocComp = 5; + JSHandle handleEcmaStrAllocComp(thread_, EcmaString::AllocStringObject(sizeAllocComp, true, ecmaVmPtr)); + for (size_t i = 0; i < sizeAllocComp; i++) { + EXPECT_EQ(handleEcmaStrAllocComp->At(i), 0); } - EXPECT_EQ(handle_ecma_str_alloc_comp->GetLength(), size_alloc_comp); - EXPECT_TRUE(handle_ecma_str_alloc_comp->IsUtf8()); - EXPECT_FALSE(handle_ecma_str_alloc_comp->IsUtf16()); + EXPECT_EQ(handleEcmaStrAllocComp->GetLength(), sizeAllocComp); + EXPECT_TRUE(handleEcmaStrAllocComp->IsUtf8()); + EXPECT_FALSE(handleEcmaStrAllocComp->IsUtf16()); // AllocStringObject( , false, ). - size_t size_alloc_not_comp = 5; - JSHandle handle_ecma_str_alloc_not_comp( - thread_, EcmaString::AllocStringObject(size_alloc_not_comp, false, ecma_vm_ptr)); - for (size_t i = 0; i < size_alloc_not_comp; i++) { - EXPECT_EQ(handle_ecma_str_alloc_not_comp->At(i), 0); + size_t sizeAllocNotComp = 5; + JSHandle handleEcmaStrAllocNotComp(thread_, + EcmaString::AllocStringObject(sizeAllocNotComp, false, ecmaVmPtr)); + for (size_t i = 0; i < sizeAllocNotComp; i++) { + EXPECT_EQ(handleEcmaStrAllocNotComp->At(i), 0); } - EXPECT_EQ(handle_ecma_str_alloc_not_comp->GetLength(), size_alloc_not_comp); - EXPECT_FALSE(handle_ecma_str_alloc_not_comp->IsUtf8()); - EXPECT_TRUE(handle_ecma_str_alloc_not_comp->IsUtf16()); + EXPECT_EQ(handleEcmaStrAllocNotComp->GetLength(), sizeAllocNotComp); + EXPECT_FALSE(handleEcmaStrAllocNotComp->IsUtf8()); + EXPECT_TRUE(handleEcmaStrAllocNotComp->IsUtf16()); EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - JSHandle handle_ecma_str_alloc_not_comp_disable_comp( - thread_, EcmaString::AllocStringObject(size_alloc_not_comp, false, ecma_vm_ptr)); - EXPECT_TRUE(handle_ecma_str_alloc_not_comp_disable_comp->IsUtf16()); + JSHandle handleEcmaStrAllocNotCompDisableComp( + thread_, EcmaString::AllocStringObject(sizeAllocNotComp, false, ecmaVmPtr)); + EXPECT_TRUE(handleEcmaStrAllocNotCompDisableComp->IsUtf16()); EcmaString::SetCompressedStringsEnabled(true); // Set compressed_strings_enabled_ true(default). } @@ -164,17 +163,17 @@ TEST_F(EcmaStringTest, AllocStringObject) */ TEST_F(EcmaStringTest, CreateFromUtf8) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); - uint8_t array_u8[] = {"xyz123!@#"}; - size_t length_ecma_str_u8 = sizeof(array_u8) - 1; - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - for (size_t i = 0; i < length_ecma_str_u8; i++) { - EXPECT_EQ(array_u8[i], handle_ecma_str_u8->At(i)); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); + uint8_t arrayU8[] = {"xyz123!@#"}; + size_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + for (size_t i = 0; i < lengthEcmaStrU8; i++) { + EXPECT_EQ(arrayU8[i], handleEcmaStrU8->At(i)); } - EXPECT_EQ(handle_ecma_str_u8->GetLength(), length_ecma_str_u8); - EXPECT_TRUE(handle_ecma_str_u8->IsUtf8()); - EXPECT_FALSE(handle_ecma_str_u8->IsUtf16()); + EXPECT_EQ(handleEcmaStrU8->GetLength(), lengthEcmaStrU8); + EXPECT_TRUE(handleEcmaStrU8->IsUtf8()); + EXPECT_FALSE(handleEcmaStrU8->IsUtf16()); } /* @@ -186,29 +185,29 @@ TEST_F(EcmaStringTest, CreateFromUtf8) */ TEST_F(EcmaStringTest, CreateFromUtf16) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // CreateFromUtf16( , , , true). - uint16_t array_u16_comp[] = {1, 23, 45, 67, 127}; - size_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - EXPECT_EQ(handle_ecma_str_u16_comp->GetLength(), length_ecma_str_u16_comp); - EXPECT_TRUE(handle_ecma_str_u16_comp->IsUtf8()); - EXPECT_FALSE(handle_ecma_str_u16_comp->IsUtf16()); + uint16_t arrayU16Comp[] = {1, 23, 45, 67, 127}; + size_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + EXPECT_EQ(handleEcmaStrU16Comp->GetLength(), lengthEcmaStrU16Comp); + EXPECT_TRUE(handleEcmaStrU16Comp->IsUtf8()); + EXPECT_FALSE(handleEcmaStrU16Comp->IsUtf16()); // CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp[] = {127, 33, 128, 12, 256, 11100, 65535}; - size_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u16_not_comp->GetLength(), length_ecma_str_u16_not_comp); - EXPECT_FALSE(handle_ecma_str_u16_not_comp->IsUtf8()); - EXPECT_TRUE(handle_ecma_str_u16_not_comp->IsUtf16()); + uint16_t arrayU16NotComp[] = {127, 33, 128, 12, 256, 11100, 65535}; + size_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU16NotComp->GetLength(), lengthEcmaStrU16NotComp); + EXPECT_FALSE(handleEcmaStrU16NotComp->IsUtf8()); + EXPECT_TRUE(handleEcmaStrU16NotComp->IsUtf16()); EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - JSHandle handle_ecma_str_u16_not_comp_disable_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_TRUE(handle_ecma_str_u16_not_comp_disable_comp->IsUtf16()); + JSHandle handleEcmaStrU16NotCompDisableComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_TRUE(handleEcmaStrU16NotCompDisableComp->IsUtf16()); EcmaString::SetCompressedStringsEnabled(true); // Set compressed_strings_enabled_ true(default). } @@ -265,43 +264,40 @@ TEST_F(EcmaStringTest, ComputeSizeUtf16) */ TEST_F(EcmaStringTest, ObjectSize) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); - JSHandle handle_ecma_str_empty(thread_, EcmaString::CreateEmptyString(ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_empty->ObjectSize(), EcmaString::SIZE + 0); + JSHandle handleEcmaStrEmpty(thread_, EcmaString::CreateEmptyString(ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrEmpty->ObjectSize(), EcmaString::SIZE + 0); - size_t length_ecma_str_alloc_comp = 5; - JSHandle handle_ecma_str_alloc_comp( - thread_, EcmaString::AllocStringObject(length_ecma_str_alloc_comp, true, ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_alloc_comp->ObjectSize(), - EcmaString::SIZE + sizeof(uint8_t) * length_ecma_str_alloc_comp); + size_t lengthEcmaStrAllocComp = 5; + JSHandle handleEcmaStrAllocComp(thread_, + EcmaString::AllocStringObject(lengthEcmaStrAllocComp, true, ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrAllocComp->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrAllocComp); - size_t length_ecma_str_alloc_not_comp = 5; - JSHandle handle_ecma_str_alloc_not_comp( - thread_, EcmaString::AllocStringObject(length_ecma_str_alloc_not_comp, false, ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_alloc_not_comp->ObjectSize(), - EcmaString::SIZE + sizeof(uint16_t) * length_ecma_str_alloc_not_comp); + size_t lengthEcmaStrAllocNotComp = 5; + JSHandle handleEcmaStrAllocNotComp( + thread_, EcmaString::AllocStringObject(lengthEcmaStrAllocNotComp, false, ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrAllocNotComp->ObjectSize(), EcmaString::SIZE + sizeof(uint16_t) * lengthEcmaStrAllocNotComp); - uint8_t array_u8[] = {"abcde"}; - size_t length_ecma_str_u8 = sizeof(array_u8) - 1; - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - EXPECT_EQ(handle_ecma_str_u8->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * length_ecma_str_u8); + uint8_t arrayU8[] = {"abcde"}; + size_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + EXPECT_EQ(handleEcmaStrU8->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrU8); // ObjectSize(). EcmaString made by CreateFromUtf16( , , , true). - uint16_t array_u16_comp[] = {1, 23, 45, 67, 127}; - size_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - EXPECT_EQ(handle_ecma_str_u16_comp->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * length_ecma_str_u16_comp); + uint16_t arrayU16Comp[] = {1, 23, 45, 67, 127}; + size_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + EXPECT_EQ(handleEcmaStrU16Comp->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrU16Comp); // ObjectSize(). EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp[] = {127, 128, 256, 11100, 65535}; - size_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u16_not_comp->ObjectSize(), - EcmaString::SIZE + sizeof(uint16_t) * length_ecma_str_u16_not_comp); + uint16_t arrayU16NotComp[] = {127, 128, 256, 11100, 65535}; + size_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU16NotComp->ObjectSize(), EcmaString::SIZE + sizeof(uint16_t) * lengthEcmaStrU16NotComp); } /* @@ -313,25 +309,25 @@ TEST_F(EcmaStringTest, ObjectSize) */ TEST_F(EcmaStringTest, Compare_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Compare(). Between EcmaStrings made by CreateFromUtf8(). - uint8_t array_u8_no1[3] = {1, 23}; - uint8_t array_u8_no2[4] = {1, 23, 49}; - uint8_t array_u8_no3[6] = {1, 23, 45, 97, 127}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u8_no2 = sizeof(array_u8_no2) - 1; - uint32_t length_ecma_str_u8_no3 = sizeof(array_u8_no3) - 1; - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no2( - thread_, EcmaString::CreateFromUtf8(&array_u8_no2[0], length_ecma_str_u8_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no3( - thread_, EcmaString::CreateFromUtf8(&array_u8_no3[0], length_ecma_str_u8_no3, ecma_vm_ptr, true)); - EXPECT_EQ(handle_ecma_str_u8_no1->Compare(*handle_ecma_str_u8_no2), -1); - EXPECT_EQ(handle_ecma_str_u8_no2->Compare(*handle_ecma_str_u8_no1), 1); - EXPECT_EQ(handle_ecma_str_u8_no2->Compare(*handle_ecma_str_u8_no3), 49 - 45); - EXPECT_EQ(handle_ecma_str_u8_no3->Compare(*handle_ecma_str_u8_no2), 45 - 49); + uint8_t arrayU8No1[3] = {1, 23}; + uint8_t arrayU8No2[4] = {1, 23, 49}; + uint8_t arrayU8No3[6] = {1, 23, 45, 97, 127}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1; + uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1; + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No2( + thread_, EcmaString::CreateFromUtf8(&arrayU8No2[0], lengthEcmaStrU8No2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No3( + thread_, EcmaString::CreateFromUtf8(&arrayU8No3[0], lengthEcmaStrU8No3, ecmaVmPtr, true)); + EXPECT_EQ(handleEcmaStrU8No1->Compare(*handleEcmaStrU8No2), -1); + EXPECT_EQ(handleEcmaStrU8No2->Compare(*handleEcmaStrU8No1), 1); + EXPECT_EQ(handleEcmaStrU8No2->Compare(*handleEcmaStrU8No3), 49 - 45); + EXPECT_EQ(handleEcmaStrU8No3->Compare(*handleEcmaStrU8No2), 45 - 49); } /* @@ -343,25 +339,25 @@ TEST_F(EcmaStringTest, Compare_001) */ TEST_F(EcmaStringTest, Compare_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Compare(). Between EcmaStrings made by CreateFromUtf16( , , , true). - uint16_t array_u16_comp_no1[] = {1, 23}; - uint16_t array_u16_comp_no2[] = {1, 23, 49}; - uint16_t array_u16_comp_no3[] = {1, 23, 45, 97, 127}; - uint32_t length_ecma_str_u16_comp_no1 = sizeof(array_u16_comp_no1) / sizeof(array_u16_comp_no1[0]); - uint32_t length_ecma_str_u16_comp_no2 = sizeof(array_u16_comp_no2) / sizeof(array_u16_comp_no2[0]); - uint32_t length_ecma_str_u16_comp_no3 = sizeof(array_u16_comp_no3) / sizeof(array_u16_comp_no3[0]); - JSHandle handle_ecma_str_u16_comp_no1( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no1[0], length_ecma_str_u16_comp_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no2( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no2[0], length_ecma_str_u16_comp_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no3( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no3[0], length_ecma_str_u16_comp_no3, ecma_vm_ptr, true)); - EXPECT_EQ(handle_ecma_str_u16_comp_no1->Compare(*handle_ecma_str_u16_comp_no2), -1); - EXPECT_EQ(handle_ecma_str_u16_comp_no2->Compare(*handle_ecma_str_u16_comp_no1), 1); - EXPECT_EQ(handle_ecma_str_u16_comp_no2->Compare(*handle_ecma_str_u16_comp_no3), 49 - 45); - EXPECT_EQ(handle_ecma_str_u16_comp_no3->Compare(*handle_ecma_str_u16_comp_no2), 45 - 49); + uint16_t arrayU16CompNo1[] = {1, 23}; + uint16_t arrayU16CompNo2[] = {1, 23, 49}; + uint16_t arrayU16CompNo3[] = {1, 23, 45, 97, 127}; + uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]); + uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]); + uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]); + JSHandle handleEcmaStrU16CompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, ecmaVmPtr, true)); + EXPECT_EQ(handleEcmaStrU16CompNo1->Compare(*handleEcmaStrU16CompNo2), -1); + EXPECT_EQ(handleEcmaStrU16CompNo2->Compare(*handleEcmaStrU16CompNo1), 1); + EXPECT_EQ(handleEcmaStrU16CompNo2->Compare(*handleEcmaStrU16CompNo3), 49 - 45); + EXPECT_EQ(handleEcmaStrU16CompNo3->Compare(*handleEcmaStrU16CompNo2), 45 - 49); } /* @@ -374,35 +370,35 @@ TEST_F(EcmaStringTest, Compare_002) */ TEST_F(EcmaStringTest, Compare_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Compare(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , true). - uint8_t array_u8_no1[3] = {1, 23}; - uint8_t array_u8_no2[4] = {1, 23, 49}; - uint16_t array_u16_comp_no1[] = {1, 23}; - uint16_t array_u16_comp_no2[] = {1, 23, 49}; - uint16_t array_u16_comp_no3[] = {1, 23, 45, 97, 127}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u8_no2 = sizeof(array_u8_no2) - 1; - uint32_t length_ecma_str_u16_comp_no1 = sizeof(array_u16_comp_no1) / sizeof(array_u16_comp_no1[0]); - uint32_t length_ecma_str_u16_comp_no2 = sizeof(array_u16_comp_no2) / sizeof(array_u16_comp_no2[0]); - uint32_t length_ecma_str_u16_comp_no3 = sizeof(array_u16_comp_no3) / sizeof(array_u16_comp_no3[0]); - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no2( - thread_, EcmaString::CreateFromUtf8(&array_u8_no2[0], length_ecma_str_u8_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no1( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no1[0], length_ecma_str_u16_comp_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no2( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no2[0], length_ecma_str_u16_comp_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no3( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no3[0], length_ecma_str_u16_comp_no3, ecma_vm_ptr, true)); - EXPECT_EQ(handle_ecma_str_u8_no1->Compare(*handle_ecma_str_u16_comp_no1), 0); - EXPECT_EQ(handle_ecma_str_u16_comp_no1->Compare(*handle_ecma_str_u8_no1), 0); - EXPECT_EQ(handle_ecma_str_u8_no1->Compare(*handle_ecma_str_u16_comp_no2), -1); - EXPECT_EQ(handle_ecma_str_u16_comp_no2->Compare(*handle_ecma_str_u8_no1), 1); - EXPECT_EQ(handle_ecma_str_u8_no2->Compare(*handle_ecma_str_u16_comp_no3), 49 - 45); - EXPECT_EQ(handle_ecma_str_u16_comp_no3->Compare(*handle_ecma_str_u8_no2), 45 - 49); + uint8_t arrayU8No1[3] = {1, 23}; + uint8_t arrayU8No2[4] = {1, 23, 49}; + uint16_t arrayU16CompNo1[] = {1, 23}; + uint16_t arrayU16CompNo2[] = {1, 23, 49}; + uint16_t arrayU16CompNo3[] = {1, 23, 45, 97, 127}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1; + uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]); + uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]); + uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]); + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No2( + thread_, EcmaString::CreateFromUtf8(&arrayU8No2[0], lengthEcmaStrU8No2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, ecmaVmPtr, true)); + EXPECT_EQ(handleEcmaStrU8No1->Compare(*handleEcmaStrU16CompNo1), 0); + EXPECT_EQ(handleEcmaStrU16CompNo1->Compare(*handleEcmaStrU8No1), 0); + EXPECT_EQ(handleEcmaStrU8No1->Compare(*handleEcmaStrU16CompNo2), -1); + EXPECT_EQ(handleEcmaStrU16CompNo2->Compare(*handleEcmaStrU8No1), 1); + EXPECT_EQ(handleEcmaStrU8No2->Compare(*handleEcmaStrU16CompNo3), 49 - 45); + EXPECT_EQ(handleEcmaStrU16CompNo3->Compare(*handleEcmaStrU8No2), 45 - 49); } /* @@ -414,28 +410,25 @@ TEST_F(EcmaStringTest, Compare_003) */ TEST_F(EcmaStringTest, Compare_004) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Compare(). Between EcmaStrings made by CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp_no1[] = {1, 23}; - uint16_t array_u16_not_comp_no2[] = {1, 23, 49}; - uint16_t array_u16_not_comp_no3[] = {1, 23, 456, 6789, 65535, 127}; - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - uint32_t length_ecma_str_u16_not_comp_no2 = sizeof(array_u16_not_comp_no2) / sizeof(array_u16_not_comp_no2[0]); - uint32_t length_ecma_str_u16_not_comp_no3 = sizeof(array_u16_not_comp_no3) / sizeof(array_u16_not_comp_no3[0]); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no2( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no2[0], length_ecma_str_u16_not_comp_no2, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no3( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no3[0], length_ecma_str_u16_not_comp_no3, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no1->Compare(*handle_ecma_str_u16_not_comp_no2), -1); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no2->Compare(*handle_ecma_str_u16_not_comp_no1), 1); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no2->Compare(*handle_ecma_str_u16_not_comp_no3), 49 - 456); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no3->Compare(*handle_ecma_str_u16_not_comp_no2), 456 - 49); + uint16_t arrayU16NotCompNo1[] = {1, 23}; + uint16_t arrayU16NotCompNo2[] = {1, 23, 49}; + uint16_t arrayU16NotCompNo3[] = {1, 23, 456, 6789, 65535, 127}; + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]); + uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU16NotCompNo1->Compare(*handleEcmaStrU16NotCompNo2), -1); + EXPECT_EQ(handleEcmaStrU16NotCompNo2->Compare(*handleEcmaStrU16NotCompNo1), 1); + EXPECT_EQ(handleEcmaStrU16NotCompNo2->Compare(*handleEcmaStrU16NotCompNo3), 49 - 456); + EXPECT_EQ(handleEcmaStrU16NotCompNo3->Compare(*handleEcmaStrU16NotCompNo2), 456 - 49); } /* @@ -447,38 +440,35 @@ TEST_F(EcmaStringTest, Compare_004) */ TEST_F(EcmaStringTest, Compare_005) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Compare(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , false). - uint8_t array_u8_no1[3] = {1, 23}; - uint8_t array_u8_no2[4] = {1, 23, 49}; - uint16_t array_u16_not_comp_no1[] = {1, 23}; - uint16_t array_u16_not_comp_no2[] = {1, 23, 49}; - uint16_t array_u16_not_comp_no3[] = {1, 23, 456, 6789, 65535, 127}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u8_no2 = sizeof(array_u8_no2) - 1; - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - uint32_t length_ecma_str_u16_not_comp_no2 = sizeof(array_u16_not_comp_no2) / sizeof(array_u16_not_comp_no2[0]); - uint32_t length_ecma_str_u16_not_comp_no3 = sizeof(array_u16_not_comp_no3) / sizeof(array_u16_not_comp_no3[0]); - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no2( - thread_, EcmaString::CreateFromUtf8(&array_u8_no2[0], length_ecma_str_u8_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no2( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no2[0], length_ecma_str_u16_not_comp_no2, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no3( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no3[0], length_ecma_str_u16_not_comp_no3, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u8_no1->Compare(*handle_ecma_str_u16_not_comp_no1), 0); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no1->Compare(*handle_ecma_str_u8_no1), 0); - EXPECT_EQ(handle_ecma_str_u8_no1->Compare(*handle_ecma_str_u16_not_comp_no2), -1); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no2->Compare(*handle_ecma_str_u8_no1), 1); - EXPECT_EQ(handle_ecma_str_u8_no2->Compare(*handle_ecma_str_u16_not_comp_no3), 49 - 456); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no3->Compare(*handle_ecma_str_u8_no2), 456 - 49); + uint8_t arrayU8No1[3] = {1, 23}; + uint8_t arrayU8No2[4] = {1, 23, 49}; + uint16_t arrayU16NotCompNo1[] = {1, 23}; + uint16_t arrayU16NotCompNo2[] = {1, 23, 49}; + uint16_t arrayU16NotCompNo3[] = {1, 23, 456, 6789, 65535, 127}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1; + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]); + uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]); + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No2( + thread_, EcmaString::CreateFromUtf8(&arrayU8No2[0], lengthEcmaStrU8No2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU8No1->Compare(*handleEcmaStrU16NotCompNo1), 0); + EXPECT_EQ(handleEcmaStrU16NotCompNo1->Compare(*handleEcmaStrU8No1), 0); + EXPECT_EQ(handleEcmaStrU8No1->Compare(*handleEcmaStrU16NotCompNo2), -1); + EXPECT_EQ(handleEcmaStrU16NotCompNo2->Compare(*handleEcmaStrU8No1), 1); + EXPECT_EQ(handleEcmaStrU8No2->Compare(*handleEcmaStrU16NotCompNo3), 49 - 456); + EXPECT_EQ(handleEcmaStrU16NotCompNo3->Compare(*handleEcmaStrU8No2), 456 - 49); } /* @@ -490,38 +480,35 @@ TEST_F(EcmaStringTest, Compare_005) */ TEST_F(EcmaStringTest, Compare_006) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Compare(). EcmaString made by CreateFromUtf16( , , , true) and EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_u16_comp_no1[] = {1, 23}; - uint16_t array_u16_comp_no2[] = {1, 23, 49}; - uint16_t array_u16_not_comp_no1[] = {1, 23}; - uint16_t array_u16_not_comp_no2[] = {1, 23, 49}; - uint16_t array_u16_not_comp_no3[] = {1, 23, 456, 6789, 65535, 127}; - uint32_t length_ecma_str_u16_comp_no1 = sizeof(array_u16_comp_no1) / sizeof(array_u16_comp_no1[0]); - uint32_t length_ecma_str_u16_comp_no2 = sizeof(array_u16_comp_no2) / sizeof(array_u16_comp_no2[0]); - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - uint32_t length_ecma_str_u16_not_comp_no2 = sizeof(array_u16_not_comp_no2) / sizeof(array_u16_not_comp_no2[0]); - uint32_t length_ecma_str_u16_not_comp_no3 = sizeof(array_u16_not_comp_no3) / sizeof(array_u16_not_comp_no3[0]); - JSHandle handle_ecma_str_u16_comp_no1( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no1[0], length_ecma_str_u16_comp_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no2( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no2[0], length_ecma_str_u16_comp_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no2( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no2[0], length_ecma_str_u16_not_comp_no2, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no3( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no3[0], length_ecma_str_u16_not_comp_no3, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u16_comp_no1->Compare(*handle_ecma_str_u16_not_comp_no1), 0); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no1->Compare(*handle_ecma_str_u16_comp_no1), 0); - EXPECT_EQ(handle_ecma_str_u16_comp_no1->Compare(*handle_ecma_str_u16_not_comp_no2), -1); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no2->Compare(*handle_ecma_str_u16_comp_no1), 1); - EXPECT_EQ(handle_ecma_str_u16_comp_no2->Compare(*handle_ecma_str_u16_not_comp_no3), 49 - 456); - EXPECT_EQ(handle_ecma_str_u16_not_comp_no3->Compare(*handle_ecma_str_u16_comp_no2), 456 - 49); + uint16_t arrayU16CompNo1[] = {1, 23}; + uint16_t arrayU16CompNo2[] = {1, 23, 49}; + uint16_t arrayU16NotCompNo1[] = {1, 23}; + uint16_t arrayU16NotCompNo2[] = {1, 23, 49}; + uint16_t arrayU16NotCompNo3[] = {1, 23, 456, 6789, 65535, 127}; + uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]); + uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]); + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]); + uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]); + JSHandle handleEcmaStrU16CompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU16CompNo1->Compare(*handleEcmaStrU16NotCompNo1), 0); + EXPECT_EQ(handleEcmaStrU16NotCompNo1->Compare(*handleEcmaStrU16CompNo1), 0); + EXPECT_EQ(handleEcmaStrU16CompNo1->Compare(*handleEcmaStrU16NotCompNo2), -1); + EXPECT_EQ(handleEcmaStrU16NotCompNo2->Compare(*handleEcmaStrU16CompNo1), 1); + EXPECT_EQ(handleEcmaStrU16CompNo2->Compare(*handleEcmaStrU16NotCompNo3), 49 - 456); + EXPECT_EQ(handleEcmaStrU16NotCompNo3->Compare(*handleEcmaStrU16CompNo2), 456 - 49); } /* @@ -533,27 +520,27 @@ TEST_F(EcmaStringTest, Compare_006) */ TEST_F(EcmaStringTest, Concat_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Concat(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf8(). - uint8_t array_front_u8[] = {"abcdef"}; - uint8_t array_back_u8[] = {"ABCDEF"}; - uint32_t length_ecma_str_front_u8 = sizeof(array_front_u8) - 1; - uint32_t length_ecma_str_back_u8 = sizeof(array_back_u8) - 1; - JSHandle handle_ecma_str_front_u8( - thread_, EcmaString::CreateFromUtf8(&array_front_u8[0], length_ecma_str_front_u8, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_back_u8( - thread_, EcmaString::CreateFromUtf8(&array_back_u8[0], length_ecma_str_back_u8, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_concat_u8( - thread_, EcmaString::Concat(handle_ecma_str_front_u8, handle_ecma_str_back_u8, ecma_vm_ptr)); - EXPECT_TRUE(handle_ecma_str_concat_u8->IsUtf8()); - for (size_t i = 0; i < length_ecma_str_front_u8; i++) { - EXPECT_EQ(handle_ecma_str_concat_u8->At(i), array_front_u8[i]); + uint8_t arrayFrontU8[] = {"abcdef"}; + uint8_t arrayBackU8[] = {"ABCDEF"}; + uint32_t lengthEcmaStrFrontU8 = sizeof(arrayFrontU8) - 1; + uint32_t lengthEcmaStrBackU8 = sizeof(arrayBackU8) - 1; + JSHandle handleEcmaStrFrontU8( + thread_, EcmaString::CreateFromUtf8(&arrayFrontU8[0], lengthEcmaStrFrontU8, ecmaVmPtr, true)); + JSHandle handleEcmaStrBackU8( + thread_, EcmaString::CreateFromUtf8(&arrayBackU8[0], lengthEcmaStrBackU8, ecmaVmPtr, true)); + JSHandle handleEcmaStrConcatU8( + thread_, EcmaString::Concat(handleEcmaStrFrontU8, handleEcmaStrBackU8, ecmaVmPtr)); + EXPECT_TRUE(handleEcmaStrConcatU8->IsUtf8()); + for (size_t i = 0; i < lengthEcmaStrFrontU8; i++) { + EXPECT_EQ(handleEcmaStrConcatU8->At(i), arrayFrontU8[i]); } - for (size_t i = 0; i < length_ecma_str_back_u8; i++) { - EXPECT_EQ(handle_ecma_str_concat_u8->At(i + length_ecma_str_front_u8), array_back_u8[i]); + for (size_t i = 0; i < lengthEcmaStrBackU8; i++) { + EXPECT_EQ(handleEcmaStrConcatU8->At(i + lengthEcmaStrFrontU8), arrayBackU8[i]); } - EXPECT_EQ(handle_ecma_str_concat_u8->GetLength(), length_ecma_str_front_u8 + length_ecma_str_back_u8); + EXPECT_EQ(handleEcmaStrConcatU8->GetLength(), lengthEcmaStrFrontU8 + lengthEcmaStrBackU8); } /* @@ -565,33 +552,27 @@ TEST_F(EcmaStringTest, Concat_001) */ TEST_F(EcmaStringTest, Concat_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Concat(). EcmaString made by CreateFromUtf16( , , , false) and EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_front_u16_not_comp[] = {128, 129, 256, 11100, 65535, 100}; - uint16_t array_back_u16_not_comp[] = {88, 768, 1, 270, 345, 333}; - uint32_t length_ecma_str_front_u16_not_comp = - sizeof(array_front_u16_not_comp) / sizeof(array_front_u16_not_comp[0]); - uint32_t length_ecma_str_back_u16_not_comp = sizeof(array_back_u16_not_comp) / sizeof(array_back_u16_not_comp[0]); - JSHandle handle_ecma_str_front_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_front_u16_not_comp[0], length_ecma_str_front_u16_not_comp, - ecma_vm_ptr, false)); - JSHandle handle_ecma_str_back_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_back_u16_not_comp[0], length_ecma_str_back_u16_not_comp, - ecma_vm_ptr, false)); - JSHandle handle_ecma_str_concat_u16_not_comp( - thread_, - EcmaString::Concat(handle_ecma_str_front_u16_not_comp, handle_ecma_str_back_u16_not_comp, ecma_vm_ptr)); - EXPECT_TRUE(handle_ecma_str_concat_u16_not_comp->IsUtf16()); - for (size_t i = 0; i < length_ecma_str_front_u16_not_comp; i++) { - EXPECT_EQ(handle_ecma_str_concat_u16_not_comp->At(i), array_front_u16_not_comp[i]); + uint16_t arrayFrontU16NotComp[] = {128, 129, 256, 11100, 65535, 100}; + uint16_t arrayBackU16NotComp[] = {88, 768, 1, 270, 345, 333}; + uint32_t lengthEcmaStrFrontU16NotComp = sizeof(arrayFrontU16NotComp) / sizeof(arrayFrontU16NotComp[0]); + uint32_t lengthEcmaStrBackU16NotComp = sizeof(arrayBackU16NotComp) / sizeof(arrayBackU16NotComp[0]); + JSHandle handleEcmaStrFrontU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayFrontU16NotComp[0], lengthEcmaStrFrontU16NotComp, ecmaVmPtr, false)); + JSHandle handleEcmaStrBackU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayBackU16NotComp[0], lengthEcmaStrBackU16NotComp, ecmaVmPtr, false)); + JSHandle handleEcmaStrConcatU16NotComp( + thread_, EcmaString::Concat(handleEcmaStrFrontU16NotComp, handleEcmaStrBackU16NotComp, ecmaVmPtr)); + EXPECT_TRUE(handleEcmaStrConcatU16NotComp->IsUtf16()); + for (size_t i = 0; i < lengthEcmaStrFrontU16NotComp; i++) { + EXPECT_EQ(handleEcmaStrConcatU16NotComp->At(i), arrayFrontU16NotComp[i]); } - for (size_t i = 0; i < length_ecma_str_back_u16_not_comp; i++) { - EXPECT_EQ(handle_ecma_str_concat_u16_not_comp->At(i + length_ecma_str_front_u16_not_comp), - array_back_u16_not_comp[i]); + for (size_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { + EXPECT_EQ(handleEcmaStrConcatU16NotComp->At(i + lengthEcmaStrFrontU16NotComp), arrayBackU16NotComp[i]); } - EXPECT_EQ(handle_ecma_str_concat_u16_not_comp->GetLength(), - length_ecma_str_front_u16_not_comp + length_ecma_str_back_u16_not_comp); + EXPECT_EQ(handleEcmaStrConcatU16NotComp->GetLength(), lengthEcmaStrFrontU16NotComp + lengthEcmaStrBackU16NotComp); } /* @@ -603,29 +584,27 @@ TEST_F(EcmaStringTest, Concat_002) */ TEST_F(EcmaStringTest, Concat_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // Concat(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , false). - uint8_t array_front_u8[] = {"abcdef"}; - uint16_t array_back_u16_not_comp[] = {88, 768, 1, 270, 345, 333}; - uint32_t length_ecma_str_front_u8 = sizeof(array_front_u8) - 1; - uint32_t length_ecma_str_back_u16_not_comp = sizeof(array_back_u16_not_comp) / sizeof(array_back_u16_not_comp[0]); - JSHandle handle_ecma_str_front_u8( - thread_, EcmaString::CreateFromUtf8(&array_front_u8[0], length_ecma_str_front_u8, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_back_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_back_u16_not_comp[0], length_ecma_str_back_u16_not_comp, - ecma_vm_ptr, false)); - JSHandle handle_ecma_str_concat_u8_u16_not_comp( - thread_, EcmaString::Concat(handle_ecma_str_front_u8, handle_ecma_str_back_u16_not_comp, ecma_vm_ptr)); - EXPECT_TRUE(handle_ecma_str_concat_u8_u16_not_comp->IsUtf16()); - for (size_t i = 0; i < length_ecma_str_front_u8; i++) { - EXPECT_EQ(handle_ecma_str_concat_u8_u16_not_comp->At(i), array_front_u8[i]); + uint8_t arrayFrontU8[] = {"abcdef"}; + uint16_t arrayBackU16NotComp[] = {88, 768, 1, 270, 345, 333}; + uint32_t lengthEcmaStrFrontU8 = sizeof(arrayFrontU8) - 1; + uint32_t lengthEcmaStrBackU16NotComp = sizeof(arrayBackU16NotComp) / sizeof(arrayBackU16NotComp[0]); + JSHandle handleEcmaStrFrontU8( + thread_, EcmaString::CreateFromUtf8(&arrayFrontU8[0], lengthEcmaStrFrontU8, ecmaVmPtr, true)); + JSHandle handleEcmaStrBackU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayBackU16NotComp[0], lengthEcmaStrBackU16NotComp, ecmaVmPtr, false)); + JSHandle handleEcmaStrConcatU8U16NotComp( + thread_, EcmaString::Concat(handleEcmaStrFrontU8, handleEcmaStrBackU16NotComp, ecmaVmPtr)); + EXPECT_TRUE(handleEcmaStrConcatU8U16NotComp->IsUtf16()); + for (size_t i = 0; i < lengthEcmaStrFrontU8; i++) { + EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->At(i), arrayFrontU8[i]); } - for (size_t i = 0; i < length_ecma_str_back_u16_not_comp; i++) { - EXPECT_EQ(handle_ecma_str_concat_u8_u16_not_comp->At(i + length_ecma_str_front_u8), array_back_u16_not_comp[i]); + for (size_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { + EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->At(i + lengthEcmaStrFrontU8), arrayBackU16NotComp[i]); } - EXPECT_EQ(handle_ecma_str_concat_u8_u16_not_comp->GetLength(), - length_ecma_str_front_u8 + length_ecma_str_back_u16_not_comp); + EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->GetLength(), lengthEcmaStrFrontU8 + lengthEcmaStrBackU16NotComp); } /* @@ -638,36 +617,32 @@ TEST_F(EcmaStringTest, Concat_003) */ TEST_F(EcmaStringTest, Concat_004) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); /* Concat() after SetCompressedStringsEnabled(false). EcmaString made by CreateFromUtf16( , , , false) and * EcmaString made by CreateFromUtf16( , , , false). */ EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - uint16_t array_front_u16_not_comp[] = {128, 129, 256, 11100, 65535, 100}; - uint16_t array_back_u16_not_comp[] = {88, 768, 1, 270, 345, 333}; - uint32_t length_ecma_str_front_u16_not_comp = - sizeof(array_front_u16_not_comp) / sizeof(array_front_u16_not_comp[0]); - uint32_t length_ecma_str_back_u16_not_comp = sizeof(array_back_u16_not_comp) / sizeof(array_back_u16_not_comp[0]); - JSHandle handle_ecma_str_front_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_front_u16_not_comp[0], length_ecma_str_front_u16_not_comp, - ecma_vm_ptr, false)); - JSHandle handle_ecma_str_back_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_back_u16_not_comp[0], length_ecma_str_back_u16_not_comp, - ecma_vm_ptr, false)); - JSHandle handle_ecma_str_concat_u16_not_comp_after_set_false( - thread_, - EcmaString::Concat(handle_ecma_str_front_u16_not_comp, handle_ecma_str_back_u16_not_comp, ecma_vm_ptr)); - EXPECT_TRUE(handle_ecma_str_concat_u16_not_comp_after_set_false->IsUtf16()); - for (size_t i = 0; i < length_ecma_str_front_u16_not_comp; i++) { - EXPECT_EQ(handle_ecma_str_concat_u16_not_comp_after_set_false->At(i), array_front_u16_not_comp[i]); + uint16_t arrayFrontU16NotComp[] = {128, 129, 256, 11100, 65535, 100}; + uint16_t arrayBackU16NotComp[] = {88, 768, 1, 270, 345, 333}; + uint32_t lengthEcmaStrFrontU16NotComp = sizeof(arrayFrontU16NotComp) / sizeof(arrayFrontU16NotComp[0]); + uint32_t lengthEcmaStrBackU16NotComp = sizeof(arrayBackU16NotComp) / sizeof(arrayBackU16NotComp[0]); + JSHandle handleEcmaStrFrontU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayFrontU16NotComp[0], lengthEcmaStrFrontU16NotComp, ecmaVmPtr, false)); + JSHandle handleEcmaStrBackU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayBackU16NotComp[0], lengthEcmaStrBackU16NotComp, ecmaVmPtr, false)); + JSHandle handleEcmaStrConcatU16NotCompAfterSetFalse( + thread_, EcmaString::Concat(handleEcmaStrFrontU16NotComp, handleEcmaStrBackU16NotComp, ecmaVmPtr)); + EXPECT_TRUE(handleEcmaStrConcatU16NotCompAfterSetFalse->IsUtf16()); + for (size_t i = 0; i < lengthEcmaStrFrontU16NotComp; i++) { + EXPECT_EQ(handleEcmaStrConcatU16NotCompAfterSetFalse->At(i), arrayFrontU16NotComp[i]); } - for (size_t i = 0; i < length_ecma_str_back_u16_not_comp; i++) { - EXPECT_EQ(handle_ecma_str_concat_u16_not_comp_after_set_false->At(i + length_ecma_str_front_u16_not_comp), - array_back_u16_not_comp[i]); + for (size_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { + EXPECT_EQ(handleEcmaStrConcatU16NotCompAfterSetFalse->At(i + lengthEcmaStrFrontU16NotComp), + arrayBackU16NotComp[i]); } - EXPECT_EQ(handle_ecma_str_concat_u16_not_comp_after_set_false->GetLength(), - length_ecma_str_front_u16_not_comp + length_ecma_str_back_u16_not_comp); + EXPECT_EQ(handleEcmaStrConcatU16NotCompAfterSetFalse->GetLength(), + lengthEcmaStrFrontU16NotComp + lengthEcmaStrBackU16NotComp); EcmaString::SetCompressedStringsEnabled(true); // Set compressed_strings_enabled_ true(default). } @@ -680,21 +655,21 @@ TEST_F(EcmaStringTest, Concat_004) */ TEST_F(EcmaStringTest, FastSubString_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // FastSubString(). From EcmaString made by CreateFromUtf8(). - uint8_t array_u8[6] = {3, 7, 19, 54, 99}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - uint32_t index_start_sub_u8 = 2; - uint32_t length_sub_u8 = 2; - JSHandle handle_ecma_str_sub_u8( - thread_, EcmaString::FastSubString(handle_ecma_str_u8, index_start_sub_u8, length_sub_u8, ecma_vm_ptr)); - for (size_t i = 0; i < length_sub_u8; i++) { - EXPECT_EQ(handle_ecma_str_sub_u8->At(i), handle_ecma_str_u8->At(i + index_start_sub_u8)); + uint8_t arrayU8[6] = {3, 7, 19, 54, 99}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + uint32_t indexStartSubU8 = 2; + uint32_t lengthSubU8 = 2; + JSHandle handleEcmaStrSubU8( + thread_, EcmaString::FastSubString(handleEcmaStrU8, indexStartSubU8, lengthSubU8, ecmaVmPtr)); + for (size_t i = 0; i < lengthSubU8; i++) { + EXPECT_EQ(handleEcmaStrSubU8->At(i), handleEcmaStrU8->At(i + indexStartSubU8)); } - EXPECT_EQ(handle_ecma_str_sub_u8->GetLength(), length_sub_u8); + EXPECT_EQ(handleEcmaStrSubU8->GetLength(), lengthSubU8); } /* @@ -706,22 +681,21 @@ TEST_F(EcmaStringTest, FastSubString_001) */ TEST_F(EcmaStringTest, FastSubString_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // FastSubString(). From EcmaString made by CreateFromUtf16( , , , true). - uint16_t array_u16_comp[] = {1, 12, 34, 56, 127}; - uint32_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - uint32_t index_start_sub_u16_comp = 0; - uint32_t length_sub_u16_comp = 2; - JSHandle handle_ecma_str_sub_u16_comp( - thread_, EcmaString::FastSubString(handle_ecma_str_u16_comp, index_start_sub_u16_comp, length_sub_u16_comp, - ecma_vm_ptr)); - for (size_t i = 0; i < length_sub_u16_comp; i++) { - EXPECT_EQ(handle_ecma_str_sub_u16_comp->At(i), handle_ecma_str_u16_comp->At(i + index_start_sub_u16_comp)); + uint16_t arrayU16Comp[] = {1, 12, 34, 56, 127}; + uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + uint32_t indexStartSubU16Comp = 0; + uint32_t lengthSubU16Comp = 2; + JSHandle handleEcmaStrSubU16Comp( + thread_, EcmaString::FastSubString(handleEcmaStrU16Comp, indexStartSubU16Comp, lengthSubU16Comp, ecmaVmPtr)); + for (size_t i = 0; i < lengthSubU16Comp; i++) { + EXPECT_EQ(handleEcmaStrSubU16Comp->At(i), handleEcmaStrU16Comp->At(i + indexStartSubU16Comp)); } - EXPECT_EQ(handle_ecma_str_sub_u16_comp->GetLength(), length_sub_u16_comp); + EXPECT_EQ(handleEcmaStrSubU16Comp->GetLength(), lengthSubU16Comp); } /* @@ -733,23 +707,22 @@ TEST_F(EcmaStringTest, FastSubString_002) */ TEST_F(EcmaStringTest, FastSubString_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // FastSubString(). From EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp[] = {19, 54, 256, 11100, 65535}; - uint32_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - uint32_t index_start_sub_u16_not_comp = 0; - uint32_t length_sub_u16_not_comp = 2; - JSHandle handle_ecma_str_sub_u16_not_comp( - thread_, EcmaString::FastSubString(handle_ecma_str_u16_not_comp, index_start_sub_u16_not_comp, - length_sub_u16_not_comp, ecma_vm_ptr)); - for (size_t i = 0; i < length_sub_u16_not_comp; i++) { - EXPECT_EQ(handle_ecma_str_sub_u16_not_comp->At(i), - handle_ecma_str_u16_not_comp->At(i + index_start_sub_u16_not_comp)); + uint16_t arrayU16NotComp[] = {19, 54, 256, 11100, 65535}; + uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + uint32_t indexStartSubU16NotComp = 0; + uint32_t lengthSubU16NotComp = 2; + JSHandle handleEcmaStrSubU16NotComp( + thread_, + EcmaString::FastSubString(handleEcmaStrU16NotComp, indexStartSubU16NotComp, lengthSubU16NotComp, ecmaVmPtr)); + for (size_t i = 0; i < lengthSubU16NotComp; i++) { + EXPECT_EQ(handleEcmaStrSubU16NotComp->At(i), handleEcmaStrU16NotComp->At(i + indexStartSubU16NotComp)); } - EXPECT_EQ(handle_ecma_str_sub_u16_not_comp->GetLength(), length_sub_u16_not_comp); + EXPECT_EQ(handleEcmaStrSubU16NotComp->GetLength(), lengthSubU16NotComp); } /* @@ -761,23 +734,22 @@ TEST_F(EcmaStringTest, FastSubString_003) */ TEST_F(EcmaStringTest, WriteData_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // WriteData(). From EcmaString made by CreateFromUtf8() to EcmaString made by AllocStringObject( , true, ). - uint8_t array_u8_write_from[6] = {1, 12, 34, 56, 127}; - uint32_t length_ecma_str_u8_write_from = sizeof(array_u8_write_from) - 1; - JSHandle handle_ecma_str_u8_write_from( - thread_, EcmaString::CreateFromUtf8(&array_u8_write_from[0], length_ecma_str_u8_write_from, ecma_vm_ptr, true)); - size_t size_ecma_str_u8_write_to = 5; - JSHandle handle_ecma_str_alloc_true_write_to( - thread_, EcmaString::AllocStringObject(size_ecma_str_u8_write_to, true, ecma_vm_ptr)); - uint32_t index_start_write_from_array_u8 = 2; - uint32_t length_write_from_array_u8 = 2; - handle_ecma_str_alloc_true_write_to->WriteData(*handle_ecma_str_u8_write_from, index_start_write_from_array_u8, - size_ecma_str_u8_write_to, length_write_from_array_u8); - for (size_t i = 0; i < length_write_from_array_u8; i++) { - EXPECT_EQ(handle_ecma_str_alloc_true_write_to->At(i + index_start_write_from_array_u8), - handle_ecma_str_u8_write_from->At(i)); + uint8_t arrayU8WriteFrom[6] = {1, 12, 34, 56, 127}; + uint32_t lengthEcmaStrU8WriteFrom = sizeof(arrayU8WriteFrom) - 1; + JSHandle handleEcmaStrU8WriteFrom( + thread_, EcmaString::CreateFromUtf8(&arrayU8WriteFrom[0], lengthEcmaStrU8WriteFrom, ecmaVmPtr, true)); + size_t sizeEcmaStrU8WriteTo = 5; + JSHandle handleEcmaStrAllocTrueWriteTo( + thread_, EcmaString::AllocStringObject(sizeEcmaStrU8WriteTo, true, ecmaVmPtr)); + uint32_t indexStartWriteFromArrayU8 = 2; + uint32_t lengthWriteFromArrayU8 = 2; + handleEcmaStrAllocTrueWriteTo->WriteData(*handleEcmaStrU8WriteFrom, indexStartWriteFromArrayU8, + sizeEcmaStrU8WriteTo, lengthWriteFromArrayU8); + for (size_t i = 0; i < lengthWriteFromArrayU8; i++) { + EXPECT_EQ(handleEcmaStrAllocTrueWriteTo->At(i + indexStartWriteFromArrayU8), handleEcmaStrU8WriteFrom->At(i)); } } @@ -790,16 +762,16 @@ TEST_F(EcmaStringTest, WriteData_001) */ TEST_F(EcmaStringTest, WriteData_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // WriteData(). From char to EcmaString made by AllocStringObject( , true, ). - char u8_write = 'a'; - size_t size_ecma_str_u8_write_to = 5; - JSHandle handle_ecma_str_alloc_true_write_to( - thread_, EcmaString::AllocStringObject(size_ecma_str_u8_write_to, true, ecma_vm_ptr)); - uint32_t index_at_write_from_u8 = 4; - handle_ecma_str_alloc_true_write_to->WriteData(u8_write, index_at_write_from_u8); - EXPECT_EQ(handle_ecma_str_alloc_true_write_to->At(index_at_write_from_u8), u8_write); + char u8Write = 'a'; + size_t sizeEcmaStrU8WriteTo = 5; + JSHandle handleEcmaStrAllocTrueWriteTo( + thread_, EcmaString::AllocStringObject(sizeEcmaStrU8WriteTo, true, ecmaVmPtr)); + uint32_t indexAtWriteFromU8 = 4; + handleEcmaStrAllocTrueWriteTo->WriteData(u8Write, indexAtWriteFromU8); + EXPECT_EQ(handleEcmaStrAllocTrueWriteTo->At(indexAtWriteFromU8), u8Write); } /* @@ -811,26 +783,24 @@ TEST_F(EcmaStringTest, WriteData_002) */ TEST_F(EcmaStringTest, WriteData_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); /* WriteData(). From EcmaString made by CreateFromUtf16( , , , false) to EcmaStringU16 made by * AllocStringObject( , false, ). */ - uint16_t array_u16_write_from[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; - uint32_t length_ecma_str_u16_write_from = sizeof(array_u16_write_from) / sizeof(array_u16_write_from[0]); - JSHandle handle_ecma_str_u16_write_from( - thread_, - EcmaString::CreateFromUtf16(&array_u16_write_from[0], length_ecma_str_u16_write_from, ecma_vm_ptr, false)); - size_t size_ecma_str_u16_write_to = 10; - JSHandle handle_ecma_str_u16_write_to( - thread_, EcmaString::AllocStringObject(size_ecma_str_u16_write_to, false, ecma_vm_ptr)); - uint32_t index_start_write_from_array_u16 = 3; - uint32_t num_bytes_write_from_array_u16 = 2 * 3; - handle_ecma_str_u16_write_to->WriteData(*handle_ecma_str_u16_write_from, index_start_write_from_array_u16, - size_ecma_str_u16_write_to, num_bytes_write_from_array_u16); - for (size_t i = 0; i < (num_bytes_write_from_array_u16 / 2); i++) { - EXPECT_EQ(handle_ecma_str_u16_write_to->At(i + index_start_write_from_array_u16), - handle_ecma_str_u16_write_from->At(i)); + uint16_t arrayU16WriteFrom[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; + uint32_t lengthEcmaStrU16WriteFrom = sizeof(arrayU16WriteFrom) / sizeof(arrayU16WriteFrom[0]); + JSHandle handleEcmaStrU16WriteFrom( + thread_, EcmaString::CreateFromUtf16(&arrayU16WriteFrom[0], lengthEcmaStrU16WriteFrom, ecmaVmPtr, false)); + size_t sizeEcmaStrU16WriteTo = 10; + JSHandle handleEcmaStrU16WriteTo( + thread_, EcmaString::AllocStringObject(sizeEcmaStrU16WriteTo, false, ecmaVmPtr)); + uint32_t indexStartWriteFromArrayU16 = 3; + uint32_t numBytesWriteFromArrayU16 = 2 * 3; + handleEcmaStrU16WriteTo->WriteData(*handleEcmaStrU16WriteFrom, indexStartWriteFromArrayU16, sizeEcmaStrU16WriteTo, + numBytesWriteFromArrayU16); + for (size_t i = 0; i < (numBytesWriteFromArrayU16 / 2); i++) { + EXPECT_EQ(handleEcmaStrU16WriteTo->At(i + indexStartWriteFromArrayU16), handleEcmaStrU16WriteFrom->At(i)); } } @@ -843,23 +813,22 @@ TEST_F(EcmaStringTest, WriteData_003) */ TEST_F(EcmaStringTest, WriteData_004) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // WriteData(). From EcmaString made by CreateFromUtf8() to EcmaString made by AllocStringObject( , false, ). - uint8_t array_u8_write_from[6] = {1, 12, 34, 56, 127}; - uint32_t length_ecma_str_u8_write_from = sizeof(array_u8_write_from) - 1; - JSHandle handle_ecma_str_u8_write_from( - thread_, EcmaString::CreateFromUtf8(&array_u8_write_from[0], length_ecma_str_u8_write_from, ecma_vm_ptr, true)); - size_t size_ecma_str_u16_write_to = 10; - JSHandle handle_ecma_str_u16_write_to( - thread_, EcmaString::AllocStringObject(size_ecma_str_u16_write_to, false, ecma_vm_ptr)); - uint32_t index_start_write_from_u8_to_u16 = 1; - uint32_t num_bytes_write_from_u8_to_u16 = 4; - handle_ecma_str_u16_write_to->WriteData(*handle_ecma_str_u8_write_from, index_start_write_from_u8_to_u16, - size_ecma_str_u16_write_to, num_bytes_write_from_u8_to_u16); - for (size_t i = 0; i < num_bytes_write_from_u8_to_u16; i++) { - EXPECT_EQ(handle_ecma_str_u16_write_to->At(i + index_start_write_from_u8_to_u16), - handle_ecma_str_u8_write_from->At(i)); + uint8_t arrayU8WriteFrom[6] = {1, 12, 34, 56, 127}; + uint32_t lengthEcmaStrU8WriteFrom = sizeof(arrayU8WriteFrom) - 1; + JSHandle handleEcmaStrU8WriteFrom( + thread_, EcmaString::CreateFromUtf8(&arrayU8WriteFrom[0], lengthEcmaStrU8WriteFrom, ecmaVmPtr, true)); + size_t sizeEcmaStrU16WriteTo = 10; + JSHandle handleEcmaStrU16WriteTo( + thread_, EcmaString::AllocStringObject(sizeEcmaStrU16WriteTo, false, ecmaVmPtr)); + uint32_t indexStartWriteFromU8ToU16 = 1; + uint32_t numBytesWriteFromU8ToU16 = 4; + handleEcmaStrU16WriteTo->WriteData(*handleEcmaStrU8WriteFrom, indexStartWriteFromU8ToU16, sizeEcmaStrU16WriteTo, + numBytesWriteFromU8ToU16); + for (size_t i = 0; i < numBytesWriteFromU8ToU16; i++) { + EXPECT_EQ(handleEcmaStrU16WriteTo->At(i + indexStartWriteFromU8ToU16), handleEcmaStrU8WriteFrom->At(i)); } } @@ -872,16 +841,16 @@ TEST_F(EcmaStringTest, WriteData_004) */ TEST_F(EcmaStringTest, WriteData_005) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // WriteData(). From char to EcmaString made by AllocStringObject( , false, ). - size_t size_ecma_str_u16_write_to = 10; - JSHandle handle_ecma_str_u16_write_to( - thread_, EcmaString::AllocStringObject(size_ecma_str_u16_write_to, false, ecma_vm_ptr)); - char u8_write = 'a'; - uint32_t index_at = 4; - handle_ecma_str_u16_write_to->WriteData(u8_write, index_at); - EXPECT_EQ(handle_ecma_str_u16_write_to->At(index_at), u8_write); + size_t sizeEcmaStrU16WriteTo = 10; + JSHandle handleEcmaStrU16WriteTo( + thread_, EcmaString::AllocStringObject(sizeEcmaStrU16WriteTo, false, ecmaVmPtr)); + char u8Write = 'a'; + uint32_t indexAt = 4; + handleEcmaStrU16WriteTo->WriteData(u8Write, indexAt); + EXPECT_EQ(handleEcmaStrU16WriteTo->At(indexAt), u8Write); } /* @@ -892,22 +861,22 @@ TEST_F(EcmaStringTest, WriteData_005) */ TEST_F(EcmaStringTest, GetUtf8Length) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); - uint8_t array_u8[6] = {3, 7, 19, 54, 99}; - uint16_t array_u16_comp[] = {1, 12, 34, 56, 127}; - uint16_t array_u16_not_comp[] = {19, 54, 256, 11100, 65535}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - uint32_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - uint32_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u8->GetUtf8Length(), length_ecma_str_u8 + 1); - EXPECT_EQ(handle_ecma_str_u16_comp->GetUtf8Length(), length_ecma_str_u16_comp + 1); - EXPECT_EQ(handle_ecma_str_u16_not_comp->GetUtf8Length(), 2 * length_ecma_str_u16_not_comp + 1); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); + uint8_t arrayU8[6] = {3, 7, 19, 54, 99}; + uint16_t arrayU16Comp[] = {1, 12, 34, 56, 127}; + uint16_t arrayU16NotComp[] = {19, 54, 256, 11100, 65535}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU8->GetUtf8Length(), lengthEcmaStrU8 + 1); + EXPECT_EQ(handleEcmaStrU16Comp->GetUtf8Length(), lengthEcmaStrU16Comp + 1); + EXPECT_EQ(handleEcmaStrU16NotComp->GetUtf8Length(), 2 * lengthEcmaStrU16NotComp + 1); } /* @@ -918,23 +887,23 @@ TEST_F(EcmaStringTest, GetUtf8Length) */ TEST_F(EcmaStringTest, GetUtf16Length) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); - - uint8_t array_u8[6] = {3, 7, 19, 54, 99}; - uint16_t array_u16_comp[] = {1, 12, 34, 56, 127}; - uint16_t array_u16_not_comp[] = {19, 54, 256, 11100, 65535}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - uint32_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - uint32_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u8->GetUtf16Length(), length_ecma_str_u8); - EXPECT_EQ(handle_ecma_str_u16_comp->GetUtf16Length(), length_ecma_str_u16_comp); - EXPECT_EQ(handle_ecma_str_u16_not_comp->GetUtf16Length(), length_ecma_str_u16_not_comp); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); + + uint8_t arrayU8[6] = {3, 7, 19, 54, 99}; + uint16_t arrayU16Comp[] = {1, 12, 34, 56, 127}; + uint16_t arrayU16NotComp[] = {19, 54, 256, 11100, 65535}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU8->GetUtf16Length(), lengthEcmaStrU8); + EXPECT_EQ(handleEcmaStrU16Comp->GetUtf16Length(), lengthEcmaStrU16Comp); + EXPECT_EQ(handleEcmaStrU16NotComp->GetUtf16Length(), lengthEcmaStrU16NotComp); } /* @@ -945,26 +914,26 @@ TEST_F(EcmaStringTest, GetUtf16Length) */ TEST_F(EcmaStringTest, GetDataUtf8) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // From EcmaString made by CreateFromUtf8(). - uint8_t array_u8[] = {"abcde"}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - for (size_t i = 0; i < length_ecma_str_u8; i++) { + uint8_t arrayU8[] = {"abcde"}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + for (size_t i = 0; i < lengthEcmaStrU8; i++) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - EXPECT_EQ(*(handle_ecma_str_u8->GetDataUtf8() + i), array_u8[i]); + EXPECT_EQ(*(handleEcmaStrU8->GetDataUtf8() + i), arrayU8[i]); } // From EcmaString made by CreateFromUtf16( , , , true). - uint16_t array_u16_comp[] = {3, 1, 34, 123, 127, 111, 42, 3, 20, 10}; - uint32_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - for (size_t i = 0; i < sizeof(array_u16_comp) / array_u16_comp[0]; i++) { + uint16_t arrayU16Comp[] = {3, 1, 34, 123, 127, 111, 42, 3, 20, 10}; + uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + for (size_t i = 0; i < sizeof(arrayU16Comp) / arrayU16Comp[0]; i++) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - EXPECT_EQ(*(handle_ecma_str_u16_comp->GetDataUtf8() + i), array_u16_comp[i]); + EXPECT_EQ(*(handleEcmaStrU16Comp->GetDataUtf8() + i), arrayU16Comp[i]); } } @@ -976,16 +945,16 @@ TEST_F(EcmaStringTest, GetDataUtf8) */ TEST_F(EcmaStringTest, GetDataUtf16) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // From EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp[] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; - uint32_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - for (size_t i = 0; i < length_ecma_str_u16_not_comp; i++) { + uint16_t arrayU16NotComp[] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; + uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + for (size_t i = 0; i < lengthEcmaStrU16NotComp; i++) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - EXPECT_EQ(*(handle_ecma_str_u16_not_comp->GetDataUtf16() + i), array_u16_not_comp[i]); + EXPECT_EQ(*(handleEcmaStrU16NotComp->GetDataUtf16() + i), arrayU16NotComp[i]); } } @@ -998,57 +967,52 @@ TEST_F(EcmaStringTest, GetDataUtf16) */ TEST_F(EcmaStringTest, CopyDataRegionUtf8) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // CopyDataRegionUtf8(). From EcmaString made by CreateFromUtf8(). - uint8_t array_u8_copy_from[6] = {1, 12, 34, 56, 127}; - uint32_t length_ecma_str_u8_copy_from = sizeof(array_u8_copy_from) - 1; - JSHandle handle_ecma_str_u8_copy_from( - thread_, EcmaString::CreateFromUtf8(&array_u8_copy_from[0], length_ecma_str_u8_copy_from, ecma_vm_ptr, true)); - const size_t length_array_u8_target = 7; - uint8_t default_byte_for_u8_copy_to = 1; - uint8_t array_u8_copy_to[length_array_u8_target]; - memset_s(&array_u8_copy_to[0], length_array_u8_target, default_byte_for_u8_copy_to, length_array_u8_target); - - size_t index_start_from_array_u8 = 2; - size_t length_copy_to_ecma_str_u8 = 3; - size_t length_return_u8 = handle_ecma_str_u8_copy_from->CopyDataRegionUtf8( - array_u8_copy_to, index_start_from_array_u8, length_copy_to_ecma_str_u8, length_array_u8_target); - - EXPECT_EQ(length_return_u8, length_copy_to_ecma_str_u8); - for (size_t i = 0; i < length_copy_to_ecma_str_u8; i++) { - EXPECT_EQ(array_u8_copy_to[i], handle_ecma_str_u8_copy_from->At(i + index_start_from_array_u8)); + uint8_t arrayU8CopyFrom[6] = {1, 12, 34, 56, 127}; + uint32_t lengthEcmaStrU8CopyFrom = sizeof(arrayU8CopyFrom) - 1; + JSHandle handleEcmaStrU8CopyFrom( + thread_, EcmaString::CreateFromUtf8(&arrayU8CopyFrom[0], lengthEcmaStrU8CopyFrom, ecmaVmPtr, true)); + const size_t lengthArrayU8Target = 7; + uint8_t defaultByteForU8CopyTo = 1; + uint8_t arrayU8CopyTo[lengthArrayU8Target]; + memset_s(&arrayU8CopyTo[0], lengthArrayU8Target, defaultByteForU8CopyTo, lengthArrayU8Target); + + size_t indexStartFromArrayU8 = 2; + size_t lengthCopyToEcmaStrU8 = 3; + size_t lengthReturnU8 = handleEcmaStrU8CopyFrom->CopyDataRegionUtf8(arrayU8CopyTo, indexStartFromArrayU8, + lengthCopyToEcmaStrU8, lengthArrayU8Target); + + EXPECT_EQ(lengthReturnU8, lengthCopyToEcmaStrU8); + for (size_t i = 0; i < lengthCopyToEcmaStrU8; i++) { + EXPECT_EQ(arrayU8CopyTo[i], handleEcmaStrU8CopyFrom->At(i + indexStartFromArrayU8)); } - for (size_t i = length_copy_to_ecma_str_u8; i < length_array_u8_target; i++) { - EXPECT_EQ(array_u8_copy_to[i], default_byte_for_u8_copy_to); + for (size_t i = lengthCopyToEcmaStrU8; i < lengthArrayU8Target; i++) { + EXPECT_EQ(arrayU8CopyTo[i], defaultByteForU8CopyTo); } // CopyDataRegionUtf8(). From EcmaString made by CreateFromUtf16( , , , true). - uint16_t array_u16_comp_copy_from[] = {1, 12, 34, 56, 127}; - uint32_t length_ecma_str_u16_comp_copy_from = - sizeof(array_u16_comp_copy_from) / sizeof(array_u16_comp_copy_from[0]); - JSHandle handle_ecma_str_u16_comp_copy_from( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_copy_from[0], length_ecma_str_u16_comp_copy_from, - ecma_vm_ptr, true)); - const size_t length_array_u16_target = 8; - uint8_t default_byte_for_u16_comp_copy_to = 1; - uint8_t array_u16_comp_copy_to[length_array_u16_target]; - memset_s(&array_u16_comp_copy_to[0], length_array_u16_target, default_byte_for_u16_comp_copy_to, - length_array_u16_target); - - size_t index_start_from_array_u16_comp = 2; - size_t length_copy_to_ecma_str_u16_comp = 3; - size_t length_return_u16_comp = handle_ecma_str_u16_comp_copy_from->CopyDataRegionUtf8( - &array_u16_comp_copy_to[0], index_start_from_array_u16_comp, length_copy_to_ecma_str_u16_comp, - length_array_u16_target); - - EXPECT_EQ(length_return_u16_comp, length_copy_to_ecma_str_u16_comp); - for (size_t i = 0; i < length_return_u16_comp; i++) { - EXPECT_EQ(array_u16_comp_copy_to[i], - handle_ecma_str_u16_comp_copy_from->At(i + index_start_from_array_u16_comp)); + uint16_t arrayU16CompCopyFrom[] = {1, 12, 34, 56, 127}; + uint32_t lengthEcmaStrU16CompCopyFrom = sizeof(arrayU16CompCopyFrom) / sizeof(arrayU16CompCopyFrom[0]); + JSHandle handleEcmaStrU16CompCopyFrom( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompCopyFrom[0], lengthEcmaStrU16CompCopyFrom, ecmaVmPtr, true)); + const size_t lengthArrayU16Target = 8; + uint8_t defaultByteForU16CompCopyTo = 1; + uint8_t arrayU16CompCopyTo[lengthArrayU16Target]; + memset_s(&arrayU16CompCopyTo[0], lengthArrayU16Target, defaultByteForU16CompCopyTo, lengthArrayU16Target); + + size_t indexStartFromArrayU16Comp = 2; + size_t lengthCopyToEcmaStrU16Comp = 3; + size_t lengthReturnU16Comp = handleEcmaStrU16CompCopyFrom->CopyDataRegionUtf8( + &arrayU16CompCopyTo[0], indexStartFromArrayU16Comp, lengthCopyToEcmaStrU16Comp, lengthArrayU16Target); + + EXPECT_EQ(lengthReturnU16Comp, lengthCopyToEcmaStrU16Comp); + for (size_t i = 0; i < lengthReturnU16Comp; i++) { + EXPECT_EQ(arrayU16CompCopyTo[i], handleEcmaStrU16CompCopyFrom->At(i + indexStartFromArrayU16Comp)); } - for (size_t i = length_return_u16_comp; i < length_array_u16_target; i++) { - EXPECT_EQ(array_u16_comp_copy_to[i], default_byte_for_u16_comp_copy_to); + for (size_t i = lengthReturnU16Comp; i < lengthArrayU16Target; i++) { + EXPECT_EQ(arrayU16CompCopyTo[i], defaultByteForU16CompCopyTo); } } @@ -1061,42 +1025,40 @@ TEST_F(EcmaStringTest, CopyDataRegionUtf8) */ TEST_F(EcmaStringTest, CopyDataUtf8) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // CopyDataUtf8(). From EcmaString made by CreateFromUtf8(). - uint8_t array_u8_copy_from[6] = {1, 12, 34, 56, 127}; - uint32_t length_ecma_str_u8_copy_from = sizeof(array_u8_copy_from) - 1; - JSHandle handle_ecma_str_u8_copy_from( - thread_, EcmaString::CreateFromUtf8(&array_u8_copy_from[0], length_ecma_str_u8_copy_from, ecma_vm_ptr, true)); - const size_t length_array_u8_target = 6; - uint8_t array_u8_copy_to[length_array_u8_target]; - - size_t length_return_u8 = handle_ecma_str_u8_copy_from->CopyDataUtf8(&array_u8_copy_to[0], length_array_u8_target); - - EXPECT_EQ(length_return_u8, length_array_u8_target); - for (size_t i = 0; i < length_return_u8 - 1; i++) { - EXPECT_EQ(array_u8_copy_to[i], array_u8_copy_from[i]); + uint8_t arrayU8CopyFrom[6] = {1, 12, 34, 56, 127}; + uint32_t lengthEcmaStrU8CopyFrom = sizeof(arrayU8CopyFrom) - 1; + JSHandle handleEcmaStrU8CopyFrom( + thread_, EcmaString::CreateFromUtf8(&arrayU8CopyFrom[0], lengthEcmaStrU8CopyFrom, ecmaVmPtr, true)); + const size_t lengthArrayU8Target = 6; + uint8_t arrayU8CopyTo[lengthArrayU8Target]; + + size_t lengthReturnU8 = handleEcmaStrU8CopyFrom->CopyDataUtf8(&arrayU8CopyTo[0], lengthArrayU8Target); + + EXPECT_EQ(lengthReturnU8, lengthArrayU8Target); + for (size_t i = 0; i < lengthReturnU8 - 1; i++) { + EXPECT_EQ(arrayU8CopyTo[i], arrayU8CopyFrom[i]); } - EXPECT_EQ(array_u8_copy_to[length_return_u8 - 1], 0); + EXPECT_EQ(arrayU8CopyTo[lengthReturnU8 - 1], 0); // CopyDataUtf8(). From EcmaString made by CreateFromUtf16( , , , true). - uint16_t array_u16_comp_copy_from[] = {1, 12, 34, 56, 127}; - uint32_t length_ecma_str_u16_comp_copy_from = - sizeof(array_u16_comp_copy_from) / sizeof(array_u16_comp_copy_from[0]); - JSHandle handle_ecma_str_u16_comp_copy_from( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_copy_from[0], length_ecma_str_u16_comp_copy_from, - ecma_vm_ptr, true)); - const size_t length_array_u16_target = 6; - uint8_t array_u8_comp_copy_to[length_array_u16_target]; - - size_t length_return_u16_comp = - handle_ecma_str_u16_comp_copy_from->CopyDataUtf8(&array_u8_comp_copy_to[0], length_array_u16_target); - - EXPECT_EQ(length_return_u16_comp, length_array_u16_target); - for (size_t i = 0; i < length_return_u16_comp - 1; i++) { - EXPECT_EQ(array_u8_comp_copy_to[i], array_u16_comp_copy_from[i]); + uint16_t arrayU16CompCopyFrom[] = {1, 12, 34, 56, 127}; + uint32_t lengthEcmaStrU16CompCopyFrom = sizeof(arrayU16CompCopyFrom) / sizeof(arrayU16CompCopyFrom[0]); + JSHandle handleEcmaStrU16CompCopyFrom( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompCopyFrom[0], lengthEcmaStrU16CompCopyFrom, ecmaVmPtr, true)); + const size_t lengthArrayU16Target = 6; + uint8_t arrayU8CompCopyTo[lengthArrayU16Target]; + + size_t lengthReturnU16Comp = + handleEcmaStrU16CompCopyFrom->CopyDataUtf8(&arrayU8CompCopyTo[0], lengthArrayU16Target); + + EXPECT_EQ(lengthReturnU16Comp, lengthArrayU16Target); + for (size_t i = 0; i < lengthReturnU16Comp - 1; i++) { + EXPECT_EQ(arrayU8CompCopyTo[i], arrayU16CompCopyFrom[i]); } - EXPECT_EQ(array_u8_comp_copy_to[length_return_u16_comp - 1], 0); + EXPECT_EQ(arrayU8CompCopyTo[lengthReturnU16Comp - 1], 0); } /* @@ -1108,35 +1070,31 @@ TEST_F(EcmaStringTest, CopyDataUtf8) */ TEST_F(EcmaStringTest, CopyDataRegionUtf16) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // CopyDataRegionUtf16(). From EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp_copy_from[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; - uint32_t length_ecma_str_u16_not_comp_copy_from = - sizeof(array_u16_not_comp_copy_from) / sizeof(array_u16_not_comp_copy_from[0]); - JSHandle handle_ecma_str_u16_not_comp_copy_from( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp_copy_from[0], length_ecma_str_u16_not_comp_copy_from, - ecma_vm_ptr, false)); - const size_t length_array_u16_target = 13; - uint16_t array_u16_not_comp_copy_to[length_array_u16_target]; - uint8_t default_one_byte_value_of_array_u16_not_comp_copy_to = 244; - memset_s(&array_u16_not_comp_copy_to[0], sizeof(uint16_t) * length_array_u16_target, - default_one_byte_value_of_array_u16_not_comp_copy_to, sizeof(uint16_t) * length_array_u16_target); - - size_t start_index_from_array_u16_not_comp = 2; - size_t length_copy_from_array_u16_not_comp = 3; - size_t length_return_u16_not_comp = handle_ecma_str_u16_not_comp_copy_from->CopyDataRegionUtf16( - &array_u16_not_comp_copy_to[0], start_index_from_array_u16_not_comp, length_copy_from_array_u16_not_comp, - length_array_u16_target); - - EXPECT_EQ(length_return_u16_not_comp, length_copy_from_array_u16_not_comp); - for (size_t i = 0; i < length_return_u16_not_comp; i++) { - EXPECT_EQ(array_u16_not_comp_copy_to[i], - handle_ecma_str_u16_not_comp_copy_from->At(i + start_index_from_array_u16_not_comp)); + uint16_t arrayU16NotCompCopyFrom[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; + uint32_t lengthEcmaStrU16NotCompCopyFrom = sizeof(arrayU16NotCompCopyFrom) / sizeof(arrayU16NotCompCopyFrom[0]); + JSHandle handleEcmaStrU16NotCompCopyFrom( + thread_, + EcmaString::CreateFromUtf16(&arrayU16NotCompCopyFrom[0], lengthEcmaStrU16NotCompCopyFrom, ecmaVmPtr, false)); + const size_t lengthArrayU16Target = 13; + uint16_t arrayU16NotCompCopyTo[lengthArrayU16Target]; + uint8_t defaultOneByteValueOfArrayU16NotCompCopyTo = 244; + memset_s(&arrayU16NotCompCopyTo[0], sizeof(uint16_t) * lengthArrayU16Target, + defaultOneByteValueOfArrayU16NotCompCopyTo, sizeof(uint16_t) * lengthArrayU16Target); + + size_t startIndexFromArrayU16NotComp = 2; + size_t lengthCopyFromArrayU16NotComp = 3; + size_t lengthReturnU16NotComp = handleEcmaStrU16NotCompCopyFrom->CopyDataRegionUtf16( + &arrayU16NotCompCopyTo[0], startIndexFromArrayU16NotComp, lengthCopyFromArrayU16NotComp, lengthArrayU16Target); + + EXPECT_EQ(lengthReturnU16NotComp, lengthCopyFromArrayU16NotComp); + for (size_t i = 0; i < lengthReturnU16NotComp; i++) { + EXPECT_EQ(arrayU16NotCompCopyTo[i], handleEcmaStrU16NotCompCopyFrom->At(i + startIndexFromArrayU16NotComp)); } - for (size_t i = length_return_u16_not_comp; i < length_array_u16_target; i++) { - EXPECT_EQ(array_u16_not_comp_copy_to[i], - ((uint16_t)default_one_byte_value_of_array_u16_not_comp_copy_to) * (1U + (1U << 8U))); + for (size_t i = lengthReturnU16NotComp; i < lengthArrayU16Target; i++) { + EXPECT_EQ(arrayU16NotCompCopyTo[i], ((uint16_t)defaultOneByteValueOfArrayU16NotCompCopyTo) * (1U + (1U << 8U))); } } @@ -1149,31 +1107,29 @@ TEST_F(EcmaStringTest, CopyDataRegionUtf16) */ TEST_F(EcmaStringTest, CopyDataUtf16) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // CopyDataUtf16(). From EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp_copy_from[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; - uint32_t length_ecma_str_u16_not_comp_copy_from = - sizeof(array_u16_not_comp_copy_from) / sizeof(array_u16_not_comp_copy_from[0]); - JSHandle handle_ecma_str_u16_not_comp_copy_from( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp_copy_from[0], length_ecma_str_u16_not_comp_copy_from, - ecma_vm_ptr, false)); - const size_t length_array_u16_target = 13; - uint16_t array_u16_not_comp_copy_to[length_array_u16_target]; - uint8_t default_one_byte_value_of_array_u16_not_comp_copy_to = 244; - memset_s(&array_u16_not_comp_copy_to[0], sizeof(uint16_t) * length_array_u16_target, - default_one_byte_value_of_array_u16_not_comp_copy_to, sizeof(uint16_t) * length_array_u16_target); - - size_t length_return_u16_not_comp = - handle_ecma_str_u16_not_comp_copy_from->CopyDataUtf16(&array_u16_not_comp_copy_to[0], length_array_u16_target); - - EXPECT_EQ(length_return_u16_not_comp, length_ecma_str_u16_not_comp_copy_from); - for (size_t i = 0; i < length_return_u16_not_comp; i++) { - EXPECT_EQ(array_u16_not_comp_copy_to[i], handle_ecma_str_u16_not_comp_copy_from->At(i)); + uint16_t arrayU16NotCompCopyFrom[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; + uint32_t lengthEcmaStrU16NotCompCopyFrom = sizeof(arrayU16NotCompCopyFrom) / sizeof(arrayU16NotCompCopyFrom[0]); + JSHandle handleEcmaStrU16NotCompCopyFrom( + thread_, + EcmaString::CreateFromUtf16(&arrayU16NotCompCopyFrom[0], lengthEcmaStrU16NotCompCopyFrom, ecmaVmPtr, false)); + const size_t lengthArrayU16Target = 13; + uint16_t arrayU16NotCompCopyTo[lengthArrayU16Target]; + uint8_t defaultOneByteValueOfArrayU16NotCompCopyTo = 244; + memset_s(&arrayU16NotCompCopyTo[0], sizeof(uint16_t) * lengthArrayU16Target, + defaultOneByteValueOfArrayU16NotCompCopyTo, sizeof(uint16_t) * lengthArrayU16Target); + + size_t lengthReturnU16NotComp = + handleEcmaStrU16NotCompCopyFrom->CopyDataUtf16(&arrayU16NotCompCopyTo[0], lengthArrayU16Target); + + EXPECT_EQ(lengthReturnU16NotComp, lengthEcmaStrU16NotCompCopyFrom); + for (size_t i = 0; i < lengthReturnU16NotComp; i++) { + EXPECT_EQ(arrayU16NotCompCopyTo[i], handleEcmaStrU16NotCompCopyFrom->At(i)); } - for (size_t i = length_return_u16_not_comp; i < length_array_u16_target; i++) { - EXPECT_EQ(array_u16_not_comp_copy_to[i], - ((uint16_t)default_one_byte_value_of_array_u16_not_comp_copy_to) * (1U + (1U << 8U))); + for (size_t i = lengthReturnU16NotComp; i < lengthArrayU16Target; i++) { + EXPECT_EQ(arrayU16NotCompCopyTo[i], ((uint16_t)defaultOneByteValueOfArrayU16NotCompCopyTo) * (1U + (1U << 8U))); } } @@ -1186,28 +1142,28 @@ TEST_F(EcmaStringTest, CopyDataUtf16) */ TEST_F(EcmaStringTest, IndexOf_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // IndexOf(). Find EcmaString made by CreateFromUtf8() From EcmaString made by CreateFromUtf8(). - uint8_t array_u8_from[7] = {23, 25, 1, 3, 39, 80}; - uint8_t array_u8_target[4] = {1, 3, 39}; - uint32_t length_ecma_str_u8_from = sizeof(array_u8_from) - 1; - uint32_t length_ecma_str_u8_target = sizeof(array_u8_target) - 1; - JSHandle handle_ecma_str( - thread_, EcmaString::CreateFromUtf8(&array_u8_from[0], length_ecma_str_u8_from, ecma_vm_ptr, true)); - JSHandle handle_ecma_str1( - thread_, EcmaString::CreateFromUtf8(&array_u8_target[0], length_ecma_str_u8_target, ecma_vm_ptr, true)); - int32_t pos_start = 0; - EXPECT_EQ(handle_ecma_str->IndexOf(*handle_ecma_str1, pos_start), 2); - EXPECT_EQ(handle_ecma_str1->IndexOf(*handle_ecma_str, pos_start), -1); - pos_start = -1; - EXPECT_EQ(handle_ecma_str->IndexOf(*handle_ecma_str1, pos_start), 2); - pos_start = 1; - EXPECT_EQ(handle_ecma_str->IndexOf(*handle_ecma_str1, pos_start), 2); - pos_start = 2; - EXPECT_EQ(handle_ecma_str->IndexOf(*handle_ecma_str1, pos_start), 2); - pos_start = 3; - EXPECT_EQ(handle_ecma_str->IndexOf(*handle_ecma_str1, pos_start), -1); + uint8_t arrayU8From[7] = {23, 25, 1, 3, 39, 80}; + uint8_t arrayU8Target[4] = {1, 3, 39}; + uint32_t lengthEcmaStrU8From = sizeof(arrayU8From) - 1; + uint32_t lengthEcmaStrU8Target = sizeof(arrayU8Target) - 1; + JSHandle handleEcmaStr( + thread_, EcmaString::CreateFromUtf8(&arrayU8From[0], lengthEcmaStrU8From, ecmaVmPtr, true)); + JSHandle handleEcmaStr1( + thread_, EcmaString::CreateFromUtf8(&arrayU8Target[0], lengthEcmaStrU8Target, ecmaVmPtr, true)); + int32_t posStart = 0; + EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2); + EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), -1); + posStart = -1; + EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2); + posStart = 1; + EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2); + posStart = 2; + EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2); + posStart = 3; + EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), -1); } /* @@ -1219,30 +1175,29 @@ TEST_F(EcmaStringTest, IndexOf_001) */ TEST_F(EcmaStringTest, IndexOf_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // IndexOf(). Find EcmaString made by CreateFromUtf8() From EcmaString made by CreateFromUtf16( , , , false). - uint8_t array_u8_target[4] = {1, 3, 39}; - uint16_t array_u16_not_comp_from_no1[] = {67, 65535, 127, 777, 1453, 44, 1, 3, 39, 80, 333}; - uint32_t length_ecma_str_u8_target = sizeof(array_u8_target) - 1; - uint32_t length_ecma_str_u16_not_comp_from_no1 = - sizeof(array_u16_not_comp_from_no1) / sizeof(array_u16_not_comp_from_no1[0]); - JSHandle handle_ecma_str( - thread_, EcmaString::CreateFromUtf8(&array_u8_target[0], length_ecma_str_u8_target, ecma_vm_ptr, true)); - JSHandle handle_ecma_str1(thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp_from_no1[0], - length_ecma_str_u16_not_comp_from_no1, - ecma_vm_ptr, false)); - int32_t pos_start = 0; - EXPECT_EQ(handle_ecma_str1->IndexOf(*handle_ecma_str, pos_start), 6); - EXPECT_EQ(handle_ecma_str->IndexOf(*handle_ecma_str1, pos_start), -1); - pos_start = -1; - EXPECT_EQ(handle_ecma_str1->IndexOf(*handle_ecma_str, pos_start), 6); - pos_start = 1; - EXPECT_EQ(handle_ecma_str1->IndexOf(*handle_ecma_str, pos_start), 6); - pos_start = 6; - EXPECT_EQ(handle_ecma_str1->IndexOf(*handle_ecma_str, pos_start), 6); - pos_start = 7; - EXPECT_EQ(handle_ecma_str1->IndexOf(*handle_ecma_str, pos_start), -1); + uint8_t arrayU8Target[4] = {1, 3, 39}; + uint16_t arrayU16NotCompFromNo1[] = {67, 65535, 127, 777, 1453, 44, 1, 3, 39, 80, 333}; + uint32_t lengthEcmaStrU8Target = sizeof(arrayU8Target) - 1; + uint32_t lengthEcmaStrU16NotCompFromNo1 = sizeof(arrayU16NotCompFromNo1) / sizeof(arrayU16NotCompFromNo1[0]); + JSHandle handleEcmaStr( + thread_, EcmaString::CreateFromUtf8(&arrayU8Target[0], lengthEcmaStrU8Target, ecmaVmPtr, true)); + JSHandle handleEcmaStr1( + thread_, + EcmaString::CreateFromUtf16(&arrayU16NotCompFromNo1[0], lengthEcmaStrU16NotCompFromNo1, ecmaVmPtr, false)); + int32_t posStart = 0; + EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6); + EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), -1); + posStart = -1; + EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6); + posStart = 1; + EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6); + posStart = 6; + EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6); + posStart = 7; + EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), -1); } /* @@ -1254,33 +1209,31 @@ TEST_F(EcmaStringTest, IndexOf_002) */ TEST_F(EcmaStringTest, IndexOf_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); /* IndexOf(). Find EcmaString made by CreateFromUtf16( , , , false) From EcmaString made by * CreateFromUtf16( , , , false). */ - uint16_t array_u16_not_comp_target[] = {1453, 44}; - uint16_t array_u16_not_comp_from[] = {67, 65535, 127, 777, 1453, 44, 1, 3, 39, 80, 333}; - uint32_t length_ecma_str_u16_not_comp_target = - sizeof(array_u16_not_comp_target) / sizeof(array_u16_not_comp_target[0]); - uint32_t length_ecma_str_u16_not_comp_from = sizeof(array_u16_not_comp_from) / sizeof(array_u16_not_comp_from[0]); - JSHandle handle_ecma_str_u16_not_comp_target( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp_target[0], length_ecma_str_u16_not_comp_target, - ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_from( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp_from[0], length_ecma_str_u16_not_comp_from, - ecma_vm_ptr, false)); - int32_t pos_start = 0; - EXPECT_EQ(handle_ecma_str_u16_not_comp_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 4); - EXPECT_EQ(handle_ecma_str_u16_not_comp_target->IndexOf(*handle_ecma_str_u16_not_comp_from, pos_start), -1); - pos_start = -1; - EXPECT_EQ(handle_ecma_str_u16_not_comp_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 4); - pos_start = 1; - EXPECT_EQ(handle_ecma_str_u16_not_comp_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 4); - pos_start = 4; - EXPECT_EQ(handle_ecma_str_u16_not_comp_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 4); - pos_start = 5; - EXPECT_EQ(handle_ecma_str_u16_not_comp_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), -1); + uint16_t arrayU16NotCompTarget[] = {1453, 44}; + uint16_t arrayU16NotCompFrom[] = {67, 65535, 127, 777, 1453, 44, 1, 3, 39, 80, 333}; + uint32_t lengthEcmaStrU16NotCompTarget = sizeof(arrayU16NotCompTarget) / sizeof(arrayU16NotCompTarget[0]); + uint32_t lengthEcmaStrU16NotCompFrom = sizeof(arrayU16NotCompFrom) / sizeof(arrayU16NotCompFrom[0]); + JSHandle handleEcmaStrU16NotCompTarget( + thread_, + EcmaString::CreateFromUtf16(&arrayU16NotCompTarget[0], lengthEcmaStrU16NotCompTarget, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompFrom( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompFrom[0], lengthEcmaStrU16NotCompFrom, ecmaVmPtr, false)); + int32_t posStart = 0; + EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4); + EXPECT_EQ(handleEcmaStrU16NotCompTarget->IndexOf(*handleEcmaStrU16NotCompFrom, posStart), -1); + posStart = -1; + EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4); + posStart = 1; + EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4); + posStart = 4; + EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4); + posStart = 5; + EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), -1); } /* @@ -1292,30 +1245,29 @@ TEST_F(EcmaStringTest, IndexOf_003) */ TEST_F(EcmaStringTest, IndexOf_004) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // IndexOf(). Find EcmaString made by CreateFromUtf16( , , , false) From EcmaString made by CreateFromUtf8(). - uint16_t ecma_str_u16_not_comp_target[] = {3, 39, 80}; - uint8_t array_u8_from[7] = {23, 25, 1, 3, 39, 80}; - uint32_t length_ecma_str_u16_not_comp_target = - sizeof(ecma_str_u16_not_comp_target) / sizeof(ecma_str_u16_not_comp_target[0]); - uint32_t length_ecma_str_u8_from = sizeof(array_u8_from) - 1; - JSHandle handle_ecma_str_u16_not_comp_target( - thread_, EcmaString::CreateFromUtf16(&ecma_str_u16_not_comp_target[0], length_ecma_str_u16_not_comp_target, - ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u8_from( - thread_, EcmaString::CreateFromUtf8(&array_u8_from[0], length_ecma_str_u8_from, ecma_vm_ptr, true)); - int32_t pos_start = 0; - EXPECT_EQ(handle_ecma_str_u8_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 3); - EXPECT_EQ(handle_ecma_str_u16_not_comp_target->IndexOf(*handle_ecma_str_u8_from, pos_start), -1); - pos_start = -1; - EXPECT_EQ(handle_ecma_str_u8_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 3); - pos_start = 1; - EXPECT_EQ(handle_ecma_str_u8_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 3); - pos_start = 3; - EXPECT_EQ(handle_ecma_str_u8_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), 3); - pos_start = 4; - EXPECT_EQ(handle_ecma_str_u8_from->IndexOf(*handle_ecma_str_u16_not_comp_target, pos_start), -1); + uint16_t ecmaStrU16NotCompTarget[] = {3, 39, 80}; + uint8_t arrayU8From[7] = {23, 25, 1, 3, 39, 80}; + uint32_t lengthEcmaStrU16NotCompTarget = sizeof(ecmaStrU16NotCompTarget) / sizeof(ecmaStrU16NotCompTarget[0]); + uint32_t lengthEcmaStrU8From = sizeof(arrayU8From) - 1; + JSHandle handleEcmaStrU16NotCompTarget( + thread_, + EcmaString::CreateFromUtf16(&ecmaStrU16NotCompTarget[0], lengthEcmaStrU16NotCompTarget, ecmaVmPtr, false)); + JSHandle handleEcmaStrU8From( + thread_, EcmaString::CreateFromUtf8(&arrayU8From[0], lengthEcmaStrU8From, ecmaVmPtr, true)); + int32_t posStart = 0; + EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3); + EXPECT_EQ(handleEcmaStrU16NotCompTarget->IndexOf(*handleEcmaStrU8From, posStart), -1); + posStart = -1; + EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3); + posStart = 1; + EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3); + posStart = 3; + EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3); + posStart = 4; + EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), -1); } /* @@ -1327,24 +1279,24 @@ TEST_F(EcmaStringTest, IndexOf_004) */ TEST_F(EcmaStringTest, StringsAreEqual_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqual(). - uint8_t array_u8_no1[4] = {45, 92, 78}; - uint8_t array_u8_no2[4] = {45, 92, 78}; - uint8_t array_u8_no3[5] = {45, 92, 78, 1}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u8_no2 = sizeof(array_u8_no2) - 1; - uint32_t length_ecma_str_u8_no3 = sizeof(array_u8_no3) - 1; - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no2( - thread_, EcmaString::CreateFromUtf8(&array_u8_no2[0], length_ecma_str_u8_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no3( - thread_, EcmaString::CreateFromUtf8(&array_u8_no3[0], length_ecma_str_u8_no3, ecma_vm_ptr, true)); - EXPECT_TRUE(EcmaString::StringsAreEqual(*handle_ecma_str_u8_no1, *handle_ecma_str_u8_no2)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u8_no1, *handle_ecma_str_u8_no3)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u8_no3, *handle_ecma_str_u8_no1)); + uint8_t arrayU8No1[4] = {45, 92, 78}; + uint8_t arrayU8No2[4] = {45, 92, 78}; + uint8_t arrayU8No3[5] = {45, 92, 78, 1}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1; + uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1; + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No2( + thread_, EcmaString::CreateFromUtf8(&arrayU8No2[0], lengthEcmaStrU8No2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No3( + thread_, EcmaString::CreateFromUtf8(&arrayU8No3[0], lengthEcmaStrU8No3, ecmaVmPtr, true)); + EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU8No2)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU8No3)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU8No3, *handleEcmaStrU8No1)); } /* @@ -1356,23 +1308,23 @@ TEST_F(EcmaStringTest, StringsAreEqual_001) */ TEST_F(EcmaStringTest, StringsAreEqual_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqual(). - uint8_t array_u8_no1[4] = {45, 92, 78}; - uint16_t array_u16_comp_no2[] = {45, 92, 78}; - uint16_t array_u16_comp_no3[] = {45, 92, 78, 1}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u16_comp_no2 = sizeof(array_u16_comp_no2) / sizeof(array_u16_comp_no2[0]); - uint32_t length_ecma_str_u16_comp_no3 = sizeof(array_u16_comp_no3) / sizeof(array_u16_comp_no3[0]); - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no2( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no2[0], length_ecma_str_u16_comp_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no3( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no3[0], length_ecma_str_u16_comp_no3, ecma_vm_ptr, true)); - EXPECT_TRUE(EcmaString::StringsAreEqual(*handle_ecma_str_u8_no1, *handle_ecma_str_u16_comp_no2)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u8_no1, *handle_ecma_str_u16_comp_no3)); + uint8_t arrayU8No1[4] = {45, 92, 78}; + uint16_t arrayU16CompNo2[] = {45, 92, 78}; + uint16_t arrayU16CompNo3[] = {45, 92, 78, 1}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]); + uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]); + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, ecmaVmPtr, true)); + EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo2)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo3)); } /* @@ -1384,24 +1336,24 @@ TEST_F(EcmaStringTest, StringsAreEqual_002) */ TEST_F(EcmaStringTest, StringsAreEqual_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqual(). - uint16_t array_u16_comp_no1[] = {45, 92, 78}; - uint16_t array_u16_comp_no2[] = {45, 92, 78}; - uint16_t array_u16_comp_no3[] = {45, 92, 78, 1}; - uint32_t length_ecma_str_u16_comp_no1 = sizeof(array_u16_comp_no1) / sizeof(array_u16_comp_no1[0]); - uint32_t length_ecma_str_u16_comp_no2 = sizeof(array_u16_comp_no2) / sizeof(array_u16_comp_no2[0]); - uint32_t length_ecma_str_u16_comp_no3 = sizeof(array_u16_comp_no3) / sizeof(array_u16_comp_no3[0]); - JSHandle handle_ecma_str_u16_comp_no1( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no1[0], length_ecma_str_u16_comp_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no2( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no2[0], length_ecma_str_u16_comp_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no3( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no3[0], length_ecma_str_u16_comp_no3, ecma_vm_ptr, true)); - EXPECT_TRUE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_comp_no1, *handle_ecma_str_u16_comp_no2)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_comp_no1, *handle_ecma_str_u16_comp_no3)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_comp_no3, *handle_ecma_str_u16_comp_no1)); + uint16_t arrayU16CompNo1[] = {45, 92, 78}; + uint16_t arrayU16CompNo2[] = {45, 92, 78}; + uint16_t arrayU16CompNo3[] = {45, 92, 78, 1}; + uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]); + uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]); + uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]); + JSHandle handleEcmaStrU16CompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, ecmaVmPtr, true)); + EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo2)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo3)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo3, *handleEcmaStrU16CompNo1)); } /* @@ -1413,20 +1365,19 @@ TEST_F(EcmaStringTest, StringsAreEqual_003) */ TEST_F(EcmaStringTest, StringsAreEqual_004) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqual(). - uint8_t array_u8_no1[4] = {45, 92, 78}; - uint16_t array_u16_not_comp_no1[] = {45, 92, 78}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u8_no1, *handle_ecma_str_u16_not_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_not_comp_no1, *handle_ecma_str_u8_no1)); + uint8_t arrayU8No1[4] = {45, 92, 78}; + uint16_t arrayU16NotCompNo1[] = {45, 92, 78}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16NotCompNo1)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU8No1)); } /* @@ -1438,20 +1389,19 @@ TEST_F(EcmaStringTest, StringsAreEqual_004) */ TEST_F(EcmaStringTest, StringsAreEqual_005) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqual(). - uint16_t array_u16_comp_no1[] = {45, 92, 78}; - uint16_t array_u16_not_comp_no1[] = {45, 92, 78}; - uint32_t length_ecma_str_u16_comp_no1 = sizeof(array_u16_comp_no1) / sizeof(array_u16_comp_no1[0]); - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - JSHandle handle_ecma_str_u16_comp_no1( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no1[0], length_ecma_str_u16_comp_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_comp_no1, *handle_ecma_str_u16_not_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_not_comp_no1, *handle_ecma_str_u16_comp_no1)); + uint16_t arrayU16CompNo1[] = {45, 92, 78}; + uint16_t arrayU16NotCompNo1[] = {45, 92, 78}; + uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]); + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + JSHandle handleEcmaStrU16CompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16NotCompNo1)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16CompNo1)); } /* @@ -1463,27 +1413,24 @@ TEST_F(EcmaStringTest, StringsAreEqual_005) */ TEST_F(EcmaStringTest, StringsAreEqual_006) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqual(). - uint16_t array_u16_not_comp_no1[] = {234, 345, 127, 2345, 65535, 5}; - uint16_t array_u16_not_comp_no2[] = {234, 345, 127, 2345, 65535, 5}; - uint16_t array_u16_not_comp_no3[] = {1, 234, 345, 127, 2345, 65535, 5}; - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - uint32_t length_ecma_str_u16_not_comp_no2 = sizeof(array_u16_not_comp_no2) / sizeof(array_u16_not_comp_no2[0]); - uint32_t length_ecma_str_u16_not_comp_no3 = sizeof(array_u16_not_comp_no3) / sizeof(array_u16_not_comp_no3[0]); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no2( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no2[0], length_ecma_str_u16_not_comp_no2, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no3( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no3[0], length_ecma_str_u16_not_comp_no3, ecma_vm_ptr, false)); - EXPECT_TRUE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_not_comp_no1, *handle_ecma_str_u16_not_comp_no2)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_not_comp_no1, *handle_ecma_str_u16_not_comp_no3)); - EXPECT_FALSE(EcmaString::StringsAreEqual(*handle_ecma_str_u16_not_comp_no3, *handle_ecma_str_u16_not_comp_no1)); + uint16_t arrayU16NotCompNo1[] = {234, 345, 127, 2345, 65535, 5}; + uint16_t arrayU16NotCompNo2[] = {234, 345, 127, 2345, 65535, 5}; + uint16_t arrayU16NotCompNo3[] = {1, 234, 345, 127, 2345, 65535, 5}; + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]); + uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, ecmaVmPtr, false)); + EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo2)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo3)); + EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo3, *handleEcmaStrU16NotCompNo1)); } /* @@ -1495,29 +1442,25 @@ TEST_F(EcmaStringTest, StringsAreEqual_006) */ TEST_F(EcmaStringTest, StringsAreEqualUtf8_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqualUtf8(). EcmaString made by CreateFromUtf8(), Array:U8. - uint8_t array_u8_no1[4] = {45, 92, 78}; - uint8_t array_u8_no2[5] = {45, 92, 78, 24}; - uint8_t array_u8_no3[3] = {45, 92}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u8_no2 = sizeof(array_u8_no2) - 1; - uint32_t length_ecma_str_u8_no3 = sizeof(array_u8_no3) - 1; - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no2( - thread_, EcmaString::CreateFromUtf8(&array_u8_no2[0], length_ecma_str_u8_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no3( - thread_, EcmaString::CreateFromUtf8(&array_u8_no3[0], length_ecma_str_u8_no3, ecma_vm_ptr, true)); - EXPECT_TRUE( - EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u8_no1, &array_u8_no1[0], length_ecma_str_u8_no1, true)); - EXPECT_FALSE( - EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u8_no1, &array_u8_no1[0], length_ecma_str_u8_no1, false)); - EXPECT_FALSE( - EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u8_no2, &array_u8_no1[0], length_ecma_str_u8_no1, true)); - EXPECT_FALSE( - EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u8_no3, &array_u8_no1[0], length_ecma_str_u8_no1, true)); + uint8_t arrayU8No1[4] = {45, 92, 78}; + uint8_t arrayU8No2[5] = {45, 92, 78, 24}; + uint8_t arrayU8No3[3] = {45, 92}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1; + uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1; + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No2( + thread_, EcmaString::CreateFromUtf8(&arrayU8No2[0], lengthEcmaStrU8No2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No3( + thread_, EcmaString::CreateFromUtf8(&arrayU8No3[0], lengthEcmaStrU8No3, ecmaVmPtr, true)); + EXPECT_TRUE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU8No2, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU8No3, &arrayU8No1[0], lengthEcmaStrU8No1, true)); } /* @@ -1529,31 +1472,27 @@ TEST_F(EcmaStringTest, StringsAreEqualUtf8_001) */ TEST_F(EcmaStringTest, StringsAreEqualUtf8_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqualUtf8(). EcmaString made by CreateFromUtf16( , , , true), Array:U8. - uint8_t array_u8_no1[4] = {45, 92, 78}; - uint16_t array_u16_comp_no1[] = {45, 92, 78}; - uint16_t array_u16_comp_no2[] = {45, 92, 78, 24}; - uint16_t array_u16_comp_no3[] = {45, 92}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u16_comp_no1 = sizeof(array_u16_comp_no1) / sizeof(array_u16_comp_no1[0]); - uint32_t length_ecma_str_u16_comp_no2 = sizeof(array_u16_comp_no2) / sizeof(array_u16_comp_no2[0]); - uint32_t length_ecma_str_u16_comp_no3 = sizeof(array_u16_comp_no3) / sizeof(array_u16_comp_no3[0]); - JSHandle handle_ecma_str_u16_comp_no1( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no1[0], length_ecma_str_u16_comp_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no2( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no2[0], length_ecma_str_u16_comp_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no3( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no3[0], length_ecma_str_u16_comp_no3, ecma_vm_ptr, true)); - EXPECT_TRUE( - EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_comp_no1, &array_u8_no1[0], length_ecma_str_u8_no1, true)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_comp_no1, &array_u8_no1[0], - length_ecma_str_u8_no1, false)); - EXPECT_FALSE( - EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_comp_no2, &array_u8_no1[0], length_ecma_str_u8_no1, true)); - EXPECT_FALSE( - EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_comp_no3, &array_u8_no1[0], length_ecma_str_u8_no1, true)); + uint8_t arrayU8No1[4] = {45, 92, 78}; + uint16_t arrayU16CompNo1[] = {45, 92, 78}; + uint16_t arrayU16CompNo2[] = {45, 92, 78, 24}; + uint16_t arrayU16CompNo3[] = {45, 92}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]); + uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]); + uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]); + JSHandle handleEcmaStrU16CompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, ecmaVmPtr, true)); + EXPECT_TRUE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16CompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16CompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16CompNo2, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16CompNo3, &arrayU8No1[0], lengthEcmaStrU8No1, true)); } /* @@ -1565,41 +1504,37 @@ TEST_F(EcmaStringTest, StringsAreEqualUtf8_002) */ TEST_F(EcmaStringTest, StringsAreEqualUtf8_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqualUtf8(). EcmaString made by CreateFromUtf16( , , , false), Array:U8. - uint8_t array_u8_no1[4] = {45, 92, 78}; - uint16_t array_u16_not_comp_no1[] = {45, 92, 78}; - uint16_t array_u16_not_comp_no2[] = {45, 92, 78, 24}; - uint16_t array_u16_not_comp_no3[] = {45, 92}; - uint16_t array_u16_not_comp_no4[] = {25645, 25692, 25678}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - uint32_t length_ecma_str_u16_not_comp_no2 = sizeof(array_u16_not_comp_no2) / sizeof(array_u16_not_comp_no2[0]); - uint32_t length_ecma_str_u16_not_comp_no3 = sizeof(array_u16_not_comp_no3) / sizeof(array_u16_not_comp_no3[0]); - uint32_t length_ecma_str_u16_not_comp_no4 = sizeof(array_u16_not_comp_no4) / sizeof(array_u16_not_comp_no4[0]); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no2( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no2[0], length_ecma_str_u16_not_comp_no2, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no3( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no3[0], length_ecma_str_u16_not_comp_no3, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no4( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no4[0], length_ecma_str_u16_not_comp_no4, ecma_vm_ptr, false)); - EXPECT_TRUE(EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_not_comp_no1, &array_u8_no1[0], - length_ecma_str_u8_no1, false)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_not_comp_no1, &array_u8_no1[0], - length_ecma_str_u8_no1, true)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_not_comp_no2, &array_u8_no1[0], - length_ecma_str_u8_no1, false)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_not_comp_no3, &array_u8_no1[0], - length_ecma_str_u8_no1, false)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf8(*handle_ecma_str_u16_not_comp_no4, &array_u8_no1[0], - length_ecma_str_u8_no1, false)); + uint8_t arrayU8No1[4] = {45, 92, 78}; + uint16_t arrayU16NotCompNo1[] = {45, 92, 78}; + uint16_t arrayU16NotCompNo2[] = {45, 92, 78, 24}; + uint16_t arrayU16NotCompNo3[] = {45, 92}; + uint16_t arrayU16NotCompNo4[] = {25645, 25692, 25678}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]); + uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]); + uint32_t lengthEcmaStrU16NotCompNo4 = sizeof(arrayU16NotCompNo4) / sizeof(arrayU16NotCompNo4[0]); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo4( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo4[0], lengthEcmaStrU16NotCompNo4, ecmaVmPtr, false)); + EXPECT_TRUE( + EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16NotCompNo2, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16NotCompNo3, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf8(*handleEcmaStrU16NotCompNo4, &arrayU8No1[0], lengthEcmaStrU8No1, false)); } /* @@ -1611,29 +1546,29 @@ TEST_F(EcmaStringTest, StringsAreEqualUtf8_003) */ TEST_F(EcmaStringTest, StringsAreEqualUtf16_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqualUtf16(). EcmaString made by CreateFromUtf8, Array:U16(1-127). - uint8_t array_u8_no1[4] = {45, 92, 78}; - uint8_t array_u8_no2[5] = {45, 92, 78, 24}; - uint8_t array_u8_no3[3] = {45, 92}; - uint16_t array_u16_not_comp_no1[] = {45, 92, 78}; - uint32_t length_ecma_str_u8_no1 = sizeof(array_u8_no1) - 1; - uint32_t length_ecma_str_u8_no2 = sizeof(array_u8_no2) - 1; - uint32_t length_ecma_str_u8_no3 = sizeof(array_u8_no3) - 1; - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - JSHandle handle_ecma_str_u8_no1( - thread_, EcmaString::CreateFromUtf8(&array_u8_no1[0], length_ecma_str_u8_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no2( - thread_, EcmaString::CreateFromUtf8(&array_u8_no2[0], length_ecma_str_u8_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u8_no3( - thread_, EcmaString::CreateFromUtf8(&array_u8_no3[0], length_ecma_str_u8_no3, ecma_vm_ptr, true)); - EXPECT_TRUE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u8_no1, &array_u16_not_comp_no1[0], - length_ecma_str_u16_not_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u8_no2, &array_u16_not_comp_no1[0], - length_ecma_str_u16_not_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u8_no3, &array_u16_not_comp_no1[0], - length_ecma_str_u16_not_comp_no1)); + uint8_t arrayU8No1[4] = {45, 92, 78}; + uint8_t arrayU8No2[5] = {45, 92, 78, 24}; + uint8_t arrayU8No3[3] = {45, 92}; + uint16_t arrayU16NotCompNo1[] = {45, 92, 78}; + uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1; + uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1; + uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1; + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + JSHandle handleEcmaStrU8No1( + thread_, EcmaString::CreateFromUtf8(&arrayU8No1[0], lengthEcmaStrU8No1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No2( + thread_, EcmaString::CreateFromUtf8(&arrayU8No2[0], lengthEcmaStrU8No2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU8No3( + thread_, EcmaString::CreateFromUtf8(&arrayU8No3[0], lengthEcmaStrU8No3, ecmaVmPtr, true)); + EXPECT_TRUE( + EcmaString::StringsAreEqualUtf16(*handleEcmaStrU8No1, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf16(*handleEcmaStrU8No2, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf16(*handleEcmaStrU8No3, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); } /* @@ -1645,33 +1580,33 @@ TEST_F(EcmaStringTest, StringsAreEqualUtf16_001) */ TEST_F(EcmaStringTest, StringsAreEqualUtf16_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqualUtf16(). EcmaString made by CreateFromUtf16( , , , true), Array:U16(1-127). - uint16_t array_u16_comp_no1[] = {45, 92, 78}; - uint16_t array_u16_comp_no2[] = {45, 92, 78, 24}; - uint16_t array_u16_comp_no3[] = {45, 92}; - uint16_t array_u16_comp_no4[] = {25645, 25692, 25678}; // 25645 % 256 == 45... - uint32_t length_ecma_str_u16_comp_no1 = sizeof(array_u16_comp_no1) / sizeof(array_u16_comp_no1[0]); - uint32_t length_ecma_str_u16_comp_no2 = sizeof(array_u16_comp_no2) / sizeof(array_u16_comp_no2[0]); - uint32_t length_ecma_str_u16_comp_no3 = sizeof(array_u16_comp_no3) / sizeof(array_u16_comp_no3[0]); - uint32_t length_ecma_str_u16_comp_no4 = sizeof(array_u16_comp_no4) / sizeof(array_u16_comp_no4[0]); - JSHandle handle_ecma_str_u16_comp_no1( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no1[0], length_ecma_str_u16_comp_no1, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no2( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no2[0], length_ecma_str_u16_comp_no2, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no3( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no3[0], length_ecma_str_u16_comp_no3, ecma_vm_ptr, true)); - JSHandle handle_ecma_str_u16_comp_no4( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp_no4[0], length_ecma_str_u16_comp_no4, ecma_vm_ptr, true)); - EXPECT_TRUE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_comp_no1, &array_u16_comp_no1[0], - length_ecma_str_u16_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_comp_no2, &array_u16_comp_no1[0], - length_ecma_str_u16_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_comp_no3, &array_u16_comp_no1[0], - length_ecma_str_u16_comp_no1)); - EXPECT_TRUE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_comp_no4, &array_u16_comp_no1[0], - length_ecma_str_u16_comp_no1)); + uint16_t arrayU16CompNo1[] = {45, 92, 78}; + uint16_t arrayU16CompNo2[] = {45, 92, 78, 24}; + uint16_t arrayU16CompNo3[] = {45, 92}; + uint16_t arrayU16CompNo4[] = {25645, 25692, 25678}; // 25645 % 256 == 45... + uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]); + uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]); + uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]); + uint32_t lengthEcmaStrU16CompNo4 = sizeof(arrayU16CompNo4) / sizeof(arrayU16CompNo4[0]); + JSHandle handleEcmaStrU16CompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, ecmaVmPtr, true)); + JSHandle handleEcmaStrU16CompNo4( + thread_, EcmaString::CreateFromUtf16(&arrayU16CompNo4[0], lengthEcmaStrU16CompNo4, ecmaVmPtr, true)); + EXPECT_TRUE( + EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo1, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo2, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); + EXPECT_FALSE( + EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo3, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); + EXPECT_TRUE( + EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo4, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); } /* @@ -1683,39 +1618,35 @@ TEST_F(EcmaStringTest, StringsAreEqualUtf16_002) */ TEST_F(EcmaStringTest, StringsAreEqualUtf16_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // StringsAreEqualUtf16(). EcmaString made by CreateFromUtf16( , , , false), Array:U16(0-65535). - uint16_t array_u16_not_comp_no1[] = {25645, 25692, 25678}; - uint16_t array_u16_not_comp_no2[] = {25645, 25692, 78}; // 25645 % 256 == 45... - uint16_t array_u16_not_comp_no3[] = {25645, 25692, 25678, 65535}; - uint16_t array_u16_not_comp_no4[] = {25645, 25692}; - uint32_t length_ecma_str_u16_not_comp_no1 = sizeof(array_u16_not_comp_no1) / sizeof(array_u16_not_comp_no1[0]); - uint32_t length_ecma_str_u16_not_comp_no2 = sizeof(array_u16_not_comp_no2) / sizeof(array_u16_not_comp_no2[0]); - uint32_t length_ecma_str_u16_not_comp_no3 = sizeof(array_u16_not_comp_no3) / sizeof(array_u16_not_comp_no3[0]); - uint32_t length_ecma_str_u16_not_comp_no4 = sizeof(array_u16_not_comp_no4) / sizeof(array_u16_not_comp_no4[0]); - JSHandle handle_ecma_str_u16_not_comp_no1( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no1[0], length_ecma_str_u16_not_comp_no1, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no2( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no2[0], length_ecma_str_u16_not_comp_no2, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no3( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no3[0], length_ecma_str_u16_not_comp_no3, ecma_vm_ptr, false)); - JSHandle handle_ecma_str_u16_not_comp_no4( - thread_, - EcmaString::CreateFromUtf16(&array_u16_not_comp_no4[0], length_ecma_str_u16_not_comp_no4, ecma_vm_ptr, false)); - EXPECT_TRUE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_not_comp_no1, &array_u16_not_comp_no1[0], - length_ecma_str_u16_not_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_not_comp_no1, &array_u16_not_comp_no2[0], - length_ecma_str_u16_not_comp_no2)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_not_comp_no2, &array_u16_not_comp_no1[0], - length_ecma_str_u16_not_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_not_comp_no3, &array_u16_not_comp_no1[0], - length_ecma_str_u16_not_comp_no1)); - EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handle_ecma_str_u16_not_comp_no4, &array_u16_not_comp_no1[0], - length_ecma_str_u16_not_comp_no1)); + uint16_t arrayU16NotCompNo1[] = {25645, 25692, 25678}; + uint16_t arrayU16NotCompNo2[] = {25645, 25692, 78}; // 25645 % 256 == 45... + uint16_t arrayU16NotCompNo3[] = {25645, 25692, 25678, 65535}; + uint16_t arrayU16NotCompNo4[] = {25645, 25692}; + uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]); + uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]); + uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]); + uint32_t lengthEcmaStrU16NotCompNo4 = sizeof(arrayU16NotCompNo4) / sizeof(arrayU16NotCompNo4[0]); + JSHandle handleEcmaStrU16NotCompNo1( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo2( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo3( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, ecmaVmPtr, false)); + JSHandle handleEcmaStrU16NotCompNo4( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotCompNo4[0], lengthEcmaStrU16NotCompNo4, ecmaVmPtr, false)); + EXPECT_TRUE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo1[0], + lengthEcmaStrU16NotCompNo1)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo2[0], + lengthEcmaStrU16NotCompNo2)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo2, &arrayU16NotCompNo1[0], + lengthEcmaStrU16NotCompNo1)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo3, &arrayU16NotCompNo1[0], + lengthEcmaStrU16NotCompNo1)); + EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo4, &arrayU16NotCompNo1[0], + lengthEcmaStrU16NotCompNo1)); } /* @@ -1727,14 +1658,13 @@ TEST_F(EcmaStringTest, StringsAreEqualUtf16_003) */ TEST_F(EcmaStringTest, ComputeHashcodeUtf8) { - uint8_t array_u8[] = {"abc"}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - uint32_t hash_expect = 0; - for (uint32_t i = 0; i < length_ecma_str_u8; i++) { - hash_expect = hash_expect * 31 + array_u8[i]; + uint8_t arrayU8[] = {"abc"}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + uint32_t hashExpect = 0; + for (uint32_t i = 0; i < lengthEcmaStrU8; i++) { + hashExpect = hashExpect * 31 + arrayU8[i]; } - EXPECT_EQ(EcmaString::ComputeHashcodeUtf8(&array_u8[0], length_ecma_str_u8, true), - static_cast(hash_expect)); + EXPECT_EQ(EcmaString::ComputeHashcodeUtf8(&arrayU8[0], lengthEcmaStrU8, true), static_cast(hashExpect)); } /* @@ -1746,13 +1676,13 @@ TEST_F(EcmaStringTest, ComputeHashcodeUtf8) */ TEST_F(EcmaStringTest, ComputeHashcodeUtf16) { - uint16_t array_u16[] = {199, 1, 256, 65535, 777}; - uint32_t length_ecma_str_u16 = sizeof(array_u16) / sizeof(array_u16[0]); - uint32_t hash_expect = 0; - for (uint32_t i = 0; i < length_ecma_str_u16; i++) { - hash_expect = hash_expect * 31 + array_u16[i]; + uint16_t arrayU16[] = {199, 1, 256, 65535, 777}; + uint32_t lengthEcmaStrU16 = sizeof(arrayU16) / sizeof(arrayU16[0]); + uint32_t hashExpect = 0; + for (uint32_t i = 0; i < lengthEcmaStrU16; i++) { + hashExpect = hashExpect * 31 + arrayU16[i]; } - EXPECT_EQ(EcmaString::ComputeHashcodeUtf16(&array_u16[0], length_ecma_str_u16), static_cast(hash_expect)); + EXPECT_EQ(EcmaString::ComputeHashcodeUtf16(&arrayU16[0], lengthEcmaStrU16), static_cast(hashExpect)); } /* @@ -1764,18 +1694,18 @@ TEST_F(EcmaStringTest, ComputeHashcodeUtf16) */ TEST_F(EcmaStringTest, GetHashcode_001) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // GetHashcode(). EcmaString made by CreateFromUtf8(). - uint8_t array_u8[] = {"abc"}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - uint32_t hash_expect = 0; - for (uint32_t i = 0; i < length_ecma_str_u8; i++) { - hash_expect = hash_expect * 31 + array_u8[i]; + uint8_t arrayU8[] = {"abc"}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + uint32_t hashExpect = 0; + for (uint32_t i = 0; i < lengthEcmaStrU8; i++) { + hashExpect = hashExpect * 31 + arrayU8[i]; } - EXPECT_EQ(handle_ecma_str_u8->GetHashcode(), static_cast(hash_expect)); + EXPECT_EQ(handleEcmaStrU8->GetHashcode(), static_cast(hashExpect)); } /* @@ -1787,18 +1717,18 @@ TEST_F(EcmaStringTest, GetHashcode_001) */ TEST_F(EcmaStringTest, GetHashcode_002) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // GetHashcode(). EcmaString made by CreateFromUtf16( , , , true). - uint16_t array_u16_comp[] = {45, 92, 78, 24}; - uint32_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - uint32_t hash_expect = 0; - for (uint32_t i = 0; i < length_ecma_str_u16_comp; i++) { - hash_expect = hash_expect * 31 + array_u16_comp[i]; + uint16_t arrayU16Comp[] = {45, 92, 78, 24}; + uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + uint32_t hashExpect = 0; + for (uint32_t i = 0; i < lengthEcmaStrU16Comp; i++) { + hashExpect = hashExpect * 31 + arrayU16Comp[i]; } - EXPECT_EQ(handle_ecma_str_u16_comp->GetHashcode(), static_cast(hash_expect)); + EXPECT_EQ(handleEcmaStrU16Comp->GetHashcode(), static_cast(hashExpect)); } /* @@ -1811,23 +1741,23 @@ TEST_F(EcmaStringTest, GetHashcode_002) */ TEST_F(EcmaStringTest, GetHashcode_003) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // GetHashcode(). EcmaString made by CreateFromUtf16( , , , false). - uint16_t array_u16_not_comp[] = {199, 1, 256, 65535, 777}; - uint32_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - uint32_t hash_expect = 0; - for (uint32_t i = 0; i < length_ecma_str_u16_not_comp; i++) { - hash_expect = hash_expect * 31 + array_u16_not_comp[i]; + uint16_t arrayU16NotComp[] = {199, 1, 256, 65535, 777}; + uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + uint32_t hashExpect = 0; + for (uint32_t i = 0; i < lengthEcmaStrU16NotComp; i++) { + hashExpect = hashExpect * 31 + arrayU16NotComp[i]; } - EXPECT_EQ(handle_ecma_str_u16_not_comp->GetHashcode(), static_cast(hash_expect)); + EXPECT_EQ(handleEcmaStrU16NotComp->GetHashcode(), static_cast(hashExpect)); EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - JSHandle handle_ecma_str_u16_not_comp_disable_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_EQ(handle_ecma_str_u16_not_comp_disable_comp->GetHashcode(), static_cast(hash_expect)); + JSHandle handleEcmaStrU16NotCompDisableComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_EQ(handleEcmaStrU16NotCompDisableComp->GetHashcode(), static_cast(hashExpect)); EcmaString::SetCompressedStringsEnabled(true); // Set compressed_strings_enabled_ true(default). } @@ -1840,15 +1770,15 @@ TEST_F(EcmaStringTest, GetHashcode_003) */ TEST_F(EcmaStringTest, GetHashcode_004) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // GetHashcode(). EcmaString made by CreateEmptyString(). - JSHandle handle_ecma_str_empty(thread_, EcmaString::CreateEmptyString(ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_empty->GetHashcode(), 0); + JSHandle handleEcmaStrEmpty(thread_, EcmaString::CreateEmptyString(ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrEmpty->GetHashcode(), 0); EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - JSHandle handle_ecma_str_empty_disable_comp(thread_, EcmaString::CreateEmptyString(ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_empty_disable_comp->GetHashcode(), 0); + JSHandle handleEcmaStrEmptyDisableComp(thread_, EcmaString::CreateEmptyString(ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrEmptyDisableComp->GetHashcode(), 0); EcmaString::SetCompressedStringsEnabled(true); // Set compressed_strings_enabled_ true(default). } @@ -1862,21 +1792,19 @@ TEST_F(EcmaStringTest, GetHashcode_004) */ TEST_F(EcmaStringTest, GetHashcode_005) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); // GetHashcode(). EcmaString made by AllocStringObject(). - size_t size_alloc = 5; - JSHandle handle_ecma_str_alloc_comp(thread_, - EcmaString::AllocStringObject(size_alloc, true, ecma_vm_ptr)); - JSHandle handle_ecma_str_alloc_not_comp(thread_, - EcmaString::AllocStringObject(size_alloc, false, ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_alloc_comp->GetHashcode(), 0); - EXPECT_EQ(handle_ecma_str_alloc_not_comp->GetHashcode(), 0); + size_t sizeAlloc = 5; + JSHandle handleEcmaStrAllocComp(thread_, EcmaString::AllocStringObject(sizeAlloc, true, ecmaVmPtr)); + JSHandle handleEcmaStrAllocNotComp(thread_, EcmaString::AllocStringObject(sizeAlloc, false, ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrAllocComp->GetHashcode(), 0); + EXPECT_EQ(handleEcmaStrAllocNotComp->GetHashcode(), 0); EcmaString::SetCompressedStringsEnabled(false); // Set compressed_strings_enabled_ false. - JSHandle handle_ecma_str_alloc_not_comp_disable_comp( - thread_, EcmaString::AllocStringObject(size_alloc, false, ecma_vm_ptr)); - EXPECT_EQ(handle_ecma_str_alloc_not_comp_disable_comp->GetHashcode(), 0); + JSHandle handleEcmaStrAllocNotCompDisableComp( + thread_, EcmaString::AllocStringObject(sizeAlloc, false, ecmaVmPtr)); + EXPECT_EQ(handleEcmaStrAllocNotCompDisableComp->GetHashcode(), 0); EcmaString::SetCompressedStringsEnabled(true); // Set compressed_strings_enabled_ true(default). } @@ -1889,25 +1817,25 @@ TEST_F(EcmaStringTest, GetHashcode_005) */ TEST_F(EcmaStringTest, GetCString) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); - - uint8_t array_u8[] = {"abc"}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - EXPECT_STREQ(PandaString(handle_ecma_str_u8->GetCString().get()).c_str(), "abc"); - - uint16_t array_u16_comp[] = {97, 98, 99}; - uint32_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - EXPECT_STREQ(PandaString(handle_ecma_str_u16_comp->GetCString().get()).c_str(), "abc"); - - uint16_t array_u16_not_comp[] = {97, 98, 99}; - uint32_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_STREQ(PandaString(handle_ecma_str_u16_not_comp->GetCString().get()).c_str(), "abc"); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); + + uint8_t arrayU8[] = {"abc"}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + EXPECT_STREQ(PandaString(handleEcmaStrU8->GetCString().get()).c_str(), "abc"); + + uint16_t arrayU16Comp[] = {97, 98, 99}; + uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + EXPECT_STREQ(PandaString(handleEcmaStrU16Comp->GetCString().get()).c_str(), "abc"); + + uint16_t arrayU16NotComp[] = {97, 98, 99}; + uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_STREQ(PandaString(handleEcmaStrU16NotComp->GetCString().get()).c_str(), "abc"); } /* @@ -1919,31 +1847,31 @@ TEST_F(EcmaStringTest, GetCString) */ TEST_F(EcmaStringTest, SetIsInternString) { - EcmaVM *ecma_vm_ptr = EcmaVM::Cast(instance_); - - uint8_t array_u8[] = {"abc"}; - uint32_t length_ecma_str_u8 = sizeof(array_u8) - 1; - JSHandle handle_ecma_str_u8( - thread_, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); - EXPECT_FALSE(handle_ecma_str_u8->IsInternString()); - handle_ecma_str_u8->SetIsInternString(); - EXPECT_TRUE(handle_ecma_str_u8->IsInternString()); - - uint16_t array_u16_comp[] = {97, 98, 99}; - uint32_t length_ecma_str_u16_comp = sizeof(array_u16_comp) / sizeof(array_u16_comp[0]); - JSHandle handle_ecma_str_u16_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); - EXPECT_FALSE(handle_ecma_str_u16_comp->IsInternString()); - handle_ecma_str_u16_comp->SetIsInternString(); - EXPECT_TRUE(handle_ecma_str_u16_comp->IsInternString()); - - uint16_t array_u16_not_comp[] = {97, 98, 99}; - uint32_t length_ecma_str_u16_not_comp = sizeof(array_u16_not_comp) / sizeof(array_u16_not_comp[0]); - JSHandle handle_ecma_str_u16_not_comp( - thread_, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); - EXPECT_FALSE(handle_ecma_str_u16_not_comp->IsInternString()); - handle_ecma_str_u16_not_comp->SetIsInternString(); - EXPECT_TRUE(handle_ecma_str_u16_not_comp->IsInternString()); + EcmaVM *ecmaVmPtr = EcmaVM::Cast(instance_); + + uint8_t arrayU8[] = {"abc"}; + uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; + JSHandle handleEcmaStrU8(thread_, + EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVmPtr, true)); + EXPECT_FALSE(handleEcmaStrU8->IsInternString()); + handleEcmaStrU8->SetIsInternString(); + EXPECT_TRUE(handleEcmaStrU8->IsInternString()); + + uint16_t arrayU16Comp[] = {97, 98, 99}; + uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); + JSHandle handleEcmaStrU16Comp( + thread_, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVmPtr, true)); + EXPECT_FALSE(handleEcmaStrU16Comp->IsInternString()); + handleEcmaStrU16Comp->SetIsInternString(); + EXPECT_TRUE(handleEcmaStrU16Comp->IsInternString()); + + uint16_t arrayU16NotComp[] = {97, 98, 99}; + uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); + JSHandle handleEcmaStrU16NotComp( + thread_, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVmPtr, false)); + EXPECT_FALSE(handleEcmaStrU16NotComp->IsInternString()); + handleEcmaStrU16NotComp->SetIsInternString(); + EXPECT_TRUE(handleEcmaStrU16NotComp->IsInternString()); } } // namespace panda::test diff --git a/tests/runtime/common/gc/pending_exception_tests.cpp b/tests/runtime/common/gc/pending_exception_tests.cpp index 231129c3686c20f657fbef46057e8256b9a270d6..4ab00aa0e2b016c48c27350682c96a6e6f59da8c 100644 --- a/tests/runtime/common/gc/pending_exception_tests.cpp +++ b/tests/runtime/common/gc/pending_exception_tests.cpp @@ -40,9 +40,9 @@ public: TEST_P(PendingExceptionTests, MovingGc) { - const std::string main_func = "_GLOBAL::func_main_0"; - const std::string file_name = "moving_gc_when_pending_exception.abc"; - auto ret2 = Runtime::GetCurrent()->ExecutePandaFile(file_name.c_str(), main_func.c_str(), {}); + const std::string mainFunc = "_GLOBAL::func_main_0"; + const std::string fileName = "moving_gc_when_pending_exception.abc"; + auto ret2 = Runtime::GetCurrent()->ExecutePandaFile(fileName.c_str(), mainFunc.c_str(), {}); ASSERT_TRUE(ret2.HasValue()); ASSERT_EQ(ret2.Value(), 1); } diff --git a/tests/runtime/common/glue_regs_test.cpp b/tests/runtime/common/glue_regs_test.cpp index d65609ef25f0f330a9a45b1a5f5bc5ee5816d600..42c726c454004b7e36d5585ac49928d9c6d4607b 100644 --- a/tests/runtime/common/glue_regs_test.cpp +++ b/tests/runtime/common/glue_regs_test.cpp @@ -50,11 +50,11 @@ private: TEST_F(GlueRegsTest, ConstantClassTest) { - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - ASSERT_NE(global_const, nullptr); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + ASSERT_NE(globalConst, nullptr); - const JSTaggedValue *address = global_const->BeginSlot(); - while (address < global_const->EndSlot()) { + const JSTaggedValue *address = globalConst->BeginSlot(); + while (address < globalConst->EndSlot()) { EXPECT_TRUE(!(*address).IsNull()); // Visit barely // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) address += sizeof(JSTaggedValue); @@ -63,21 +63,21 @@ TEST_F(GlueRegsTest, ConstantClassTest) TEST_F(GlueRegsTest, ConstantSpecialTest) { - auto global_const = const_cast(thread_->GlobalConstants()); - ASSERT_NE(global_const, nullptr); + auto globalConst = const_cast(thread_->GlobalConstants()); + ASSERT_NE(globalConst, nullptr); - EXPECT_TRUE(global_const->GetUndefined().IsUndefined()); - EXPECT_TRUE(global_const->GetHandledUndefined()->IsUndefined()); - EXPECT_TRUE(global_const->GetNull().IsNull()); - EXPECT_TRUE(global_const->GetHandledNull()->IsNull()); - EXPECT_TRUE(global_const->GetEmptyString().IsString()); - EXPECT_TRUE(global_const->GetHandledEmptyString()->IsString()); + EXPECT_TRUE(globalConst->GetUndefined().IsUndefined()); + EXPECT_TRUE(globalConst->GetHandledUndefined()->IsUndefined()); + EXPECT_TRUE(globalConst->GetNull().IsNull()); + EXPECT_TRUE(globalConst->GetHandledNull()->IsNull()); + EXPECT_TRUE(globalConst->GetEmptyString().IsString()); + EXPECT_TRUE(globalConst->GetHandledEmptyString()->IsString()); } TEST_F(GlueRegsTest, ConstantStringTest) { - auto global_const = const_cast(thread_->GlobalConstants()); - ASSERT_NE(global_const, nullptr); + auto globalConst = const_cast(thread_->GlobalConstants()); + ASSERT_NE(globalConst, nullptr); // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define CONSTANT_STRING_ITERATOR(Type, Name, Index, Desc) \ @@ -91,8 +91,8 @@ TEST_F(GlueRegsTest, ConstantStringTest) TEST_F(GlueRegsTest, ConstantAccessorTest) { - auto global_const = const_cast(thread_->GlobalConstants()); - ASSERT_NE(global_const, nullptr); + auto globalConst = const_cast(thread_->GlobalConstants()); + ASSERT_NE(globalConst, nullptr); // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define CONSTANT_ACCESSOR_ITERATOR(Type, Name, Index, Desc) \ diff --git a/tests/runtime/common/huge_object_test.cpp b/tests/runtime/common/huge_object_test.cpp index c291ca279d4fd8e111e191bdc2b90c3dacbbe516..cdd27893c108f6b3967a08232532e5c96f5a0873 100644 --- a/tests/runtime/common/huge_object_test.cpp +++ b/tests/runtime/common/huge_object_test.cpp @@ -64,12 +64,11 @@ using panda::ecmascript::TaggedObject; static JSObject *JSObjectTestCreate(JSThread *thread) { [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - auto global_env = ecma_vm->GetGlobalEnv(); - JSHandle js_func = global_env->GetObjectFunction(); - JSHandle new_obj = - ecma_vm->GetFactory()->NewJSObjectByConstructor(JSHandle(js_func), js_func); - return *new_obj; + EcmaVM *ecmaVm = thread->GetEcmaVM(); + auto globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle jsFunc = globalEnv->GetObjectFunction(); + JSHandle newObj = ecmaVm->GetFactory()->NewJSObjectByConstructor(JSHandle(jsFunc), jsFunc); + return *newObj; } #endif @@ -88,15 +87,15 @@ TEST_F(HugeObjectTest, LargeArrayKeep) #if !defined(NDEBUG) TaggedArray *array = LargeArrayTestCreate(thread_); EXPECT_TRUE(array != nullptr); - JSHandle array_handle(thread_, array); - JSHandle new_obj(thread_, JSObjectTestCreate(thread_)); - array_handle->Set(thread_, 0, new_obj.GetTaggedValue()); - auto ecma_vm = thread_->GetEcmaVM(); - EXPECT_EQ(*array_handle, reinterpret_cast(array)); - ecma_vm->CollectGarbage(); // Trigger GC. - ecma_vm->CollectGarbage(); // Trigger GC. - EXPECT_EQ(*new_obj, array->Get(0).GetTaggedObject()); - EXPECT_EQ(*array_handle, reinterpret_cast(array)); + JSHandle arrayHandle(thread_, array); + JSHandle newObj(thread_, JSObjectTestCreate(thread_)); + arrayHandle->Set(thread_, 0, newObj.GetTaggedValue()); + auto ecmaVm = thread_->GetEcmaVM(); + EXPECT_EQ(*arrayHandle, reinterpret_cast(array)); + ecmaVm->CollectGarbage(); // Trigger GC. + ecmaVm->CollectGarbage(); // Trigger GC. + EXPECT_EQ(*newObj, array->Get(0).GetTaggedObject()); + EXPECT_EQ(*arrayHandle, reinterpret_cast(array)); #endif } } // namespace panda::test diff --git a/tests/runtime/common/js_arguments_test.cpp b/tests/runtime/common/js_arguments_test.cpp index 10c1719218d67fce2d049b99ffc869e025355cb3..fe98bfcc8759bc1237b95d2aed0971e88ce57d3c 100644 --- a/tests/runtime/common/js_arguments_test.cpp +++ b/tests/runtime/common/js_arguments_test.cpp @@ -62,16 +62,16 @@ private: static JSFunction *JSObjectTestCreate(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - return global_env->GetObjectFunction().GetObject(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + return globalEnv->GetObjectFunction().GetObject(); } TEST_F(JsArgumentsTest, SetProperty) { - JSHandle arg_func(thread_, JSObjectTestCreate(thread_)); + JSHandle argFunc(thread_, JSObjectTestCreate(thread_)); JSHandle jsarg = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread_->GetEcmaVM()->GetFactory()->NewJSArguments(); // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -93,9 +93,9 @@ TEST_F(JsArgumentsTest, SetProperty) TEST_F(JsArgumentsTest, GetProperty) { - JSHandle arg_func(thread_, JSObjectTestCreate(thread_)); + JSHandle argFunc(thread_, JSObjectTestCreate(thread_)); JSHandle jsarg = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread_->GetEcmaVM()->GetFactory()->NewJSArguments(); // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -116,9 +116,9 @@ TEST_F(JsArgumentsTest, GetProperty) TEST_F(JsArgumentsTest, DeleteProperty) { - JSHandle arg_func(thread_, JSObjectTestCreate(thread_)); + JSHandle argFunc(thread_, JSObjectTestCreate(thread_)); JSHandle jsarg = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread_->GetEcmaVM()->GetFactory()->NewJSArguments(); // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -137,9 +137,9 @@ TEST_F(JsArgumentsTest, DeleteProperty) TEST_F(JsArgumentsTest, DefineOwnProperty) { - JSHandle arg_func(thread_, JSObjectTestCreate(thread_)); + JSHandle argFunc(thread_, JSObjectTestCreate(thread_)); JSHandle jsarg = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread_->GetEcmaVM()->GetFactory()->NewJSArguments(); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); @@ -159,9 +159,9 @@ TEST_F(JsArgumentsTest, DefineOwnProperty) TEST_F(JsArgumentsTest, GetOwnProperty) { - JSHandle arg_func(thread_, JSObjectTestCreate(thread_)); + JSHandle argFunc(thread_, JSObjectTestCreate(thread_)); JSHandle jsarg = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread_->GetEcmaVM()->GetFactory()->NewJSArguments(); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); diff --git a/tests/runtime/common/js_array_iterator_test.cpp b/tests/runtime/common/js_array_iterator_test.cpp index 30c0dc80f53e1b5a46ce922738094972ebc61cdc..540b9b36eff5be1b3246ed8014ed14c44719b202 100644 --- a/tests/runtime/common/js_array_iterator_test.cpp +++ b/tests/runtime/common/js_array_iterator_test.cpp @@ -69,49 +69,45 @@ private: */ TEST_F(JSArrayIteratorTest, SetIteratedArray) { - EcmaVM *ecma_vm_ptr = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm_ptr->GetFactory(); + EcmaVM *ecmaVmPtr = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVmPtr->GetFactory(); // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) - uint32_t array_from1[10] = {0, 6, 8, 99, 200, 1, static_cast(-1), static_cast(-199), 33, 100}; + uint32_t arrayFrom1[10] = {0, 6, 8, 99, 200, 1, static_cast(-1), static_cast(-199), 33, 100}; // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) - uint32_t array_from2[10] = {1111, 3211, 737, 0, 1267, 174, 2763, 832, 11, 93}; - int num_array_from1 = sizeof(array_from1) / sizeof(array_from1[0]); - int num_array_from2 = sizeof(array_from2) / sizeof(array_from2[0]); - JSHandle handle_tagged_array_from1(factory->NewTaggedArray(num_array_from1)); - JSHandle handle_tagged_array_from2(factory->NewTaggedArray(num_array_from2)); - for (int i = 0; i < num_array_from1; i++) { - handle_tagged_array_from1->Set(thread, i, JSTaggedValue(array_from1[i])); + uint32_t arrayFrom2[10] = {1111, 3211, 737, 0, 1267, 174, 2763, 832, 11, 93}; + int numArrayFrom1 = sizeof(arrayFrom1) / sizeof(arrayFrom1[0]); + int numArrayFrom2 = sizeof(arrayFrom2) / sizeof(arrayFrom2[0]); + JSHandle handleTaggedArrayFrom1(factory->NewTaggedArray(numArrayFrom1)); + JSHandle handleTaggedArrayFrom2(factory->NewTaggedArray(numArrayFrom2)); + for (int i = 0; i < numArrayFrom1; i++) { + handleTaggedArrayFrom1->Set(thread, i, JSTaggedValue(arrayFrom1[i])); } - for (int i = 0; i < num_array_from2; i++) { - handle_tagged_array_from2->Set(thread, i, JSTaggedValue(array_from2[i])); + for (int i = 0; i < numArrayFrom2; i++) { + handleTaggedArrayFrom2->Set(thread, i, JSTaggedValue(arrayFrom2[i])); } - JSHandle handle_js_object_tagged_array_from1( - JSArray::CreateArrayFromList(thread, handle_tagged_array_from1)); - JSHandle handle_js_object_tagged_array_from2( - JSArray::CreateArrayFromList(thread, handle_tagged_array_from2)); + JSHandle handleJsObjectTaggedArrayFrom1(JSArray::CreateArrayFromList(thread, handleTaggedArrayFrom1)); + JSHandle handleJsObjectTaggedArrayFrom2(JSArray::CreateArrayFromList(thread, handleTaggedArrayFrom2)); // Call "SetIteratedArray" function through "NewJSArrayIterator" function of "object_factory.cpp". - JSHandle handle_js_array_iter = - factory->NewJSArrayIterator(handle_js_object_tagged_array_from1, IterationKind::KEY); - - JSHandle handle_js_array_to1(thread, - JSArray::Cast(handle_js_array_iter->GetIteratedArray().GetTaggedObject())); - EXPECT_EQ(handle_js_array_to1->GetArrayLength(), num_array_from1); - for (int i = 0; i < num_array_from1; i++) { - EXPECT_EQ(JSArray::FastGetPropertyByValue(thread, JSHandle(handle_js_array_to1), i)->GetNumber(), - array_from1[i]); + JSHandle handleJsArrayIter = + factory->NewJSArrayIterator(handleJsObjectTaggedArrayFrom1, IterationKind::KEY); + + JSHandle handleJsArrayTo1(thread, JSArray::Cast(handleJsArrayIter->GetIteratedArray().GetTaggedObject())); + EXPECT_EQ(handleJsArrayTo1->GetArrayLength(), numArrayFrom1); + for (int i = 0; i < numArrayFrom1; i++) { + EXPECT_EQ(JSArray::FastGetPropertyByValue(thread, JSHandle(handleJsArrayTo1), i)->GetNumber(), + arrayFrom1[i]); } // Call "SetIteratedArray" function in this TEST_F. - handle_js_array_iter->SetIteratedArray(thread, handle_js_object_tagged_array_from2); - - JSHandle handle_js_array_to2(thread, - JSArray::Cast(handle_js_array_iter->GetIteratedArray().GetTaggedObject())); - EXPECT_EQ(handle_js_array_to2->GetArrayLength(), num_array_from2); - for (int i = 0; i < num_array_from2; i++) { - EXPECT_EQ(JSArray::FastGetPropertyByValue(thread, JSHandle(handle_js_array_to2), i)->GetNumber(), - array_from2[i]); + handleJsArrayIter->SetIteratedArray(thread, handleJsObjectTaggedArrayFrom2); + + JSHandle handleJsArrayTo2(thread, JSArray::Cast(handleJsArrayIter->GetIteratedArray().GetTaggedObject())); + EXPECT_EQ(handleJsArrayTo2->GetArrayLength(), numArrayFrom2); + for (int i = 0; i < numArrayFrom2; i++) { + EXPECT_EQ(JSArray::FastGetPropertyByValue(thread, JSHandle(handleJsArrayTo2), i)->GetNumber(), + arrayFrom2[i]); } } @@ -125,31 +121,31 @@ TEST_F(JSArrayIteratorTest, SetIteratedArray) */ TEST_F(JSArrayIteratorTest, SetNextIndex) { - EcmaVM *ecma_vm_ptr = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm_ptr->GetFactory(); + EcmaVM *ecmaVmPtr = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVmPtr->GetFactory(); // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) uint32_t array[10] = {0, 6, 8, 99, 200, 1, static_cast(-1), static_cast(-199), 33, 100}; - int num_array = sizeof(array) / sizeof(array[0]); - JSHandle handle_tagged_array(factory->NewTaggedArray(num_array)); - for (int i = 0; i < num_array; i++) { - handle_tagged_array->Set(thread, i, JSTaggedValue(array[i])); + int numArray = sizeof(array) / sizeof(array[0]); + JSHandle handleTaggedArray(factory->NewTaggedArray(numArray)); + for (int i = 0; i < numArray; i++) { + handleTaggedArray->Set(thread, i, JSTaggedValue(array[i])); } - JSHandle handle_js_object_tagged_array(JSArray::CreateArrayFromList(thread, handle_tagged_array)); + JSHandle handleJsObjectTaggedArray(JSArray::CreateArrayFromList(thread, handleTaggedArray)); // Call "SetNextIndex" function through "NewJSArrayIterator" function of "object_factory.cpp". - JSHandle handle_js_array_iter = - factory->NewJSArrayIterator(handle_js_object_tagged_array, IterationKind::KEY); - EXPECT_EQ(handle_js_array_iter->GetNextIndex().GetNumber(), 0); + JSHandle handleJsArrayIter = + factory->NewJSArrayIterator(handleJsObjectTaggedArray, IterationKind::KEY); + EXPECT_EQ(handleJsArrayIter->GetNextIndex().GetNumber(), 0); // NOLINTNEXTLINE(readability-magic-numbers) - int test_quantity = 100; - for (int i = 1; i <= test_quantity; i++) { - JSHandle handle_tag_val_next_index(thread, JSTaggedValue(i)); + int testQuantity = 100; + for (int i = 1; i <= testQuantity; i++) { + JSHandle handleTagValNextIndex(thread, JSTaggedValue(i)); // Call "SetNextIndex" function in this TEST_F. - handle_js_array_iter->SetNextIndex(thread, handle_tag_val_next_index); - EXPECT_EQ(handle_js_array_iter->GetNextIndex().GetNumber(), i); + handleJsArrayIter->SetNextIndex(thread, handleTagValNextIndex); + EXPECT_EQ(handleJsArrayIter->GetNextIndex().GetNumber(), i); } } @@ -163,36 +159,36 @@ TEST_F(JSArrayIteratorTest, SetNextIndex) */ TEST_F(JSArrayIteratorTest, SetIterationKind) { - EcmaVM *ecma_vm_ptr = thread->GetEcmaVM(); - ObjectFactory *factory = ecma_vm_ptr->GetFactory(); + EcmaVM *ecmaVmPtr = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVmPtr->GetFactory(); // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) uint32_t array[10] = {0, 6, 8, 99, 200, 1, static_cast(-1), static_cast(-199), 33, 100}; - int num_array = sizeof(array) / sizeof(array[0]); - JSHandle handle_tagged_array(factory->NewTaggedArray(num_array)); - for (int i = 0; i < num_array; i++) { - handle_tagged_array->Set(thread, i, JSTaggedValue(array[i])); + int numArray = sizeof(array) / sizeof(array[0]); + JSHandle handleTaggedArray(factory->NewTaggedArray(numArray)); + for (int i = 0; i < numArray; i++) { + handleTaggedArray->Set(thread, i, JSTaggedValue(array[i])); } - JSHandle handle_tag_val0(thread, JSTaggedValue(0)); - JSHandle handle_tag_val1(thread, JSTaggedValue(1)); - JSHandle handle_tag_val2(thread, JSTaggedValue(2)); - JSHandle handle_js_object_tagged_array(JSArray::CreateArrayFromList(thread, handle_tagged_array)); + JSHandle handleTagVal0(thread, JSTaggedValue(0)); + JSHandle handleTagVal1(thread, JSTaggedValue(1)); + JSHandle handleTagVal2(thread, JSTaggedValue(2)); + JSHandle handleJsObjectTaggedArray(JSArray::CreateArrayFromList(thread, handleTaggedArray)); // Call "SetIterationKind" function through "NewJSArrayIterator" function of "object_factory.cpp". - JSHandle handle_js_array_iter = - factory->NewJSArrayIterator(handle_js_object_tagged_array, IterationKind::KEY); - EXPECT_EQ(handle_js_array_iter->GetIterationKind().GetNumber(), 0); - handle_js_array_iter = factory->NewJSArrayIterator(handle_js_object_tagged_array, IterationKind::VALUE); - EXPECT_EQ(handle_js_array_iter->GetIterationKind().GetNumber(), 1); - handle_js_array_iter = factory->NewJSArrayIterator(handle_js_object_tagged_array, IterationKind::KEY_AND_VALUE); - EXPECT_EQ(handle_js_array_iter->GetIterationKind().GetNumber(), 2); + JSHandle handleJsArrayIter = + factory->NewJSArrayIterator(handleJsObjectTaggedArray, IterationKind::KEY); + EXPECT_EQ(handleJsArrayIter->GetIterationKind().GetNumber(), 0); + handleJsArrayIter = factory->NewJSArrayIterator(handleJsObjectTaggedArray, IterationKind::VALUE); + EXPECT_EQ(handleJsArrayIter->GetIterationKind().GetNumber(), 1); + handleJsArrayIter = factory->NewJSArrayIterator(handleJsObjectTaggedArray, IterationKind::KEY_AND_VALUE); + EXPECT_EQ(handleJsArrayIter->GetIterationKind().GetNumber(), 2); // Call "SetIterationKind" function in this TEST_F. - handle_js_array_iter->SetIterationKind(thread, handle_tag_val0); - EXPECT_EQ(handle_js_array_iter->GetIterationKind().GetNumber(), 0); - handle_js_array_iter->SetIterationKind(thread, handle_tag_val1); - EXPECT_EQ(handle_js_array_iter->GetIterationKind().GetNumber(), 1); - handle_js_array_iter->SetIterationKind(thread, handle_tag_val2); - EXPECT_EQ(handle_js_array_iter->GetIterationKind().GetNumber(), 2); + handleJsArrayIter->SetIterationKind(thread, handleTagVal0); + EXPECT_EQ(handleJsArrayIter->GetIterationKind().GetNumber(), 0); + handleJsArrayIter->SetIterationKind(thread, handleTagVal1); + EXPECT_EQ(handleJsArrayIter->GetIterationKind().GetNumber(), 1); + handleJsArrayIter->SetIterationKind(thread, handleTagVal2); + EXPECT_EQ(handleJsArrayIter->GetIterationKind().GetNumber(), 2); } } // namespace panda::test diff --git a/tests/runtime/common/js_array_test.cpp b/tests/runtime/common/js_array_test.cpp index fdfe1f8ec6c4a5efb96acd019f4f34177c2dbdb9..b80cda665a62c784bc3024141a78d2c9867f192f 100644 --- a/tests/runtime/common/js_array_test.cpp +++ b/tests/runtime/common/js_array_test.cpp @@ -74,62 +74,62 @@ private: TEST_F(JSArrayTest, ArrayCreate) { - JSHandle length_key_handle(thread_->GlobalConstants()->GetHandledLengthString()); + JSHandle lengthKeyHandle(thread_->GlobalConstants()->GetHandledLengthString()); auto *arr = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 0); // NOLINTNEXTLINE(readability-magic-numbers) auto *arr2 = JSArray::ArrayCreate(thread_, JSTaggedNumber(10)).GetObject(); EXPECT_TRUE(arr2 != nullptr); JSHandle obj2(thread_, arr2); - EXPECT_EQ(JSArray::GetProperty(thread_, obj2, length_key_handle).GetValue()->GetInt(), 10); + EXPECT_EQ(JSArray::GetProperty(thread_, obj2, lengthKeyHandle).GetValue()->GetInt(), 10); } TEST_F(JSArrayTest, ArraySpeciesCreate) { - JSHandle length_key_handle(thread_->GlobalConstants()->GetHandledLengthString()); + JSHandle lengthKeyHandle(thread_->GlobalConstants()->GetHandledLengthString()); auto *arr = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, JSHandle(obj), lengthKeyHandle).GetValue()->GetInt(), 0); // NOLINTNEXTLINE(readability-magic-numbers) JSArray *arr2 = JSArray::Cast(JSArray::ArraySpeciesCreate(thread_, obj, JSTaggedNumber(10)).GetHeapObject()); EXPECT_TRUE(arr2 != nullptr); JSHandle obj2(thread_, arr2); // NOLINTNEXTLINE(readability-magic-numbers) - EXPECT_EQ(JSArray::GetProperty(thread_, obj2, length_key_handle).GetValue()->GetInt(), 10); + EXPECT_EQ(JSArray::GetProperty(thread_, obj2, lengthKeyHandle).GetValue()->GetInt(), 10); } TEST_F(JSArrayTest, DefineOwnProperty) { - auto ecma_vm = thread_->GetEcmaVM(); - auto factory = ecma_vm->GetFactory(); - JSHandle length_key_handle(thread_->GlobalConstants()->GetHandledLengthString()); + auto ecmaVm = thread_->GetEcmaVM(); + auto factory = ecmaVm->GetFactory(); + JSHandle lengthKeyHandle(thread_->GlobalConstants()->GetHandledLengthString()); auto *arr = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread_, arr); - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 0); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 0); // NOLINTNEXTLINE(readability-magic-numbers) PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(100)), true, true, true); - EcmaLanguageContext ecma_language_context; - LanguageContext ctx(&ecma_language_context); + EcmaLanguageContext ecmaLanguageContext; + LanguageContext ctx(&ecmaLanguageContext); EcmaString *string1 = *factory->NewFromString("1"); JSHandle key1(thread_, static_cast(string1)); JSHandle index1(thread_, JSTaggedValue(1)); EXPECT_TRUE(JSArray::DefineOwnProperty(thread_, JSHandle(obj), key1, desc)); - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 2); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 2); TaggedValue v = JSArray::GetProperty(thread_, obj, key1).GetValue().GetTaggedValue(); // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(v.GetInt(), 100); v = JSArray::GetProperty(thread_, obj, index1).GetValue().GetTaggedValue(); // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(v.GetInt(), 100); - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 2); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 2); EcmaString *string100 = *factory->NewFromString("100"); JSHandle key100(thread_, static_cast(string100)); @@ -142,7 +142,7 @@ TEST_F(JSArrayTest, DefineOwnProperty) // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread_, obj, index100).GetValue()->GetInt(), 100); // NOLINTNEXTLINE(readability-magic-numbers) - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 101); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 101); EcmaString *stringx = *factory->NewFromString("2147483646"); JSHandle keyx(thread_, static_cast(stringx)); @@ -155,7 +155,7 @@ TEST_F(JSArrayTest, DefineOwnProperty) // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread_, obj, indexx).GetValue()->GetInt(), 100); // NOLINTNEXTLINE(readability-magic-numbers) - EXPECT_EQ(JSArray::GetProperty(thread_, obj, length_key_handle).GetValue()->GetInt(), 2147483647); + EXPECT_EQ(JSArray::GetProperty(thread_, obj, lengthKeyHandle).GetValue()->GetInt(), 2147483647); EXPECT_TRUE(JSArray::DeleteProperty(thread_, JSHandle(obj), indexx)); EXPECT_TRUE(JSArray::GetProperty(thread_, obj, keyx).GetValue()->IsUndefined()); @@ -171,12 +171,12 @@ TEST_F(JSArrayTest, Next) } JSHandle array(JSArray::CreateArrayFromList(thread_, values)); JSHandle iter(factory->NewJSArrayIterator(array, IterationKind::KEY)); - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); for (int i = 0; i < 5; i++) { - ecma_runtime_call_info->SetThis(iter.GetTaggedValue()); - JSTaggedValue ret = JSArrayIterator::Next(ecma_runtime_call_info.get()); + ecmaRuntimeCallInfo->SetThis(iter.GetTaggedValue()); + JSTaggedValue ret = JSArrayIterator::Next(ecmaRuntimeCallInfo.get()); JSHandle result(thread_, ret); EXPECT_EQ(JSIterator::IteratorValue(thread_, result)->GetInt(), i); } @@ -191,8 +191,8 @@ TEST_F(JSArrayTest, Iterator) values->Set(thread_, i, JSTaggedValue(i)); } JSHandle array(JSArray::CreateArrayFromList(thread_, values)); - JSHandle key_iter(factory->NewJSArrayIterator(array, IterationKind::KEY)); - JSHandle value_iter(factory->NewJSArrayIterator(array, IterationKind::VALUE)); + JSHandle keyIter(factory->NewJSArrayIterator(array, IterationKind::KEY)); + JSHandle valueIter(factory->NewJSArrayIterator(array, IterationKind::VALUE)); JSHandle iter(factory->NewJSArrayIterator(array, IterationKind::KEY_AND_VALUE)); for (int i = 0; i < 5; i++) { @@ -200,24 +200,24 @@ TEST_F(JSArrayTest, Iterator) JSHandle key(thread_, JSTaggedValue(i)); JSObject::DeleteProperty(thread_, JSHandle(array), key); } - JSHandle key_result(JSIterator::IteratorStep(thread_, key_iter)); - JSHandle value_result(JSIterator::IteratorStep(thread_, value_iter)); - JSHandle iter_result(JSIterator::IteratorStep(thread_, iter)); - JSHandle iter_value(JSIterator::IteratorValue(thread_, iter_result)); - JSHandle index_key(thread_, JSTaggedValue(0)); - JSHandle element_key(thread_, JSTaggedValue(1)); + JSHandle keyResult(JSIterator::IteratorStep(thread_, keyIter)); + JSHandle valueResult(JSIterator::IteratorStep(thread_, valueIter)); + JSHandle iterResult(JSIterator::IteratorStep(thread_, iter)); + JSHandle iterValue(JSIterator::IteratorValue(thread_, iterResult)); + JSHandle indexKey(thread_, JSTaggedValue(0)); + JSHandle elementKey(thread_, JSTaggedValue(1)); if (i == 2) { - EXPECT_EQ(i, JSIterator::IteratorValue(thread_, key_result)->GetInt()); - EXPECT_EQ(JSTaggedValue::Undefined(), JSIterator::IteratorValue(thread_, value_result).GetTaggedValue()); - EXPECT_EQ(i, JSObject::GetProperty(thread_, iter_value, index_key).GetValue()->GetInt()); + EXPECT_EQ(i, JSIterator::IteratorValue(thread_, keyResult)->GetInt()); + EXPECT_EQ(JSTaggedValue::Undefined(), JSIterator::IteratorValue(thread_, valueResult).GetTaggedValue()); + EXPECT_EQ(i, JSObject::GetProperty(thread_, iterValue, indexKey).GetValue()->GetInt()); EXPECT_EQ(JSTaggedValue::Undefined(), - JSObject::GetProperty(thread_, iter_value, element_key).GetValue().GetTaggedValue()); + JSObject::GetProperty(thread_, iterValue, elementKey).GetValue().GetTaggedValue()); continue; } - EXPECT_EQ(i, JSIterator::IteratorValue(thread_, key_result)->GetInt()); - EXPECT_EQ(i, JSIterator::IteratorValue(thread_, value_result)->GetInt()); - EXPECT_EQ(i, JSObject::GetProperty(thread_, iter_value, index_key).GetValue()->GetInt()); - EXPECT_EQ(i, JSObject::GetProperty(thread_, iter_value, element_key).GetValue()->GetInt()); + EXPECT_EQ(i, JSIterator::IteratorValue(thread_, keyResult)->GetInt()); + EXPECT_EQ(i, JSIterator::IteratorValue(thread_, valueResult)->GetInt()); + EXPECT_EQ(i, JSObject::GetProperty(thread_, iterValue, indexKey).GetValue()->GetInt()); + EXPECT_EQ(i, JSObject::GetProperty(thread_, iterValue, elementKey).GetValue()->GetInt()); } } diff --git a/tests/runtime/common/js_dataview_test.cpp b/tests/runtime/common/js_dataview_test.cpp index 56988bdb2de318141f043367ecd424d9ce0257a7..d4b7c04306028db28d6a289bb2d1cd92d5394745 100644 --- a/tests/runtime/common/js_dataview_test.cpp +++ b/tests/runtime/common/js_dataview_test.cpp @@ -84,29 +84,28 @@ TEST_F(JSDataViewTest, GetElementSize) */ TEST_F(JSDataViewTest, SetDataView) { - EcmaVM *ecma_vm_ptr = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm_ptr->GetFactory(); - JSHandle handle_global_env = ecma_vm_ptr->GetGlobalEnv(); - - int32_t length_data_array_buf = 8; - int32_t offset_data_view = 4; - int32_t length_data_view = 4; - JSHandle handle_func_array_buf(handle_global_env->GetArrayBufferFunction()); - JSHandle handle_tag_val_func_array_buf(handle_func_array_buf); - JSHandle handle_array_buf( - factory->NewJSObjectByConstructor(handle_func_array_buf, handle_tag_val_func_array_buf)); - handle_array_buf->SetArrayBufferByteLength(thread_, JSTaggedValue(length_data_array_buf)); + EcmaVM *ecmaVmPtr = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVmPtr->GetFactory(); + JSHandle handleGlobalEnv = ecmaVmPtr->GetGlobalEnv(); + + int32_t lengthDataArrayBuf = 8; + int32_t offsetDataView = 4; + int32_t lengthDataView = 4; + JSHandle handleFuncArrayBuf(handleGlobalEnv->GetArrayBufferFunction()); + JSHandle handleTagValFuncArrayBuf(handleFuncArrayBuf); + JSHandle handleArrayBuf( + factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); + handleArrayBuf->SetArrayBufferByteLength(thread_, JSTaggedValue(lengthDataArrayBuf)); // Call "SetDataView" function through "NewJSDataView" function of "object_factory.cpp" - JSHandle handle_data_view = - factory->NewJSDataView(handle_array_buf, offset_data_view, length_data_view); - EXPECT_TRUE(handle_data_view->GetDataView().IsTrue()); + JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf, offsetDataView, lengthDataView); + EXPECT_TRUE(handleDataView->GetDataView().IsTrue()); // Call "SetDataView" function in this TEST_F. - handle_data_view->SetDataView(thread_, JSTaggedValue::False()); - EXPECT_TRUE(handle_data_view->GetDataView().IsFalse()); - handle_data_view->SetDataView(thread_, JSTaggedValue::True()); - EXPECT_TRUE(handle_data_view->GetDataView().IsTrue()); + handleDataView->SetDataView(thread_, JSTaggedValue::False()); + EXPECT_TRUE(handleDataView->GetDataView().IsFalse()); + handleDataView->SetDataView(thread_, JSTaggedValue::True()); + EXPECT_TRUE(handleDataView->GetDataView().IsTrue()); } /* @@ -119,36 +118,35 @@ TEST_F(JSDataViewTest, SetDataView) */ TEST_F(JSDataViewTest, SetViewedArrayBuffer) { - EcmaVM *ecma_vm_ptr = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm_ptr->GetFactory(); - JSHandle handle_func_array_buf(ecma_vm_ptr->GetGlobalEnv()->GetArrayBufferFunction()); - JSHandle handle_tag_val_func_array_buf(handle_func_array_buf); + EcmaVM *ecmaVmPtr = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVmPtr->GetFactory(); + JSHandle handleFuncArrayBuf(ecmaVmPtr->GetGlobalEnv()->GetArrayBufferFunction()); + JSHandle handleTagValFuncArrayBuf(handleFuncArrayBuf); - int32_t length_data_array_buf1 = 8; + int32_t lengthDataArrayBuf1 = 8; // NOLINTNEXTLINE(readability-magic-numbers) - int32_t length_data_array_buf2 = 16; - int32_t offset_data_view = 4; - int32_t length_data_view = 4; - JSHandle handle_array_buf1( - factory->NewJSObjectByConstructor(handle_func_array_buf, handle_tag_val_func_array_buf)); - JSHandle handle_array_buf2( - factory->NewJSObjectByConstructor(handle_func_array_buf, handle_tag_val_func_array_buf)); - handle_array_buf1->SetArrayBufferByteLength(thread_, JSTaggedValue(length_data_array_buf1)); - handle_array_buf2->SetArrayBufferByteLength(thread_, JSTaggedValue(length_data_array_buf2)); + int32_t lengthDataArrayBuf2 = 16; + int32_t offsetDataView = 4; + int32_t lengthDataView = 4; + JSHandle handleArrayBuf1( + factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); + JSHandle handleArrayBuf2( + factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); + handleArrayBuf1->SetArrayBufferByteLength(thread_, JSTaggedValue(lengthDataArrayBuf1)); + handleArrayBuf2->SetArrayBufferByteLength(thread_, JSTaggedValue(lengthDataArrayBuf2)); // Call "SetViewedArrayBuffer" function through "NewJSDataView" function of "object_factory.cpp" - JSHandle handle_data_view = - factory->NewJSDataView(handle_array_buf1, offset_data_view, length_data_view); - JSHandle handle_tag_val_data_view_from1(thread_, handle_array_buf1.GetTaggedValue()); - JSHandle handle_tag_val_data_view_to1(thread_, handle_data_view->GetViewedArrayBuffer()); - EXPECT_TRUE(JSTaggedValue::Equal(thread_, handle_tag_val_data_view_from1, handle_tag_val_data_view_to1)); + JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf1, offsetDataView, lengthDataView); + JSHandle handleTagValDataViewFrom1(thread_, handleArrayBuf1.GetTaggedValue()); + JSHandle handleTagValDataViewTo1(thread_, handleDataView->GetViewedArrayBuffer()); + EXPECT_TRUE(JSTaggedValue::Equal(thread_, handleTagValDataViewFrom1, handleTagValDataViewTo1)); // Call "SetViewedArrayBuffer" function in this TEST_F. - handle_data_view->SetViewedArrayBuffer(thread_, handle_array_buf2.GetTaggedValue()); - JSHandle handle_tag_val_data_view_from2(thread_, handle_array_buf2.GetTaggedValue()); - JSHandle handle_tag_val_data_view_to2(thread_, handle_data_view->GetViewedArrayBuffer()); - EXPECT_TRUE(JSTaggedValue::Equal(thread_, handle_tag_val_data_view_from2, handle_tag_val_data_view_to2)); - EXPECT_FALSE(JSTaggedValue::Equal(thread_, handle_tag_val_data_view_from1, handle_tag_val_data_view_from2)); + handleDataView->SetViewedArrayBuffer(thread_, handleArrayBuf2.GetTaggedValue()); + JSHandle handleTagValDataViewFrom2(thread_, handleArrayBuf2.GetTaggedValue()); + JSHandle handleTagValDataViewTo2(thread_, handleDataView->GetViewedArrayBuffer()); + EXPECT_TRUE(JSTaggedValue::Equal(thread_, handleTagValDataViewFrom2, handleTagValDataViewTo2)); + EXPECT_FALSE(JSTaggedValue::Equal(thread_, handleTagValDataViewFrom1, handleTagValDataViewFrom2)); } /* @@ -161,28 +159,27 @@ TEST_F(JSDataViewTest, SetViewedArrayBuffer) */ TEST_F(JSDataViewTest, SetByteLength) { - EcmaVM *ecma_vm_ptr = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm_ptr->GetFactory(); - JSHandle handle_func_array_buf(ecma_vm_ptr->GetGlobalEnv()->GetArrayBufferFunction()); - JSHandle handle_tag_val_func_array_buf(handle_func_array_buf); - - int32_t length_data_array_buf = 8; - int32_t offset_data_view = 4; - int32_t length_data_view1 = 4; - int32_t length_data_view2 = 2; - JSHandle handle_tag_val_length_data_view2(thread_, JSTaggedValue(length_data_view2)); - JSHandle handle_array_buf( - factory->NewJSObjectByConstructor(handle_func_array_buf, handle_tag_val_func_array_buf)); - handle_array_buf->SetArrayBufferByteLength(thread_, JSTaggedValue(length_data_array_buf)); + EcmaVM *ecmaVmPtr = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVmPtr->GetFactory(); + JSHandle handleFuncArrayBuf(ecmaVmPtr->GetGlobalEnv()->GetArrayBufferFunction()); + JSHandle handleTagValFuncArrayBuf(handleFuncArrayBuf); + + int32_t lengthDataArrayBuf = 8; + int32_t offsetDataView = 4; + int32_t lengthDataView1 = 4; + int32_t lengthDataView2 = 2; + JSHandle handleTagValLengthDataView2(thread_, JSTaggedValue(lengthDataView2)); + JSHandle handleArrayBuf( + factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); + handleArrayBuf->SetArrayBufferByteLength(thread_, JSTaggedValue(lengthDataArrayBuf)); // Call "SetByteLength" function through "NewJSDataView" function of "object_factory.cpp" - JSHandle handle_data_view = - factory->NewJSDataView(handle_array_buf, offset_data_view, length_data_view1); - EXPECT_EQ(handle_data_view->GetByteLength().GetNumber(), length_data_view1); + JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf, offsetDataView, lengthDataView1); + EXPECT_EQ(handleDataView->GetByteLength().GetNumber(), lengthDataView1); // Call "SetByteLength" function in this TEST_F. - handle_data_view->SetByteLength(thread_, handle_tag_val_length_data_view2); - EXPECT_EQ(handle_data_view->GetByteLength().GetNumber(), length_data_view2); + handleDataView->SetByteLength(thread_, handleTagValLengthDataView2); + EXPECT_EQ(handleDataView->GetByteLength().GetNumber(), lengthDataView2); } /* @@ -195,27 +192,26 @@ TEST_F(JSDataViewTest, SetByteLength) */ TEST_F(JSDataViewTest, SetByteOffset) { - EcmaVM *ecma_vm_ptr = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm_ptr->GetFactory(); - JSHandle handle_func_array_buf1(ecma_vm_ptr->GetGlobalEnv()->GetArrayBufferFunction()); - JSHandle handle_tag_val_func_array_buf1(handle_func_array_buf1); - - int32_t length_data_array_buf = 8; - int32_t offset_data_view1 = 4; - int32_t offset_data_view2 = 6; - int32_t length_data_view = 2; - JSHandle handle_tag_val_offset_data_view2(thread_, JSTaggedValue(offset_data_view2)); - JSHandle handle_array_buf( - factory->NewJSObjectByConstructor(handle_func_array_buf1, handle_tag_val_func_array_buf1)); - handle_array_buf->SetArrayBufferByteLength(thread_, JSTaggedValue(length_data_array_buf)); + EcmaVM *ecmaVmPtr = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVmPtr->GetFactory(); + JSHandle handleFuncArrayBuf1(ecmaVmPtr->GetGlobalEnv()->GetArrayBufferFunction()); + JSHandle handleTagValFuncArrayBuf1(handleFuncArrayBuf1); + + int32_t lengthDataArrayBuf = 8; + int32_t offsetDataView1 = 4; + int32_t offsetDataView2 = 6; + int32_t lengthDataView = 2; + JSHandle handleTagValOffsetDataView2(thread_, JSTaggedValue(offsetDataView2)); + JSHandle handleArrayBuf( + factory->NewJSObjectByConstructor(handleFuncArrayBuf1, handleTagValFuncArrayBuf1)); + handleArrayBuf->SetArrayBufferByteLength(thread_, JSTaggedValue(lengthDataArrayBuf)); // Call "SetByteOffset" function through "NewJSDataView" function of "object_factory.cpp" - JSHandle handle_data_view = - factory->NewJSDataView(handle_array_buf, offset_data_view1, length_data_view); - EXPECT_EQ(handle_data_view->GetByteOffset().GetNumber(), offset_data_view1); + JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf, offsetDataView1, lengthDataView); + EXPECT_EQ(handleDataView->GetByteOffset().GetNumber(), offsetDataView1); // Call "SetByteOffset" function in this TEST_F. - handle_data_view->SetByteOffset(thread_, handle_tag_val_offset_data_view2); - EXPECT_EQ(handle_data_view->GetByteOffset().GetNumber(), offset_data_view2); + handleDataView->SetByteOffset(thread_, handleTagValOffsetDataView2); + EXPECT_EQ(handleDataView->GetByteOffset().GetNumber(), offsetDataView2); } } // namespace panda::test diff --git a/tests/runtime/common/js_date_test.cpp b/tests/runtime/common/js_date_test.cpp index e230f3db03ec401cc563754c3b21c90a94bc68d5..17ec36baa8cde8a641468c113cb165021f3b0bce 100644 --- a/tests/runtime/common/js_date_test.cpp +++ b/tests/runtime/common/js_date_test.cpp @@ -52,26 +52,26 @@ private: JSDate *JSDateCreate(JSThread *thread) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle date_function = global_env->GetDateFunction(); - JSHandle date_object = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(date_function), date_function)); - return *date_object; + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle dateFunction = globalEnv->GetDateFunction(); + JSHandle dateObject = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(dateFunction), dateFunction)); + return *dateObject; } TEST_F(JSDateTest, Create) { double tm = 0.0; - JSHandle js_date(thread_, JSDateCreate(thread_)); - EXPECT_EQ(js_date->GetTimeValue(), JSTaggedValue(tm)); - EXPECT_EQ(js_date->GetLocalOffset(), JSTaggedValue(JSDate::MAX_DOUBLE)); + JSHandle jsDate(thread_, JSDateCreate(thread_)); + EXPECT_EQ(jsDate->GetTimeValue(), JSTaggedValue(tm)); + EXPECT_EQ(jsDate->GetLocalOffset(), JSTaggedValue(JSDate::MAX_DOUBLE)); // NOLINTNEXTLINE(readability-magic-numbers) tm = 28 * 60 * 60 * 1000; - js_date->SetTimeValue(thread_, JSTaggedValue(tm)); + jsDate->SetTimeValue(thread_, JSTaggedValue(tm)); - [[maybe_unused]] double temp = js_date->GetTimeValue().GetDouble(); - EXPECT_EQ(js_date->GetTimeValue(), JSTaggedValue(tm)); + [[maybe_unused]] double temp = jsDate->GetTimeValue().GetDouble(); + EXPECT_EQ(jsDate->GetTimeValue(), JSTaggedValue(tm)); } TEST_F(JSDateTest, MakeTime) diff --git a/tests/runtime/common/js_forin_iterator_test.cpp b/tests/runtime/common/js_forin_iterator_test.cpp index 7d4797c62d6a994aa8f0648866be00560a2d0a30..8372adb52de9d94b7a74ba47c262cf925ad69b68 100644 --- a/tests/runtime/common/js_forin_iterator_test.cpp +++ b/tests/runtime/common/js_forin_iterator_test.cpp @@ -50,8 +50,8 @@ private: TEST_F(JSForinIteratorTest, Create) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle grandfather = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle grandfather = JSObject::ObjectCreate(thread_, nullHandle); EXPECT_TRUE(grandfather->GetPrototype(thread_).IsNull()); JSHandle father = JSObject::ObjectCreate(thread_, grandfather); @@ -61,16 +61,16 @@ TEST_F(JSForinIteratorTest, Create) JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString("key1")); JSHandle key2(thread_->GetEcmaVM()->GetFactory()->NewFromString("key2")); JSHandle key3(thread_->GetEcmaVM()->GetFactory()->NewFromString("key3")); - JSHandle key1_value(thread_, JSTaggedValue(1)); - JSHandle key2_value(thread_, JSTaggedValue(2)); - JSHandle key3_value(thread_, JSTaggedValue(3)); + JSHandle key1Value(thread_, JSTaggedValue(1)); + JSHandle key2Value(thread_, JSTaggedValue(2)); + JSHandle key3Value(thread_, JSTaggedValue(3)); - JSObject::SetProperty(thread_, JSHandle(grandfather), key3, key3_value); - JSObject::SetProperty(thread_, JSHandle(father), key2, key2_value); + JSObject::SetProperty(thread_, JSHandle(grandfather), key3, key3Value); + JSObject::SetProperty(thread_, JSHandle(father), key2, key2Value); - JSObject::SetProperty(thread_, JSHandle(son), key1, key1_value); - JSObject::SetProperty(thread_, JSHandle(son), key2, key1_value); - JSObject::SetProperty(thread_, JSHandle(son), key3, key1_value); + JSObject::SetProperty(thread_, JSHandle(son), key1, key1Value); + JSObject::SetProperty(thread_, JSHandle(son), key2, key1Value); + JSObject::SetProperty(thread_, JSHandle(son), key3, key1Value); JSHandle it = thread_->GetEcmaVM()->GetFactory()->NewJSForinIterator(JSHandle(son)); std::pair n1 = JSForInIterator::NextInternal(thread_, it); diff --git a/tests/runtime/common/js_function_test.cpp b/tests/runtime/common/js_function_test.cpp index 2c2b844d18f4a2c7bd906db6f4801f65623b38c1..445677c8709910ddc5497f998fa8f7a705728ed6 100644 --- a/tests/runtime/common/js_function_test.cpp +++ b/tests/runtime/common/js_function_test.cpp @@ -56,63 +56,63 @@ private: JSFunction *JSObjectCreate(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - return global_env->GetObjectFunction().GetObject(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + return globalEnv->GetObjectFunction().GetObject(); } TEST_F(JSFunctionTest, Create) { - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - JSHandle fun_handle = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env); - EXPECT_TRUE(*fun_handle != nullptr); - EXPECT_EQ(fun_handle->GetProtoOrDynClass(), JSTaggedValue::Hole()); - - JSHandle lexical_env = thread_->GetEcmaVM()->GetFactory()->NewLexicalEnv(0); - fun_handle->SetLexicalEnv(thread_, lexical_env.GetTaggedValue()); - EXPECT_EQ(fun_handle->GetLexicalEnv(), lexical_env.GetTaggedValue()); - EXPECT_TRUE(*lexical_env != nullptr); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + JSHandle funHandle = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env); + EXPECT_TRUE(*funHandle != nullptr); + EXPECT_EQ(funHandle->GetProtoOrDynClass(), JSTaggedValue::Hole()); + + JSHandle lexicalEnv = thread_->GetEcmaVM()->GetFactory()->NewLexicalEnv(0); + funHandle->SetLexicalEnv(thread_, lexicalEnv.GetTaggedValue()); + EXPECT_EQ(funHandle->GetLexicalEnv(), lexicalEnv.GetTaggedValue()); + EXPECT_TRUE(*lexicalEnv != nullptr); } TEST_F(JSFunctionTest, MakeConstructor) { - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle func = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, static_cast(nullptr), FunctionKind::BASE_CONSTRUCTOR); EXPECT_TRUE(*func != nullptr); - JSHandle func_handle(func); + JSHandle funcHandle(func); func->GetJSHClass()->SetExtensible(true); - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle obj = JSObject::ObjectCreate(thread_, null_handle); - JSHandle obj_value(obj); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle obj = JSObject::ObjectCreate(thread_, nullHandle); + JSHandle objValue(obj); - JSFunction::MakeConstructor(thread_, func, obj_value); + JSFunction::MakeConstructor(thread_, func, objValue); - JSHandle constructor_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("constructor")); + JSHandle constructorKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("constructor")); - JSHandle proto_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("prototype")); - JSTaggedValue proto = JSObject::GetProperty(thread_, func_handle, proto_key).GetValue().GetTaggedValue(); + JSHandle protoKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("prototype")); + JSTaggedValue proto = JSObject::GetProperty(thread_, funcHandle, protoKey).GetValue().GetTaggedValue(); JSTaggedValue constructor = - JSObject::GetProperty(thread_, JSHandle(obj), constructor_key).GetValue().GetTaggedValue(); - EXPECT_EQ(constructor, func_handle.GetTaggedValue()); + JSObject::GetProperty(thread_, JSHandle(obj), constructorKey).GetValue().GetTaggedValue(); + EXPECT_EQ(constructor, funcHandle.GetTaggedValue()); EXPECT_EQ(proto, obj.GetTaggedValue()); EXPECT_EQ(func->GetFunctionKind(), FunctionKind::BASE_CONSTRUCTOR); } TEST_F(JSFunctionTest, OrdinaryHasInstance) { - JSHandle obj_fun(thread_, JSObjectCreate(thread_)); + JSHandle objFun(thread_, JSObjectCreate(thread_)); JSHandle jsobject = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle obj(thread_, jsobject.GetTaggedValue()); EXPECT_TRUE(*jsobject != nullptr); - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle constructor = global_env->GetObjectFunction(); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle constructor = globalEnv->GetObjectFunction(); EXPECT_TRUE(ecmascript::JSFunction::OrdinaryHasInstance(thread_, constructor, obj)); } @@ -126,24 +126,24 @@ JSTaggedValue TestInvokeInternal(EcmaRuntimeCallInfo *argv) TEST_F(JSFunctionTest, Invoke) { - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle dynclass(thread_, JSObjectCreate(thread_)); JSHandle callee( thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(dynclass), dynclass)); EXPECT_TRUE(*callee != nullptr); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char key_array[] = "invoked"; - JSHandle callee_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(&key_array[0])); - JSHandle callee_func = + char keyArray[] = "invoked"; + JSHandle calleeKey(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(&keyArray[0])); + JSHandle calleeFunc = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, reinterpret_cast(TestInvokeInternal)); - JSHandle callee_value(callee_func); - JSObject::SetProperty(thread_, JSHandle(callee), callee_key, callee_value); + JSHandle calleeValue(calleeFunc); + JSObject::SetProperty(thread_, JSHandle(callee), calleeKey, calleeValue); auto info = NewRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), callee, JSTaggedValue::Undefined(), 1); info->SetCallArgs(JSTaggedValue(1)); - JSTaggedValue res = JSFunction::Invoke(info.Get(), callee_key); + JSTaggedValue res = JSFunction::Invoke(info.Get(), calleeKey); JSTaggedValue ruler = builtins_common::GetTaggedBoolean(true); EXPECT_EQ(res.GetRawData(), ruler.GetRawData()); @@ -153,16 +153,15 @@ TEST_F(JSFunctionTest, SetSymbolFunctionName) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle js_function = factory->NewJSFunction(env); + JSHandle jsFunction = factory->NewJSFunction(env); JSHandle symbol = factory->NewPublicSymbolWithChar("name"); JSHandle name = factory->NewFromString("[name]"); JSHandle prefix(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, JSHandle(js_function), JSHandle(symbol), - prefix); - JSHandle function_name = - JSFunctionBase::GetFunctionName(thread_, JSHandle(js_function)); - EXPECT_TRUE(function_name->IsString()); - EXPECT_TRUE(EcmaString::StringsAreEqual(*(JSHandle(function_name)), *name)); + JSFunction::SetFunctionName(thread_, JSHandle(jsFunction), JSHandle(symbol), prefix); + JSHandle functionName = + JSFunctionBase::GetFunctionName(thread_, JSHandle(jsFunction)); + EXPECT_TRUE(functionName->IsString()); + EXPECT_TRUE(EcmaString::StringsAreEqual(*(JSHandle(functionName)), *name)); } } // namespace panda::test diff --git a/tests/runtime/common/js_handle_test.cpp b/tests/runtime/common/js_handle_test.cpp index 6848c8ec2454f1831df045199f234ad46d7ce19d..453b786a2d66e458fc299576ad1f9c0e26dd413b 100644 --- a/tests/runtime/common/js_handle_test.cpp +++ b/tests/runtime/common/js_handle_test.cpp @@ -62,29 +62,29 @@ TEST_F(JSHandleTest, NewGlobalHandle) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); auto global = thread_->GetEcmaGlobalStorage(); - uintptr_t global_string = 0; + uintptr_t globalString = 0; { - [[maybe_unused]] EcmaHandleScope scope_nested(thread_); + [[maybe_unused]] EcmaHandleScope scopeNested(thread_); auto string1 = factory->NewFromString("test1"); - global_string = global->NewGlobalHandle(string1.GetTaggedType()); + globalString = global->NewGlobalHandle(string1.GetTaggedType()); } // trigger GC thread_->GetEcmaVM()->CollectGarbage(); // check result - EXPECT_TRUE(factory->NewFromString("test1")->Compare(*reinterpret_cast(global_string)) == 0); + EXPECT_TRUE(factory->NewFromString("test1")->Compare(*reinterpret_cast(globalString)) == 0); } -static void FillGlobalString(uintptr_t global_string[], int length, EcmaGlobalStorage *global, ObjectFactory *factory, +static void FillGlobalString(uintptr_t globalString[], int length, EcmaGlobalStorage *global, ObjectFactory *factory, JSThread *thread) { { - [[maybe_unused]] EcmaHandleScope scope_nested(thread); + [[maybe_unused]] EcmaHandleScope scopeNested(thread); for (int i = 0; i < length; i++) { std::string test = "test" + std::to_string(i); auto string1 = factory->NewFromString(test.c_str()); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - global_string[i] = global->NewGlobalHandle(string1.GetTaggedType()); + globalString[i] = global->NewGlobalHandle(string1.GetTaggedType()); } } } @@ -94,24 +94,24 @@ TEST_F(JSHandleTest, NewGlobalHandle1) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); auto global = thread_->GetEcmaGlobalStorage(); - uintptr_t global_string[600] = {0}; - FillGlobalString(global_string, 600, global, factory, thread_); + uintptr_t globalString[600] = {0}; + FillGlobalString(globalString, 600, global, factory, thread_); // trigger GC thread_->GetEcmaVM()->CollectGarbage(); for (int i = 300; i > 200; i--) { - global->DisposeGlobalHandle(global_string[i]); + global->DisposeGlobalHandle(globalString[i]); } // check result for (int i = 0; i <= 200; i++) { std::string test = "test" + std::to_string(i); - EXPECT_TRUE(factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(global_string[i])) == + EXPECT_TRUE(factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(globalString[i])) == 0); } // trigger GC thread_->GetEcmaVM()->CollectGarbage(); for (int i = 301; i < 600; i++) { std::string test = "test" + std::to_string(i); - EXPECT_TRUE(factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(global_string[i])) == + EXPECT_TRUE(factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(globalString[i])) == 0); } } @@ -121,10 +121,10 @@ TEST_F(JSHandleTest, DisposeGlobalHandle) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); auto global = thread_->GetEcmaGlobalStorage(); - uintptr_t global_string[600] = {0}; - FillGlobalString(global_string, 600, global, factory, thread_); + uintptr_t globalString[600] = {0}; + FillGlobalString(globalString, 600, global, factory, thread_); for (int i = 512; i > 200; i--) { - global->DisposeGlobalHandle(global_string[i]); + global->DisposeGlobalHandle(globalString[i]); } int count = 0; global->IterateUsageGlobal([&count](EcmaGlobalStorage::Node *node) { @@ -140,25 +140,25 @@ TEST_F(JSHandleTest, DisposeAndNewGlobalHandle) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); auto global = thread_->GetEcmaGlobalStorage(); - uintptr_t global_string[768] = {0}; - FillGlobalString(global_string, 768, global, factory, thread_); + uintptr_t globalString[768] = {0}; + FillGlobalString(globalString, 768, global, factory, thread_); for (int i = 767; i > 200; i--) { - global->DisposeGlobalHandle(global_string[i]); + global->DisposeGlobalHandle(globalString[i]); } // trigger GC thread_->GetEcmaVM()->CollectGarbage(); { - [[maybe_unused]] EcmaHandleScope scope_nested(thread_); + [[maybe_unused]] EcmaHandleScope scopeNested(thread_); for (int i = 200; i < 400; i++) { std::string test = "test" + std::to_string(i); auto string1 = factory->NewFromString(test.c_str()); - global_string[i] = global->NewGlobalHandle(string1.GetTaggedType()); + globalString[i] = global->NewGlobalHandle(string1.GetTaggedType()); } } // check result for (int i = 0; i <= 300; i++) { std::string test = "test" + std::to_string(i); - EXPECT_TRUE(factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(global_string[i])) == + EXPECT_TRUE(factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(globalString[i])) == 0); } } @@ -168,25 +168,25 @@ TEST_F(JSHandleTest, DISABLED_NewWeakGlobalHandle) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); auto global = thread_->GetEcmaGlobalStorage(); - uintptr_t global_string = 0; + uintptr_t globalString = 0; { - [[maybe_unused]] EcmaHandleScope scope_nested(thread_); + [[maybe_unused]] EcmaHandleScope scopeNested(thread_); auto string1 = factory->NewFromString("test1"); - global_string = global->NewGlobalHandle(string1.GetTaggedType()); - global_string = global->SetWeak(global_string); + globalString = global->NewGlobalHandle(string1.GetTaggedType()); + globalString = global->SetWeak(globalString); // trigger GC thread_->GetEcmaVM()->CollectGarbage(); // check result - EXPECT_TRUE(factory->NewFromString("test1")->Compare(*reinterpret_cast(global_string)) == 0); - EXPECT_TRUE(global->IsWeak(global_string)); + EXPECT_TRUE(factory->NewFromString("test1")->Compare(*reinterpret_cast(globalString)) == 0); + EXPECT_TRUE(global->IsWeak(globalString)); } // trigger GC thread_->GetEcmaVM()->CollectGarbage(); // check weak reference - JSTaggedType result = *reinterpret_cast(global_string); + JSTaggedType result = *reinterpret_cast(globalString); EXPECT_TRUE(result == JSTaggedValue::Undefined().GetRawData()); } @@ -195,18 +195,18 @@ TEST_F(JSHandleTest, DISABLED_NewWeakGlobalHandle1) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); auto global = thread_->GetEcmaGlobalStorage(); - uintptr_t global_string[800] = {0}; + uintptr_t globalString[800] = {0}; { - [[maybe_unused]] EcmaHandleScope scope_nested(thread_); + [[maybe_unused]] EcmaHandleScope scopeNested(thread_); for (int i = 0; i < 800; i++) { std::string test = "test" + std::to_string(i); auto string1 = factory->NewFromString(test.c_str()); - global_string[i] = global->NewGlobalHandle(string1.GetTaggedType()); - global_string[i] = global->SetWeak(global_string[i]); - EXPECT_TRUE(global->IsWeak(global_string[i])); + globalString[i] = global->NewGlobalHandle(string1.GetTaggedType()); + globalString[i] = global->SetWeak(globalString[i]); + EXPECT_TRUE(global->IsWeak(globalString[i])); } for (int i = 600; i > 200; i--) { - global->DisposeGlobalHandle(global_string[i]); + global->DisposeGlobalHandle(globalString[i]); } // trigger GC thread_->GetEcmaVM()->CollectGarbage(); @@ -214,13 +214,13 @@ TEST_F(JSHandleTest, DISABLED_NewWeakGlobalHandle1) for (int i = 0; i <= 200; i++) { std::string test = "test" + std::to_string(i); EXPECT_TRUE( - factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(global_string[i])) == 0); + factory->NewFromString(test.c_str())->Compare(*reinterpret_cast(globalString[i])) == 0); } } // trigger GC thread_->GetEcmaVM()->CollectGarbage(); for (int i = 601; i < 800; i++) { - EXPECT_TRUE(*reinterpret_cast(global_string[i]) == JSTaggedValue::Undefined().GetRawData()); + EXPECT_TRUE(*reinterpret_cast(globalString[i]) == JSTaggedValue::Undefined().GetRawData()); } } } // namespace panda::test diff --git a/tests/runtime/common/js_iterator_test.cpp b/tests/runtime/common/js_iterator_test.cpp index 69a0c94126c29b91d284d51f88fd17f1fed55ca6..b0aa2b6f7558c50c617ee415919b3d7fe02ac39f 100644 --- a/tests/runtime/common/js_iterator_test.cpp +++ b/tests/runtime/common/js_iterator_test.cpp @@ -71,15 +71,15 @@ TEST_F(JSIteratorTest, GetIterator) TEST_F(JSIteratorTest, IteratorNext) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle value_str = thread_->GlobalConstants()->GetHandledValueString(); + JSHandle valueStr = thread_->GlobalConstants()->GetHandledValueString(); JSHandle data(factory->NewTaggedArray(1)); data->Set(thread_, 0, JSTaggedValue(1)); JSHandle array(JSArray::CreateArrayFromList(thread_, data)); JSHandle iter(JSIterator::GetIterator(thread_, array)); JSHandle result(JSIterator::IteratorNextOld(thread_, iter)); - JSHandle result_value(JSObject::GetProperty(thread_, result, value_str).GetValue()); - EXPECT_EQ(result_value->GetInt(), 1); + JSHandle resultValue(JSObject::GetProperty(thread_, result, valueStr).GetValue()); + EXPECT_EQ(resultValue->GetInt(), 1); } TEST_F(JSIteratorTest, IteratorComplete) @@ -109,8 +109,8 @@ TEST_F(JSIteratorTest, IteratorValue) JSHandle array(JSArray::CreateArrayFromList(thread_, data)); JSHandle iter(JSIterator::GetIterator(thread_, array)); JSHandle result(JSIterator::IteratorNextOld(thread_, iter)); - JSHandle result_value(JSIterator::IteratorValue(thread_, result)); - EXPECT_EQ(result_value->GetInt(), 1); + JSHandle resultValue(JSIterator::IteratorValue(thread_, result)); + EXPECT_EQ(resultValue->GetInt(), 1); } TEST_F(JSIteratorTest, IteratorStep) diff --git a/tests/runtime/common/js_map_test.cpp b/tests/runtime/common/js_map_test.cpp index 0b9ead9320993fad57c24f9795d49d3c71a0e638..2d1efad71ccc47e96ccd379f1c628a7167947acc 100644 --- a/tests/runtime/common/js_map_test.cpp +++ b/tests/runtime/common/js_map_test.cpp @@ -59,8 +59,8 @@ protected: JSHandle constructor = env->GetMapFunction(); JSHandle map = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); - JSHandle hash_map = LinkedHashMap::Create(thread_); - map->SetLinkedMap(thread_, hash_map); + JSHandle hashMap = LinkedHashMap::Create(thread_); + map->SetLinkedMap(thread_, hashMap); return *map; } @@ -96,11 +96,11 @@ TEST_F(JSMapTest, DeleteAndGet) // add 40 keys // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char key_array[] = "key0"; + char keyArray[] = "key0"; // NOLINTNEXTLINE(readability-magic-numbers) for (int i = 0; i < 40; i++) { - key_array[3] = '1' + i; - JSHandle key(factory->NewFromString(key_array)); + keyArray[3] = '1' + i; + JSHandle key(factory->NewFromString(keyArray)); JSHandle value(thread_, JSTaggedValue(i)); JSMap::Set(thread_, map, key, value); int hash = LinkedHash::Hash(key.GetTaggedValue()); @@ -108,12 +108,12 @@ TEST_F(JSMapTest, DeleteAndGet) } EXPECT_EQ(map->GetSize(), 40); // whether js_map has delete key - key_array[3] = '1' + 8; - JSHandle delete_key(factory->NewFromString(key_array)); + keyArray[3] = '1' + 8; + JSHandle deleteKey(factory->NewFromString(keyArray)); EXPECT_EQ(map->GetValue(8), JSTaggedValue(8)); - JSMap::Delete(thread_, map, delete_key); - int hash = LinkedHash::Hash(delete_key.GetTaggedValue()); - EXPECT_FALSE(map->Has(delete_key.GetTaggedValue(), hash)); + JSMap::Delete(thread_, map, deleteKey); + int hash = LinkedHash::Hash(deleteKey.GetTaggedValue()); + EXPECT_FALSE(map->Has(deleteKey.GetTaggedValue(), hash)); EXPECT_EQ(map->GetSize(), 39); } @@ -129,40 +129,40 @@ TEST_F(JSMapTest, Iterator) JSMap::Set(thread_, map, key, value); } - JSHandle key_iter(factory->NewJSMapIterator(map, IterationKind::KEY)); - JSHandle value_iter(factory->NewJSMapIterator(map, IterationKind::VALUE)); + JSHandle keyIter(factory->NewJSMapIterator(map, IterationKind::KEY)); + JSHandle valueIter(factory->NewJSMapIterator(map, IterationKind::VALUE)); JSHandle iter(factory->NewJSMapIterator(map, IterationKind::KEY_AND_VALUE)); - JSHandle index_key(thread_, JSTaggedValue(0)); - JSHandle element_key(thread_, JSTaggedValue(1)); + JSHandle indexKey(thread_, JSTaggedValue(0)); + JSHandle elementKey(thread_, JSTaggedValue(1)); - JSHandle key_result0 = JSIterator::IteratorStep(thread_, key_iter); - JSHandle value_result0 = JSIterator::IteratorStep(thread_, value_iter); + JSHandle keyResult0 = JSIterator::IteratorStep(thread_, keyIter); + JSHandle valueResult0 = JSIterator::IteratorStep(thread_, valueIter); JSHandle result0 = JSIterator::IteratorStep(thread_, iter); - EXPECT_EQ(0, JSIterator::IteratorValue(thread_, key_result0)->GetInt()); - EXPECT_EQ(10, JSIterator::IteratorValue(thread_, value_result0)->GetInt()); - JSHandle result0_handle = JSIterator::IteratorValue(thread_, result0); - EXPECT_EQ(0, JSObject::GetProperty(thread_, result0_handle, index_key).GetValue()->GetInt()); - EXPECT_EQ(10, JSObject::GetProperty(thread_, result0_handle, element_key).GetValue()->GetInt()); + EXPECT_EQ(0, JSIterator::IteratorValue(thread_, keyResult0)->GetInt()); + EXPECT_EQ(10, JSIterator::IteratorValue(thread_, valueResult0)->GetInt()); + JSHandle result0Handle = JSIterator::IteratorValue(thread_, result0); + EXPECT_EQ(0, JSObject::GetProperty(thread_, result0Handle, indexKey).GetValue()->GetInt()); + EXPECT_EQ(10, JSObject::GetProperty(thread_, result0Handle, elementKey).GetValue()->GetInt()); - JSHandle key_result1 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(1, JSIterator::IteratorValue(thread_, key_result1)->GetInt()); + JSHandle keyResult1 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(1, JSIterator::IteratorValue(thread_, keyResult1)->GetInt()); for (int i = 0; i < 3; i++) { JSHandle key(thread_, JSTaggedValue(i)); JSMap::Delete(thread_, map, key); } - JSHandle key_result2 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(3, JSIterator::IteratorValue(thread_, key_result2)->GetInt()); - JSHandle key_result3 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(4, JSIterator::IteratorValue(thread_, key_result3)->GetInt()); + JSHandle keyResult2 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(3, JSIterator::IteratorValue(thread_, keyResult2)->GetInt()); + JSHandle keyResult3 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(4, JSIterator::IteratorValue(thread_, keyResult3)->GetInt()); JSHandle key(thread_, JSTaggedValue(5)); JSMap::Set(thread_, map, key, key); - JSHandle key_result4 = JSIterator::IteratorStep(thread_, key_iter); + JSHandle keyResult4 = JSIterator::IteratorStep(thread_, keyIter); - EXPECT_EQ(5, JSIterator::IteratorValue(thread_, key_result4)->GetInt()); - JSHandle key_result5 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(JSTaggedValue::False(), key_result5.GetTaggedValue()); + EXPECT_EQ(5, JSIterator::IteratorValue(thread_, keyResult4)->GetInt()); + JSHandle keyResult5 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(JSTaggedValue::False(), keyResult5.GetTaggedValue()); } } // namespace panda::test diff --git a/tests/runtime/common/js_object_test.cpp b/tests/runtime/common/js_object_test.cpp index 2ae5f0947f9755f5139ccc38d8c82392c412d21f..4dcddf21754580855c065ca84288ff68d7616bca 100644 --- a/tests/runtime/common/js_object_test.cpp +++ b/tests/runtime/common/js_object_test.cpp @@ -50,23 +50,23 @@ private: static JSFunction *JSObjectTestCreate(JSThread *thread) { - JSHandle global_env = thread->GetEcmaVM()->GetGlobalEnv(); - return global_env->GetObjectFunction().GetObject(); + JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + return globalEnv->GetObjectFunction().GetObject(); } TEST_F(JSObjectTest, Create) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle jsobject = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*jsobject != nullptr); } TEST_F(JSObjectTest, SetProperty) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle jsobject = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*jsobject != nullptr); char array[] = "x"; @@ -83,9 +83,9 @@ TEST_F(JSObjectTest, SetProperty) TEST_F(JSObjectTest, GetProperty) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*obj != nullptr); char array[] = "x"; @@ -100,9 +100,9 @@ TEST_F(JSObjectTest, GetProperty) TEST_F(JSObjectTest, DeleteProperty) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*obj != nullptr); char array[] = "print"; @@ -127,47 +127,46 @@ TEST_F(JSObjectTest, DeleteProperty) TEST_F(JSObjectTest, DeletePropertyGlobal) { - JSHandle global_env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle global(thread_, global_env->GetGlobalObject()); - JSHandle print_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("print")); - JSHandle print_test_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("print_test")); + JSHandle globalEnv = thread_->GetEcmaVM()->GetGlobalEnv(); + JSHandle global(thread_, globalEnv->GetGlobalObject()); + JSHandle printKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("print")); + JSHandle printTestKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("print_test")); - JSHandle value = JSObject::GetProperty(thread_, global, print_key).GetValue(); + JSHandle value = JSObject::GetProperty(thread_, global, printKey).GetValue(); - JSObject::SetProperty(thread_, global, print_test_key, value); + JSObject::SetProperty(thread_, global, printTestKey, value); - JSTaggedValue val2 = JSObject::GetProperty(thread_, global, print_test_key).GetValue().GetTaggedValue(); + JSTaggedValue val2 = JSObject::GetProperty(thread_, global, printTestKey).GetValue().GetTaggedValue(); EXPECT_EQ(val2, value.GetTaggedValue()); - JSTaggedValue::DeletePropertyOrThrow(thread_, global, print_test_key); - JSTaggedValue val3 = JSObject::GetProperty(thread_, global, print_key).GetValue().GetTaggedValue(); + JSTaggedValue::DeletePropertyOrThrow(thread_, global, printTestKey); + JSTaggedValue val3 = JSObject::GetProperty(thread_, global, printKey).GetValue().GetTaggedValue(); EXPECT_NE(val3, JSTaggedValue::Undefined()); } TEST_F(JSObjectTest, GetPropertyInPrototypeChain) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle grandfather = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle grandfather = JSObject::ObjectCreate(thread_, nullHandle); JSHandle father = JSObject::ObjectCreate(thread_, grandfather); JSHandle son = JSObject::ObjectCreate(thread_, father); - JSHandle son_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key1")); - JSHandle father_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key2")); - JSHandle grandfather_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key3")); - JSHandle son_value(thread_, JSTaggedValue(1)); - JSHandle father_value(thread_, JSTaggedValue(2)); - JSHandle grandfather_value(thread_, JSTaggedValue(3)); - - JSObject::SetProperty(thread_, JSHandle(son), son_key, son_value); - JSObject::SetProperty(thread_, JSHandle(father), father_key, father_value); - JSObject::SetProperty(thread_, JSHandle(grandfather), grandfather_key, grandfather_value); - - EXPECT_EQ(son_value.GetTaggedValue(), - JSObject::GetProperty(thread_, JSHandle(son), son_key).GetValue().GetTaggedValue()); - EXPECT_EQ(father_value.GetTaggedValue(), - JSObject::GetProperty(thread_, JSHandle(son), father_key).GetValue().GetTaggedValue()); - EXPECT_EQ( - grandfather_value.GetTaggedValue(), - JSObject::GetProperty(thread_, JSHandle(son), grandfather_key).GetValue().GetTaggedValue()); + JSHandle sonKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key1")); + JSHandle fatherKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key2")); + JSHandle grandfatherKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key3")); + JSHandle sonValue(thread_, JSTaggedValue(1)); + JSHandle fatherValue(thread_, JSTaggedValue(2)); + JSHandle grandfatherValue(thread_, JSTaggedValue(3)); + + JSObject::SetProperty(thread_, JSHandle(son), sonKey, sonValue); + JSObject::SetProperty(thread_, JSHandle(father), fatherKey, fatherValue); + JSObject::SetProperty(thread_, JSHandle(grandfather), grandfatherKey, grandfatherValue); + + EXPECT_EQ(sonValue.GetTaggedValue(), + JSObject::GetProperty(thread_, JSHandle(son), sonKey).GetValue().GetTaggedValue()); + EXPECT_EQ(fatherValue.GetTaggedValue(), + JSObject::GetProperty(thread_, JSHandle(son), fatherKey).GetValue().GetTaggedValue()); + EXPECT_EQ(grandfatherValue.GetTaggedValue(), + JSObject::GetProperty(thread_, JSHandle(son), grandfatherKey).GetValue().GetTaggedValue()); } TEST_F(JSObjectTest, PropertyAttribute) @@ -214,9 +213,9 @@ TEST_F(JSObjectTest, PropertyAttribute) TEST_F(JSObjectTest, CreateDataProperty) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*obj != nullptr); char array[] = "x"; @@ -239,9 +238,9 @@ TEST_F(JSObjectTest, CreateDataProperty) TEST_F(JSObjectTest, CreateMethodProperty) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*obj != nullptr); char array[] = "x"; @@ -264,9 +263,9 @@ TEST_F(JSObjectTest, CreateMethodProperty) TEST_F(JSObjectTest, DefinePropertyOrThrow) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*obj != nullptr); char array[] = "x"; @@ -275,24 +274,24 @@ TEST_F(JSObjectTest, DefinePropertyOrThrow) PropertyDescriptor desc1(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); bool success = JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc1); EXPECT_TRUE(success); - PropertyDescriptor desc_res1(thread_); - success = JSObject::GetOwnProperty(thread_, obj, key, desc_res1); + PropertyDescriptor descRes1(thread_); + success = JSObject::GetOwnProperty(thread_, obj, key, descRes1); EXPECT_TRUE(success); - EXPECT_EQ(1, desc_res1.GetValue()->GetInt()); - EXPECT_EQ(true, desc_res1.IsWritable()); - EXPECT_EQ(true, desc_res1.IsEnumerable()); - EXPECT_EQ(true, desc_res1.IsConfigurable()); + EXPECT_EQ(1, descRes1.GetValue()->GetInt()); + EXPECT_EQ(true, descRes1.IsWritable()); + EXPECT_EQ(true, descRes1.IsEnumerable()); + EXPECT_EQ(true, descRes1.IsConfigurable()); PropertyDescriptor desc2(thread_, false, true, true); success = JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc2); EXPECT_TRUE(success); - PropertyDescriptor desc_res2(thread_); - success = JSObject::GetOwnProperty(thread_, obj, key, desc_res2); + PropertyDescriptor descRes2(thread_); + success = JSObject::GetOwnProperty(thread_, obj, key, descRes2); EXPECT_TRUE(success); - EXPECT_EQ(1, desc_res2.GetValue()->GetInt()); - EXPECT_EQ(false, desc_res2.IsWritable()); - EXPECT_EQ(true, desc_res2.IsEnumerable()); - EXPECT_EQ(true, desc_res2.IsConfigurable()); + EXPECT_EQ(1, descRes2.GetValue()->GetInt()); + EXPECT_EQ(false, descRes2.IsWritable()); + EXPECT_EQ(true, descRes2.IsEnumerable()); + EXPECT_EQ(true, descRes2.IsConfigurable()); PropertyDescriptor desc3(thread_); desc3.SetWritable(false); @@ -300,13 +299,13 @@ TEST_F(JSObjectTest, DefinePropertyOrThrow) desc3.SetConfigurable(false); success = JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc3); EXPECT_TRUE(success); - PropertyDescriptor desc_res3(thread_); - success = JSObject::GetOwnProperty(thread_, obj, key, desc_res3); + PropertyDescriptor descRes3(thread_); + success = JSObject::GetOwnProperty(thread_, obj, key, descRes3); EXPECT_TRUE(success); - EXPECT_EQ(1, desc_res3.GetValue()->GetInt()); - EXPECT_EQ(false, desc_res3.IsWritable()); - EXPECT_EQ(false, desc_res3.IsEnumerable()); - EXPECT_EQ(false, desc_res3.IsConfigurable()); + EXPECT_EQ(1, descRes3.GetValue()->GetInt()); + EXPECT_EQ(false, descRes3.IsWritable()); + EXPECT_EQ(false, descRes3.IsEnumerable()); + EXPECT_EQ(false, descRes3.IsConfigurable()); PropertyDescriptor desc4(thread_, JSHandle(thread_, JSTaggedValue(2))); success = JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc4); @@ -315,9 +314,9 @@ TEST_F(JSObjectTest, DefinePropertyOrThrow) TEST_F(JSObjectTest, HasProperty) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*obj != nullptr); char array[] = "x"; @@ -338,58 +337,58 @@ TEST_F(JSObjectTest, HasProperty) TEST_F(JSObjectTest, HasPropertyWithProtoType) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle grandfather = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle grandfather = JSObject::ObjectCreate(thread_, nullHandle); JSHandle father = JSObject::ObjectCreate(thread_, grandfather); JSHandle son = JSObject::ObjectCreate(thread_, father); - auto test_grand = grandfather->GetPrototype(thread_); - auto test_father = father->GetPrototype(thread_); - auto test_son = son->GetPrototype(thread_); - EXPECT_TRUE(test_son != test_father); - EXPECT_TRUE(test_grand != test_father); - JSHandle son_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key1")); - JSHandle father_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key2")); - JSHandle grandfather_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key3")); - JSHandle son_value(thread_, JSTaggedValue(1)); - JSHandle father_value(thread_, JSTaggedValue(2)); - JSHandle grandfather_value(thread_, JSTaggedValue(3)); - - JSObject::SetProperty(thread_, JSHandle(son), son_key, son_value); - JSObject::SetProperty(thread_, JSHandle(father), father_key, father_value); - JSObject::SetProperty(thread_, JSHandle(grandfather), grandfather_key, grandfather_value); - - bool flag = JSObject::HasProperty(thread_, son, son_key); + auto testGrand = grandfather->GetPrototype(thread_); + auto testFather = father->GetPrototype(thread_); + auto testSon = son->GetPrototype(thread_); + EXPECT_TRUE(testSon != testFather); + EXPECT_TRUE(testGrand != testFather); + JSHandle sonKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key1")); + JSHandle fatherKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key2")); + JSHandle grandfatherKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key3")); + JSHandle sonValue(thread_, JSTaggedValue(1)); + JSHandle fatherValue(thread_, JSTaggedValue(2)); + JSHandle grandfatherValue(thread_, JSTaggedValue(3)); + + JSObject::SetProperty(thread_, JSHandle(son), sonKey, sonValue); + JSObject::SetProperty(thread_, JSHandle(father), fatherKey, fatherValue); + JSObject::SetProperty(thread_, JSHandle(grandfather), grandfatherKey, grandfatherValue); + + bool flag = JSObject::HasProperty(thread_, son, sonKey); EXPECT_TRUE(flag); - flag = JSObject::HasProperty(thread_, son, father_key); + flag = JSObject::HasProperty(thread_, son, fatherKey); EXPECT_TRUE(flag); - flag = JSObject::HasProperty(thread_, son, grandfather_key); + flag = JSObject::HasProperty(thread_, son, grandfatherKey); EXPECT_TRUE(flag); } TEST_F(JSObjectTest, HasOwnProperty) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle grandfather = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle grandfather = JSObject::ObjectCreate(thread_, nullHandle); JSHandle father = JSObject::ObjectCreate(thread_, grandfather); JSHandle son = JSObject::ObjectCreate(thread_, father); - JSHandle son_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key1")); - JSHandle father_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key2")); - JSHandle grandfather_key(thread_->GetEcmaVM()->GetFactory()->NewFromString("key3")); - JSHandle son_value(thread_, JSTaggedValue(1)); - JSHandle father_value(thread_, JSTaggedValue(2)); - JSHandle grandfather_value(thread_, JSTaggedValue(3)); + JSHandle sonKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key1")); + JSHandle fatherKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key2")); + JSHandle grandfatherKey(thread_->GetEcmaVM()->GetFactory()->NewFromString("key3")); + JSHandle sonValue(thread_, JSTaggedValue(1)); + JSHandle fatherValue(thread_, JSTaggedValue(2)); + JSHandle grandfatherValue(thread_, JSTaggedValue(3)); - JSObject::SetProperty(thread_, JSHandle(son), son_key, son_value); - JSObject::SetProperty(thread_, JSHandle(father), father_key, father_value); - JSObject::SetProperty(thread_, JSHandle(grandfather), grandfather_key, grandfather_value); + JSObject::SetProperty(thread_, JSHandle(son), sonKey, sonValue); + JSObject::SetProperty(thread_, JSHandle(father), fatherKey, fatherValue); + JSObject::SetProperty(thread_, JSHandle(grandfather), grandfatherKey, grandfatherValue); - bool flag = JSTaggedValue::HasOwnProperty(thread_, JSHandle::Cast(son), son_key); + bool flag = JSTaggedValue::HasOwnProperty(thread_, JSHandle::Cast(son), sonKey); EXPECT_TRUE(flag); - flag = JSTaggedValue::HasOwnProperty(thread_, JSHandle::Cast(son), father_key); + flag = JSTaggedValue::HasOwnProperty(thread_, JSHandle::Cast(son), fatherKey); EXPECT_FALSE(flag); - flag = JSTaggedValue::HasOwnProperty(thread_, JSHandle::Cast(son), grandfather_key); + flag = JSTaggedValue::HasOwnProperty(thread_, JSHandle::Cast(son), grandfatherKey); EXPECT_FALSE(flag); } @@ -426,8 +425,8 @@ TEST_F(JSObjectTest, GetOwnPropertyKeys) TEST_F(JSObjectTest, ObjectCreateMethod) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle grandfather = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle grandfather = JSObject::ObjectCreate(thread_, nullHandle); JSHandle father = JSObject::ObjectCreate(thread_, grandfather); JSHandle son = JSObject::ObjectCreate(thread_, father); @@ -438,8 +437,8 @@ TEST_F(JSObjectTest, ObjectCreateMethod) TEST_F(JSObjectTest, GetMethod) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle obj = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle obj = JSObject::ObjectCreate(thread_, nullHandle); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle func(thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env)); EXPECT_TRUE(*func != nullptr); @@ -451,14 +450,14 @@ TEST_F(JSObjectTest, GetMethod) TEST_F(JSObjectTest, EnumerableOwnNames) { - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(*obj != nullptr); - PandaString tag_c_str = "x"; - JSHandle tag_string = thread_->GetEcmaVM()->GetFactory()->NewFromString(&tag_c_str[0]); - JSHandle key(tag_string); + PandaString tagCStr = "x"; + JSHandle tagString = thread_->GetEcmaVM()->GetFactory()->NewFromString(&tagCStr[0]); + JSHandle key(tagString); JSHandle value(thread_, JSTaggedValue(1)); @@ -467,27 +466,27 @@ TEST_F(JSObjectTest, EnumerableOwnNames) JSHandle names = JSObject::EnumerableOwnNames(thread_, obj); - JSHandle key_from_names(thread_, JSTaggedValue(names->Get(0))); - EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj), key_from_names).GetValue()->GetInt(), 1); + JSHandle keyFromNames(thread_, JSTaggedValue(names->Get(0))); + EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj), keyFromNames).GetValue()->GetInt(), 1); - PropertyDescriptor desc_no_enum(thread_); - desc_no_enum.SetEnumerable(false); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc_no_enum); + PropertyDescriptor descNoEnum(thread_); + descNoEnum.SetEnumerable(false); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, descNoEnum); EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj), key).GetValue()->GetInt(), 1); - JSHandle names_no_enum = JSObject::EnumerableOwnNames(thread_, obj); - EXPECT_TRUE(names_no_enum->GetLength() == 0); + JSHandle namesNoEnum = JSObject::EnumerableOwnNames(thread_, obj); + EXPECT_TRUE(namesNoEnum->GetLength() == 0); - PropertyDescriptor desc_enum(thread_); - desc_enum.SetConfigurable(false); - desc_enum.SetEnumerable(true); - JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, desc_enum); + PropertyDescriptor descEnum(thread_); + descEnum.SetConfigurable(false); + descEnum.SetEnumerable(true); + JSTaggedValue::DefinePropertyOrThrow(thread_, JSHandle(obj), key, descEnum); EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj), key).GetValue()->GetInt(), 1); - JSHandle names_no_config = JSObject::EnumerableOwnNames(thread_, obj); + JSHandle namesNoConfig = JSObject::EnumerableOwnNames(thread_, obj); - JSHandle key_no_config(thread_, JSTaggedValue(names_no_config->Get(0))); - EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj), key_no_config).GetValue()->GetInt(), 1); + JSHandle keyNoConfig(thread_, JSTaggedValue(namesNoConfig->Get(0))); + EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj), keyNoConfig).GetValue()->GetInt(), 1); } TEST_F(JSObjectTest, SetIntegrityLevelSealed) @@ -496,8 +495,8 @@ TEST_F(JSObjectTest, SetIntegrityLevelSealed) JSHandle obj1 = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(dynclass1), dynclass1); EXPECT_TRUE(*obj1 != nullptr); - PandaString undefined_c_str = "x"; - JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefined_c_str[0])); + PandaString undefinedCStr = "x"; + JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefinedCStr[0])); JSHandle value1(thread_, JSTaggedValue(1)); JSObject::SetProperty(thread_, JSHandle(obj1), key1, value1); @@ -522,8 +521,8 @@ TEST_F(JSObjectTest, SetIntegrityLevelFrozen) thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(dynclass1), dynclass1); EXPECT_TRUE(*obj1 != nullptr); - PandaString undefined_c_str = "x"; - JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefined_c_str[0])); + PandaString undefinedCStr = "x"; + JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefinedCStr[0])); JSHandle value1(thread_, JSTaggedValue(1)); JSObject::SetProperty(thread_, JSHandle(obj1), key1, value1); @@ -545,8 +544,8 @@ TEST_F(JSObjectTest, TestIntegrityLevelSealed) JSHandle dynclass1(thread_, JSObjectTestCreate(thread_)); JSHandle obj1 = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(dynclass1), dynclass1); - PandaString undefined_c_str = "level"; - JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefined_c_str[0])); + PandaString undefinedCStr = "level"; + JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefinedCStr[0])); JSHandle value1(thread_, JSTaggedValue(1)); JSObject::SetProperty(thread_, JSHandle(obj1), key1, value1); obj1->GetJSHClass()->SetExtensible(false); @@ -569,8 +568,8 @@ TEST_F(JSObjectTest, TestIntegrityLevelFrozen) JSHandle dynclass1(thread_, JSObjectTestCreate(thread_)); JSHandle obj1 = thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(dynclass1), dynclass1); - PandaString undefined_c_str = "level"; - JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefined_c_str[0])); + PandaString undefinedCStr = "level"; + JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefinedCStr[0])); JSHandle value1(thread_, JSTaggedValue(1)); JSObject::SetProperty(thread_, JSHandle(obj1), key1, value1); obj1->GetJSHClass()->SetExtensible(false); @@ -594,8 +593,8 @@ TEST_F(JSObjectTest, TestIntegrityLevelWithoutProperty) JSHandle obj1( thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(dynclass1), dynclass1)); JSHandle::Cast(obj1)->GetJSHClass()->SetExtensible(false); - PandaString undefined_c_str = "level"; - JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefined_c_str[0])); + PandaString undefinedCStr = "level"; + JSHandle key1(thread_->GetEcmaVM()->GetFactory()->NewFromString(&undefinedCStr[0])); // test SetIntegrityLevel::FROZEN JSHandle jsobject(obj1); @@ -612,7 +611,7 @@ TEST_F(JSObjectTest, TestIntegrityLevelWithoutProperty) JSTaggedValue TestGetter(EcmaRuntimeCallInfo *argv) { auto thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj(builtins_common::GetThis(argv)); JSHandle key(factory->NewFromString("y")); @@ -649,13 +648,13 @@ TEST_F(JSObjectTest, Getter) JSTaggedValue TestSetter(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj(builtins_common::GetThis(argv)); JSHandle key(factory->NewFromString("y")); JSTaggedValue value(JSObject::GetProperty(thread, JSHandle(obj), key).GetValue().GetTaggedValue()); - JSHandle value_handle(thread, JSTaggedValue(value.GetInt() + 1)); - JSObject::SetProperty(thread, JSHandle(obj), key, value_handle); + JSHandle valueHandle(thread, JSTaggedValue(value.GetInt() + 1)); + JSObject::SetProperty(thread, JSHandle(obj), key, valueHandle); return JSTaggedValue(JSTaggedValue::True()); } @@ -680,8 +679,8 @@ TEST_F(JSObjectTest, Setter) success1 = JSObject::DefineOwnProperty(thread_, obj, key2, desc2); EXPECT_TRUE(success1); - JSHandle value_handle(thread_, JSTaggedValue::Undefined()); - EXPECT_TRUE(JSObject::SetProperty(thread_, JSHandle(obj), key1, value_handle)); + JSHandle valueHandle(thread_, JSTaggedValue::Undefined()); + EXPECT_TRUE(JSObject::SetProperty(thread_, JSHandle(obj), key1, valueHandle)); EXPECT_EQ(JSObject::GetProperty(thread_, JSHandle(obj), key2).GetValue().GetTaggedValue(), JSTaggedValue(2)); } @@ -690,34 +689,33 @@ TEST_F(JSObjectTest, SpeciesConstructor) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); - JSHandle constructor_func = + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle constructorFunc = factory->NewJSFunction(env, static_cast(nullptr), FunctionKind::BASE_CONSTRUCTOR); - JSHandle constructor_func_value(constructor_func); - constructor_func->GetJSHClass()->SetExtensible(true); - JSFunction::NewJSFunctionPrototype(thread_, factory, constructor_func); + JSHandle constructorFuncValue(constructorFunc); + constructorFunc->GetJSHClass()->SetExtensible(true); + JSFunction::NewJSFunctionPrototype(thread_, factory, constructorFunc); - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle undefined_value(thread_, JSTaggedValue::Undefined()); - JSHandle proto_obj = JSObject::ObjectCreate(thread_, null_handle); - JSHandle proto_obj_value(proto_obj); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle undefinedValue(thread_, JSTaggedValue::Undefined()); + JSHandle protoObj = JSObject::ObjectCreate(thread_, nullHandle); + JSHandle protoObjValue(protoObj); - JSHandle constructor_key = global_const->GetHandledConstructorString(); - JSObject::SetProperty(thread_, proto_obj_value, constructor_key, constructor_func_value); + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread_, protoObjValue, constructorKey, constructorFuncValue); - factory->NewJSObjectByConstructor(constructor_func, JSHandle::Cast(constructor_func)); - JSHandle species_construct = + factory->NewJSObjectByConstructor(constructorFunc, JSHandle::Cast(constructorFunc)); + JSHandle speciesConstruct = factory->NewJSFunction(env, static_cast(nullptr), FunctionKind::BASE_CONSTRUCTOR); - JSHandle species_construct_value(species_construct); - constructor_func->GetJSHClass()->SetExtensible(true); - JSFunction::MakeConstructor(thread_, species_construct, undefined_value); + JSHandle speciesConstructValue(speciesConstruct); + constructorFunc->GetJSHClass()->SetExtensible(true); + JSFunction::MakeConstructor(thread_, speciesConstruct, undefinedValue); - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSObject::SetProperty(thread_, constructor_func_value, species_symbol, species_construct_value); + JSHandle speciesSymbol = env->GetSpeciesSymbol(); + JSObject::SetProperty(thread_, constructorFuncValue, speciesSymbol, speciesConstructValue); - JSTaggedValue species_value = - JSObject::SpeciesConstructor(thread_, proto_obj, constructor_func_value).GetTaggedValue(); - EXPECT_EQ(species_value, species_construct_value.GetTaggedValue()); + JSTaggedValue speciesValue = JSObject::SpeciesConstructor(thread_, protoObj, constructorFuncValue).GetTaggedValue(); + EXPECT_EQ(speciesValue, speciesConstructValue.GetTaggedValue()); } JSTaggedValue TestUndefinedGetter([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -741,7 +739,7 @@ TEST_F(JSObjectTest, GetterIsUndefined) thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, reinterpret_cast(TestUndefinedGetter)); JSHandle setter = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, reinterpret_cast(TestUndefinedSetter)); - JSHandle un_getter(thread_, JSTaggedValue::Undefined()); + JSHandle unGetter(thread_, JSTaggedValue::Undefined()); PropertyDescriptor desc1(thread_); desc1.SetGetter(JSHandle::Cast(getter)); @@ -752,7 +750,7 @@ TEST_F(JSObjectTest, GetterIsUndefined) EXPECT_TRUE(success1); PropertyDescriptor desc2(thread_); - desc2.SetGetter(un_getter); + desc2.SetGetter(unGetter); bool success2 = JSObject::DefineOwnProperty(thread_, obj, key, desc2); EXPECT_TRUE(success2); @@ -774,7 +772,7 @@ TEST_F(JSObjectTest, SetterIsUndefined) thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, reinterpret_cast(TestUndefinedGetter)); JSHandle setter = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, reinterpret_cast(TestUndefinedSetter)); - JSHandle un_setter(thread_, JSTaggedValue::Undefined()); + JSHandle unSetter(thread_, JSTaggedValue::Undefined()); PropertyDescriptor desc1(thread_); desc1.SetGetter(JSHandle::Cast(getter)); @@ -785,7 +783,7 @@ TEST_F(JSObjectTest, SetterIsUndefined) EXPECT_TRUE(success1); PropertyDescriptor desc2(thread_); - desc2.SetSetter(un_setter); + desc2.SetSetter(unSetter); bool success2 = JSObject::DefineOwnProperty(thread_, obj, key, desc2); EXPECT_TRUE(success2); @@ -801,8 +799,8 @@ TEST_F(JSObjectTest, SetterIsUndefined) TEST_F(JSObjectTest, HClass) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); - JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); + JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSHandle hc0(thread_, obj1->GetJSHClass()); JSHandle key1(factory->NewFromCanBeCompressString("x")); @@ -820,7 +818,7 @@ TEST_F(JSObjectTest, HClass) EXPECT_NE(hc1.GetTaggedValue(), hc2.GetTaggedValue()); EXPECT_EQ(hc1.GetTaggedValue(), hc2->GetParent()); - JSHandle obj2 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle obj2 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_EQ(hc0.GetTaggedValue().GetTaggedObject(), obj2->GetJSHClass()); JSObject::SetProperty(thread_, JSHandle(obj2), key1, value); @@ -831,7 +829,7 @@ TEST_F(JSObjectTest, HClass) EXPECT_NE(hc1.GetTaggedValue().GetTaggedObject(), obj2->GetJSHClass()); EXPECT_EQ(hc1.GetTaggedValue(), obj2->GetJSHClass()->GetParent()); - JSHandle obj3 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle obj3 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_EQ(hc0.GetTaggedValue().GetTaggedObject(), obj3->GetJSHClass()); JSObject::SetProperty(thread_, JSHandle(obj3), key1, value); EXPECT_EQ(hc1.GetTaggedValue().GetTaggedObject(), obj3->GetJSHClass()); @@ -846,11 +844,11 @@ TEST_F(JSObjectTest, HClass) TEST_F(JSObjectTest, FastToSlow) { - auto ecma_vm = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); - JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); + JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSMutableHandle key(factory->NewFromCanBeCompressString("x")); JSMutableHandle number(thread_, JSTaggedValue(0)); @@ -860,8 +858,8 @@ TEST_F(JSObjectTest, FastToSlow) for (uint32_t i = 0; i < PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES; i++) { number.Update(JSTaggedValue(i)); number.Update(JSTaggedValue::ToString(thread_, number).GetTaggedValue()); - EcmaString *new_string = *factory->ConcatFromString(key, JSTaggedValue::ToString(thread_, number)); - newkey.Update(JSTaggedValue(new_string)); + EcmaString *newString = *factory->ConcatFromString(key, JSTaggedValue::ToString(thread_, number)); + newkey.Update(JSTaggedValue(newString)); JSObject::SetProperty(thread_, JSHandle(obj1), newkey, value); } @@ -869,8 +867,8 @@ TEST_F(JSObjectTest, FastToSlow) number.Update(JSTaggedValue(PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES)); number.Update(JSTaggedValue::ToString(thread_, number).GetTaggedValue()); - EcmaString *new_string = *factory->ConcatFromString(key, JSTaggedValue::ToString(thread_, number)); - newkey.Update(JSTaggedValue(new_string)); + EcmaString *newString = *factory->ConcatFromString(key, JSTaggedValue::ToString(thread_, number)); + newkey.Update(JSTaggedValue(newString)); JSObject::SetProperty(thread_, JSHandle(obj1), newkey, value); EXPECT_TRUE(TaggedArray::Cast(obj1->GetProperties().GetTaggedObject())->IsDictionaryMode()); @@ -881,11 +879,11 @@ TEST_F(JSObjectTest, FastToSlow) TEST_F(JSObjectTest, DeleteMiddle) { - auto ecma_vm = thread_->GetEcmaVM(); - ObjectFactory *factory = ecma_vm->GetFactory(); + auto ecmaVm = thread_->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); - JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); + JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSMutableHandle key(factory->NewFromCanBeCompressString("x")); JSMutableHandle number(thread_, JSTaggedValue(0)); @@ -895,8 +893,8 @@ TEST_F(JSObjectTest, DeleteMiddle) for (uint32_t i = 0; i < 10; i++) { number.Update(JSTaggedValue(i)); number.Update(JSTaggedValue::ToString(thread_, number).GetTaggedValue()); - EcmaString *new_string = *factory->ConcatFromString(key, JSTaggedValue::ToString(thread_, number)); - newkey.Update(JSTaggedValue(new_string)); + EcmaString *newString = *factory->ConcatFromString(key, JSTaggedValue::ToString(thread_, number)); + newkey.Update(JSTaggedValue(newString)); JSObject::SetProperty(thread_, JSHandle(obj1), newkey, value); } @@ -914,39 +912,39 @@ TEST_F(JSObjectTest, DeleteMiddle) TEST_F(JSObjectTest, ElementFastToSlow) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); JSHandle key0(thread_, JSTaggedValue(0)); JSHandle key1(thread_, JSTaggedValue(1)); JSHandle key2(thread_, JSTaggedValue(2)); JSHandle key2000(thread_, JSTaggedValue(2000)); - JSHandle key_str(factory->NewFromCanBeCompressString("str")); + JSHandle keyStr(factory->NewFromCanBeCompressString("str")); // test dictionary [0,1,2,...,2000] - JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); - JSObject::SetProperty(thread_, JSHandle(obj1), key_str, key2); + JSObject::SetProperty(thread_, JSHandle(obj1), keyStr, key2); JSObject::SetProperty(thread_, JSHandle(obj1), key0, key0); EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); - JSHandle dyn_class(thread_, obj1->GetJSHClass()); + JSHandle dynClass(thread_, obj1->GetJSHClass()); JSObject::SetProperty(thread_, JSHandle(obj1), key1, key1); EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); - EXPECT_EQ(obj1->GetJSHClass(), *dyn_class); + EXPECT_EQ(obj1->GetJSHClass(), *dynClass); JSObject::SetProperty(thread_, JSHandle(obj1), key2000, key2000); EXPECT_TRUE(TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); JSTaggedValue value = - JSObject::GetProperty(thread_, JSHandle(obj1), key_str).GetValue().GetTaggedValue(); + JSObject::GetProperty(thread_, JSHandle(obj1), keyStr).GetValue().GetTaggedValue(); EXPECT_EQ(value, key2.GetTaggedValue()); // test holey [0,,2] - JSHandle obj2 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle obj2 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSObject::SetProperty(thread_, JSHandle(obj2), key0, key0); EXPECT_TRUE(!TaggedArray::Cast(obj2->GetElements().GetTaggedObject())->IsDictionaryMode()); - JSHandle dyn_class2(thread_, obj2->GetJSHClass()); + JSHandle dynClass2(thread_, obj2->GetJSHClass()); JSObject::SetProperty(thread_, JSHandle(obj2), key2, key2); EXPECT_TRUE(!TaggedArray::Cast(obj2->GetElements().GetTaggedObject())->IsDictionaryMode()); - EXPECT_EQ(obj2->GetJSHClass(), *dyn_class2); + EXPECT_EQ(obj2->GetJSHClass(), *dynClass2); // test change attr - JSHandle obj3 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle obj3 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSObject::SetProperty(thread_, JSHandle(obj3), key0, key0); JSObject::SetProperty(thread_, JSHandle(obj3), key1, key1); JSObject::SetProperty(thread_, JSHandle(obj3), key2, key2); @@ -957,7 +955,7 @@ TEST_F(JSObjectTest, ElementFastToSlow) JSObject::DefineOwnProperty(thread_, obj3, key1, desc); EXPECT_TRUE(TaggedArray::Cast(obj3->GetElements().GetTaggedObject())->IsDictionaryMode()); // test delete element - JSHandle obj4 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle obj4 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSObject::SetProperty(thread_, JSHandle(obj4), key0, key0); JSObject::SetProperty(thread_, JSHandle(obj4), key1, key1); JSObject::SetProperty(thread_, JSHandle(obj4), key2, key2); @@ -966,7 +964,7 @@ TEST_F(JSObjectTest, ElementFastToSlow) EXPECT_TRUE(TaggedArray::Cast(obj4->GetElements().GetTaggedObject())->IsDictionaryMode()); JSHandle value1001(thread_, JSTaggedValue(1001)); - JSHandle obj100 = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle obj100 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); PropertyDescriptor desc1(thread_); desc1.SetValue(value1001); desc1.SetWritable(false); @@ -981,54 +979,54 @@ TEST_F(JSObjectTest, ElementFastToSlow) TEST_F(JSObjectTest, EnableProtoChangeMarker) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle obj1 = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle obj1 = JSObject::ObjectCreate(thread_, nullHandle); JSHandle obj2 = JSObject::ObjectCreate(thread_, obj1); JSHandle obj3 = JSObject::ObjectCreate(thread_, obj2); - JSHandle obj1_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); - JSHandle obj2_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); - JSHandle obj3_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); - JSHandle obj1_value(thread_, JSTaggedValue(1)); - JSHandle obj2_value(thread_, JSTaggedValue(2)); - JSHandle obj3_value(thread_, JSTaggedValue(3)); - - JSObject::SetProperty(thread_, JSHandle(obj1), obj1_key, obj1_value); - JSObject::SetProperty(thread_, JSHandle(obj2), obj2_key, obj2_value); - JSObject::SetProperty(thread_, JSHandle(obj3), obj3_key, obj3_value); - JSHandle obj3_dynclass(thread_, obj3->GetJSHClass()); - JSHandle result_marker = JSHClass::EnableProtoChangeMarker(thread_, obj3_dynclass); - EXPECT_TRUE(result_marker->IsProtoChangeMarker()); - bool has_changed = ProtoChangeMarker::Cast(result_marker->GetTaggedObject())->GetHasChanged(); - EXPECT_TRUE(!has_changed); - - JSHandle obj1_dynclass(thread_, obj1->GetJSHClass()); - JSHandle obj2_dynclass(thread_, obj2->GetJSHClass()); - JSTaggedValue obj2_marker = obj2_dynclass->GetProtoChangeMarker(); - EXPECT_TRUE(obj2_marker.IsProtoChangeMarker()); - bool has_changed2 = ProtoChangeMarker::Cast(obj2_marker.GetTaggedObject())->GetHasChanged(); - EXPECT_TRUE(!has_changed2); - - JSTaggedValue obj1_marker = obj1_dynclass->GetProtoChangeMarker(); - EXPECT_TRUE(!obj1_marker.IsProtoChangeMarker()); - - JSTaggedValue proto_details2 = obj2_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details2.IsProtoChangeDetails()); - JSTaggedValue proto_details1 = obj1_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details1.IsProtoChangeDetails()); - JSTaggedValue listeners1 = ProtoChangeDetails::Cast(proto_details1.GetTaggedObject())->GetChangeListener(); + JSHandle obj1Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); + JSHandle obj2Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); + JSHandle obj3Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); + JSHandle obj1Value(thread_, JSTaggedValue(1)); + JSHandle obj2Value(thread_, JSTaggedValue(2)); + JSHandle obj3Value(thread_, JSTaggedValue(3)); + + JSObject::SetProperty(thread_, JSHandle(obj1), obj1Key, obj1Value); + JSObject::SetProperty(thread_, JSHandle(obj2), obj2Key, obj2Value); + JSObject::SetProperty(thread_, JSHandle(obj3), obj3Key, obj3Value); + JSHandle obj3Dynclass(thread_, obj3->GetJSHClass()); + JSHandle resultMarker = JSHClass::EnableProtoChangeMarker(thread_, obj3Dynclass); + EXPECT_TRUE(resultMarker->IsProtoChangeMarker()); + bool hasChanged = ProtoChangeMarker::Cast(resultMarker->GetTaggedObject())->GetHasChanged(); + EXPECT_TRUE(!hasChanged); + + JSHandle obj1Dynclass(thread_, obj1->GetJSHClass()); + JSHandle obj2Dynclass(thread_, obj2->GetJSHClass()); + JSTaggedValue obj2Marker = obj2Dynclass->GetProtoChangeMarker(); + EXPECT_TRUE(obj2Marker.IsProtoChangeMarker()); + bool hasChanged2 = ProtoChangeMarker::Cast(obj2Marker.GetTaggedObject())->GetHasChanged(); + EXPECT_TRUE(!hasChanged2); + + JSTaggedValue obj1Marker = obj1Dynclass->GetProtoChangeMarker(); + EXPECT_TRUE(!obj1Marker.IsProtoChangeMarker()); + + JSTaggedValue protoDetails2 = obj2Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); + JSTaggedValue protoDetails1 = obj1Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); + JSTaggedValue listeners1 = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners1 != JSTaggedValue(0)); - JSTaggedValue listeners2 = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners2 == JSTaggedValue(0)); - JSTaggedValue index = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue listeners_result = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index.GetArrayLength()); - EXPECT_TRUE(listeners_result == obj2_dynclass.GetTaggedValue()); + JSTaggedValue index = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); + JSTaggedValue listenersResult = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index.GetArrayLength()); + EXPECT_TRUE(listenersResult == obj2Dynclass.GetTaggedValue()); } TEST_F(JSObjectTest, BuildRegisterTree) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle obj1 = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle obj1 = JSObject::ObjectCreate(thread_, nullHandle); JSHandle obj2 = JSObject::ObjectCreate(thread_, obj1); JSHandle obj3 = JSObject::ObjectCreate(thread_, obj2); JSHandle obj4 = JSObject::ObjectCreate(thread_, obj2); @@ -1036,73 +1034,73 @@ TEST_F(JSObjectTest, BuildRegisterTree) JSHandle obj6 = JSObject::ObjectCreate(thread_, obj2); JSHandle obj7 = JSObject::ObjectCreate(thread_, obj6); - JSHandle obj1_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); - JSHandle obj2_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); - JSHandle obj3_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); - JSHandle obj4_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key4")); - JSHandle obj5_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key5")); - JSHandle obj6_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key6")); - JSHandle obj7_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key7")); - - JSHandle obj1_value(thread_, JSTaggedValue(1)); - JSHandle obj2_value(thread_, JSTaggedValue(2)); - JSHandle obj3_value(thread_, JSTaggedValue(3)); - JSHandle obj4_value(thread_, JSTaggedValue(4)); - JSHandle obj5_value(thread_, JSTaggedValue(5)); - JSHandle obj6_value(thread_, JSTaggedValue(6)); - JSHandle obj7_value(thread_, JSTaggedValue(7)); - - JSObject::SetProperty(thread_, JSHandle(obj1), obj1_key, obj1_value); - JSObject::SetProperty(thread_, JSHandle(obj2), obj2_key, obj2_value); - JSObject::SetProperty(thread_, JSHandle(obj3), obj3_key, obj3_value); - JSObject::SetProperty(thread_, JSHandle(obj4), obj4_key, obj4_value); - JSObject::SetProperty(thread_, JSHandle(obj5), obj5_key, obj5_value); - JSObject::SetProperty(thread_, JSHandle(obj6), obj6_key, obj6_value); - JSObject::SetProperty(thread_, JSHandle(obj7), obj7_key, obj7_value); - - JSHandle obj1_dynclass(thread_, obj1->GetJSHClass()); - JSHandle obj2_dynclass(thread_, obj2->GetJSHClass()); - JSHandle obj3_dynclass(thread_, obj3->GetJSHClass()); - JSHandle obj4_dynclass(thread_, obj4->GetJSHClass()); - JSHandle obj5_dynclass(thread_, obj5->GetJSHClass()); - JSHandle obj6_dynclass(thread_, obj6->GetJSHClass()); - JSHandle obj7_dynclass(thread_, obj7->GetJSHClass()); - - JSHandle result3_marker = JSHClass::EnableProtoChangeMarker(thread_, obj3_dynclass); - JSHandle result5_marker = JSHClass::EnableProtoChangeMarker(thread_, obj5_dynclass); - EXPECT_TRUE(result3_marker->IsProtoChangeMarker()); - EXPECT_TRUE(!(ProtoChangeMarker::Cast(result3_marker->GetTaggedObject())->GetHasChanged())); - EXPECT_TRUE(result5_marker->IsProtoChangeMarker()); - EXPECT_TRUE(!(ProtoChangeMarker::Cast(result5_marker->GetTaggedObject())->GetHasChanged())); - - EXPECT_TRUE(obj4_dynclass->GetProtoChangeMarker().IsProtoChangeMarker()); - EXPECT_TRUE(!obj6_dynclass->GetProtoChangeMarker().IsProtoChangeMarker()); - - JSHandle result7_marker = JSHClass::EnableProtoChangeMarker(thread_, obj7_dynclass); - EXPECT_TRUE(result7_marker->IsProtoChangeMarker()); - EXPECT_TRUE(!(ProtoChangeMarker::Cast(result7_marker->GetTaggedObject())->GetHasChanged())); - - JSTaggedValue proto_details1 = obj1_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details1.IsProtoChangeDetails()); - JSTaggedValue listeners1_value = ProtoChangeDetails::Cast(proto_details1.GetTaggedObject())->GetChangeListener(); - EXPECT_TRUE(listeners1_value != JSTaggedValue(0)); - JSHandle listeners1(thread_, listeners1_value.GetTaggedObject()); - JSTaggedValue proto_details2 = obj2_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details2.IsProtoChangeDetails()); - JSTaggedValue index2 = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners1->Get(index2.GetArrayLength()) == obj2_dynclass.GetTaggedValue()); - - JSTaggedValue listeners2_value = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetChangeListener(); - EXPECT_TRUE(listeners2_value != JSTaggedValue(0)); - JSHandle listeners2(thread_, listeners2_value.GetTaggedObject()); - JSTaggedValue proto_details4 = obj4_dynclass->GetProtoChangeDetails(); - JSTaggedValue proto_details6 = obj6_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details4.IsProtoChangeDetails()); - EXPECT_TRUE(proto_details6.IsProtoChangeDetails()); - JSTaggedValue index4 = ProtoChangeDetails::Cast(proto_details4.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners2->Get(index4.GetArrayLength()) == obj4_dynclass.GetTaggedValue()); - JSTaggedValue index6 = ProtoChangeDetails::Cast(proto_details6.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners2->Get(index6.GetArrayLength()) == obj6_dynclass.GetTaggedValue()); + JSHandle obj1Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); + JSHandle obj2Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); + JSHandle obj3Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); + JSHandle obj4Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key4")); + JSHandle obj5Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key5")); + JSHandle obj6Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key6")); + JSHandle obj7Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key7")); + + JSHandle obj1Value(thread_, JSTaggedValue(1)); + JSHandle obj2Value(thread_, JSTaggedValue(2)); + JSHandle obj3Value(thread_, JSTaggedValue(3)); + JSHandle obj4Value(thread_, JSTaggedValue(4)); + JSHandle obj5Value(thread_, JSTaggedValue(5)); + JSHandle obj6Value(thread_, JSTaggedValue(6)); + JSHandle obj7Value(thread_, JSTaggedValue(7)); + + JSObject::SetProperty(thread_, JSHandle(obj1), obj1Key, obj1Value); + JSObject::SetProperty(thread_, JSHandle(obj2), obj2Key, obj2Value); + JSObject::SetProperty(thread_, JSHandle(obj3), obj3Key, obj3Value); + JSObject::SetProperty(thread_, JSHandle(obj4), obj4Key, obj4Value); + JSObject::SetProperty(thread_, JSHandle(obj5), obj5Key, obj5Value); + JSObject::SetProperty(thread_, JSHandle(obj6), obj6Key, obj6Value); + JSObject::SetProperty(thread_, JSHandle(obj7), obj7Key, obj7Value); + + JSHandle obj1Dynclass(thread_, obj1->GetJSHClass()); + JSHandle obj2Dynclass(thread_, obj2->GetJSHClass()); + JSHandle obj3Dynclass(thread_, obj3->GetJSHClass()); + JSHandle obj4Dynclass(thread_, obj4->GetJSHClass()); + JSHandle obj5Dynclass(thread_, obj5->GetJSHClass()); + JSHandle obj6Dynclass(thread_, obj6->GetJSHClass()); + JSHandle obj7Dynclass(thread_, obj7->GetJSHClass()); + + JSHandle result3Marker = JSHClass::EnableProtoChangeMarker(thread_, obj3Dynclass); + JSHandle result5Marker = JSHClass::EnableProtoChangeMarker(thread_, obj5Dynclass); + EXPECT_TRUE(result3Marker->IsProtoChangeMarker()); + EXPECT_TRUE(!(ProtoChangeMarker::Cast(result3Marker->GetTaggedObject())->GetHasChanged())); + EXPECT_TRUE(result5Marker->IsProtoChangeMarker()); + EXPECT_TRUE(!(ProtoChangeMarker::Cast(result5Marker->GetTaggedObject())->GetHasChanged())); + + EXPECT_TRUE(obj4Dynclass->GetProtoChangeMarker().IsProtoChangeMarker()); + EXPECT_TRUE(!obj6Dynclass->GetProtoChangeMarker().IsProtoChangeMarker()); + + JSHandle result7Marker = JSHClass::EnableProtoChangeMarker(thread_, obj7Dynclass); + EXPECT_TRUE(result7Marker->IsProtoChangeMarker()); + EXPECT_TRUE(!(ProtoChangeMarker::Cast(result7Marker->GetTaggedObject())->GetHasChanged())); + + JSTaggedValue protoDetails1 = obj1Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); + JSTaggedValue listeners1Value = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); + EXPECT_TRUE(listeners1Value != JSTaggedValue(0)); + JSHandle listeners1(thread_, listeners1Value.GetTaggedObject()); + JSTaggedValue protoDetails2 = obj2Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); + JSTaggedValue index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); + EXPECT_TRUE(listeners1->Get(index2.GetArrayLength()) == obj2Dynclass.GetTaggedValue()); + + JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); + EXPECT_TRUE(listeners2Value != JSTaggedValue(0)); + JSHandle listeners2(thread_, listeners2Value.GetTaggedObject()); + JSTaggedValue protoDetails4 = obj4Dynclass->GetProtoChangeDetails(); + JSTaggedValue protoDetails6 = obj6Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails4.IsProtoChangeDetails()); + EXPECT_TRUE(protoDetails6.IsProtoChangeDetails()); + JSTaggedValue index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); + EXPECT_TRUE(listeners2->Get(index4.GetArrayLength()) == obj4Dynclass.GetTaggedValue()); + JSTaggedValue index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); + EXPECT_TRUE(listeners2->Get(index6.GetArrayLength()) == obj6Dynclass.GetTaggedValue()); EXPECT_TRUE(listeners1->GetEnd() == 1); EXPECT_TRUE(listeners2->GetEnd() == 2); @@ -1110,8 +1108,8 @@ TEST_F(JSObjectTest, BuildRegisterTree) TEST_F(JSObjectTest, NoticeThroughChain) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle obj1 = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle obj1 = JSObject::ObjectCreate(thread_, nullHandle); JSHandle obj2 = JSObject::ObjectCreate(thread_, obj1); JSHandle obj3 = JSObject::ObjectCreate(thread_, obj2); JSHandle obj4 = JSObject::ObjectCreate(thread_, obj2); @@ -1119,74 +1117,74 @@ TEST_F(JSObjectTest, NoticeThroughChain) JSHandle obj6 = JSObject::ObjectCreate(thread_, obj2); JSHandle obj7 = JSObject::ObjectCreate(thread_, obj6); - JSHandle obj1_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); - JSHandle obj2_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); - JSHandle obj3_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); - JSHandle obj4_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key4")); - JSHandle obj5_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key5")); - JSHandle obj6_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key6")); - JSHandle obj7_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key7")); - - JSHandle obj1_value(thread_, JSTaggedValue(1)); - JSHandle obj2_value(thread_, JSTaggedValue(2)); - JSHandle obj3_value(thread_, JSTaggedValue(3)); - JSHandle obj4_value(thread_, JSTaggedValue(4)); - JSHandle obj5_value(thread_, JSTaggedValue(5)); - JSHandle obj6_value(thread_, JSTaggedValue(6)); - JSHandle obj7_value(thread_, JSTaggedValue(7)); - - JSObject::SetProperty(thread_, JSHandle(obj1), obj1_key, obj1_value); - JSObject::SetProperty(thread_, JSHandle(obj2), obj2_key, obj2_value); - JSObject::SetProperty(thread_, JSHandle(obj3), obj3_key, obj3_value); - JSObject::SetProperty(thread_, JSHandle(obj4), obj4_key, obj4_value); - JSObject::SetProperty(thread_, JSHandle(obj5), obj5_key, obj5_value); - JSObject::SetProperty(thread_, JSHandle(obj6), obj6_key, obj6_value); - JSObject::SetProperty(thread_, JSHandle(obj7), obj7_key, obj7_value); - - JSHandle obj1_dynclass(thread_, obj1->GetJSHClass()); - JSHandle obj2_dynclass(thread_, obj2->GetJSHClass()); - JSHandle obj3_dynclass(thread_, obj3->GetJSHClass()); - JSHandle obj4_dynclass(thread_, obj4->GetJSHClass()); - JSHandle obj5_dynclass(thread_, obj5->GetJSHClass()); - JSHandle obj6_dynclass(thread_, obj6->GetJSHClass()); - JSHandle obj7_dynclass(thread_, obj7->GetJSHClass()); - - JSHClass::EnableProtoChangeMarker(thread_, obj3_dynclass); - JSHClass::EnableProtoChangeMarker(thread_, obj7_dynclass); - JSHClass::EnableProtoChangeMarker(thread_, obj5_dynclass); - - JSHClass::NoticeThroughChain(thread_, obj2_dynclass); - JSHClass::UnregisterOnProtoChain(thread_, obj2_dynclass); - JSTaggedValue proto_details1 = obj1_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details1.IsProtoChangeDetails()); - JSTaggedValue listeners1_value = ProtoChangeDetails::Cast(proto_details1.GetTaggedObject())->GetChangeListener(); - EXPECT_TRUE(listeners1_value != JSTaggedValue(0)); - JSHandle listeners1(thread_, listeners1_value.GetTaggedObject()); - uint32_t hole_index = ChangeListener::CheckHole(listeners1); - EXPECT_TRUE(hole_index == 0); - - JSTaggedValue proto_details2 = obj2_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details2.IsProtoChangeDetails()); - JSTaggedValue listeners2_value = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetChangeListener(); - EXPECT_TRUE(listeners2_value != JSTaggedValue(0)); - JSTaggedValue index2 = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetRegisterIndex(); + JSHandle obj1Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); + JSHandle obj2Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); + JSHandle obj3Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); + JSHandle obj4Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key4")); + JSHandle obj5Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key5")); + JSHandle obj6Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key6")); + JSHandle obj7Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key7")); + + JSHandle obj1Value(thread_, JSTaggedValue(1)); + JSHandle obj2Value(thread_, JSTaggedValue(2)); + JSHandle obj3Value(thread_, JSTaggedValue(3)); + JSHandle obj4Value(thread_, JSTaggedValue(4)); + JSHandle obj5Value(thread_, JSTaggedValue(5)); + JSHandle obj6Value(thread_, JSTaggedValue(6)); + JSHandle obj7Value(thread_, JSTaggedValue(7)); + + JSObject::SetProperty(thread_, JSHandle(obj1), obj1Key, obj1Value); + JSObject::SetProperty(thread_, JSHandle(obj2), obj2Key, obj2Value); + JSObject::SetProperty(thread_, JSHandle(obj3), obj3Key, obj3Value); + JSObject::SetProperty(thread_, JSHandle(obj4), obj4Key, obj4Value); + JSObject::SetProperty(thread_, JSHandle(obj5), obj5Key, obj5Value); + JSObject::SetProperty(thread_, JSHandle(obj6), obj6Key, obj6Value); + JSObject::SetProperty(thread_, JSHandle(obj7), obj7Key, obj7Value); + + JSHandle obj1Dynclass(thread_, obj1->GetJSHClass()); + JSHandle obj2Dynclass(thread_, obj2->GetJSHClass()); + JSHandle obj3Dynclass(thread_, obj3->GetJSHClass()); + JSHandle obj4Dynclass(thread_, obj4->GetJSHClass()); + JSHandle obj5Dynclass(thread_, obj5->GetJSHClass()); + JSHandle obj6Dynclass(thread_, obj6->GetJSHClass()); + JSHandle obj7Dynclass(thread_, obj7->GetJSHClass()); + + JSHClass::EnableProtoChangeMarker(thread_, obj3Dynclass); + JSHClass::EnableProtoChangeMarker(thread_, obj7Dynclass); + JSHClass::EnableProtoChangeMarker(thread_, obj5Dynclass); + + JSHClass::NoticeThroughChain(thread_, obj2Dynclass); + JSHClass::UnregisterOnProtoChain(thread_, obj2Dynclass); + JSTaggedValue protoDetails1 = obj1Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); + JSTaggedValue listeners1Value = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); + EXPECT_TRUE(listeners1Value != JSTaggedValue(0)); + JSHandle listeners1(thread_, listeners1Value.GetTaggedObject()); + uint32_t holeIndex = ChangeListener::CheckHole(listeners1); + EXPECT_TRUE(holeIndex == 0); + + JSTaggedValue protoDetails2 = obj2Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); + JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); + EXPECT_TRUE(listeners2Value != JSTaggedValue(0)); + JSTaggedValue index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); EXPECT_TRUE(listeners1->Get(index2.GetArrayLength()) == JSTaggedValue::Hole()); - JSTaggedValue obj6_marker = obj6_dynclass->GetProtoChangeMarker(); - EXPECT_TRUE(obj6_marker.IsProtoChangeMarker()); - bool has_changed6 = ProtoChangeMarker::Cast(obj6_marker.GetTaggedObject())->GetHasChanged(); - EXPECT_TRUE(has_changed6); + JSTaggedValue obj6Marker = obj6Dynclass->GetProtoChangeMarker(); + EXPECT_TRUE(obj6Marker.IsProtoChangeMarker()); + bool hasChanged6 = ProtoChangeMarker::Cast(obj6Marker.GetTaggedObject())->GetHasChanged(); + EXPECT_TRUE(hasChanged6); - JSTaggedValue obj4_marker = obj4_dynclass->GetProtoChangeMarker(); - EXPECT_TRUE(obj4_marker.IsProtoChangeMarker()); - bool has_changed4 = ProtoChangeMarker::Cast(obj4_marker.GetTaggedObject())->GetHasChanged(); - EXPECT_TRUE(has_changed4); + JSTaggedValue obj4Marker = obj4Dynclass->GetProtoChangeMarker(); + EXPECT_TRUE(obj4Marker.IsProtoChangeMarker()); + bool hasChanged4 = ProtoChangeMarker::Cast(obj4Marker.GetTaggedObject())->GetHasChanged(); + EXPECT_TRUE(hasChanged4); } TEST_F(JSObjectTest, ChangeProtoAndNoticeTheChain) { - JSHandle null_handle(thread_, JSTaggedValue::Null()); - JSHandle obj1 = JSObject::ObjectCreate(thread_, null_handle); + JSHandle nullHandle(thread_, JSTaggedValue::Null()); + JSHandle obj1 = JSObject::ObjectCreate(thread_, nullHandle); JSHandle obj2 = JSObject::ObjectCreate(thread_, obj1); JSHandle obj3 = JSObject::ObjectCreate(thread_, obj1); JSHandle obj4 = JSObject::ObjectCreate(thread_, obj2); @@ -1194,93 +1192,93 @@ TEST_F(JSObjectTest, ChangeProtoAndNoticeTheChain) JSHandle obj6 = JSObject::ObjectCreate(thread_, obj2); JSHandle obj7 = JSObject::ObjectCreate(thread_, obj6); - JSHandle obj1_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); - JSHandle obj2_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); - JSHandle obj3_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); - JSHandle obj4_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key4")); - JSHandle obj5_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key5")); - JSHandle obj6_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key6")); - JSHandle obj7_key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key7")); - - JSHandle obj1_value(thread_, JSTaggedValue(1)); - JSHandle obj2_value(thread_, JSTaggedValue(2)); - JSHandle obj3_value(thread_, JSTaggedValue(3)); - JSHandle obj4_value(thread_, JSTaggedValue(4)); - JSHandle obj5_value(thread_, JSTaggedValue(5)); - JSHandle obj6_value(thread_, JSTaggedValue(6)); - JSHandle obj7_value(thread_, JSTaggedValue(7)); - - JSObject::SetProperty(thread_, JSHandle(obj1), obj1_key, obj1_value); - JSObject::SetProperty(thread_, JSHandle(obj2), obj2_key, obj2_value); - JSObject::SetProperty(thread_, JSHandle(obj3), obj3_key, obj3_value); - JSObject::SetProperty(thread_, JSHandle(obj4), obj4_key, obj4_value); - JSObject::SetProperty(thread_, JSHandle(obj5), obj5_key, obj5_value); - JSObject::SetProperty(thread_, JSHandle(obj6), obj6_key, obj6_value); - JSObject::SetProperty(thread_, JSHandle(obj7), obj7_key, obj7_value); - - JSHandle obj5_dynclass(thread_, obj5->GetJSHClass()); - JSHandle obj7_dynclass(thread_, obj7->GetJSHClass()); - - JSHClass::EnableProtoChangeMarker(thread_, obj7_dynclass); - JSHClass::EnableProtoChangeMarker(thread_, obj5_dynclass); + JSHandle obj1Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key1")); + JSHandle obj2Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key2")); + JSHandle obj3Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key3")); + JSHandle obj4Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key4")); + JSHandle obj5Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key5")); + JSHandle obj6Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key6")); + JSHandle obj7Key(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("key7")); + + JSHandle obj1Value(thread_, JSTaggedValue(1)); + JSHandle obj2Value(thread_, JSTaggedValue(2)); + JSHandle obj3Value(thread_, JSTaggedValue(3)); + JSHandle obj4Value(thread_, JSTaggedValue(4)); + JSHandle obj5Value(thread_, JSTaggedValue(5)); + JSHandle obj6Value(thread_, JSTaggedValue(6)); + JSHandle obj7Value(thread_, JSTaggedValue(7)); + + JSObject::SetProperty(thread_, JSHandle(obj1), obj1Key, obj1Value); + JSObject::SetProperty(thread_, JSHandle(obj2), obj2Key, obj2Value); + JSObject::SetProperty(thread_, JSHandle(obj3), obj3Key, obj3Value); + JSObject::SetProperty(thread_, JSHandle(obj4), obj4Key, obj4Value); + JSObject::SetProperty(thread_, JSHandle(obj5), obj5Key, obj5Value); + JSObject::SetProperty(thread_, JSHandle(obj6), obj6Key, obj6Value); + JSObject::SetProperty(thread_, JSHandle(obj7), obj7Key, obj7Value); + + JSHandle obj5Dynclass(thread_, obj5->GetJSHClass()); + JSHandle obj7Dynclass(thread_, obj7->GetJSHClass()); + + JSHClass::EnableProtoChangeMarker(thread_, obj7Dynclass); + JSHClass::EnableProtoChangeMarker(thread_, obj5Dynclass); JSObject::SetPrototype(thread_, obj2, JSHandle(obj3)); - JSHandle obj1_dynclass(thread_, obj1->GetJSHClass()); - JSHandle obj2_dynclass(thread_, obj2->GetJSHClass()); - JSHandle obj3_dynclass(thread_, obj3->GetJSHClass()); - JSHandle obj4_dynclass(thread_, obj4->GetJSHClass()); - JSHandle obj6_dynclass(thread_, obj6->GetJSHClass()); - - JSTaggedValue obj6_marker = obj6_dynclass->GetProtoChangeMarker(); - EXPECT_TRUE(obj6_marker.IsProtoChangeMarker()); - bool has_changed6 = ProtoChangeMarker::Cast(obj6_marker.GetTaggedObject())->GetHasChanged(); - EXPECT_TRUE(has_changed6); - - JSTaggedValue obj4_marker = obj4_dynclass->GetProtoChangeMarker(); - EXPECT_TRUE(obj4_marker.IsProtoChangeMarker()); - bool has_changed4 = ProtoChangeMarker::Cast(obj4_marker.GetTaggedObject())->GetHasChanged(); - EXPECT_TRUE(has_changed4); - - JSTaggedValue proto_details1 = obj1_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details1.IsProtoChangeDetails()); - JSTaggedValue proto_details2 = obj2_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details2.IsProtoChangeDetails()); - JSTaggedValue proto_details3 = obj3_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details3.IsProtoChangeDetails()); - JSTaggedValue proto_details4 = obj4_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details4.IsProtoChangeDetails()); - JSTaggedValue proto_details6 = obj6_dynclass->GetProtoChangeDetails(); - EXPECT_TRUE(proto_details6.IsProtoChangeDetails()); - - JSTaggedValue listeners1 = ProtoChangeDetails::Cast(proto_details1.GetTaggedObject())->GetChangeListener(); + JSHandle obj1Dynclass(thread_, obj1->GetJSHClass()); + JSHandle obj2Dynclass(thread_, obj2->GetJSHClass()); + JSHandle obj3Dynclass(thread_, obj3->GetJSHClass()); + JSHandle obj4Dynclass(thread_, obj4->GetJSHClass()); + JSHandle obj6Dynclass(thread_, obj6->GetJSHClass()); + + JSTaggedValue obj6Marker = obj6Dynclass->GetProtoChangeMarker(); + EXPECT_TRUE(obj6Marker.IsProtoChangeMarker()); + bool hasChanged6 = ProtoChangeMarker::Cast(obj6Marker.GetTaggedObject())->GetHasChanged(); + EXPECT_TRUE(hasChanged6); + + JSTaggedValue obj4Marker = obj4Dynclass->GetProtoChangeMarker(); + EXPECT_TRUE(obj4Marker.IsProtoChangeMarker()); + bool hasChanged4 = ProtoChangeMarker::Cast(obj4Marker.GetTaggedObject())->GetHasChanged(); + EXPECT_TRUE(hasChanged4); + + JSTaggedValue protoDetails1 = obj1Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); + JSTaggedValue protoDetails2 = obj2Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); + JSTaggedValue protoDetails3 = obj3Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails3.IsProtoChangeDetails()); + JSTaggedValue protoDetails4 = obj4Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails4.IsProtoChangeDetails()); + JSTaggedValue protoDetails6 = obj6Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails6.IsProtoChangeDetails()); + + JSTaggedValue listeners1 = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners1 != JSTaggedValue(0)); - JSTaggedValue listeners2 = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners2 != JSTaggedValue(0)); - JSTaggedValue listeners3 = ProtoChangeDetails::Cast(proto_details3.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners3 = ProtoChangeDetails::Cast(protoDetails3.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners3 != JSTaggedValue(0)); - JSTaggedValue index2 = ProtoChangeDetails::Cast(proto_details2.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue index3 = ProtoChangeDetails::Cast(proto_details3.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue index4 = ProtoChangeDetails::Cast(proto_details4.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue index6 = ProtoChangeDetails::Cast(proto_details6.GetTaggedObject())->GetRegisterIndex(); + JSTaggedValue index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); + JSTaggedValue index3 = ProtoChangeDetails::Cast(protoDetails3.GetTaggedObject())->GetRegisterIndex(); + JSTaggedValue index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); + JSTaggedValue index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); JSTaggedValue result2 = ChangeListener::Cast(listeners3.GetTaggedObject())->Get(index2.GetArrayLength()); JSTaggedValue result3 = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index3.GetArrayLength()); JSTaggedValue result4 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index4.GetArrayLength()); JSTaggedValue result6 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index6.GetArrayLength()); - EXPECT_TRUE(result2 == obj2_dynclass.GetTaggedValue()); - EXPECT_TRUE(result3 == obj3_dynclass.GetTaggedValue()); - EXPECT_TRUE(result4 == obj4_dynclass.GetTaggedValue()); - EXPECT_TRUE(result6 == obj6_dynclass.GetTaggedValue()); + EXPECT_TRUE(result2 == obj2Dynclass.GetTaggedValue()); + EXPECT_TRUE(result3 == obj3Dynclass.GetTaggedValue()); + EXPECT_TRUE(result4 == obj4Dynclass.GetTaggedValue()); + EXPECT_TRUE(result6 == obj6Dynclass.GetTaggedValue()); } TEST_F(JSObjectTest, NativePointerField) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle obj_func(thread_, JSObjectTestCreate(thread_)); - JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(obj_func), obj_func); + JSHandle objFunc(thread_, JSObjectTestCreate(thread_)); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); obj->SetHash(87); EXPECT_TRUE(obj->GetHash() == 87); diff --git a/tests/runtime/common/js_promise_test.cpp b/tests/runtime/common/js_promise_test.cpp index f2258b35c706792132a22527421ea72b2f772325..28598805d5aab93e63af1034c54da0e8b713c394 100644 --- a/tests/runtime/common/js_promise_test.cpp +++ b/tests/runtime/common/js_promise_test.cpp @@ -56,14 +56,14 @@ private: TEST_F(JSPromiseTest, CreateResolvingFunctions) { - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); - ObjectFactory *factory = ecma_vm->GetFactory(); - - JSHandle promise_func = env->GetPromiseFunction(); - JSHandle js_promise = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promise_func), promise_func)); - JSHandle reactions = JSPromise::CreateResolvingFunctions(thread_, js_promise); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); + + JSHandle promiseFunc = env->GetPromiseFunction(); + JSHandle jsPromise = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promiseFunc), promiseFunc)); + JSHandle reactions = JSPromise::CreateResolvingFunctions(thread_, jsPromise); JSHandle resolve(thread_, reactions->GetResolveFunction()); JSHandle reject(thread_, reactions->GetRejectFunction()); EXPECT_EQ(resolve->IsCallable(), true); @@ -72,34 +72,34 @@ TEST_F(JSPromiseTest, CreateResolvingFunctions) TEST_F(JSPromiseTest, NewPromiseCapability) { - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread_, promise); - JSHandle new_promise(thread_, capbility->GetPromise()); - EXPECT_EQ(static_cast(new_promise->GetPromiseState().GetInt()), PromiseStatus::PENDING); + JSHandle newPromise(thread_, capbility->GetPromise()); + EXPECT_EQ(static_cast(newPromise->GetPromiseState().GetInt()), PromiseStatus::PENDING); JSHandle resolve(thread_, capbility->GetResolve()); JSHandle reject(thread_, capbility->GetReject()); EXPECT_EQ(resolve.GetTaggedValue().IsCallable(), true); EXPECT_EQ(resolve.GetTaggedValue().IsCallable(), true); - JSHandle resolve_promise(thread_, resolve->GetPromise()); - JSHandle reject_promise(thread_, reject->GetPromise()); - EXPECT_EQ(JSTaggedValue::SameValue(new_promise.GetTaggedValue(), resolve_promise.GetTaggedValue()), true); - EXPECT_EQ(JSTaggedValue::SameValue(new_promise.GetTaggedValue(), reject_promise.GetTaggedValue()), true); + JSHandle resolvePromise(thread_, resolve->GetPromise()); + JSHandle rejectPromise(thread_, reject->GetPromise()); + EXPECT_EQ(JSTaggedValue::SameValue(newPromise.GetTaggedValue(), resolvePromise.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(newPromise.GetTaggedValue(), rejectPromise.GetTaggedValue()), true); } TEST_F(JSPromiseTest, FullFillPromise) { - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread_, promise); - JSHandle new_promise(thread_, capbility->GetPromise()); - EXPECT_EQ(static_cast(new_promise->GetPromiseState().GetInt()), PromiseStatus::PENDING); - EXPECT_EQ(new_promise->GetPromiseResult().IsUndefined(), true); + JSHandle newPromise(thread_, capbility->GetPromise()); + EXPECT_EQ(static_cast(newPromise->GetPromiseState().GetInt()), PromiseStatus::PENDING); + EXPECT_EQ(newPromise->GetPromiseResult().IsUndefined(), true); JSHandle resolve(thread_, capbility->GetResolve()); JSHandle undefined(thread_, JSTaggedValue::Undefined()); @@ -108,19 +108,19 @@ TEST_F(JSPromiseTest, FullFillPromise) // NOLINTNEXTLINE(readability-magic-numbers) info->SetCallArgs(JSTaggedValue(33)); JSFunction::Call(info.Get()); - EXPECT_EQ(static_cast(new_promise->GetPromiseState().GetInt()), PromiseStatus::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(new_promise->GetPromiseResult(), JSTaggedValue(33)), true); + EXPECT_EQ(static_cast(newPromise->GetPromiseState().GetInt()), PromiseStatus::FULFILLED); + EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseResult(), JSTaggedValue(33)), true); } TEST_F(JSPromiseTest, RejectPromise) { - EcmaVM *ecma_vm = thread_->GetEcmaVM(); - JSHandle env = ecma_vm->GetGlobalEnv(); + EcmaVM *ecmaVm = thread_->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread_, promise); - JSHandle new_promise(thread_, capbility->GetPromise()); - EXPECT_EQ(static_cast(new_promise->GetPromiseState().GetInt()), PromiseStatus::PENDING); - EXPECT_EQ(new_promise->GetPromiseResult().IsUndefined(), true); + JSHandle newPromise(thread_, capbility->GetPromise()); + EXPECT_EQ(static_cast(newPromise->GetPromiseState().GetInt()), PromiseStatus::PENDING); + EXPECT_EQ(newPromise->GetPromiseResult().IsUndefined(), true); JSHandle reject(thread_, capbility->GetReject()); JSHandle undefined(thread_, JSTaggedValue::Undefined()); @@ -129,7 +129,7 @@ TEST_F(JSPromiseTest, RejectPromise) // NOLINTNEXTLINE(readability-magic-numbers) info->SetCallArgs(JSTaggedValue(44)); JSFunction::Call(info.Get()); - EXPECT_EQ(static_cast(new_promise->GetPromiseState().GetInt()), PromiseStatus::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(new_promise->GetPromiseResult(), JSTaggedValue(44)), true); + EXPECT_EQ(static_cast(newPromise->GetPromiseState().GetInt()), PromiseStatus::REJECTED); + EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseResult(), JSTaggedValue(44)), true); } } // namespace panda::test diff --git a/tests/runtime/common/js_proxy_test.cpp b/tests/runtime/common/js_proxy_test.cpp index baa79d02aab6d25727b8244446df2a5cfa4b469d..fd91faf5298c8b02be29fd1ca25b00f9b06d7aea 100644 --- a/tests/runtime/common/js_proxy_test.cpp +++ b/tests/runtime/common/js_proxy_test.cpp @@ -57,32 +57,32 @@ private: static JSFunction *JSObjectTestCreate(JSThread *thread) { - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - return global_env->GetObjectFunction().GetObject(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + return globalEnv->GetObjectFunction().GetObject(); } TEST_F(JSProxyTest, ProxyCreate) { JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle( + JSHandle targetHandle( thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(dynclass), dynclass)); JSHandle key(thread_->GetEcmaVM()->GetFactory()->NewFromString("x")); JSHandle value(thread_, JSTaggedValue(1)); - JSObject::SetProperty(thread_, target_handle, key, value); - EXPECT_EQ(JSObject::GetProperty(thread_, target_handle, key).GetValue()->GetInt(), 1); + JSObject::SetProperty(thread_, targetHandle, key, value); + EXPECT_EQ(JSObject::GetProperty(thread_, targetHandle, key).GetValue()->GetInt(), 1); - JSHandle handler_handle( + JSHandle handlerHandle( thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle::Cast(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle, key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle, key).GetValue()->GetInt(), 1); PropertyDescriptor desc(thread_); - JSProxy::GetOwnProperty(thread_, proxy_handle, key, desc); + JSProxy::GetOwnProperty(thread_, proxyHandle, key, desc); EXPECT_EQ(desc.GetValue()->GetInt(), 1); } @@ -98,33 +98,33 @@ TEST_F(JSProxyTest, GetProperty) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "get" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); JSHandle key(factory->NewFromString("x")); JSHandle value(thread_, JSTaggedValue(1)); - JSObject::SetProperty(thread_, target_handle, key, value); - EXPECT_EQ(JSObject::GetProperty(thread_, target_handle, key).GetValue()->GetInt(), 1); + JSObject::SetProperty(thread_, targetHandle, key, value); + EXPECT_EQ(JSObject::GetProperty(thread_, targetHandle, key).GetValue()->GetInt(), 1); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle, key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle, key).GetValue()->GetInt(), 1); // 2. handler has "get" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle get_key = thread_->GlobalConstants()->GetHandledGetString(); - JSHandle get_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerGetProperty))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), get_key, get_handle); + JSHandle getKey = thread_->GlobalConstants()->GetHandledGetString(); + JSHandle getHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerGetProperty))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), getKey, getHandle); - JSHandle proxy_handle2(JSProxy::ProxyCreate(thread_, target_handle, handler_handle)); - EXPECT_TRUE(*proxy_handle2 != nullptr); + JSHandle proxyHandle2(JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle)); + EXPECT_TRUE(*proxyHandle2 != nullptr); JSHandle key2(factory->NewFromString("y")); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle2, key2).GetValue()->GetInt(), 10); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle2, key2).GetValue()->GetInt(), 10); } // ES6 9.5.5 [[GetOwnProperty]] (P) @@ -138,36 +138,36 @@ TEST_F(JSProxyTest, GetOwnProperty) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "get" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); JSHandle key(factory->NewFromString("x")); JSHandle value(thread_, JSTaggedValue(1)); - JSObject::SetProperty(thread_, target_handle, key, value); - EXPECT_EQ(JSObject::GetProperty(thread_, target_handle, key).GetValue()->GetInt(), 1); + JSObject::SetProperty(thread_, targetHandle, key, value); + EXPECT_EQ(JSObject::GetProperty(thread_, targetHandle, key).GetValue()->GetInt(), 1); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); PropertyDescriptor desc(thread_); - JSProxy::GetOwnProperty(thread_, proxy_handle, key, desc); + JSProxy::GetOwnProperty(thread_, proxyHandle, key, desc); EXPECT_EQ(desc.GetValue()->GetInt(), 1); // 2. handler has "get" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle define_key = thread_->GlobalConstants()->GetHandledGetOwnPropertyDescriptorString(); - JSHandle define_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerGetOwnProperty))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), define_key, define_handle); + JSHandle defineKey = thread_->GlobalConstants()->GetHandledGetOwnPropertyDescriptorString(); + JSHandle defineHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerGetOwnProperty))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), defineKey, defineHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); JSHandle key2(factory->NewFromString("y")); PropertyDescriptor desc2(thread_); - EXPECT_FALSE(JSProxy::GetOwnProperty(thread_, proxy_handle2, key2, desc2)); + EXPECT_FALSE(JSProxy::GetOwnProperty(thread_, proxyHandle2, key2, desc2)); } // ES6 9.5.9 [[Set]] ( P, V, Receiver) @@ -182,35 +182,35 @@ TEST_F(JSProxyTest, SetProperty) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "get" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); JSHandle key(factory->NewFromString("x")); JSHandle value(thread_, JSTaggedValue(1)); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - EXPECT_TRUE(JSProxy::SetProperty(thread_, proxy_handle, key, value)); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle, key).GetValue()->GetInt(), 1); - EXPECT_EQ(JSObject::GetProperty(thread_, target_handle, key).GetValue()->GetInt(), 1); + EXPECT_TRUE(JSProxy::SetProperty(thread_, proxyHandle, key, value)); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle, key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSObject::GetProperty(thread_, targetHandle, key).GetValue()->GetInt(), 1); // 2. handler has "set" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle set_key = thread_->GlobalConstants()->GetHandledSetString(); - JSHandle set_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerSetProperty))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), set_key, set_handle); + JSHandle setKey = thread_->GlobalConstants()->GetHandledSetString(); + JSHandle setHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerSetProperty))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), setKey, setHandle); - JSHandle proxy_handle2(JSProxy::ProxyCreate(thread_, target_handle, handler_handle)); - EXPECT_TRUE(*proxy_handle2 != nullptr); + JSHandle proxyHandle2(JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle)); + EXPECT_TRUE(*proxyHandle2 != nullptr); // NOLINTNEXTLINE(readability-magic-numbers) JSHandle value2(thread_, JSTaggedValue(10)); - EXPECT_FALSE(JSProxy::SetProperty(thread_, proxy_handle2, key, value2)); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle2, key).GetValue()->GetInt(), 1); + EXPECT_FALSE(JSProxy::SetProperty(thread_, proxyHandle2, key, value2)); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle2, key).GetValue()->GetInt(), 1); } // ES6 9.5.6 [[DefineOwnProperty]] (P, Desc) @@ -224,36 +224,36 @@ TEST_F(JSProxyTest, DefineOwnProperty) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "defineProperty" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); JSHandle key(factory->NewFromString("x")); JSHandle value(thread_, JSTaggedValue(1)); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(1))); - EXPECT_TRUE(JSProxy::DefineOwnProperty(thread_, proxy_handle, key, desc)); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle, key).GetValue()->GetInt(), 1); - EXPECT_EQ(JSObject::GetProperty(thread_, target_handle, key).GetValue()->GetInt(), 1); + EXPECT_TRUE(JSProxy::DefineOwnProperty(thread_, proxyHandle, key, desc)); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle, key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSObject::GetProperty(thread_, targetHandle, key).GetValue()->GetInt(), 1); // 2. handler has "defineProperty" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle set_key = thread_->GlobalConstants()->GetHandledDefinePropertyString(); - JSHandle set_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerDefineOwnProperty))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), set_key, set_handle); + JSHandle setKey = thread_->GlobalConstants()->GetHandledDefinePropertyString(); + JSHandle setHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerDefineOwnProperty))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), setKey, setHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); // NOLINTNEXTLINE(readability-magic-numbers) PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(10))); - EXPECT_FALSE(JSProxy::DefineOwnProperty(thread_, proxy_handle, key, desc2)); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle2, key).GetValue()->GetInt(), 1); + EXPECT_FALSE(JSProxy::DefineOwnProperty(thread_, proxyHandle, key, desc2)); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle2, key).GetValue()->GetInt(), 1); } JSTaggedValue HandlerDeleteProperty([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -267,40 +267,40 @@ TEST_F(JSProxyTest, DeleteProperty) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "deleteProperty" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); JSHandle key(factory->NewFromString("x")); JSHandle value(thread_, JSTaggedValue(1)); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); - EXPECT_TRUE(JSProxy::DefineOwnProperty(thread_, proxy_handle, key, desc)); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle, key).GetValue()->GetInt(), 1); - EXPECT_EQ(JSObject::GetProperty(thread_, target_handle, key).GetValue()->GetInt(), 1); - EXPECT_TRUE(JSProxy::DeleteProperty(thread_, proxy_handle, key)); - PropertyDescriptor res_desc(thread_); - JSProxy::GetOwnProperty(thread_, proxy_handle, key, res_desc); - EXPECT_TRUE(JSTaggedValue::SameValue(res_desc.GetValue().GetTaggedValue(), JSTaggedValue::Undefined())); + EXPECT_TRUE(JSProxy::DefineOwnProperty(thread_, proxyHandle, key, desc)); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle, key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSObject::GetProperty(thread_, targetHandle, key).GetValue()->GetInt(), 1); + EXPECT_TRUE(JSProxy::DeleteProperty(thread_, proxyHandle, key)); + PropertyDescriptor resDesc(thread_); + JSProxy::GetOwnProperty(thread_, proxyHandle, key, resDesc); + EXPECT_TRUE(JSTaggedValue::SameValue(resDesc.GetValue().GetTaggedValue(), JSTaggedValue::Undefined())); // 2. handler has "deleteProperty" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle func_key = thread_->GlobalConstants()->GetHandledDeletePropertyString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerDeleteProperty))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledDeletePropertyString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerDeleteProperty))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); PropertyDescriptor desc2(thread_, JSHandle(thread_, JSTaggedValue(1)), true, true, true); - EXPECT_TRUE(JSProxy::DefineOwnProperty(thread_, proxy_handle2, key, desc2)); - EXPECT_EQ(JSProxy::GetProperty(thread_, proxy_handle2, key).GetValue()->GetInt(), 1); - EXPECT_FALSE(JSProxy::DeleteProperty(thread_, proxy_handle2, key)); + EXPECT_TRUE(JSProxy::DefineOwnProperty(thread_, proxyHandle2, key, desc2)); + EXPECT_EQ(JSProxy::GetProperty(thread_, proxyHandle2, key).GetValue()->GetInt(), 1); + EXPECT_FALSE(JSProxy::DeleteProperty(thread_, proxyHandle2, key)); } JSTaggedValue HandlerGetPrototype([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -315,30 +315,30 @@ TEST_F(JSProxyTest, GetPrototypeOf) // 1. handler has no "GetPrototypeOf" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); JSHandle proto(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); - JSObject::SetPrototype(thread_, JSHandle(target_handle), proto); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); + JSObject::SetPrototype(thread_, JSHandle(targetHandle), proto); EXPECT_TRUE( - JSTaggedValue::SameValue(JSHandle(target_handle)->GetPrototype(thread_), proto.GetTaggedValue())); + JSTaggedValue::SameValue(JSHandle(targetHandle)->GetPrototype(thread_), proto.GetTaggedValue())); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - EXPECT_TRUE(JSTaggedValue::SameValue(JSProxy::GetPrototype(thread_, proxy_handle), proto.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(JSProxy::GetPrototype(thread_, proxyHandle), proto.GetTaggedValue())); // 2. handler has "GetPrototypeOf" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle func_key = thread_->GlobalConstants()->GetHandledGetPrototypeOfString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerGetPrototype))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledGetPrototypeOfString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerGetPrototype))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); - EXPECT_TRUE(JSTaggedValue::SameValue(JSProxy::GetPrototype(thread_, proxy_handle2), JSTaggedValue::Null())); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); + EXPECT_TRUE(JSTaggedValue::SameValue(JSProxy::GetPrototype(thread_, proxyHandle2), JSTaggedValue::Null())); } JSTaggedValue HandlerSetPrototype([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -353,29 +353,29 @@ TEST_F(JSProxyTest, SetPrototypeOf) // 1. handler has no "SetPrototypeOf" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); JSHandle proto(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - JSProxy::SetPrototype(thread_, proxy_handle, proto); + JSProxy::SetPrototype(thread_, proxyHandle, proto); EXPECT_TRUE( - JSTaggedValue::SameValue(JSHandle(target_handle)->GetPrototype(thread_), proto.GetTaggedValue())); + JSTaggedValue::SameValue(JSHandle(targetHandle)->GetPrototype(thread_), proto.GetTaggedValue())); // 2. handler has "SetPrototypeOf" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle func_key = thread_->GlobalConstants()->GetHandledSetPrototypeOfString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerSetPrototype))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledSetPrototypeOfString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerSetPrototype))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); - EXPECT_FALSE(JSProxy::SetPrototype(thread_, proxy_handle2, proto)); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); + EXPECT_FALSE(JSProxy::SetPrototype(thread_, proxyHandle2, proto)); } JSTaggedValue HandlerIsExtensible([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -389,29 +389,29 @@ TEST_F(JSProxyTest, IsExtensible) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "IsExtensible" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - bool status1 = JSProxy::IsExtensible(thread_, proxy_handle); - bool status2 = JSHandle::Cast(target_handle)->IsExtensible(); + bool status1 = JSProxy::IsExtensible(thread_, proxyHandle); + bool status2 = JSHandle::Cast(targetHandle)->IsExtensible(); EXPECT_TRUE(status1 == status2); // 2. handler has "IsExtensible" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle func_key = thread_->GlobalConstants()->GetHandledIsExtensibleString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerIsExtensible))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledIsExtensibleString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerIsExtensible))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); - EXPECT_FALSE(JSProxy::IsExtensible(thread_, proxy_handle2)); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); + EXPECT_FALSE(JSProxy::IsExtensible(thread_, proxyHandle2)); } JSTaggedValue HandlerPreventExtensions([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -425,31 +425,30 @@ TEST_F(JSProxyTest, PreventExtensions) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "PreventExtensions" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - bool status1 = JSProxy::PreventExtensions(thread_, proxy_handle); + bool status1 = JSProxy::PreventExtensions(thread_, proxyHandle); EXPECT_TRUE(status1); - bool status2 = JSHandle::Cast(target_handle)->IsExtensible(); + bool status2 = JSHandle::Cast(targetHandle)->IsExtensible(); EXPECT_FALSE(status2); // 2. handler has "PreventExtensions" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle func_key = thread_->GlobalConstants()->GetHandledPreventExtensionsString(); - JSHandle func_handle( - factory->NewJSFunction(env, reinterpret_cast(HandlerPreventExtensions))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); - - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); - EXPECT_FALSE(JSProxy::PreventExtensions(thread_, proxy_handle2)); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledPreventExtensionsString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerPreventExtensions))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); + + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); + EXPECT_FALSE(JSProxy::PreventExtensions(thread_, proxyHandle2)); } JSTaggedValue HandlerHasProperty([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -463,37 +462,37 @@ TEST_F(JSProxyTest, HasProperty) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "HasProperty" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); JSHandle key(factory->NewFromString("x")); PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(1))); - JSObject::DefineOwnProperty(thread_, JSHandle::Cast(target_handle), key, desc); + JSObject::DefineOwnProperty(thread_, JSHandle::Cast(targetHandle), key, desc); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); - EXPECT_TRUE(JSProxy::HasProperty(thread_, proxy_handle, key)); + EXPECT_TRUE(JSProxy::HasProperty(thread_, proxyHandle, key)); // 2. handler has "HasProperty" EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle func_key = thread_->GlobalConstants()->GetHandledHasString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerHasProperty))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledHasString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerHasProperty))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); - EXPECT_FALSE(JSProxy::HasProperty(thread_, proxy_handle2, key)); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); + EXPECT_FALSE(JSProxy::HasProperty(thread_, proxyHandle2, key)); } JSTaggedValue HandlerOwnPropertyKeys([[maybe_unused]] EcmaRuntimeCallInfo *argv) { auto thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle arr = factory->NewJSArray(); return JSTaggedValue(arr.GetTaggedValue()); @@ -505,35 +504,35 @@ TEST_F(JSProxyTest, OwnPropertyKeys) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // 1. handler has no "OwnPropertyKeys" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle->IsECMAObject()); JSHandle key(factory->NewFromString("x")); PropertyDescriptor desc(thread_, JSHandle(thread_, JSTaggedValue(1))); - JSObject::DefineOwnProperty(thread_, JSHandle::Cast(target_handle), key, desc); + JSObject::DefineOwnProperty(thread_, JSHandle::Cast(targetHandle), key, desc); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); - JSHandle res = JSProxy::OwnPropertyKeys(thread_, proxy_handle); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); + JSHandle res = JSProxy::OwnPropertyKeys(thread_, proxyHandle); EXPECT_TRUE(JSTaggedValue::SameValue(res->Get(0), key.GetTaggedValue())); // 2. handler has "OwnPropertyKeys" // create new empty target so we wont throw TypeError at (18. - 21.) - JSHandle target_handle2(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(target_handle2->IsECMAObject()); + JSHandle targetHandle2(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(targetHandle2->IsECMAObject()); EcmaVM *vm = thread_->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); - JSHandle func_key = thread_->GlobalConstants()->GetHandledOwnKeysString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerOwnPropertyKeys))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledOwnKeysString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerOwnPropertyKeys))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle2, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); - JSHandle res2 = JSProxy::OwnPropertyKeys(thread_, proxy_handle2); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle2, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); + JSHandle res2 = JSProxy::OwnPropertyKeys(thread_, proxyHandle2); EXPECT_TRUE(res2->GetLength() == 0 || !JSTaggedValue::SameValue(res2->Get(0), key.GetTaggedValue())); } @@ -553,46 +552,46 @@ TEST_F(JSProxyTest, Call) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); // 1. handler has no "Call" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerFunction))); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerFunction))); + EXPECT_TRUE(targetHandle->IsECMAObject()); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); JSTaggedValue res; - EXPECT_TRUE(*proxy_handle != nullptr); + EXPECT_TRUE(*proxyHandle != nullptr); { - auto info = NewRuntimeCallInfo(thread_, proxy_handle, JSHandle::Cast(proxy_handle), + auto info = NewRuntimeCallInfo(thread_, proxyHandle, JSHandle::Cast(proxyHandle), JSTaggedValue::Undefined(), 0); res = JSProxy::CallInternal(info.Get()); } - JSHandle tagged_res(thread_, res); + JSHandle taggedRes(thread_, res); - EXPECT_TRUE(JSTaggedValue::SameValue(tagged_res.GetTaggedValue(), JSTaggedValue::True())); + EXPECT_TRUE(JSTaggedValue::SameValue(taggedRes.GetTaggedValue(), JSTaggedValue::True())); // 2. handler has "Call" - JSHandle func_key = thread_->GlobalConstants()->GetHandledApplyString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerCall))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledApplyString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerCall))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); JSTaggedValue res2; { - auto info = NewRuntimeCallInfo(thread_, proxy_handle2, JSHandle::Cast(proxy_handle2), + auto info = NewRuntimeCallInfo(thread_, proxyHandle2, JSHandle::Cast(proxyHandle2), JSTaggedValue::Undefined(), 0); res2 = JSProxy::CallInternal(info.Get()); } - JSHandle tagged_res2(thread_, res2); + JSHandle taggedRes2(thread_, res2); - EXPECT_TRUE(JSTaggedValue::SameValue(tagged_res2.GetTaggedValue(), JSTaggedValue::False())); + EXPECT_TRUE(JSTaggedValue::SameValue(taggedRes2.GetTaggedValue(), JSTaggedValue::False())); } JSTaggedValue HandlerConstruct([[maybe_unused]] EcmaRuntimeCallInfo *argv) { auto thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dynclass(thread, JSObjectTestCreate(thread)); JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); @@ -605,7 +604,7 @@ JSTaggedValue HandlerConstruct([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSTaggedValue HandlerConFunc([[maybe_unused]] EcmaRuntimeCallInfo *argv) { auto thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); + [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dynclass(thread, JSObjectTestCreate(thread)); JSHandle obj(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); @@ -623,37 +622,37 @@ TEST_F(JSProxyTest, Construct) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); // 1. handler has no "Construct" JSHandle dynclass(thread_, JSObjectTestCreate(thread_)); - JSHandle target_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerConFunc))); - JSHandle::Cast(target_handle)->GetJSHClass()->SetConstructor(true); - EXPECT_TRUE(target_handle->IsECMAObject()); + JSHandle targetHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerConFunc))); + JSHandle::Cast(targetHandle)->GetJSHClass()->SetConstructor(true); + EXPECT_TRUE(targetHandle->IsECMAObject()); - JSHandle handler_handle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); - EXPECT_TRUE(handler_handle->IsECMAObject()); + JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(dynclass), dynclass)); + EXPECT_TRUE(handlerHandle->IsECMAObject()); - JSHandle proxy_handle = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle != nullptr); + JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle != nullptr); JSTaggedValue res; { - auto info = NewRuntimeCallInfo(thread_, proxy_handle, JSTaggedValue::Undefined(), target_handle, 0); + auto info = NewRuntimeCallInfo(thread_, proxyHandle, JSTaggedValue::Undefined(), targetHandle, 0); res = JSProxy::ConstructInternal(info.Get()); } - JSHandle tagged_res(thread_, res); + JSHandle taggedRes(thread_, res); JSHandle key(factory->NewFromCanBeCompressString("x")); - EXPECT_EQ(JSObject::GetProperty(thread_, tagged_res, key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSObject::GetProperty(thread_, taggedRes, key).GetValue()->GetInt(), 1); // 2. handler has "Construct" - JSHandle func_key = thread_->GlobalConstants()->GetHandledProxyConstructString(); - JSHandle func_handle(factory->NewJSFunction(env, reinterpret_cast(HandlerConstruct))); - JSObject::SetProperty(thread_, JSHandle(handler_handle), func_key, func_handle); + JSHandle funcKey = thread_->GlobalConstants()->GetHandledProxyConstructString(); + JSHandle funcHandle(factory->NewJSFunction(env, reinterpret_cast(HandlerConstruct))); + JSObject::SetProperty(thread_, JSHandle(handlerHandle), funcKey, funcHandle); - JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread_, target_handle, handler_handle); - EXPECT_TRUE(*proxy_handle2 != nullptr); + JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); + EXPECT_TRUE(*proxyHandle2 != nullptr); JSTaggedValue res2; { - auto info = NewRuntimeCallInfo(thread_, proxy_handle2, JSTaggedValue::Undefined(), target_handle, 0); + auto info = NewRuntimeCallInfo(thread_, proxyHandle2, JSTaggedValue::Undefined(), targetHandle, 0); res2 = JSProxy::ConstructInternal(info.Get()); } - JSHandle tagged_res2(thread_, res2); - EXPECT_EQ(JSObject::GetProperty(thread_, tagged_res2, key).GetValue()->GetInt(), 2); + JSHandle taggedRes2(thread_, res2); + EXPECT_EQ(JSObject::GetProperty(thread_, taggedRes2, key).GetValue()->GetInt(), 2); } } // namespace panda::test diff --git a/tests/runtime/common/js_set_iterator_test.cpp b/tests/runtime/common/js_set_iterator_test.cpp index 2127300151aae7a61ca3a7a914fb7065fc8092ff..f88d3c831e572e15fdb00d1b1ad16f9c85b65beb 100644 --- a/tests/runtime/common/js_set_iterator_test.cpp +++ b/tests/runtime/common/js_set_iterator_test.cpp @@ -63,8 +63,8 @@ JSSet *CreateSet(JSThread *thread) JSHandle constructor = env->GetSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); - JSHandle hash_set = LinkedHashSet::Create(thread); - set->SetLinkedSet(thread, hash_set); + JSHandle hashSet = LinkedHashSet::Create(thread); + set->SetLinkedSet(thread, hashSet); return JSSet::Cast(set.GetTaggedValue().GetTaggedObject()); } @@ -77,30 +77,30 @@ JSSet *CreateSet(JSThread *thread) */ TEST_F(JSSetIteratorTest, CreateSetIterator) { - JSHandle js_set(thread_, CreateSet(thread_)); - EXPECT_TRUE(*js_set != nullptr); + JSHandle jsSet(thread_, CreateSet(thread_)); + EXPECT_TRUE(*jsSet != nullptr); - JSHandle set_iterator_value1 = - JSSetIterator::CreateSetIterator(thread_, JSHandle(js_set), IterationKind::KEY); + JSHandle setIteratorValue1 = + JSSetIterator::CreateSetIterator(thread_, JSHandle(jsSet), IterationKind::KEY); - EXPECT_EQ(set_iterator_value1->IsJSSetIterator(), true); - JSHandle set_iterator1(set_iterator_value1); - EXPECT_EQ(JSTaggedValue::SameValue(set_iterator1->GetIteratedSet(), js_set->GetLinkedSet()), true); - EXPECT_EQ(set_iterator1->GetNextIndex().GetInt(), 0); + EXPECT_EQ(setIteratorValue1->IsJSSetIterator(), true); + JSHandle setIterator1(setIteratorValue1); + EXPECT_EQ(JSTaggedValue::SameValue(setIterator1->GetIteratedSet(), jsSet->GetLinkedSet()), true); + EXPECT_EQ(setIterator1->GetNextIndex().GetInt(), 0); - JSTaggedValue iteration_kind1 = set_iterator1->GetIterationKind(); - EXPECT_EQ(JSTaggedValue::SameValue(iteration_kind1, JSTaggedValue(static_cast(IterationKind::KEY))), true); + JSTaggedValue iterationKind1 = setIterator1->GetIterationKind(); + EXPECT_EQ(JSTaggedValue::SameValue(iterationKind1, JSTaggedValue(static_cast(IterationKind::KEY))), true); - JSHandle set_iterator_value2 = - JSSetIterator::CreateSetIterator(thread_, JSHandle(js_set), IterationKind::VALUE); + JSHandle setIteratorValue2 = + JSSetIterator::CreateSetIterator(thread_, JSHandle(jsSet), IterationKind::VALUE); - EXPECT_EQ(set_iterator_value2->IsJSSetIterator(), true); - JSHandle set_iterator2(set_iterator_value2); - EXPECT_EQ(JSTaggedValue::SameValue(set_iterator2->GetIteratedSet(), js_set->GetLinkedSet()), true); - EXPECT_EQ(set_iterator2->GetNextIndex().GetInt(), 0); + EXPECT_EQ(setIteratorValue2->IsJSSetIterator(), true); + JSHandle setIterator2(setIteratorValue2); + EXPECT_EQ(JSTaggedValue::SameValue(setIterator2->GetIteratedSet(), jsSet->GetLinkedSet()), true); + EXPECT_EQ(setIterator2->GetNextIndex().GetInt(), 0); - JSTaggedValue iteration_kind2 = set_iterator2->GetIterationKind(); - EXPECT_EQ(JSTaggedValue::SameValue(iteration_kind2, JSTaggedValue(static_cast(IterationKind::VALUE))), true); + JSTaggedValue iterationKind2 = setIterator2->GetIterationKind(); + EXPECT_EQ(JSTaggedValue::SameValue(iterationKind2, JSTaggedValue(static_cast(IterationKind::VALUE))), true); } /* @@ -112,43 +112,43 @@ TEST_F(JSSetIteratorTest, CreateSetIterator) */ TEST_F(JSSetIteratorTest, Next) { - JSHandle js_set(thread_, CreateSet(thread_)); - EXPECT_TRUE(*js_set != nullptr); + JSHandle jsSet(thread_, CreateSet(thread_)); + EXPECT_TRUE(*jsSet != nullptr); for (int i = 0; i < 3; i++) { JSHandle key(thread_, JSTaggedValue(i)); - JSSet::Add(thread_, js_set, key); + JSSet::Add(thread_, jsSet, key); } // set IterationKind(key or value) - JSHandle set_iterator_value = - JSSetIterator::CreateSetIterator(thread_, JSHandle(js_set), IterationKind::KEY); - JSHandle set_iterator(set_iterator_value); - - auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); - ecma_runtime_call_info->SetFunction(JSTaggedValue::Undefined()); - ecma_runtime_call_info->SetThis(set_iterator_value.GetTaggedValue()); - ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - - JSTaggedValue result1 = JSSetIterator::Next(ecma_runtime_call_info.get()); - EXPECT_EQ(set_iterator->GetNextIndex().GetInt(), 1); - JSHandle result_obj1(thread_, result1); - EXPECT_EQ(0, JSIterator::IteratorValue(thread_, result_obj1)->GetInt()); - - JSTaggedValue result2 = JSSetIterator::Next(ecma_runtime_call_info.get()); - EXPECT_EQ(set_iterator->GetNextIndex().GetInt(), 2); - JSHandle result_obj2(thread_, result2); - EXPECT_EQ(1, JSIterator::IteratorValue(thread_, result_obj2)->GetInt()); - - JSTaggedValue result3 = JSSetIterator::Next(ecma_runtime_call_info.get()); - EXPECT_EQ(set_iterator->GetNextIndex().GetInt(), 3); - JSHandle result_obj3(thread_, result3); - EXPECT_EQ(2, JSIterator::IteratorValue(thread_, result_obj3)->GetInt()); - - JSTaggedValue result4 = JSSetIterator::Next(ecma_runtime_call_info.get()); - JSHandle result_obj4(thread_, result4); - EXPECT_EQ(JSIterator::IteratorValue(thread_, result_obj4).GetTaggedValue(), JSTaggedValue::Undefined()); + JSHandle setIteratorValue = + JSSetIterator::CreateSetIterator(thread_, JSHandle(jsSet), IterationKind::KEY); + JSHandle setIterator(setIteratorValue); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(setIteratorValue.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); + + JSTaggedValue result1 = JSSetIterator::Next(ecmaRuntimeCallInfo.get()); + EXPECT_EQ(setIterator->GetNextIndex().GetInt(), 1); + JSHandle resultObj1(thread_, result1); + EXPECT_EQ(0, JSIterator::IteratorValue(thread_, resultObj1)->GetInt()); + + JSTaggedValue result2 = JSSetIterator::Next(ecmaRuntimeCallInfo.get()); + EXPECT_EQ(setIterator->GetNextIndex().GetInt(), 2); + JSHandle resultObj2(thread_, result2); + EXPECT_EQ(1, JSIterator::IteratorValue(thread_, resultObj2)->GetInt()); + + JSTaggedValue result3 = JSSetIterator::Next(ecmaRuntimeCallInfo.get()); + EXPECT_EQ(setIterator->GetNextIndex().GetInt(), 3); + JSHandle resultObj3(thread_, result3); + EXPECT_EQ(2, JSIterator::IteratorValue(thread_, resultObj3)->GetInt()); + + JSTaggedValue result4 = JSSetIterator::Next(ecmaRuntimeCallInfo.get()); + JSHandle resultObj4(thread_, result4); + EXPECT_EQ(JSIterator::IteratorValue(thread_, resultObj4).GetTaggedValue(), JSTaggedValue::Undefined()); TestHelper::TearDownFrame(thread_, prev); } diff --git a/tests/runtime/common/js_set_test.cpp b/tests/runtime/common/js_set_test.cpp index e528e193a88a52210b41f586df07c340af1cb594..a59f00dac7bce8502a53c68304cb33dff40c94eb 100644 --- a/tests/runtime/common/js_set_test.cpp +++ b/tests/runtime/common/js_set_test.cpp @@ -60,8 +60,8 @@ protected: JSHandle constructor = env->GetSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); - JSHandle hash_set = LinkedHashSet::Create(thread_); - set->SetLinkedSet(thread_, hash_set); + JSHandle hashSet = LinkedHashSet::Create(thread_); + set->SetLinkedSet(thread_, hashSet); return JSSet::Cast(set.GetTaggedValue().GetTaggedObject()); } @@ -97,22 +97,22 @@ TEST_F(JSSetTest, DeleteAndGet) // add 40 keys // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char key_array[] = "key0"; + char keyArray[] = "key0"; // NOLINTNEXTLINE(readability-magic-numbers) for (int i = 0; i < 40; i++) { - key_array[3] = '1' + i; - JSHandle key(factory->NewFromString(key_array)); + keyArray[3] = '1' + i; + JSHandle key(factory->NewFromString(keyArray)); JSSet::Add(thread_, set, key); int hash = LinkedHash::Hash(key.GetTaggedValue()); EXPECT_TRUE(set->Has(key.GetTaggedValue(), hash)); } EXPECT_EQ(set->GetSize(), 40); // whether js_set has delete key - key_array[3] = '1' + 8; - JSHandle delete_key(factory->NewFromString(key_array)); - JSSet::Delete(thread_, set, delete_key); - int hash = LinkedHash::Hash(delete_key.GetTaggedValue()); - EXPECT_FALSE(set->Has(delete_key.GetTaggedValue(), hash)); + keyArray[3] = '1' + 8; + JSHandle deleteKey(factory->NewFromString(keyArray)); + JSSet::Delete(thread_, set, deleteKey); + int hash = LinkedHash::Hash(deleteKey.GetTaggedValue()); + EXPECT_FALSE(set->Has(deleteKey.GetTaggedValue(), hash)); EXPECT_EQ(set->GetSize(), 39); } @@ -125,33 +125,33 @@ TEST_F(JSSetTest, Iterator) JSSet::Add(thread_, set, key); } - JSHandle key_iter(factory->NewJSSetIterator(set, IterationKind::KEY)); - JSHandle value_iter(factory->NewJSSetIterator(set, IterationKind::VALUE)); + JSHandle keyIter(factory->NewJSSetIterator(set, IterationKind::KEY)); + JSHandle valueIter(factory->NewJSSetIterator(set, IterationKind::VALUE)); - JSHandle key_result0 = JSIterator::IteratorStep(thread_, key_iter); - JSHandle value_result0 = JSIterator::IteratorStep(thread_, value_iter); + JSHandle keyResult0 = JSIterator::IteratorStep(thread_, keyIter); + JSHandle valueResult0 = JSIterator::IteratorStep(thread_, valueIter); - EXPECT_EQ(0, JSIterator::IteratorValue(thread_, key_result0)->GetInt()); - EXPECT_EQ(0, JSIterator::IteratorValue(thread_, value_result0)->GetInt()); + EXPECT_EQ(0, JSIterator::IteratorValue(thread_, keyResult0)->GetInt()); + EXPECT_EQ(0, JSIterator::IteratorValue(thread_, valueResult0)->GetInt()); - JSHandle key_result1 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(1, JSIterator::IteratorValue(thread_, key_result1)->GetInt()); + JSHandle keyResult1 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(1, JSIterator::IteratorValue(thread_, keyResult1)->GetInt()); for (int i = 0; i < 3; i++) { JSHandle key(thread_, JSTaggedValue(i)); JSSet::Delete(thread_, set, key); } - JSHandle key_result2 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(3, JSIterator::IteratorValue(thread_, key_result2)->GetInt()); - JSHandle key_result3 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(4, JSIterator::IteratorValue(thread_, key_result3)->GetInt()); + JSHandle keyResult2 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(3, JSIterator::IteratorValue(thread_, keyResult2)->GetInt()); + JSHandle keyResult3 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(4, JSIterator::IteratorValue(thread_, keyResult3)->GetInt()); JSHandle key(thread_, JSTaggedValue(5)); JSSet::Add(thread_, set, key); - JSHandle key_result4 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(5, JSIterator::IteratorValue(thread_, key_result4)->GetInt()); - JSHandle key_result5 = JSIterator::IteratorStep(thread_, key_iter); - EXPECT_EQ(JSTaggedValue::False(), key_result5.GetTaggedValue()); + JSHandle keyResult4 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(5, JSIterator::IteratorValue(thread_, keyResult4)->GetInt()); + JSHandle keyResult5 = JSIterator::IteratorStep(thread_, keyIter); + EXPECT_EQ(JSTaggedValue::False(), keyResult5.GetTaggedValue()); } } // namespace panda::test diff --git a/tests/runtime/common/js_typed_array_test.cpp b/tests/runtime/common/js_typed_array_test.cpp index c40a9f176b8f4708822adae36764de7998869093..220795b714845d2f657d01a557f9ec396676d963 100644 --- a/tests/runtime/common/js_typed_array_test.cpp +++ b/tests/runtime/common/js_typed_array_test.cpp @@ -49,14 +49,14 @@ protected: JSThread *thread_ {nullptr}; // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) - const std::vector c_vec_js_type_ { + const std::vector cVecJsType_ { JSType::JS_INT8_ARRAY, JSType::JS_UINT8_ARRAY, JSType::JS_UINT8_CLAMPED_ARRAY, JSType::JS_INT16_ARRAY, JSType::JS_UINT16_ARRAY, JSType::JS_INT32_ARRAY, JSType::JS_UINT32_ARRAY, JSType::JS_FLOAT32_ARRAY, JSType::JS_FLOAT64_ARRAY}; // PandaVector pushed with JSTaggedValue made from compatible input value for the JSType // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) - const std::vector c_vec_handle_tag_val_value_for_typed_array_ { + const std::vector cVecHandleTagValValueForTypedArray_ { // Use "(S)(...)" cast to make v in "JSTaggedValue(T v) : coretypes::TaggedValue(v) {}" compatible with S JSTaggedValue((int8_t)(-111)), JSTaggedValue((uint8_t)(222)), JSTaggedValue((uint8_t)(222)), JSTaggedValue((int16_t)(-31111)), JSTaggedValue((uint16_t)(61111)), @@ -69,38 +69,38 @@ private: EcmaHandleScope *scope_ {nullptr}; }; -JSHandle CreateNumberTypedArray(JSThread *thread, JSType js_type) +JSHandle CreateNumberTypedArray(JSThread *thread, JSType jsType) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle handle_tag_val_func = env->GetInt8ArrayFunction(); - switch (js_type) { + JSHandle handleTagValFunc = env->GetInt8ArrayFunction(); + switch (jsType) { case JSType::JS_INT8_ARRAY: break; case JSType::JS_UINT8_ARRAY: - handle_tag_val_func = env->GetUint8ArrayFunction(); + handleTagValFunc = env->GetUint8ArrayFunction(); break; case JSType::JS_UINT8_CLAMPED_ARRAY: - handle_tag_val_func = env->GetUint8ClampedArrayFunction(); + handleTagValFunc = env->GetUint8ClampedArrayFunction(); break; case JSType::JS_INT16_ARRAY: - handle_tag_val_func = env->GetInt16ArrayFunction(); + handleTagValFunc = env->GetInt16ArrayFunction(); break; case JSType::JS_UINT16_ARRAY: - handle_tag_val_func = env->GetUint16ArrayFunction(); + handleTagValFunc = env->GetUint16ArrayFunction(); break; case JSType::JS_INT32_ARRAY: - handle_tag_val_func = env->GetInt32ArrayFunction(); + handleTagValFunc = env->GetInt32ArrayFunction(); break; case JSType::JS_UINT32_ARRAY: - handle_tag_val_func = env->GetUint32ArrayFunction(); + handleTagValFunc = env->GetUint32ArrayFunction(); break; case JSType::JS_FLOAT32_ARRAY: - handle_tag_val_func = env->GetFloat32ArrayFunction(); + handleTagValFunc = env->GetFloat32ArrayFunction(); break; case JSType::JS_FLOAT64_ARRAY: - handle_tag_val_func = env->GetFloat64ArrayFunction(); + handleTagValFunc = env->GetFloat64ArrayFunction(); break; default: ASSERT_PRINT(false, "the second argument is a wrong JSType for CreateNumberTypedArray function"); @@ -108,7 +108,7 @@ JSHandle CreateNumberTypedArray(JSThread *thread, JSType js_type) } return JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle::Cast(handle_tag_val_func), handle_tag_val_func)); + factory->NewJSObjectByConstructor(JSHandle::Cast(handleTagValFunc), handleTagValFunc)); } /* @@ -121,29 +121,27 @@ JSHandle CreateNumberTypedArray(JSThread *thread, JSType js_type) */ TEST_F(JSTypedArrayTest, ToPropKey_001) { - JSHandle handle_undefined(thread_, JSTaggedValue::Undefined()); - JSHandle handle_hole(thread_, JSTaggedValue::Hole()); - JSHandle hnadle_tag_val_ecma_str_prop_key_to1 = JSTypedArray::ToPropKey(thread_, handle_undefined); - JSHandle hnadle_tag_val_ecma_str_prop_key_to2 = JSTypedArray::ToPropKey(thread_, handle_hole); - JSHandle handle_ecma_str_prop_key_to1 = - JSHandle::Cast(hnadle_tag_val_ecma_str_prop_key_to1); - JSHandle handle_ecma_str_prop_key_to2 = - JSHandle::Cast(hnadle_tag_val_ecma_str_prop_key_to2); - EXPECT_NE(0, sizeof(handle_undefined)); - EXPECT_NE(0, sizeof(handle_hole)); - std::unique_ptr uni_char_arr_to1(handle_ecma_str_prop_key_to1->GetCString()); - std::unique_ptr uni_char_arr_to2(handle_ecma_str_prop_key_to2->GetCString()); - EXPECT_EQ(uni_char_arr_to1[0], 'u'); - EXPECT_EQ(uni_char_arr_to1[1], 'n'); - EXPECT_EQ(uni_char_arr_to1[2], 'd'); - EXPECT_EQ(uni_char_arr_to1[3], 'e'); - EXPECT_EQ(uni_char_arr_to1[4], 'f'); - EXPECT_EQ(uni_char_arr_to1[5], 'i'); - EXPECT_EQ(uni_char_arr_to1[6], 'n'); - EXPECT_EQ(uni_char_arr_to1[7], 'e'); - EXPECT_EQ(uni_char_arr_to1[8], 'd'); - EXPECT_EQ(uni_char_arr_to1[9], 0); // "undefined" - EXPECT_EQ(uni_char_arr_to2[0], 0); // "" + JSHandle handleUndefined(thread_, JSTaggedValue::Undefined()); + JSHandle handleHole(thread_, JSTaggedValue::Hole()); + JSHandle hnadleTagValEcmaStrPropKeyTo1 = JSTypedArray::ToPropKey(thread_, handleUndefined); + JSHandle hnadleTagValEcmaStrPropKeyTo2 = JSTypedArray::ToPropKey(thread_, handleHole); + JSHandle handleEcmaStrPropKeyTo1 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo1); + JSHandle handleEcmaStrPropKeyTo2 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo2); + EXPECT_NE(0, sizeof(handleUndefined)); + EXPECT_NE(0, sizeof(handleHole)); + std::unique_ptr uniCharArrTo1(handleEcmaStrPropKeyTo1->GetCString()); + std::unique_ptr uniCharArrTo2(handleEcmaStrPropKeyTo2->GetCString()); + EXPECT_EQ(uniCharArrTo1[0], 'u'); + EXPECT_EQ(uniCharArrTo1[1], 'n'); + EXPECT_EQ(uniCharArrTo1[2], 'd'); + EXPECT_EQ(uniCharArrTo1[3], 'e'); + EXPECT_EQ(uniCharArrTo1[4], 'f'); + EXPECT_EQ(uniCharArrTo1[5], 'i'); + EXPECT_EQ(uniCharArrTo1[6], 'n'); + EXPECT_EQ(uniCharArrTo1[7], 'e'); + EXPECT_EQ(uniCharArrTo1[8], 'd'); + EXPECT_EQ(uniCharArrTo1[9], 0); // "undefined" + EXPECT_EQ(uniCharArrTo2[0], 0); // "" } /* @@ -156,44 +154,40 @@ TEST_F(JSTypedArrayTest, ToPropKey_001) */ TEST_F(JSTypedArrayTest, ToPropKey_002) { - JSHandle handle_tag_val1(thread_, JSTaggedValue(0)); - JSHandle handle_tag_val2(thread_, JSTaggedValue(-1)); - JSHandle handle_tag_val3(thread_, JSTaggedValue(1.789)); - JSHandle handle_tag_val4(thread_, JSTaggedValue(-789.1)); - JSHandle hnadle_tag_val_ecma_str_prop_key_to1 = JSTypedArray::ToPropKey(thread_, handle_tag_val1); - JSHandle hnadle_tag_val_ecma_str_prop_key_to2 = JSTypedArray::ToPropKey(thread_, handle_tag_val2); - JSHandle hnadle_tag_val_ecma_str_prop_key_to3 = JSTypedArray::ToPropKey(thread_, handle_tag_val3); - JSHandle hnadle_tag_val_ecma_str_prop_key_to4 = JSTypedArray::ToPropKey(thread_, handle_tag_val4); - JSHandle handle_ecma_str_prop_key_to1 = - JSHandle::Cast(hnadle_tag_val_ecma_str_prop_key_to1); - JSHandle handle_ecma_str_prop_key_to2 = - JSHandle::Cast(hnadle_tag_val_ecma_str_prop_key_to2); - JSHandle handle_ecma_str_prop_key_to3 = - JSHandle::Cast(hnadle_tag_val_ecma_str_prop_key_to3); - JSHandle handle_ecma_str_prop_key_to4 = - JSHandle::Cast(hnadle_tag_val_ecma_str_prop_key_to4); - std::unique_ptr uni_char_arr_to1(handle_ecma_str_prop_key_to1->GetCString()); - std::unique_ptr uni_char_arr_to2(handle_ecma_str_prop_key_to2->GetCString()); - std::unique_ptr uni_char_arr_to3(handle_ecma_str_prop_key_to3->GetCString()); - std::unique_ptr uni_char_arr_to4(handle_ecma_str_prop_key_to4->GetCString()); - EXPECT_EQ(uni_char_arr_to1[0], '0'); - EXPECT_EQ(uni_char_arr_to1[1], 0); // "0" - EXPECT_EQ(uni_char_arr_to2[0], '-'); - EXPECT_EQ(uni_char_arr_to2[1], '1'); - EXPECT_EQ(uni_char_arr_to2[2], 0); // "-1" - EXPECT_EQ(uni_char_arr_to3[0], '1'); - EXPECT_EQ(uni_char_arr_to3[1], '.'); - EXPECT_EQ(uni_char_arr_to3[2], '7'); - EXPECT_EQ(uni_char_arr_to3[3], '8'); - EXPECT_EQ(uni_char_arr_to3[4], '9'); - EXPECT_EQ(uni_char_arr_to3[5], 0); // "1.789" - EXPECT_EQ(uni_char_arr_to4[0], '-'); - EXPECT_EQ(uni_char_arr_to4[1], '7'); - EXPECT_EQ(uni_char_arr_to4[2], '8'); - EXPECT_EQ(uni_char_arr_to4[3], '9'); - EXPECT_EQ(uni_char_arr_to4[4], '.'); - EXPECT_EQ(uni_char_arr_to4[5], '1'); - EXPECT_EQ(uni_char_arr_to4[6], 0); // "-789.1" + JSHandle handleTagVal1(thread_, JSTaggedValue(0)); + JSHandle handleTagVal2(thread_, JSTaggedValue(-1)); + JSHandle handleTagVal3(thread_, JSTaggedValue(1.789)); + JSHandle handleTagVal4(thread_, JSTaggedValue(-789.1)); + JSHandle hnadleTagValEcmaStrPropKeyTo1 = JSTypedArray::ToPropKey(thread_, handleTagVal1); + JSHandle hnadleTagValEcmaStrPropKeyTo2 = JSTypedArray::ToPropKey(thread_, handleTagVal2); + JSHandle hnadleTagValEcmaStrPropKeyTo3 = JSTypedArray::ToPropKey(thread_, handleTagVal3); + JSHandle hnadleTagValEcmaStrPropKeyTo4 = JSTypedArray::ToPropKey(thread_, handleTagVal4); + JSHandle handleEcmaStrPropKeyTo1 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo1); + JSHandle handleEcmaStrPropKeyTo2 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo2); + JSHandle handleEcmaStrPropKeyTo3 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo3); + JSHandle handleEcmaStrPropKeyTo4 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo4); + std::unique_ptr uniCharArrTo1(handleEcmaStrPropKeyTo1->GetCString()); + std::unique_ptr uniCharArrTo2(handleEcmaStrPropKeyTo2->GetCString()); + std::unique_ptr uniCharArrTo3(handleEcmaStrPropKeyTo3->GetCString()); + std::unique_ptr uniCharArrTo4(handleEcmaStrPropKeyTo4->GetCString()); + EXPECT_EQ(uniCharArrTo1[0], '0'); + EXPECT_EQ(uniCharArrTo1[1], 0); // "0" + EXPECT_EQ(uniCharArrTo2[0], '-'); + EXPECT_EQ(uniCharArrTo2[1], '1'); + EXPECT_EQ(uniCharArrTo2[2], 0); // "-1" + EXPECT_EQ(uniCharArrTo3[0], '1'); + EXPECT_EQ(uniCharArrTo3[1], '.'); + EXPECT_EQ(uniCharArrTo3[2], '7'); + EXPECT_EQ(uniCharArrTo3[3], '8'); + EXPECT_EQ(uniCharArrTo3[4], '9'); + EXPECT_EQ(uniCharArrTo3[5], 0); // "1.789" + EXPECT_EQ(uniCharArrTo4[0], '-'); + EXPECT_EQ(uniCharArrTo4[1], '7'); + EXPECT_EQ(uniCharArrTo4[2], '8'); + EXPECT_EQ(uniCharArrTo4[3], '9'); + EXPECT_EQ(uniCharArrTo4[4], '.'); + EXPECT_EQ(uniCharArrTo4[5], '1'); + EXPECT_EQ(uniCharArrTo4[6], 0); // "-789.1" } /* @@ -206,43 +200,42 @@ TEST_F(JSTypedArrayTest, ToPropKey_002) */ TEST_F(JSTypedArrayTest, TypedArrayCreate) { - JSHandle handle_int8_array = CreateNumberTypedArray(thread_, JSType::JS_INT8_ARRAY); - JSHandle handle_tag_val_int8_array = JSHandle::Cast(handle_int8_array); - EXPECT_TRUE(handle_tag_val_int8_array->IsJSInt8Array() && handle_tag_val_int8_array->IsTypedArray()); - - JSHandle handle_uint8_array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_ARRAY); - JSHandle handle_tag_val_uint8_array = JSHandle::Cast(handle_uint8_array); - EXPECT_TRUE(handle_tag_val_uint8_array->IsJSUint8Array() && handle_tag_val_uint8_array->IsTypedArray()); - - JSHandle handle_uint8_clamped_array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_CLAMPED_ARRAY); - JSHandle handle_tag_val_uint8_clamped_array = - JSHandle::Cast(handle_uint8_clamped_array); - EXPECT_TRUE(handle_tag_val_uint8_clamped_array->IsJSUint8ClampedArray() && - handle_tag_val_uint8_clamped_array->IsTypedArray()); - - JSHandle handle_int16_array = CreateNumberTypedArray(thread_, JSType::JS_INT16_ARRAY); - JSHandle handle_tag_val_int16_array = JSHandle::Cast(handle_int16_array); - EXPECT_TRUE(handle_tag_val_int16_array->IsJSInt16Array() && handle_tag_val_int16_array->IsTypedArray()); - - JSHandle handle_uint16_array = CreateNumberTypedArray(thread_, JSType::JS_UINT16_ARRAY); - JSHandle handle_tag_val_uint16_array = JSHandle::Cast(handle_uint16_array); - EXPECT_TRUE(handle_tag_val_uint16_array->IsJSUint16Array() && handle_tag_val_uint16_array->IsTypedArray()); - - JSHandle handle_int32_array = CreateNumberTypedArray(thread_, JSType::JS_INT32_ARRAY); - JSHandle handle_tag_val_int32_array = JSHandle::Cast(handle_int32_array); - EXPECT_TRUE(handle_tag_val_int32_array->IsJSInt32Array() && handle_tag_val_int32_array->IsTypedArray()); - - JSHandle handle_uint32_array = CreateNumberTypedArray(thread_, JSType::JS_UINT32_ARRAY); - JSHandle handle_tag_val_uint32_array = JSHandle::Cast(handle_uint32_array); - EXPECT_TRUE(handle_tag_val_uint32_array->IsJSUint32Array() && handle_tag_val_uint32_array->IsTypedArray()); - - JSHandle handle_float32_array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT32_ARRAY); - JSHandle handle_tag_val_float32_array = JSHandle::Cast(handle_float32_array); - EXPECT_TRUE(handle_tag_val_float32_array->IsJSFloat32Array() && handle_tag_val_float32_array->IsTypedArray()); - - JSHandle handle_float64_array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT64_ARRAY); - JSHandle handle_tag_val_float64_array = JSHandle::Cast(handle_float64_array); - EXPECT_TRUE(handle_tag_val_float64_array->IsJSFloat64Array() && handle_tag_val_float64_array->IsTypedArray()); + JSHandle handleInt8Array = CreateNumberTypedArray(thread_, JSType::JS_INT8_ARRAY); + JSHandle handleTagValInt8Array = JSHandle::Cast(handleInt8Array); + EXPECT_TRUE(handleTagValInt8Array->IsJSInt8Array() && handleTagValInt8Array->IsTypedArray()); + + JSHandle handleUint8Array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_ARRAY); + JSHandle handleTagValUint8Array = JSHandle::Cast(handleUint8Array); + EXPECT_TRUE(handleTagValUint8Array->IsJSUint8Array() && handleTagValUint8Array->IsTypedArray()); + + JSHandle handleUint8ClampedArray = CreateNumberTypedArray(thread_, JSType::JS_UINT8_CLAMPED_ARRAY); + JSHandle handleTagValUint8ClampedArray = JSHandle::Cast(handleUint8ClampedArray); + EXPECT_TRUE(handleTagValUint8ClampedArray->IsJSUint8ClampedArray() && + handleTagValUint8ClampedArray->IsTypedArray()); + + JSHandle handleInt16Array = CreateNumberTypedArray(thread_, JSType::JS_INT16_ARRAY); + JSHandle handleTagValInt16Array = JSHandle::Cast(handleInt16Array); + EXPECT_TRUE(handleTagValInt16Array->IsJSInt16Array() && handleTagValInt16Array->IsTypedArray()); + + JSHandle handleUint16Array = CreateNumberTypedArray(thread_, JSType::JS_UINT16_ARRAY); + JSHandle handleTagValUint16Array = JSHandle::Cast(handleUint16Array); + EXPECT_TRUE(handleTagValUint16Array->IsJSUint16Array() && handleTagValUint16Array->IsTypedArray()); + + JSHandle handleInt32Array = CreateNumberTypedArray(thread_, JSType::JS_INT32_ARRAY); + JSHandle handleTagValInt32Array = JSHandle::Cast(handleInt32Array); + EXPECT_TRUE(handleTagValInt32Array->IsJSInt32Array() && handleTagValInt32Array->IsTypedArray()); + + JSHandle handleUint32Array = CreateNumberTypedArray(thread_, JSType::JS_UINT32_ARRAY); + JSHandle handleTagValUint32Array = JSHandle::Cast(handleUint32Array); + EXPECT_TRUE(handleTagValUint32Array->IsJSUint32Array() && handleTagValUint32Array->IsTypedArray()); + + JSHandle handleFloat32Array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT32_ARRAY); + JSHandle handleTagValFloat32Array = JSHandle::Cast(handleFloat32Array); + EXPECT_TRUE(handleTagValFloat32Array->IsJSFloat32Array() && handleTagValFloat32Array->IsTypedArray()); + + JSHandle handleFloat64Array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT64_ARRAY); + JSHandle handleTagValFloat64Array = JSHandle::Cast(handleFloat64Array); + EXPECT_TRUE(handleTagValFloat64Array->IsJSFloat64Array() && handleTagValFloat64Array->IsTypedArray()); } /* @@ -256,15 +249,15 @@ TEST_F(JSTypedArrayTest, TypedArrayCreate) TEST_F(JSTypedArrayTest, SetViewedArrayBuffer) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_array_buffer_from = factory->NewJSArrayBuffer(10); - JSHandle handle_tag_val_array_buffer_from = JSHandle::Cast(handle_array_buffer_from); + JSHandle handleArrayBufferFrom = factory->NewJSArrayBuffer(10); + JSHandle handleTagValArrayBufferFrom = JSHandle::Cast(handleArrayBufferFrom); - for (size_t i = 0; i < c_vec_js_type_.size(); i++) { - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(i)); + for (size_t i = 0; i < cVecJsType_.size(); i++) { + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(i)); - EXPECT_EQ(handle_typed_array->GetViewedArrayBuffer(), JSTaggedValue::Undefined()); - handle_typed_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - EXPECT_EQ(handle_typed_array->GetViewedArrayBuffer(), handle_tag_val_array_buffer_from.GetTaggedValue()); + EXPECT_EQ(handleTypedArray->GetViewedArrayBuffer(), JSTaggedValue::Undefined()); + handleTypedArray->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + EXPECT_EQ(handleTypedArray->GetViewedArrayBuffer(), handleTagValArrayBufferFrom.GetTaggedValue()); } } @@ -278,18 +271,17 @@ TEST_F(JSTypedArrayTest, SetViewedArrayBuffer) */ TEST_F(JSTypedArrayTest, SetTypedArrayName) { - PandaString c_str_name = "cStrName"; + PandaString cStrName = "cStrName"; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_ecma_str_name_from = factory->NewFromString(c_str_name); - JSHandle handle_tag_val_ecma_str_name_from = - JSHandle::Cast(handle_ecma_str_name_from); + JSHandle handleEcmaStrNameFrom = factory->NewFromString(cStrName); + JSHandle handleTagValEcmaStrNameFrom = JSHandle::Cast(handleEcmaStrNameFrom); - for (size_t i = 0; i < c_vec_js_type_.size(); i++) { - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(i)); + for (size_t i = 0; i < cVecJsType_.size(); i++) { + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(i)); - EXPECT_EQ(handle_typed_array->GetTypedArrayName(), JSTaggedValue::Undefined()); - handle_typed_array->SetTypedArrayName(thread_, handle_tag_val_ecma_str_name_from); - EXPECT_EQ(handle_typed_array->GetTypedArrayName(), handle_tag_val_ecma_str_name_from.GetTaggedValue()); + EXPECT_EQ(handleTypedArray->GetTypedArrayName(), JSTaggedValue::Undefined()); + handleTypedArray->SetTypedArrayName(thread_, handleTagValEcmaStrNameFrom); + EXPECT_EQ(handleTypedArray->GetTypedArrayName(), handleTagValEcmaStrNameFrom.GetTaggedValue()); } } @@ -303,15 +295,15 @@ TEST_F(JSTypedArrayTest, SetTypedArrayName) */ TEST_F(JSTypedArrayTest, SetByteLength) { - uint32_t u32_byte_length = 2; - JSHandle handle_tag_val_byte_length_from(thread_, JSTaggedValue(u32_byte_length)); + uint32_t u32ByteLength = 2; + JSHandle handleTagValByteLengthFrom(thread_, JSTaggedValue(u32ByteLength)); - for (size_t i = 0; i < c_vec_js_type_.size(); i++) { - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(i)); + for (size_t i = 0; i < cVecJsType_.size(); i++) { + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(i)); - EXPECT_EQ(handle_typed_array->GetByteLength(), JSTaggedValue(0)); - handle_typed_array->SetByteLength(thread_, handle_tag_val_byte_length_from); - EXPECT_EQ(handle_typed_array->GetByteLength(), handle_tag_val_byte_length_from.GetTaggedValue()); + EXPECT_EQ(handleTypedArray->GetByteLength(), JSTaggedValue(0)); + handleTypedArray->SetByteLength(thread_, handleTagValByteLengthFrom); + EXPECT_EQ(handleTypedArray->GetByteLength(), handleTagValByteLengthFrom.GetTaggedValue()); } } @@ -325,15 +317,15 @@ TEST_F(JSTypedArrayTest, SetByteLength) */ TEST_F(JSTypedArrayTest, SetByteOffset) { - uint32_t u32_byte_offset = 2; - JSHandle handle_tag_val_byte_offset_from(thread_, JSTaggedValue(u32_byte_offset)); + uint32_t u32ByteOffset = 2; + JSHandle handleTagValByteOffsetFrom(thread_, JSTaggedValue(u32ByteOffset)); - for (size_t i = 0; i < c_vec_js_type_.size(); i++) { - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(i)); + for (size_t i = 0; i < cVecJsType_.size(); i++) { + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(i)); - EXPECT_EQ(handle_typed_array->GetByteOffset(), JSTaggedValue(0)); - handle_typed_array->SetByteOffset(thread_, handle_tag_val_byte_offset_from); - EXPECT_EQ(handle_typed_array->GetByteOffset(), handle_tag_val_byte_offset_from.GetTaggedValue()); + EXPECT_EQ(handleTypedArray->GetByteOffset(), JSTaggedValue(0)); + handleTypedArray->SetByteOffset(thread_, handleTagValByteOffsetFrom); + EXPECT_EQ(handleTypedArray->GetByteOffset(), handleTagValByteOffsetFrom.GetTaggedValue()); } } @@ -347,15 +339,15 @@ TEST_F(JSTypedArrayTest, SetByteOffset) */ TEST_F(JSTypedArrayTest, SetArrayLength) { - uint32_t u32_array_length = 2; - JSHandle handle_tag_val_array_length_from(thread_, JSTaggedValue(u32_array_length)); + uint32_t u32ArrayLength = 2; + JSHandle handleTagValArrayLengthFrom(thread_, JSTaggedValue(u32ArrayLength)); - for (size_t i = 0; i < c_vec_js_type_.size(); i++) { - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(i)); + for (size_t i = 0; i < cVecJsType_.size(); i++) { + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(i)); - EXPECT_EQ(handle_typed_array->GetArrayLength(), JSTaggedValue(0)); - handle_typed_array->SetArrayLength(thread_, handle_tag_val_array_length_from); - EXPECT_EQ(handle_typed_array->GetArrayLength(), handle_tag_val_array_length_from.GetTaggedValue()); + EXPECT_EQ(handleTypedArray->GetArrayLength(), JSTaggedValue(0)); + handleTypedArray->SetArrayLength(thread_, handleTagValArrayLengthFrom); + EXPECT_EQ(handleTypedArray->GetArrayLength(), handleTagValArrayLengthFrom.GetTaggedValue()); } } @@ -369,829 +361,824 @@ TEST_F(JSTypedArrayTest, SetArrayLength) */ TEST_F(JSTypedArrayTest, DISABLED_IntegerIndexedElementSet_Int8Array_001) { - uint32_t num_elements_int8_array = 256; + uint32_t numElementsInt8Array = 256; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_int8_array = CreateNumberTypedArray(thread_, JSType::JS_INT8_ARRAY); - JSHandle handle_tag_val_int8_array = JSHandle::Cast(handle_int8_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_int8_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_int8_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_int8_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_int8_array->SetArrayLength(thread_, JSTaggedValue(num_elements_int8_array)); - - PandaVector c_vec_op_result = {}; - for (size_t i = 0; i < num_elements_int8_array; i++) { + JSHandle handleInt8Array = CreateNumberTypedArray(thread_, JSType::JS_INT8_ARRAY); + JSHandle handleTagValInt8Array = JSHandle::Cast(handleInt8Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleInt8Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsInt8Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleInt8Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleInt8Array->SetArrayLength(thread_, JSTaggedValue(numElementsInt8Array)); + + PandaVector cVecOpResult = {}; + for (size_t i = 0; i < numElementsInt8Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_int8_array, JSTaggedValue(i), + thread_, handleTagValInt8Array, JSTaggedValue(i), JSHandle(thread_, JSTaggedValue(std::numeric_limits::min() + i)))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (size_t i = 0; i < num_elements_int8_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - std::numeric_limits::min() + i); + for (size_t i = 0; i < numElementsInt8Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), std::numeric_limits::min() + i); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, - JSTaggedValue(num_elements_int8_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int8_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(1.1)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(numElementsInt8Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt8Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int8_array, - JSTaggedValue(num_elements_int8_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt8Array, + JSTaggedValue(numElementsInt8Array), JSHandle(thread_, JSTaggedValue(0)))); } // Nonstandard input value for Int8Array TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Int8Array_002) { - uint32_t num_elements_int8_array = 16; + uint32_t numElementsInt8Array = 16; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_int8_array = CreateNumberTypedArray(thread_, JSType::JS_INT8_ARRAY); - JSHandle handle_tag_val_int8_array = JSHandle::Cast(handle_int8_array); + JSHandle handleInt8Array = CreateNumberTypedArray(thread_, JSType::JS_INT8_ARRAY); + JSHandle handleTagValInt8Array = JSHandle::Cast(handleInt8Array); - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_int8_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_int8_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_int8_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_int8_array->SetArrayLength(thread_, JSTaggedValue(num_elements_int8_array)); + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleInt8Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsInt8Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleInt8Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleInt8Array->SetArrayLength(thread_, JSTaggedValue(numElementsInt8Array)); int64_t value1 = -129; // to int8 : 127 int64_t value2 = 128; // to int8 : -128 double value3 = 13.4; // to int8 : 13 double value4 = 13.6; // to int8 : 13 - JSHandle handle_tag_val_value_set1(thread_, JSTaggedValue(value1)); - JSHandle handle_tag_val_value_set2(thread_, JSTaggedValue(value2)); - JSHandle handle_tag_val_value_set3(thread_, JSTaggedValue(value3)); - JSHandle handle_tag_val_value_set4(thread_, JSTaggedValue(value4)); - - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int8_array, JSTaggedValue(0), - handle_tag_val_value_set1)); - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int8_array, JSTaggedValue(0), - handle_tag_val_value_set2)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int8_array, JSTaggedValue(0), - handle_tag_val_value_set3)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int8_array, JSTaggedValue(0), - handle_tag_val_value_set4)); - OperationResult op_result4 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int8_array, JSTaggedValue(0)); - - EXPECT_NE(value1, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value2, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value3, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value4, op_result4.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(127, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(-128, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result4.GetValue().GetTaggedValue().GetNumber()); + JSHandle handleTagValValueSet1(thread_, JSTaggedValue(value1)); + JSHandle handleTagValValueSet2(thread_, JSTaggedValue(value2)); + JSHandle handleTagValValueSet3(thread_, JSTaggedValue(value3)); + JSHandle handleTagValValueSet4(thread_, JSTaggedValue(value4)); + + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt8Array, JSTaggedValue(0), + handleTagValValueSet1)); + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt8Array, JSTaggedValue(0), + handleTagValValueSet2)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt8Array, JSTaggedValue(0), + handleTagValValueSet3)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt8Array, JSTaggedValue(0), + handleTagValValueSet4)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt8Array, JSTaggedValue(0)); + + EXPECT_NE(value1, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value2, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value3, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value4, opResult4.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(127, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(-128, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult4.GetValue().GetTaggedValue().GetNumber()); } TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint8Array_001) { - uint32_t num_elements_uint8_array = 256; + uint32_t numElementsUint8Array = 256; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint8_array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_ARRAY); - JSHandle handle_tag_val_uint8_array = JSHandle::Cast(handle_uint8_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint8_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_uint8_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint8_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint8_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint8_array)); - - PandaVector c_vec_op_result = {}; - for (uint32_t i = 0; i < num_elements_uint8_array; i++) { + JSHandle handleUint8Array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_ARRAY); + JSHandle handleTagValUint8Array = JSHandle::Cast(handleUint8Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint8Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint8Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint8Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint8Array->SetArrayLength(thread_, JSTaggedValue(numElementsUint8Array)); + + PandaVector cVecOpResult = {}; + for (uint32_t i = 0; i < numElementsUint8Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_uint8_array, JSTaggedValue(i), + thread_, handleTagValUint8Array, JSTaggedValue(i), JSHandle(thread_, JSTaggedValue(std::numeric_limits::min() + i)))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (uint32_t i = 0; i < num_elements_uint8_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - std::numeric_limits::min() + i); + for (uint32_t i = 0; i < numElementsUint8Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), std::numeric_limits::min() + i); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, - JSTaggedValue(num_elements_uint8_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(1.1)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(numElementsUint8Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_array, - JSTaggedValue(num_elements_uint8_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8Array, + JSTaggedValue(numElementsUint8Array), JSHandle(thread_, JSTaggedValue(0)))); } // Nonstandard input value for Uint8Array TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint8Array_002) { - uint32_t num_elements_uint8_array = 16; + uint32_t numElementsUint8Array = 16; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint8_array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_ARRAY); - JSHandle handle_tag_val_uint8_array = JSHandle::Cast(handle_uint8_array); + JSHandle handleUint8Array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_ARRAY); + JSHandle handleTagValUint8Array = JSHandle::Cast(handleUint8Array); - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint8_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_uint8_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint8_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint8_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint8_array)); + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint8Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint8Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint8Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint8Array->SetArrayLength(thread_, JSTaggedValue(numElementsUint8Array)); int64_t value1 = -1; // to uint8 : 255 int64_t value2 = 256; // to uint8 : 0 double value3 = 13.4; // to uint8 : 13 double value4 = 13.6; // to uint8 : 13 - JSHandle handle_tag_val_value_set1(thread_, JSTaggedValue(value1)); - JSHandle handle_tag_val_value_set2(thread_, JSTaggedValue(value2)); - JSHandle handle_tag_val_value_set3(thread_, JSTaggedValue(value3)); - JSHandle handle_tag_val_value_set4(thread_, JSTaggedValue(value4)); - - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0), - handle_tag_val_value_set1)); - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0), - handle_tag_val_value_set2)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0), - handle_tag_val_value_set3)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0), - handle_tag_val_value_set4)); - OperationResult op_result4 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_array, JSTaggedValue(0)); - - EXPECT_NE(value1, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value2, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value3, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value4, op_result4.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(255, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(0, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result4.GetValue().GetTaggedValue().GetNumber()); + JSHandle handleTagValValueSet1(thread_, JSTaggedValue(value1)); + JSHandle handleTagValValueSet2(thread_, JSTaggedValue(value2)); + JSHandle handleTagValValueSet3(thread_, JSTaggedValue(value3)); + JSHandle handleTagValValueSet4(thread_, JSTaggedValue(value4)); + + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8Array, JSTaggedValue(0), + handleTagValValueSet1)); + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8Array, JSTaggedValue(0), + handleTagValValueSet2)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8Array, JSTaggedValue(0), + handleTagValValueSet3)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8Array, JSTaggedValue(0), + handleTagValValueSet4)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8Array, JSTaggedValue(0)); + + EXPECT_NE(value1, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value2, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value3, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value4, opResult4.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(255, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(0, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult4.GetValue().GetTaggedValue().GetNumber()); } TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint8ClampedArray_001) { - uint32_t num_elements_uint8_clamped_array = 256; + uint32_t numElementsUint8ClampedArray = 256; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint8_clamped_array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_CLAMPED_ARRAY); - JSHandle handle_tag_val_uint8_clamped_array = - JSHandle::Cast(handle_uint8_clamped_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint8_clamped_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_uint8_clamped_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint8_clamped_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint8_clamped_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint8_clamped_array)); - - PandaVector c_vec_op_result = {}; - for (uint32_t i = 0; i < num_elements_uint8_clamped_array; i++) { + JSHandle handleUint8ClampedArray = CreateNumberTypedArray(thread_, JSType::JS_UINT8_CLAMPED_ARRAY); + JSHandle handleTagValUint8ClampedArray = JSHandle::Cast(handleUint8ClampedArray); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint8ClampedArray)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint8ClampedArray; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint8ClampedArray->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint8ClampedArray->SetArrayLength(thread_, JSTaggedValue(numElementsUint8ClampedArray)); + + PandaVector cVecOpResult = {}; + for (uint32_t i = 0; i < numElementsUint8ClampedArray; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(i), + thread_, handleTagValUint8ClampedArray, JSTaggedValue(i), JSHandle(thread_, JSTaggedValue(std::numeric_limits::min() + i)))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (uint32_t i = 0; i < num_elements_uint8_clamped_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - std::numeric_limits::min() + i); + for (uint32_t i = 0; i < numElementsUint8ClampedArray; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), std::numeric_limits::min() + i); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet( - thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(num_elements_uint8_clamped_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(1.1)); + OperationResult opResult4 = JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, + JSTaggedValue(numElementsUint8ClampedArray)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_clamped_array, - JSTaggedValue(num_elements_uint8_clamped_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8ClampedArray, + JSTaggedValue(numElementsUint8ClampedArray), JSHandle(thread_, JSTaggedValue(0)))); } // Nonstandard input value for Uint8ClampedArray TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint8ClampedArray_002) { - uint32_t num_elements_uint8_clamped_array = 16; + uint32_t numElementsUint8ClampedArray = 16; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint8_clamped_array = CreateNumberTypedArray(thread_, JSType::JS_UINT8_CLAMPED_ARRAY); - JSHandle handle_tag_val_uint8_clamped_array = - JSHandle::Cast(handle_uint8_clamped_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint8_clamped_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_uint8_clamped_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint8_clamped_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint8_clamped_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint8_clamped_array)); + JSHandle handleUint8ClampedArray = CreateNumberTypedArray(thread_, JSType::JS_UINT8_CLAMPED_ARRAY); + JSHandle handleTagValUint8ClampedArray = JSHandle::Cast(handleUint8ClampedArray); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint8ClampedArray)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint8ClampedArray; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint8ClampedArray->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint8ClampedArray->SetArrayLength(thread_, JSTaggedValue(numElementsUint8ClampedArray)); int64_t value1 = -1; // to uint8_clamped : 0 int64_t value2 = 256; // to uint8_clamped : 255 double value3 = 13.4; // to uint8_clamped : 13 double value4 = 13.6; // to uint8_clamped : 14 - JSHandle handle_tag_val_value_set1(thread_, JSTaggedValue(value1)); - JSHandle handle_tag_val_value_set2(thread_, JSTaggedValue(value2)); - JSHandle handle_tag_val_value_set3(thread_, JSTaggedValue(value3)); - JSHandle handle_tag_val_value_set4(thread_, JSTaggedValue(value4)); - - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0), - handle_tag_val_value_set1)); - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0), - handle_tag_val_value_set2)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0), - handle_tag_val_value_set3)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0), - handle_tag_val_value_set4)); - OperationResult op_result4 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint8_clamped_array, JSTaggedValue(0)); - - EXPECT_NE(value1, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value2, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value3, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value4, op_result4.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(0, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(255, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(14, op_result4.GetValue().GetTaggedValue().GetNumber()); + JSHandle handleTagValValueSet1(thread_, JSTaggedValue(value1)); + JSHandle handleTagValValueSet2(thread_, JSTaggedValue(value2)); + JSHandle handleTagValValueSet3(thread_, JSTaggedValue(value3)); + JSHandle handleTagValValueSet4(thread_, JSTaggedValue(value4)); + + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0), + handleTagValValueSet1)); + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0), + handleTagValValueSet2)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0), + handleTagValValueSet3)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0), + handleTagValValueSet4)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint8ClampedArray, JSTaggedValue(0)); + + EXPECT_NE(value1, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value2, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value3, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value4, opResult4.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(0, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(255, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(14, opResult4.GetValue().GetTaggedValue().GetNumber()); } TEST_F(JSTypedArrayTest, DISABLED_IntegerIndexedElementSet_Int16Array_001) { - uint32_t num_elements_int16_array = 100; - int16_t scale_for_int16_value_set = 100; + uint32_t numElementsInt16Array = 100; + int16_t scaleForInt16ValueSet = 100; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_int16_array = CreateNumberTypedArray(thread_, JSType::JS_INT16_ARRAY); - JSHandle handle_tag_val_int16_array = JSHandle::Cast(handle_int16_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_int16_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_int16_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_int16_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_int16_array->SetArrayLength(thread_, JSTaggedValue(num_elements_int16_array)); - - PandaVector c_vec_op_result = {}; - for (size_t i = 0; i < num_elements_int16_array; i++) { + JSHandle handleInt16Array = CreateNumberTypedArray(thread_, JSType::JS_INT16_ARRAY); + JSHandle handleTagValInt16Array = JSHandle::Cast(handleInt16Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleInt16Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsInt16Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleInt16Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleInt16Array->SetArrayLength(thread_, JSTaggedValue(numElementsInt16Array)); + + PandaVector cVecOpResult = {}; + for (size_t i = 0; i < numElementsInt16Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_int16_array, JSTaggedValue(i), - JSHandle( - thread_, JSTaggedValue(std::numeric_limits::min() + i * scale_for_int16_value_set)))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + thread_, handleTagValInt16Array, JSTaggedValue(i), + JSHandle(thread_, + JSTaggedValue(std::numeric_limits::min() + i * scaleForInt16ValueSet)))); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (size_t i = 0; i < num_elements_int16_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - std::numeric_limits::min() + i * scale_for_int16_value_set); + for (size_t i = 0; i < numElementsInt16Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), + std::numeric_limits::min() + i * scaleForInt16ValueSet); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, - JSTaggedValue(num_elements_int16_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int16_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(1.1)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(numElementsInt16Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt16Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int16_array, - JSTaggedValue(num_elements_int16_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt16Array, + JSTaggedValue(numElementsInt16Array), JSHandle(thread_, JSTaggedValue(0)))); } // Nonstandard input value for Int16Array TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Int16Array_002) { - uint32_t num_elements_int16_array = 16; + uint32_t numElementsInt16Array = 16; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_int16_array = CreateNumberTypedArray(thread_, JSType::JS_INT16_ARRAY); - JSHandle handle_tag_val_int16_array = JSHandle::Cast(handle_int16_array); + JSHandle handleInt16Array = CreateNumberTypedArray(thread_, JSType::JS_INT16_ARRAY); + JSHandle handleTagValInt16Array = JSHandle::Cast(handleInt16Array); - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_int16_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_int16_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_int16_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_int16_array->SetArrayLength(thread_, JSTaggedValue(num_elements_int16_array)); + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleInt16Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsInt16Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleInt16Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleInt16Array->SetArrayLength(thread_, JSTaggedValue(numElementsInt16Array)); int64_t value1 = -32769; // to int16 : 32767 int64_t value2 = 32768; // to int16 : -32768 double value3 = 13.4; // to int16 : 13 double value4 = 13.6; // to int16 : 13 - JSHandle handle_tag_val_value_set1(thread_, JSTaggedValue(value1)); - JSHandle handle_tag_val_value_set2(thread_, JSTaggedValue(value2)); - JSHandle handle_tag_val_value_set3(thread_, JSTaggedValue(value3)); - JSHandle handle_tag_val_value_set4(thread_, JSTaggedValue(value4)); - - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int16_array, JSTaggedValue(0), - handle_tag_val_value_set1)); - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int16_array, JSTaggedValue(0), - handle_tag_val_value_set2)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int16_array, JSTaggedValue(0), - handle_tag_val_value_set3)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int16_array, JSTaggedValue(0), - handle_tag_val_value_set4)); - OperationResult op_result4 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int16_array, JSTaggedValue(0)); - - EXPECT_NE(value1, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value2, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value3, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value4, op_result4.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(32767, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(-32768, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result4.GetValue().GetTaggedValue().GetNumber()); + JSHandle handleTagValValueSet1(thread_, JSTaggedValue(value1)); + JSHandle handleTagValValueSet2(thread_, JSTaggedValue(value2)); + JSHandle handleTagValValueSet3(thread_, JSTaggedValue(value3)); + JSHandle handleTagValValueSet4(thread_, JSTaggedValue(value4)); + + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt16Array, JSTaggedValue(0), + handleTagValValueSet1)); + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt16Array, JSTaggedValue(0), + handleTagValValueSet2)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt16Array, JSTaggedValue(0), + handleTagValValueSet3)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt16Array, JSTaggedValue(0), + handleTagValValueSet4)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt16Array, JSTaggedValue(0)); + + EXPECT_NE(value1, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value2, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value3, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value4, opResult4.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(32767, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(-32768, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult4.GetValue().GetTaggedValue().GetNumber()); } TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint16Array_001) { - uint32_t num_elements_uint16_array = 100; - uint32_t scale_for_uint16_value_set = 100; + uint32_t numElementsUint16Array = 100; + uint32_t scaleForUint16ValueSet = 100; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint16_array = CreateNumberTypedArray(thread_, JSType::JS_UINT16_ARRAY); - JSHandle handle_tag_val_uint16_array = JSHandle::Cast(handle_uint16_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint16_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_uint16_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint16_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint16_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint16_array)); - - PandaVector c_vec_op_result = {}; - for (uint32_t i = 0; i < num_elements_uint16_array; i++) { + JSHandle handleUint16Array = CreateNumberTypedArray(thread_, JSType::JS_UINT16_ARRAY); + JSHandle handleTagValUint16Array = JSHandle::Cast(handleUint16Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint16Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint16Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint16Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint16Array->SetArrayLength(thread_, JSTaggedValue(numElementsUint16Array)); + + PandaVector cVecOpResult = {}; + for (uint32_t i = 0; i < numElementsUint16Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_uint16_array, JSTaggedValue(i), - JSHandle( - thread_, JSTaggedValue(std::numeric_limits::min() + i * scale_for_uint16_value_set)))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + thread_, handleTagValUint16Array, JSTaggedValue(i), + JSHandle(thread_, + JSTaggedValue(std::numeric_limits::min() + i * scaleForUint16ValueSet)))); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (uint32_t i = 0; i < num_elements_uint16_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - std::numeric_limits::min() + i * scale_for_uint16_value_set); + for (uint32_t i = 0; i < numElementsUint16Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), + std::numeric_limits::min() + i * scaleForUint16ValueSet); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, - JSTaggedValue(num_elements_uint16_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint16_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(1.1)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(numElementsUint16Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint16Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint16_array, - JSTaggedValue(num_elements_uint16_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint16Array, + JSTaggedValue(numElementsUint16Array), JSHandle(thread_, JSTaggedValue(0)))); } // Nonstandard input value for Uint16Array TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint16Array_002) { - uint32_t num_elements_uint16_array = 16; + uint32_t numElementsUint16Array = 16; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint16_array = CreateNumberTypedArray(thread_, JSType::JS_UINT16_ARRAY); - JSHandle handle_tag_val_uint16_array = JSHandle::Cast(handle_uint16_array); + JSHandle handleUint16Array = CreateNumberTypedArray(thread_, JSType::JS_UINT16_ARRAY); + JSHandle handleTagValUint16Array = JSHandle::Cast(handleUint16Array); - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint16_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_uint16_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint16_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint16_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint16_array)); + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint16Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint16Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint16Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint16Array->SetArrayLength(thread_, JSTaggedValue(numElementsUint16Array)); int64_t value1 = -1; // to uint16 : 65535 int64_t value2 = 65536; // to uint16 : 0 double value3 = 13.4; // to uint16 : 13 double value4 = 13.6; // to uint16 : 13 - JSHandle handle_tag_val_value_set1(thread_, JSTaggedValue(value1)); - JSHandle handle_tag_val_value_set2(thread_, JSTaggedValue(value2)); - JSHandle handle_tag_val_value_set3(thread_, JSTaggedValue(value3)); - JSHandle handle_tag_val_value_set4(thread_, JSTaggedValue(value4)); - - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0), - handle_tag_val_value_set1)); - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0), - handle_tag_val_value_set2)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0), - handle_tag_val_value_set3)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0), - handle_tag_val_value_set4)); - OperationResult op_result4 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint16_array, JSTaggedValue(0)); - - EXPECT_NE(value1, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value2, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value3, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value4, op_result4.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(65535, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(0, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result4.GetValue().GetTaggedValue().GetNumber()); + JSHandle handleTagValValueSet1(thread_, JSTaggedValue(value1)); + JSHandle handleTagValValueSet2(thread_, JSTaggedValue(value2)); + JSHandle handleTagValValueSet3(thread_, JSTaggedValue(value3)); + JSHandle handleTagValValueSet4(thread_, JSTaggedValue(value4)); + + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint16Array, JSTaggedValue(0), + handleTagValValueSet1)); + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint16Array, JSTaggedValue(0), + handleTagValValueSet2)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint16Array, JSTaggedValue(0), + handleTagValValueSet3)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint16Array, JSTaggedValue(0), + handleTagValValueSet4)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint16Array, JSTaggedValue(0)); + + EXPECT_NE(value1, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value2, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value3, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value4, opResult4.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(65535, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(0, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult4.GetValue().GetTaggedValue().GetNumber()); } TEST_F(JSTypedArrayTest, DISABLED_IntegerIndexedElementSet_Int32Array_001) { - uint32_t num_elements_int32_array = 100; - int32_t scale_for_int32_value_set = 100000; + uint32_t numElementsInt32Array = 100; + int32_t scaleForInt32ValueSet = 100000; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_int32_array = CreateNumberTypedArray(thread_, JSType::JS_INT32_ARRAY); - JSHandle handle_tag_val_int32_array = JSHandle::Cast(handle_int32_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_int32_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_int32_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_int32_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_int32_array->SetArrayLength(thread_, JSTaggedValue(num_elements_int32_array)); - - PandaVector c_vec_op_result = {}; - for (size_t i = 0; i < num_elements_int32_array; i++) { + JSHandle handleInt32Array = CreateNumberTypedArray(thread_, JSType::JS_INT32_ARRAY); + JSHandle handleTagValInt32Array = JSHandle::Cast(handleInt32Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleInt32Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsInt32Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleInt32Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleInt32Array->SetArrayLength(thread_, JSTaggedValue(numElementsInt32Array)); + + PandaVector cVecOpResult = {}; + for (size_t i = 0; i < numElementsInt32Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_int32_array, JSTaggedValue(i), - JSHandle( - thread_, JSTaggedValue(std::numeric_limits::min() + i * scale_for_int32_value_set)))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + thread_, handleTagValInt32Array, JSTaggedValue(i), + JSHandle(thread_, + JSTaggedValue(std::numeric_limits::min() + i * scaleForInt32ValueSet)))); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (size_t i = 0; i < num_elements_int32_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - std::numeric_limits::min() + i * scale_for_int32_value_set); + for (size_t i = 0; i < numElementsInt32Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), + std::numeric_limits::min() + i * scaleForInt32ValueSet); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, - JSTaggedValue(num_elements_int32_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int32_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(1.1)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(numElementsInt32Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt32Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int32_array, - JSTaggedValue(num_elements_int32_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt32Array, + JSTaggedValue(numElementsInt32Array), JSHandle(thread_, JSTaggedValue(0)))); } // Nonstandard input value for Int32Array TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Int32Array_002) { - uint32_t num_elements_int32_array = 16; + uint32_t numElementsInt32Array = 16; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_int32_array = CreateNumberTypedArray(thread_, JSType::JS_INT32_ARRAY); - JSHandle handle_tag_val_int32_array = JSHandle::Cast(handle_int32_array); + JSHandle handleInt32Array = CreateNumberTypedArray(thread_, JSType::JS_INT32_ARRAY); + JSHandle handleTagValInt32Array = JSHandle::Cast(handleInt32Array); - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_int32_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_int32_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_int32_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_int32_array->SetArrayLength(thread_, JSTaggedValue(num_elements_int32_array)); + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleInt32Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsInt32Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleInt32Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleInt32Array->SetArrayLength(thread_, JSTaggedValue(numElementsInt32Array)); int64_t value1 = -2147483649; // to int32 : 2147483647 int64_t value2 = 2147483648; // to int32 : -2147483648 double value3 = 13.4; // to int32 : 13 double value4 = 13.6; // to int32 : 13 - JSHandle handle_tag_val_value_set1(thread_, JSTaggedValue(value1)); - JSHandle handle_tag_val_value_set2(thread_, JSTaggedValue(value2)); - JSHandle handle_tag_val_value_set3(thread_, JSTaggedValue(value3)); - JSHandle handle_tag_val_value_set4(thread_, JSTaggedValue(value4)); - - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int32_array, JSTaggedValue(0), - handle_tag_val_value_set1)); - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int32_array, JSTaggedValue(0), - handle_tag_val_value_set2)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int32_array, JSTaggedValue(0), - handle_tag_val_value_set3)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_int32_array, JSTaggedValue(0), - handle_tag_val_value_set4)); - OperationResult op_result4 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_int32_array, JSTaggedValue(0)); - - EXPECT_NE(value1, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value2, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value3, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value4, op_result4.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(2147483647, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(-2147483648, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result4.GetValue().GetTaggedValue().GetNumber()); + JSHandle handleTagValValueSet1(thread_, JSTaggedValue(value1)); + JSHandle handleTagValValueSet2(thread_, JSTaggedValue(value2)); + JSHandle handleTagValValueSet3(thread_, JSTaggedValue(value3)); + JSHandle handleTagValValueSet4(thread_, JSTaggedValue(value4)); + + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt32Array, JSTaggedValue(0), + handleTagValValueSet1)); + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt32Array, JSTaggedValue(0), + handleTagValValueSet2)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt32Array, JSTaggedValue(0), + handleTagValValueSet3)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValInt32Array, JSTaggedValue(0), + handleTagValValueSet4)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValInt32Array, JSTaggedValue(0)); + + EXPECT_NE(value1, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value2, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value3, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value4, opResult4.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(2147483647, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(-2147483648, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult4.GetValue().GetTaggedValue().GetNumber()); } TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint32Array_001) { - uint32_t num_elements_uint32_array = 100; - uint32_t scale_for_uint32_value_set = 100000; + uint32_t numElementsUint32Array = 100; + uint32_t scaleForUint32ValueSet = 100000; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint32_array = CreateNumberTypedArray(thread_, JSType::JS_UINT32_ARRAY); - JSHandle handle_tag_val_uint32_array = JSHandle::Cast(handle_uint32_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint32_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_uint32_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint32_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint32_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint32_array)); - - PandaVector c_vec_op_result = {}; - for (uint32_t i = 0; i < num_elements_uint32_array; i++) { + JSHandle handleUint32Array = CreateNumberTypedArray(thread_, JSType::JS_UINT32_ARRAY); + JSHandle handleTagValUint32Array = JSHandle::Cast(handleUint32Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint32Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint32Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint32Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint32Array->SetArrayLength(thread_, JSTaggedValue(numElementsUint32Array)); + + PandaVector cVecOpResult = {}; + for (uint32_t i = 0; i < numElementsUint32Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_uint32_array, JSTaggedValue(i), - JSHandle( - thread_, JSTaggedValue(std::numeric_limits::min() + i * scale_for_uint32_value_set)))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + thread_, handleTagValUint32Array, JSTaggedValue(i), + JSHandle(thread_, + JSTaggedValue(std::numeric_limits::min() + i * scaleForUint32ValueSet)))); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (uint32_t i = 0; i < num_elements_uint32_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - std::numeric_limits::min() + i * scale_for_uint32_value_set); + for (uint32_t i = 0; i < numElementsUint32Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), + std::numeric_limits::min() + i * scaleForUint32ValueSet); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, - JSTaggedValue(num_elements_uint32_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint32_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(1.1)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(numElementsUint32Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint32Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint32_array, - JSTaggedValue(num_elements_uint32_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint32Array, + JSTaggedValue(numElementsUint32Array), JSHandle(thread_, JSTaggedValue(0)))); } // Nonstandard input value for Uint32Array TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Uint32Array_002) { - int32_t num_elements_uint32_array = 16; + int32_t numElementsUint32Array = 16; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_uint32_array = CreateNumberTypedArray(thread_, JSType::JS_UINT32_ARRAY); - JSHandle handle_tag_val_uint32_array = JSHandle::Cast(handle_uint32_array); + JSHandle handleUint32Array = CreateNumberTypedArray(thread_, JSType::JS_UINT32_ARRAY); + JSHandle handleTagValUint32Array = JSHandle::Cast(handleUint32Array); - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_uint32_array)); - int32_t byte_length_viewd_array_buffer = size_element * num_elements_uint32_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_uint32_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_uint32_array->SetArrayLength(thread_, JSTaggedValue(num_elements_uint32_array)); + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleUint32Array)); + int32_t byteLengthViewdArrayBuffer = sizeElement * numElementsUint32Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleUint32Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleUint32Array->SetArrayLength(thread_, JSTaggedValue(numElementsUint32Array)); int64_t value1 = -1; // to uint32 : 4294967295 int64_t value2 = 4294967296; // to uint32 : 0 double value3 = 13.4; // to uint32 : 13 double value4 = 13.6; // to uint32 : 13 - JSHandle handle_tag_val_value_set1(thread_, JSTaggedValue(value1)); - JSHandle handle_tag_val_value_set2(thread_, JSTaggedValue(value2)); - JSHandle handle_tag_val_value_set3(thread_, JSTaggedValue(value3)); - JSHandle handle_tag_val_value_set4(thread_, JSTaggedValue(value4)); - - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0), - handle_tag_val_value_set1)); - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0), - handle_tag_val_value_set2)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0), - handle_tag_val_value_set3)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0)); - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0), - handle_tag_val_value_set4)); - OperationResult op_result4 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_uint32_array, JSTaggedValue(0)); - - EXPECT_NE(value1, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value2, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value3, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_NE(value4, op_result4.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(4294967295, op_result1.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(0, op_result2.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result3.GetValue().GetTaggedValue().GetNumber()); - EXPECT_EQ(13, op_result4.GetValue().GetTaggedValue().GetNumber()); + JSHandle handleTagValValueSet1(thread_, JSTaggedValue(value1)); + JSHandle handleTagValValueSet2(thread_, JSTaggedValue(value2)); + JSHandle handleTagValValueSet3(thread_, JSTaggedValue(value3)); + JSHandle handleTagValValueSet4(thread_, JSTaggedValue(value4)); + + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint32Array, JSTaggedValue(0), + handleTagValValueSet1)); + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint32Array, JSTaggedValue(0), + handleTagValValueSet2)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint32Array, JSTaggedValue(0), + handleTagValValueSet3)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(0)); + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValUint32Array, JSTaggedValue(0), + handleTagValValueSet4)); + OperationResult opResult4 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValUint32Array, JSTaggedValue(0)); + + EXPECT_NE(value1, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value2, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value3, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_NE(value4, opResult4.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(4294967295, opResult1.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(0, opResult2.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult3.GetValue().GetTaggedValue().GetNumber()); + EXPECT_EQ(13, opResult4.GetValue().GetTaggedValue().GetNumber()); } TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Float32Array) { - uint32_t num_elements_float32_array = 100; + uint32_t numElementsFloat32Array = 100; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_float32_array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT32_ARRAY); - JSHandle handle_tag_val_float32_array = JSHandle::Cast(handle_float32_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_float32_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_float32_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_float32_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_float32_array->SetArrayLength(thread_, JSTaggedValue(num_elements_float32_array)); - - PandaVector c_vec_op_result = {}; - float float_max_value = std::numeric_limits::max(); - for (uint32_t i = 0; i < num_elements_float32_array; i++) { + JSHandle handleFloat32Array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT32_ARRAY); + JSHandle handleTagValFloat32Array = JSHandle::Cast(handleFloat32Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleFloat32Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsFloat32Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleFloat32Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleFloat32Array->SetArrayLength(thread_, JSTaggedValue(numElementsFloat32Array)); + + PandaVector cVecOpResult = {}; + float floatMaxValue = std::numeric_limits::max(); + for (uint32_t i = 0; i < numElementsFloat32Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_float32_array, JSTaggedValue(i), - JSHandle( - thread_, JSTaggedValue(float_max_value - (i * (float_max_value / num_elements_float32_array)))))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float32_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + thread_, handleTagValFloat32Array, JSTaggedValue(i), + JSHandle(thread_, + JSTaggedValue(floatMaxValue - (i * (floatMaxValue / numElementsFloat32Array)))))); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat32Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (uint32_t i = 0; i < num_elements_float32_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - float_max_value - (i * (float_max_value / num_elements_float32_array))); + for (uint32_t i = 0; i < numElementsFloat32Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), + floatMaxValue - (i * (floatMaxValue / numElementsFloat32Array))); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float32_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float32_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float32_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float32_array, - JSTaggedValue(num_elements_float32_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_float32_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat32Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat32Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat32Array, JSTaggedValue(1.1)); + OperationResult opResult4 = JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat32Array, + JSTaggedValue(numElementsFloat32Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValFloat32Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_float32_array, - JSTaggedValue(num_elements_float32_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValFloat32Array, + JSTaggedValue(numElementsFloat32Array), JSHandle(thread_, JSTaggedValue(0)))); } TEST_F(JSTypedArrayTest, IntegerIndexedElementSet_Float64Array) { - uint32_t num_elements_float64_array = 100; + uint32_t numElementsFloat64Array = 100; ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle handle_float64_array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT64_ARRAY); - JSHandle handle_tag_val_float64_array = JSHandle::Cast(handle_float64_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_float64_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_float64_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_float64_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_float64_array->SetArrayLength(thread_, JSTaggedValue(num_elements_float64_array)); - - PandaVector c_vec_op_result = {}; - double double_max_value = std::numeric_limits::max(); - for (uint32_t i = 0; i < num_elements_float64_array; i++) { + JSHandle handleFloat64Array = CreateNumberTypedArray(thread_, JSType::JS_FLOAT64_ARRAY); + JSHandle handleTagValFloat64Array = JSHandle::Cast(handleFloat64Array); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleFloat64Array)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsFloat64Array; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleFloat64Array->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleFloat64Array->SetArrayLength(thread_, JSTaggedValue(numElementsFloat64Array)); + + PandaVector cVecOpResult = {}; + double doubleMaxValue = std::numeric_limits::max(); + for (uint32_t i = 0; i < numElementsFloat64Array; i++) { EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet( - thread_, handle_tag_val_float64_array, JSTaggedValue(i), - JSHandle( - thread_, JSTaggedValue(double_max_value - (i * (double_max_value / num_elements_float64_array)))))); - OperationResult op_result = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float64_array, JSTaggedValue(i)); - c_vec_op_result.push_back(op_result); + thread_, handleTagValFloat64Array, JSTaggedValue(i), + JSHandle(thread_, + JSTaggedValue(doubleMaxValue - (i * (doubleMaxValue / numElementsFloat64Array)))))); + OperationResult opResult = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat64Array, JSTaggedValue(i)); + cVecOpResult.push_back(opResult); } - for (uint32_t i = 0; i < num_elements_float64_array; i++) { - EXPECT_EQ(c_vec_op_result.at(i).GetValue().GetTaggedValue().GetNumber(), - double_max_value - (i * (double_max_value / num_elements_float64_array))); + for (uint32_t i = 0; i < numElementsFloat64Array; i++) { + EXPECT_EQ(cVecOpResult.at(i).GetValue().GetTaggedValue().GetNumber(), + doubleMaxValue - (i * (doubleMaxValue / numElementsFloat64Array))); } - c_vec_op_result.clear(); - - OperationResult op_result1 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float64_array, JSTaggedValue(-1)); - OperationResult op_result2 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float64_array, JSTaggedValue(-0.0)); - OperationResult op_result3 = - JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float64_array, JSTaggedValue(1.1)); - OperationResult op_result4 = JSTypedArray::IntegerIndexedElementGet(thread_, handle_tag_val_float64_array, - JSTaggedValue(num_elements_float64_array)); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_float64_array, JSTaggedValue(-1), + cVecOpResult.clear(); + + OperationResult opResult1 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat64Array, JSTaggedValue(-1)); + OperationResult opResult2 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat64Array, JSTaggedValue(-0.0)); + OperationResult opResult3 = + JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat64Array, JSTaggedValue(1.1)); + OperationResult opResult4 = JSTypedArray::IntegerIndexedElementGet(thread_, handleTagValFloat64Array, + JSTaggedValue(numElementsFloat64Array)); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult3.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult4.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValFloat64Array, JSTaggedValue(-1), JSHandle(thread_, JSTaggedValue(0)))); - EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_float64_array, - JSTaggedValue(num_elements_float64_array), + EXPECT_FALSE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValFloat64Array, + JSTaggedValue(numElementsFloat64Array), JSHandle(thread_, JSTaggedValue(0)))); } @@ -1207,36 +1194,35 @@ TEST_F(JSTypedArrayTest, FastElementGet_TypedArray) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - for (uint32_t j = 0; j < c_vec_js_type_.size(); j++) { - uint32_t num_elements_typed_array = 10; - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(j)); - JSHandle handle_tag_val_typed_array = JSHandle::Cast(handle_typed_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_typed_array)); - uint32_t byte_length_viewd_array_buffer = size_element * num_elements_typed_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_typed_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_typed_array->SetArrayLength(thread_, JSTaggedValue(num_elements_typed_array)); - - JSHandle handle_tag_val_value_set( - thread_, JSTaggedValue(c_vec_handle_tag_val_value_for_typed_array_.at(j))); - for (uint32_t i = 0; i < num_elements_typed_array; i++) { - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_typed_array, JSTaggedValue(i), - handle_tag_val_value_set)); + for (uint32_t j = 0; j < cVecJsType_.size(); j++) { + uint32_t numElementsTypedArray = 10; + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(j)); + JSHandle handleTagValTypedArray = JSHandle::Cast(handleTypedArray); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleTypedArray)); + uint32_t byteLengthViewdArrayBuffer = sizeElement * numElementsTypedArray; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleTypedArray->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleTypedArray->SetArrayLength(thread_, JSTaggedValue(numElementsTypedArray)); + + JSHandle handleTagValValueSet(thread_, JSTaggedValue(cVecHandleTagValValueForTypedArray_.at(j))); + for (uint32_t i = 0; i < numElementsTypedArray; i++) { + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValTypedArray, JSTaggedValue(i), + handleTagValValueSet)); } - for (uint32_t i = 0; i < num_elements_typed_array; i++) { - OperationResult op_result = JSTypedArray::FastElementGet(thread_, handle_tag_val_typed_array, i); - EXPECT_EQ(op_result.GetValue().GetTaggedValue().GetNumber(), - handle_tag_val_value_set.GetTaggedValue().GetNumber()); + for (uint32_t i = 0; i < numElementsTypedArray; i++) { + OperationResult opResult = JSTypedArray::FastElementGet(thread_, handleTagValTypedArray, i); + EXPECT_EQ(opResult.GetValue().GetTaggedValue().GetNumber(), + handleTagValValueSet.GetTaggedValue().GetNumber()); } - OperationResult op_result1 = JSTypedArray::FastElementGet(thread_, handle_tag_val_typed_array, -1); - OperationResult op_result2 = - JSTypedArray::FastElementGet(thread_, handle_tag_val_typed_array, num_elements_typed_array); - EXPECT_EQ(op_result1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); - EXPECT_EQ(op_result2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + OperationResult opResult1 = JSTypedArray::FastElementGet(thread_, handleTagValTypedArray, -1); + OperationResult opResult2 = + JSTypedArray::FastElementGet(thread_, handleTagValTypedArray, numElementsTypedArray); + EXPECT_EQ(opResult1.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); + EXPECT_EQ(opResult2.GetValue().GetTaggedValue(), JSTaggedValue::Undefined()); } } @@ -1255,38 +1241,36 @@ TEST_F(JSTypedArrayTest, DefineOwnProperty_TypedArray) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - for (size_t j = 0; j < c_vec_js_type_.size(); j++) { - int32_t num_elements_typed_array = 10; - JSHandle handle_tag_val_value_def(thread_, c_vec_handle_tag_val_value_for_typed_array_.at(j)); - PropertyDescriptor desc_from1(thread_, handle_tag_val_value_def, true, true, true); - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(j)); - JSHandle handle_tag_val_typed_array = JSHandle::Cast(handle_typed_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_typed_array)); - int32_t byte_length_viewd_array_buffer = size_element * num_elements_typed_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_typed_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_typed_array->SetArrayLength(thread_, JSTaggedValue(num_elements_typed_array)); - - for (int32_t i = 0; i < num_elements_typed_array; i++) { - JSHandle handle_tag_val_key(thread_, JSTaggedValue(i)); - EXPECT_FALSE(JSTypedArray::HasProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key)); - EXPECT_TRUE( - JSTypedArray::DefineOwnProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key, desc_from1)); - EXPECT_TRUE(JSTypedArray::HasProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key)); + for (size_t j = 0; j < cVecJsType_.size(); j++) { + int32_t numElementsTypedArray = 10; + JSHandle handleTagValValueDef(thread_, cVecHandleTagValValueForTypedArray_.at(j)); + PropertyDescriptor descFrom1(thread_, handleTagValValueDef, true, true, true); + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(j)); + JSHandle handleTagValTypedArray = JSHandle::Cast(handleTypedArray); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleTypedArray)); + int32_t byteLengthViewdArrayBuffer = sizeElement * numElementsTypedArray; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleTypedArray->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleTypedArray->SetArrayLength(thread_, JSTaggedValue(numElementsTypedArray)); + + for (int32_t i = 0; i < numElementsTypedArray; i++) { + JSHandle handleTagValKey(thread_, JSTaggedValue(i)); + EXPECT_FALSE(JSTypedArray::HasProperty(thread_, handleTagValTypedArray, handleTagValKey)); + EXPECT_TRUE(JSTypedArray::DefineOwnProperty(thread_, handleTagValTypedArray, handleTagValKey, descFrom1)); + EXPECT_TRUE(JSTypedArray::HasProperty(thread_, handleTagValTypedArray, handleTagValKey)); EXPECT_TRUE(JSTaggedValue::StrictEqual( - thread_, handle_tag_val_value_def, - JSTypedArray::GetProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key).GetValue())); - - PropertyDescriptor desc_to1(thread_); - EXPECT_FALSE(desc_to1.HasWritable() || desc_to1.HasEnumerable() || desc_to1.HasConfigurable()); - EXPECT_TRUE( - JSTypedArray::GetOwnProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key, desc_to1)); - EXPECT_TRUE(desc_to1.HasWritable() && desc_to1.HasEnumerable() && desc_to1.HasConfigurable()); - EXPECT_TRUE(desc_to1.IsWritable() && desc_to1.IsEnumerable() && desc_to1.IsConfigurable()); - EXPECT_TRUE(JSTaggedValue::StrictEqual(thread_, desc_to1.GetValue(), handle_tag_val_value_def)); + thread_, handleTagValValueDef, + JSTypedArray::GetProperty(thread_, handleTagValTypedArray, handleTagValKey).GetValue())); + + PropertyDescriptor descTo1(thread_); + EXPECT_FALSE(descTo1.HasWritable() || descTo1.HasEnumerable() || descTo1.HasConfigurable()); + EXPECT_TRUE(JSTypedArray::GetOwnProperty(thread_, handleTagValTypedArray, handleTagValKey, descTo1)); + EXPECT_TRUE(descTo1.HasWritable() && descTo1.HasEnumerable() && descTo1.HasConfigurable()); + EXPECT_TRUE(descTo1.IsWritable() && descTo1.IsEnumerable() && descTo1.IsConfigurable()); + EXPECT_TRUE(JSTaggedValue::StrictEqual(thread_, descTo1.GetValue(), handleTagValValueDef)); } } } @@ -1306,29 +1290,29 @@ TEST_F(JSTypedArrayTest, SetProperty_TypedArray) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - for (size_t j = 0; j < c_vec_js_type_.size(); j++) { - int32_t num_elements_typed_array = 10; - JSHandle handle_tag_val_value_set(thread_, c_vec_handle_tag_val_value_for_typed_array_.at(j)); - JSHandle handle_typed_array = CreateNumberTypedArray(thread_, c_vec_js_type_.at(j)); - JSHandle handle_tag_val_typed_array = JSHandle::Cast(handle_typed_array); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_typed_array)); - int32_t byte_length_viewd_array_buffer = size_element * num_elements_typed_array; - JSHandle handle_tag_val_array_buffer_from = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - handle_typed_array->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer_from); - handle_typed_array->SetArrayLength(thread_, JSTaggedValue(num_elements_typed_array)); - - for (int32_t i = 0; i < num_elements_typed_array; i++) { - JSHandle handle_tag_val_key(thread_, JSTaggedValue(i)); - EXPECT_FALSE(JSTypedArray::HasProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key)); - EXPECT_TRUE(JSTypedArray::SetProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key, - handle_tag_val_value_set)); - EXPECT_TRUE(JSTypedArray::HasProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key)); + for (size_t j = 0; j < cVecJsType_.size(); j++) { + int32_t numElementsTypedArray = 10; + JSHandle handleTagValValueSet(thread_, cVecHandleTagValValueForTypedArray_.at(j)); + JSHandle handleTypedArray = CreateNumberTypedArray(thread_, cVecJsType_.at(j)); + JSHandle handleTagValTypedArray = JSHandle::Cast(handleTypedArray); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleTypedArray)); + int32_t byteLengthViewdArrayBuffer = sizeElement * numElementsTypedArray; + JSHandle handleTagValArrayBufferFrom = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + handleTypedArray->SetViewedArrayBuffer(thread_, handleTagValArrayBufferFrom); + handleTypedArray->SetArrayLength(thread_, JSTaggedValue(numElementsTypedArray)); + + for (int32_t i = 0; i < numElementsTypedArray; i++) { + JSHandle handleTagValKey(thread_, JSTaggedValue(i)); + EXPECT_FALSE(JSTypedArray::HasProperty(thread_, handleTagValTypedArray, handleTagValKey)); + EXPECT_TRUE( + JSTypedArray::SetProperty(thread_, handleTagValTypedArray, handleTagValKey, handleTagValValueSet)); + EXPECT_TRUE(JSTypedArray::HasProperty(thread_, handleTagValTypedArray, handleTagValKey)); EXPECT_TRUE(JSTaggedValue::StrictEqual( - thread_, handle_tag_val_value_set, - JSTypedArray::GetProperty(thread_, handle_tag_val_typed_array, handle_tag_val_key).GetValue())); + thread_, handleTagValValueSet, + JSTypedArray::GetProperty(thread_, handleTagValTypedArray, handleTagValKey).GetValue())); } } } @@ -1348,29 +1332,28 @@ TEST_F(JSTypedArrayTest, FastCopyElementToArray_TypedArray) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - for (size_t j = 0; j < c_vec_js_type_.size(); j++) { - int32_t num_elements_typed_array = 10; - JSHandle handle_tag_val_value_set(thread_, c_vec_handle_tag_val_value_for_typed_array_.at(j)); - JSHandle handle_typed_array_from = CreateNumberTypedArray(thread_, c_vec_js_type_.at(j)); - JSHandle handle_tag_val_typed_array_from = - JSHandle::Cast(handle_typed_array_from); - - uint32_t size_element = - ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handle_typed_array_from)); - int32_t byte_length_viewd_array_buffer = size_element * num_elements_typed_array; - JSHandle handle_tag_val_array_buffer = - JSHandle::Cast(factory->NewJSArrayBuffer(byte_length_viewd_array_buffer)); - JSHandle handle_tag_arr_to = factory->NewTaggedArray(byte_length_viewd_array_buffer); - handle_typed_array_from->SetViewedArrayBuffer(thread_, handle_tag_val_array_buffer); - handle_typed_array_from->SetArrayLength(thread_, JSTaggedValue(num_elements_typed_array)); - - for (int32_t i = 0; i < num_elements_typed_array; i++) { - EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handle_tag_val_typed_array_from, - JSTaggedValue(i), handle_tag_val_value_set)); + for (size_t j = 0; j < cVecJsType_.size(); j++) { + int32_t numElementsTypedArray = 10; + JSHandle handleTagValValueSet(thread_, cVecHandleTagValValueForTypedArray_.at(j)); + JSHandle handleTypedArrayFrom = CreateNumberTypedArray(thread_, cVecJsType_.at(j)); + JSHandle handleTagValTypedArrayFrom = JSHandle::Cast(handleTypedArrayFrom); + + uint32_t sizeElement = + ecmascript::base::TypedArrayHelper::GetElementSize(JSHandle::Cast(handleTypedArrayFrom)); + int32_t byteLengthViewdArrayBuffer = sizeElement * numElementsTypedArray; + JSHandle handleTagValArrayBuffer = + JSHandle::Cast(factory->NewJSArrayBuffer(byteLengthViewdArrayBuffer)); + JSHandle handleTagArrTo = factory->NewTaggedArray(byteLengthViewdArrayBuffer); + handleTypedArrayFrom->SetViewedArrayBuffer(thread_, handleTagValArrayBuffer); + handleTypedArrayFrom->SetArrayLength(thread_, JSTaggedValue(numElementsTypedArray)); + + for (int32_t i = 0; i < numElementsTypedArray; i++) { + EXPECT_TRUE(JSTypedArray::IntegerIndexedElementSet(thread_, handleTagValTypedArrayFrom, JSTaggedValue(i), + handleTagValValueSet)); } - EXPECT_TRUE(JSTypedArray::FastCopyElementToArray(thread_, handle_tag_val_typed_array_from, handle_tag_arr_to)); - for (int32_t i = 0; i < num_elements_typed_array; i++) { - EXPECT_EQ(handle_tag_arr_to->Get(i), handle_tag_val_value_set.GetTaggedValue()); + EXPECT_TRUE(JSTypedArray::FastCopyElementToArray(thread_, handleTagValTypedArrayFrom, handleTagArrTo)); + for (int32_t i = 0; i < numElementsTypedArray; i++) { + EXPECT_EQ(handleTagArrTo->Get(i), handleTagValValueSet.GetTaggedValue()); } } } diff --git a/tests/runtime/common/large_object_test.cpp b/tests/runtime/common/large_object_test.cpp index 69a9051f88dd2d02e94f40779502cf0550c18a68..df63ce5aed474310b17872ca7e199fee09cf320a 100644 --- a/tests/runtime/common/large_object_test.cpp +++ b/tests/runtime/common/large_object_test.cpp @@ -55,12 +55,11 @@ private: static JSObject *JSObjectTestCreate(JSThread *thread) { [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle global_env = ecma_vm->GetGlobalEnv(); - JSHandle js_func = global_env->GetObjectFunction(); - JSHandle new_obj = - ecma_vm->GetFactory()->NewJSObjectByConstructor(JSHandle(js_func), js_func); - return *new_obj; + EcmaVM *ecmaVm = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + JSHandle jsFunc = globalEnv->GetObjectFunction(); + JSHandle newObj = ecmaVm->GetFactory()->NewJSObjectByConstructor(JSHandle(jsFunc), jsFunc); + return *newObj; } #endif @@ -79,15 +78,15 @@ TEST_F(LargeObjectTest, LargeArrayKeep) #if !defined(NDEBUG) TaggedArray *array = LargeArrayTestCreate(thread_); EXPECT_TRUE(array != nullptr); - JSHandle array_handle(thread_, array); - JSHandle new_obj(thread_, JSObjectTestCreate(thread_)); - array_handle->Set(thread_, 0, new_obj.GetTaggedValue()); - auto ecma_vm = thread_->GetEcmaVM(); - EXPECT_EQ(*array_handle, reinterpret_cast(array)); - ecma_vm->GetGC()->WaitForGCInManaged(GCTask(GCTaskCause::EXPLICIT_CAUSE)); // Trigger GC. - ecma_vm->GetGC()->WaitForGCInManaged(GCTask(GCTaskCause::EXPLICIT_CAUSE)); // Trigger GC. - EXPECT_EQ(*new_obj, array->Get(0).GetHeapObject()); - EXPECT_EQ(*array_handle, reinterpret_cast(array)); + JSHandle arrayHandle(thread_, array); + JSHandle newObj(thread_, JSObjectTestCreate(thread_)); + arrayHandle->Set(thread_, 0, newObj.GetTaggedValue()); + auto ecmaVm = thread_->GetEcmaVM(); + EXPECT_EQ(*arrayHandle, reinterpret_cast(array)); + ecmaVm->GetGC()->WaitForGCInManaged(GCTask(GCTaskCause::EXPLICIT_CAUSE)); // Trigger GC. + ecmaVm->GetGC()->WaitForGCInManaged(GCTask(GCTaskCause::EXPLICIT_CAUSE)); // Trigger GC. + EXPECT_EQ(*newObj, array->Get(0).GetHeapObject()); + EXPECT_EQ(*arrayHandle, reinterpret_cast(array)); #endif } diff --git a/tests/runtime/common/lexical_env_test.cpp b/tests/runtime/common/lexical_env_test.cpp index e01a15cba8bf5eb98ad2c3a3514b00497d085343..0755908ca541d96a665a903b18fae7068254222a 100644 --- a/tests/runtime/common/lexical_env_test.cpp +++ b/tests/runtime/common/lexical_env_test.cpp @@ -46,7 +46,7 @@ private: TEST_F(LexicalEnvTest, LexicalEnv_Create) { - JSHandle lexical_env = thread_->GetEcmaVM()->GetFactory()->NewLexicalEnv(0); - EXPECT_TRUE(lexical_env.GetTaggedValue().IsObject()); + JSHandle lexicalEnv = thread_->GetEcmaVM()->GetFactory()->NewLexicalEnv(0); + EXPECT_TRUE(lexicalEnv.GetTaggedValue().IsObject()); } } // namespace panda::test diff --git a/tests/runtime/common/linked_hash_table_test.cpp b/tests/runtime/common/linked_hash_table_test.cpp index 2609c558fd888eb669b00bfcfa310c6ede652f8e..21ad62e0b766a97a04596c7353323d38199ace5d 100644 --- a/tests/runtime/common/linked_hash_table_test.cpp +++ b/tests/runtime/common/linked_hash_table_test.cpp @@ -69,15 +69,15 @@ private: TEST_F(LinkedHashTableTest, MapCreate) { - int num_of_element = 64; - JSHandle dict = LinkedHashMap::Create(thread_, num_of_element); + int numOfElement = 64; + JSHandle dict = LinkedHashMap::Create(thread_, numOfElement); EXPECT_TRUE(*dict != nullptr); } TEST_F(LinkedHashTableTest, SetCreate) { - int num_of_element = 64; - JSHandle set = LinkedHashSet::Create(thread_, num_of_element); + int numOfElement = 64; + JSHandle set = LinkedHashSet::Create(thread_, numOfElement); EXPECT_TRUE(*set != nullptr); } @@ -85,216 +85,216 @@ TEST_F(LinkedHashTableTest, addKeyAndValue) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // mock object needed in test - int num_of_element = 64; - JSHandle dict_handle = LinkedHashMap::Create(thread_, num_of_element); - EXPECT_TRUE(*dict_handle != nullptr); - JSHandle obj_fun = GetGlobalEnv()->GetObjectFunction(); + int numOfElement = 64; + JSHandle dictHandle = LinkedHashMap::Create(thread_, numOfElement); + EXPECT_TRUE(*dictHandle != nullptr); + JSHandle objFun = GetGlobalEnv()->GetObjectFunction(); - char key_array[] = "hello"; - JSHandle string_key1 = factory->NewFromCanBeCompressString(key_array); - JSHandle key1(string_key1); - JSHandle value1(factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun)); + char keyArray[] = "hello"; + JSHandle stringKey1 = factory->NewFromCanBeCompressString(keyArray); + JSHandle key1(stringKey1); + JSHandle value1(factory->NewJSObjectByConstructor(JSHandle(objFun), objFun)); - char key2_array[] = "hello2"; - JSHandle string_key2 = factory->NewFromCanBeCompressString(key2_array); - JSHandle key2(string_key2); - JSHandle value2(factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun)); + char key2Array[] = "hello2"; + JSHandle stringKey2 = factory->NewFromCanBeCompressString(key2Array); + JSHandle key2(stringKey2); + JSHandle value2(factory->NewJSObjectByConstructor(JSHandle(objFun), objFun)); // test set() - dict_handle = LinkedHashMap::Set(thread_, dict_handle, key1, value1); - EXPECT_EQ(dict_handle->NumberOfElements(), 1); + dictHandle = LinkedHashMap::Set(thread_, dictHandle, key1, value1); + EXPECT_EQ(dictHandle->NumberOfElements(), 1); // test find() int hash = LinkedHash::Hash(key1.GetTaggedValue()); - int entry1 = dict_handle->FindElement(key1.GetTaggedValue(), hash); - EXPECT_EQ(key1.GetTaggedValue(), dict_handle->GetKey(entry1)); - EXPECT_EQ(value1.GetTaggedValue(), dict_handle->GetValue(entry1)); + int entry1 = dictHandle->FindElement(key1.GetTaggedValue(), hash); + EXPECT_EQ(key1.GetTaggedValue(), dictHandle->GetKey(entry1)); + EXPECT_EQ(value1.GetTaggedValue(), dictHandle->GetValue(entry1)); - dict_handle = LinkedHashMap::Set(thread_, dict_handle, key2, value2); - EXPECT_EQ(dict_handle->NumberOfElements(), 2); + dictHandle = LinkedHashMap::Set(thread_, dictHandle, key2, value2); + EXPECT_EQ(dictHandle->NumberOfElements(), 2); // test remove() - dict_handle = LinkedHashMap::Delete(thread_, dict_handle, key1); - EXPECT_EQ(-1, dict_handle->FindElement(key1.GetTaggedValue(), hash)); - EXPECT_EQ(dict_handle->NumberOfElements(), 1); - - JSHandle undefined_key(thread_, JSTaggedValue::Undefined()); - dict_handle = LinkedHashMap::Set(thread_, dict_handle, undefined_key, value1); - int undefined_hash = LinkedHash::Hash(undefined_key.GetTaggedValue()); - int entry2 = dict_handle->FindElement(undefined_key.GetTaggedValue(), undefined_hash); - EXPECT_EQ(value1.GetTaggedValue(), dict_handle->GetValue(entry2)); + dictHandle = LinkedHashMap::Delete(thread_, dictHandle, key1); + EXPECT_EQ(-1, dictHandle->FindElement(key1.GetTaggedValue(), hash)); + EXPECT_EQ(dictHandle->NumberOfElements(), 1); + + JSHandle undefinedKey(thread_, JSTaggedValue::Undefined()); + dictHandle = LinkedHashMap::Set(thread_, dictHandle, undefinedKey, value1); + int undefinedHash = LinkedHash::Hash(undefinedKey.GetTaggedValue()); + int entry2 = dictHandle->FindElement(undefinedKey.GetTaggedValue(), undefinedHash); + EXPECT_EQ(value1.GetTaggedValue(), dictHandle->GetValue(entry2)); } TEST_F(LinkedHashTableTest, SetaddKeyAndValue) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // mock object needed in test - int num_of_element = 64; - JSHandle set_handle = LinkedHashSet::Create(thread_, num_of_element); - EXPECT_TRUE(*set_handle != nullptr); - JSHandle obj_fun = GetGlobalEnv()->GetObjectFunction(); + int numOfElement = 64; + JSHandle setHandle = LinkedHashSet::Create(thread_, numOfElement); + EXPECT_TRUE(*setHandle != nullptr); + JSHandle objFun = GetGlobalEnv()->GetObjectFunction(); - char key_array[] = "hello"; - JSHandle string_key1 = factory->NewFromCanBeCompressString(key_array); - JSHandle key1(string_key1); - JSHandle value1(factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun)); + char keyArray[] = "hello"; + JSHandle stringKey1 = factory->NewFromCanBeCompressString(keyArray); + JSHandle key1(stringKey1); + JSHandle value1(factory->NewJSObjectByConstructor(JSHandle(objFun), objFun)); - char key2_array[] = "hello2"; - JSHandle string_key2 = factory->NewFromCanBeCompressString(key2_array); - JSHandle key2(string_key2); - JSHandle value2(factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun)); + char key2Array[] = "hello2"; + JSHandle stringKey2 = factory->NewFromCanBeCompressString(key2Array); + JSHandle key2(stringKey2); + JSHandle value2(factory->NewJSObjectByConstructor(JSHandle(objFun), objFun)); // test set() - set_handle = LinkedHashSet::Add(thread_, set_handle, key1); - EXPECT_EQ(set_handle->NumberOfElements(), 1); + setHandle = LinkedHashSet::Add(thread_, setHandle, key1); + EXPECT_EQ(setHandle->NumberOfElements(), 1); // test has() int hash = LinkedHash::Hash(key1.GetTaggedValue()); - EXPECT_TRUE(set_handle->Has(key1.GetTaggedValue(), hash)); + EXPECT_TRUE(setHandle->Has(key1.GetTaggedValue(), hash)); - set_handle = LinkedHashSet::Add(thread_, set_handle, key2); - EXPECT_EQ(set_handle->NumberOfElements(), 2); + setHandle = LinkedHashSet::Add(thread_, setHandle, key2); + EXPECT_EQ(setHandle->NumberOfElements(), 2); // test remove() - set_handle = LinkedHashSet::Delete(thread_, set_handle, key1); - EXPECT_EQ(-1, set_handle->FindElement(key1.GetTaggedValue(), hash)); - EXPECT_EQ(set_handle->NumberOfElements(), 1); - - JSHandle undefined_key(thread_, JSTaggedValue::Undefined()); - set_handle = LinkedHashSet::Add(thread_, set_handle, undefined_key); - int undefined_hash = LinkedHash::Hash(undefined_key.GetTaggedValue()); - EXPECT_TRUE(set_handle->Has(undefined_key.GetTaggedValue(), undefined_hash)); + setHandle = LinkedHashSet::Delete(thread_, setHandle, key1); + EXPECT_EQ(-1, setHandle->FindElement(key1.GetTaggedValue(), hash)); + EXPECT_EQ(setHandle->NumberOfElements(), 1); + + JSHandle undefinedKey(thread_, JSTaggedValue::Undefined()); + setHandle = LinkedHashSet::Add(thread_, setHandle, undefinedKey); + int undefinedHash = LinkedHash::Hash(undefinedKey.GetTaggedValue()); + EXPECT_TRUE(setHandle->Has(undefinedKey.GetTaggedValue(), undefinedHash)); } TEST_F(LinkedHashTableTest, GrowCapacity) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - int num_of_element = 8; - JSHandle dict_handle = LinkedHashMap::Create(thread_, num_of_element); - EXPECT_TRUE(*dict_handle != nullptr); - JSHandle obj_fun(GetGlobalEnv()->GetObjectFunction()); - char key_array[7] = "hello"; + int numOfElement = 8; + JSHandle dictHandle = LinkedHashMap::Create(thread_, numOfElement); + EXPECT_TRUE(*dictHandle != nullptr); + JSHandle objFun(GetGlobalEnv()->GetObjectFunction()); + char keyArray[7] = "hello"; for (int i = 0; i < 33; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle key(factory->NewFromCanBeCompressString(key_array)); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle key(factory->NewFromCanBeCompressString(keyArray)); JSHandle value(thread_, JSTaggedValue(i)); // test insert() - dict_handle = LinkedHashMap::Set(thread_, dict_handle, key, value); + dictHandle = LinkedHashMap::Set(thread_, dictHandle, key, value); int hash = LinkedHash::Hash(key.GetTaggedValue()); - EXPECT_EQ(i, dict_handle->FindElement(key.GetTaggedValue(), hash)); + EXPECT_EQ(i, dictHandle->FindElement(key.GetTaggedValue(), hash)); } // test order for (int i = 0; i < 33; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle string_key = factory->NewFromCanBeCompressString(key_array); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle stringKey = factory->NewFromCanBeCompressString(keyArray); // test insert() - int hash = LinkedHash::Hash(string_key.GetTaggedValue()); - EXPECT_EQ(i, dict_handle->FindElement(string_key.GetTaggedValue(), hash)); + int hash = LinkedHash::Hash(stringKey.GetTaggedValue()); + EXPECT_EQ(i, dictHandle->FindElement(stringKey.GetTaggedValue(), hash)); } - EXPECT_EQ(dict_handle->NumberOfElements(), 33); - EXPECT_EQ(dict_handle->Capacity(), 64); + EXPECT_EQ(dictHandle->NumberOfElements(), 33); + EXPECT_EQ(dictHandle->Capacity(), 64); } TEST_F(LinkedHashTableTest, SetGrowCapacity) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - int num_of_element = 8; - JSHandle set_handle = LinkedHashSet::Create(thread_, num_of_element); - EXPECT_TRUE(*set_handle != nullptr); - JSHandle obj_fun(GetGlobalEnv()->GetObjectFunction()); + int numOfElement = 8; + JSHandle setHandle = LinkedHashSet::Create(thread_, numOfElement); + EXPECT_TRUE(*setHandle != nullptr); + JSHandle objFun(GetGlobalEnv()->GetObjectFunction()); // create key and values - char key_array[7] = "hello"; + char keyArray[7] = "hello"; for (int i = 0; i < 33; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle string_key = factory->NewFromCanBeCompressString(key_array); - JSHandle key(string_key); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle stringKey = factory->NewFromCanBeCompressString(keyArray); + JSHandle key(stringKey); // test insert() - set_handle = LinkedHashSet::Add(thread_, set_handle, key); + setHandle = LinkedHashSet::Add(thread_, setHandle, key); int hash = LinkedHash::Hash(key.GetTaggedValue()); - EXPECT_EQ(i, set_handle->FindElement(key.GetTaggedValue(), hash)); + EXPECT_EQ(i, setHandle->FindElement(key.GetTaggedValue(), hash)); } // test order for (int i = 0; i < 33; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle string_key = factory->NewFromCanBeCompressString(key_array); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle stringKey = factory->NewFromCanBeCompressString(keyArray); // test insert() - int hash = LinkedHash::Hash(string_key.GetTaggedValue()); - EXPECT_EQ(i, set_handle->FindElement(string_key.GetTaggedValue(), hash)); + int hash = LinkedHash::Hash(stringKey.GetTaggedValue()); + EXPECT_EQ(i, setHandle->FindElement(stringKey.GetTaggedValue(), hash)); } - EXPECT_EQ(set_handle->NumberOfElements(), 33); - EXPECT_EQ(set_handle->Capacity(), 64); + EXPECT_EQ(setHandle->NumberOfElements(), 33); + EXPECT_EQ(setHandle->Capacity(), 64); } TEST_F(LinkedHashTableTest, ShrinkCapacity) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - int num_of_element = 64; - JSHandle dict_handle = LinkedHashMap::Create(thread_, num_of_element); - EXPECT_TRUE(*dict_handle != nullptr); - JSHandle obj_fun(GetGlobalEnv()->GetObjectFunction()); - char key_array[7] = "hello"; + int numOfElement = 64; + JSHandle dictHandle = LinkedHashMap::Create(thread_, numOfElement); + EXPECT_TRUE(*dictHandle != nullptr); + JSHandle objFun(GetGlobalEnv()->GetObjectFunction()); + char keyArray[7] = "hello"; for (int i = 0; i < 10; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle key(factory->NewFromCanBeCompressString(key_array)); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle key(factory->NewFromCanBeCompressString(keyArray)); JSHandle value(thread_, JSTaggedValue(i)); // test insert() - dict_handle = LinkedHashMap::Set(thread_, dict_handle, key, value); + dictHandle = LinkedHashMap::Set(thread_, dictHandle, key, value); } - key_array[5] = '1' + 9; - JSHandle key(factory->NewFromCanBeCompressString(key_array)); - dict_handle = LinkedHashMap::Delete(thread_, dict_handle, key); + keyArray[5] = '1' + 9; + JSHandle key(factory->NewFromCanBeCompressString(keyArray)); + dictHandle = LinkedHashMap::Delete(thread_, dictHandle, key); // test order for (int i = 0; i < 9; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle string_key = factory->NewFromCanBeCompressString(key_array); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle stringKey = factory->NewFromCanBeCompressString(keyArray); // test insert() - int hash = LinkedHash::Hash(string_key.GetTaggedValue()); - EXPECT_EQ(i, dict_handle->FindElement(string_key.GetTaggedValue(), hash)); + int hash = LinkedHash::Hash(stringKey.GetTaggedValue()); + EXPECT_EQ(i, dictHandle->FindElement(stringKey.GetTaggedValue(), hash)); } - EXPECT_EQ(dict_handle->NumberOfElements(), 9); - EXPECT_EQ(dict_handle->Capacity(), 16); + EXPECT_EQ(dictHandle->NumberOfElements(), 9); + EXPECT_EQ(dictHandle->Capacity(), 16); } TEST_F(LinkedHashTableTest, SetShrinkCapacity) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - int num_of_element = 64; - JSHandle set_handle = LinkedHashSet::Create(thread_, num_of_element); - EXPECT_TRUE(*set_handle != nullptr); - JSHandle obj_fun(GetGlobalEnv()->GetObjectFunction()); + int numOfElement = 64; + JSHandle setHandle = LinkedHashSet::Create(thread_, numOfElement); + EXPECT_TRUE(*setHandle != nullptr); + JSHandle objFun(GetGlobalEnv()->GetObjectFunction()); // create key and values - char key_array[7] = "hello"; + char keyArray[7] = "hello"; for (int i = 0; i < 10; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle key(factory->NewFromCanBeCompressString(key_array)); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle key(factory->NewFromCanBeCompressString(keyArray)); // test insert() - set_handle = LinkedHashSet::Add(thread_, set_handle, key); + setHandle = LinkedHashSet::Add(thread_, setHandle, key); } - key_array[5] = '1' + 9; - JSHandle key_handle(factory->NewFromCanBeCompressString(key_array)); - set_handle = LinkedHashSet::Delete(thread_, set_handle, key_handle); + keyArray[5] = '1' + 9; + JSHandle keyHandle(factory->NewFromCanBeCompressString(keyArray)); + setHandle = LinkedHashSet::Delete(thread_, setHandle, keyHandle); // test order for (int i = 0; i < 9; i++) { - key_array[5] = '1' + i; - key_array[6] = 0; - JSHandle string_key = factory->NewFromCanBeCompressString(key_array); + keyArray[5] = '1' + i; + keyArray[6] = 0; + JSHandle stringKey = factory->NewFromCanBeCompressString(keyArray); // test insert() - int hash = LinkedHash::Hash(string_key.GetTaggedValue()); - EXPECT_EQ(i, set_handle->FindElement(string_key.GetTaggedValue(), hash)); + int hash = LinkedHash::Hash(stringKey.GetTaggedValue()); + EXPECT_EQ(i, setHandle->FindElement(stringKey.GetTaggedValue(), hash)); } - EXPECT_EQ(set_handle->NumberOfElements(), 9); - EXPECT_EQ(set_handle->Capacity(), 16); + EXPECT_EQ(setHandle->NumberOfElements(), 9); + EXPECT_EQ(setHandle->Capacity(), 16); } } // namespace panda::test diff --git a/tests/runtime/common/name_dictionary_test.cpp b/tests/runtime/common/name_dictionary_test.cpp index c3ac90f2a4aa290d744b9ed4b46d6db4ac9fc10e..96d3df799388734d5b78fbd1d2e92c402067eb26 100644 --- a/tests/runtime/common/name_dictionary_test.cpp +++ b/tests/runtime/common/name_dictionary_test.cpp @@ -72,44 +72,44 @@ static JSHandle GetGlobalEnv(JSThread *thread) TEST_F(NameDictionaryTest, createDictionary) { - int num_of_element = 64; - JSHandle dict = NameDictionary::Create(thread_, num_of_element); + int numOfElement = 64; + JSHandle dict = NameDictionary::Create(thread_, numOfElement); EXPECT_TRUE(*dict != nullptr); } TEST_F(NameDictionaryTest, addKeyAndValue) { // mock object needed in test - int num_of_element = 64; - JSHandle dict_j_shandle(NameDictionary::Create(thread_, num_of_element)); - EXPECT_TRUE(*dict_j_shandle != nullptr); - JSMutableHandle dict_handle(dict_j_shandle); - JSHandle obj_fun = GetGlobalEnv(thread_)->GetObjectFunction(); + int numOfElement = 64; + JSHandle dictJShandle(NameDictionary::Create(thread_, numOfElement)); + EXPECT_TRUE(*dictJShandle != nullptr); + JSMutableHandle dictHandle(dictJShandle); + JSHandle objFun = GetGlobalEnv(thread_)->GetObjectFunction(); // create key and values - JSHandle js_object = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - EXPECT_TRUE(*js_object != nullptr); - - char key_array[] = "hello"; - JSHandle string_key1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(key_array); - JSHandle key1(string_key1); - JSHandle taggedkey1(string_key1); + JSHandle jsObject = + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFun), objFun); + EXPECT_TRUE(*jsObject != nullptr); + + char keyArray[] = "hello"; + JSHandle stringKey1 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(keyArray); + JSHandle key1(stringKey1); + JSHandle taggedkey1(stringKey1); JSHandle value1( - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun)); - PropertyAttributes meta_data1; + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFun), objFun)); + PropertyAttributes metaData1; - char key2_array[] = "hello2"; - JSHandle string_key2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(key2_array); - JSHandle key2(string_key2); - JSHandle taggedkey2(string_key2); + char key2Array[] = "hello2"; + JSHandle stringKey2 = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(key2Array); + JSHandle key2(stringKey2); + JSHandle taggedkey2(stringKey2); JSHandle value2( - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun)); - PropertyAttributes meta_data2; + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFun), objFun)); + PropertyAttributes metaData2; // test insert() - JSHandle dict(NameDictionary::PutIfAbsent(thread_, dict_handle, key1, value1, meta_data1)); - dict_handle.Update(dict.GetTaggedValue()); + JSHandle dict(NameDictionary::PutIfAbsent(thread_, dictHandle, key1, value1, metaData1)); + dictHandle.Update(dict.GetTaggedValue()); EXPECT_EQ(dict->EntriesCount(), 1); // test find() and lookup() @@ -117,83 +117,82 @@ TEST_F(NameDictionaryTest, addKeyAndValue) EXPECT_EQ(key1.GetTaggedValue(), JSTaggedValue(dict->GetKey(entry1).GetRawData())); EXPECT_EQ(value1.GetTaggedValue(), JSTaggedValue(dict->GetValue(entry1).GetRawData())); - JSHandle dict2(NameDictionary::PutIfAbsent(thread_, dict_handle, key2, value2, meta_data2)); + JSHandle dict2(NameDictionary::PutIfAbsent(thread_, dictHandle, key2, value2, metaData2)); EXPECT_EQ(dict2->EntriesCount(), 2); // test remove() - dict = NameDictionary::Remove(thread_, dict_handle, entry1); + dict = NameDictionary::Remove(thread_, dictHandle, entry1); EXPECT_EQ(-1, dict->FindEntry(key1.GetTaggedValue())); EXPECT_EQ(dict->EntriesCount(), 1); } TEST_F(NameDictionaryTest, GrowCapacity) { - int num_of_element = 8; - JSHandle dict_handle(NameDictionary::Create(thread_, num_of_element)); - EXPECT_TRUE(*dict_handle != nullptr); - JSHandle obj_fun = GetGlobalEnv(thread_)->GetObjectFunction(); + int numOfElement = 8; + JSHandle dictHandle(NameDictionary::Create(thread_, numOfElement)); + EXPECT_TRUE(*dictHandle != nullptr); + JSHandle objFun = GetGlobalEnv(thread_)->GetObjectFunction(); // create key and values - JSHandle js_object = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - EXPECT_TRUE(*js_object != nullptr); - char key_array[7] = "hello"; + JSHandle jsObject = + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFun), objFun); + EXPECT_TRUE(*jsObject != nullptr); + char keyArray[7] = "hello"; for (int i = 0; i < 9; i++) { - JSHandle temp_handle = dict_handle; - key_array[5] = '1' + i; - key_array[6] = 0; + JSHandle tempHandle = dictHandle; + keyArray[5] = '1' + i; + keyArray[6] = 0; - JSHandle string_key = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(key_array); - ecmascript::JSHandle key(string_key); - JSHandle key_handle(key); + JSHandle stringKey = thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(keyArray); + ecmascript::JSHandle key(stringKey); + JSHandle keyHandle(key); ecmascript::JSHandle value(thread_, JSTaggedValue(i)); - JSHandle value_handle(value); - PropertyAttributes meta_data; + JSHandle valueHandle(value); + PropertyAttributes metaData; // test insert() - dict_handle = NameDictionary::PutIfAbsent(thread_, temp_handle, key_handle, value_handle, meta_data); + dictHandle = NameDictionary::PutIfAbsent(thread_, tempHandle, keyHandle, valueHandle, metaData); } - EXPECT_EQ(dict_handle->EntriesCount(), 9); - EXPECT_EQ(dict_handle->Size(), 16); + EXPECT_EQ(dictHandle->EntriesCount(), 9); + EXPECT_EQ(dictHandle->Size(), 16); } TEST_F(NameDictionaryTest, ShrinkCapacity) { - int num_of_element = 64; - JSMutableHandle dict_handle(NameDictionary::Create(thread_, num_of_element)); - EXPECT_TRUE(*dict_handle != nullptr); - JSHandle obj_fun = GetGlobalEnv(thread_)->GetObjectFunction(); + int numOfElement = 64; + JSMutableHandle dictHandle(NameDictionary::Create(thread_, numOfElement)); + EXPECT_TRUE(*dictHandle != nullptr); + JSHandle objFun = GetGlobalEnv(thread_)->GetObjectFunction(); // create key and values - JSHandle js_object = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - EXPECT_TRUE(*js_object != nullptr); - uint8_t key_array[7] = "hello"; + JSHandle jsObject = + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFun), objFun); + EXPECT_TRUE(*jsObject != nullptr); + uint8_t keyArray[7] = "hello"; - auto string_table = thread_->GetEcmaVM()->GetEcmaStringTable(); + auto stringTable = thread_->GetEcmaVM()->GetEcmaStringTable(); for (int i = 0; i < 10; i++) { - key_array[5] = '0' + i; - key_array[6] = 0; + keyArray[5] = '0' + i; + keyArray[6] = 0; - JSHandle key(thread_, - string_table->GetOrInternString(key_array, utf::Mutf8Size(key_array), true)); + JSHandle key(thread_, stringTable->GetOrInternString(keyArray, utf::Mutf8Size(keyArray), true)); JSHandle value(thread_, JSTaggedValue(i)); - PropertyAttributes meta_data; + PropertyAttributes metaData; // test insert() - JSHandle new_dict = NameDictionary::PutIfAbsent(thread_, dict_handle, key, value, meta_data); - dict_handle.Update(new_dict.GetTaggedValue()); + JSHandle newDict = NameDictionary::PutIfAbsent(thread_, dictHandle, key, value, metaData); + dictHandle.Update(newDict.GetTaggedValue()); } - key_array[5] = '2'; - key_array[6] = 0; - JSHandle array_handle(thread_, - string_table->GetOrInternString(key_array, utf::Mutf8Size(key_array), true)); + keyArray[5] = '2'; + keyArray[6] = 0; + JSHandle arrayHandle(thread_, + stringTable->GetOrInternString(keyArray, utf::Mutf8Size(keyArray), true)); - int entry = dict_handle->FindEntry(array_handle.GetTaggedValue()); + int entry = dictHandle->FindEntry(arrayHandle.GetTaggedValue()); EXPECT_NE(entry, -1); - JSHandle new_dict1 = NameDictionary::Remove(thread_, dict_handle, entry); - dict_handle.Update(new_dict1.GetTaggedValue()); - EXPECT_EQ(dict_handle->EntriesCount(), 9); - EXPECT_EQ(dict_handle->Size(), 16); + JSHandle newDict1 = NameDictionary::Remove(thread_, dictHandle, entry); + dictHandle.Update(newDict1.GetTaggedValue()); + EXPECT_EQ(dictHandle->EntriesCount(), 9); + EXPECT_EQ(dictHandle->Size(), 16); } } // namespace panda::test diff --git a/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp b/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp index 0d11309ce8df0d5ace8db2521064be4cd0a1e5ec..e876fc545072671b51399153d824f891807c0fd3 100644 --- a/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp +++ b/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp @@ -23,17 +23,17 @@ class EcmaEmptyClassCheck : public testing::Test { public: EcmaEmptyClassCheck() { - auto exec_path = panda::os::file::File::GetExecutablePath(); - ecma_std_lib_ = exec_path.Value() + "/../plugins/ecmascript/ecmastdlib/ecmastdlib.abc"; + auto execPath = panda::os::file::File::GetExecutablePath(); + ecmaStdLib_ = execPath.Value() + "/../plugins/ecmascript/ecmastdlib/ecmastdlib.abc"; } const std::string &GetEcmaStdLibPath() const { - return ecma_std_lib_; + return ecmaStdLib_; } private: - std::string ecma_std_lib_; + std::string ecmaStdLib_; }; static void CheckAPINoCrash(Method *m) @@ -105,9 +105,9 @@ TEST_F(EcmaEmptyClassCheck, TestJSABC) ASSERT_TRUE(Runtime::Create(options)); - auto *ecma_vm = reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); + auto *ecmaVm = reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); - for (Method *m : ecma_vm->GetNativeMethods()) { + for (Method *m : ecmaVm->GetNativeMethods()) { CheckAPINoCrash(m); } diff --git a/tests/runtime/common/native_pointer_test.cpp b/tests/runtime/common/native_pointer_test.cpp index 85aa1d018fbdd7ce2a860b7ad4d911673f388054..ca703b2f1399f4d31bc4d70f8ac961c18eaf566b 100644 --- a/tests/runtime/common/native_pointer_test.cpp +++ b/tests/runtime/common/native_pointer_test.cpp @@ -69,13 +69,13 @@ TEST_F(NativePointerTest, Print) JSHandle str = factory->NewFromCanBeCompressString(array); EXPECT_TRUE(*str != nullptr); - JSHandle js_function = factory->NewJSFunction(env); - EXPECT_TRUE(*js_function != nullptr); + JSHandle jsFunction = factory->NewJSFunction(env); + EXPECT_TRUE(*jsFunction != nullptr); JSMethod *target = thread_->GetEcmaVM()->GetMethodForNativeFunction(nullptr); - js_function->SetCallTarget(thread_, target); + jsFunction->SetCallTarget(thread_, target); // run cpp methed 'Print' - ASSERT_EQ(target, js_function->GetCallTarget()); + ASSERT_EQ(target, jsFunction->GetCallTarget()); } } // namespace panda::test diff --git a/tests/runtime/common/object_factory_test.cpp b/tests/runtime/common/object_factory_test.cpp index 03bef037a7686b2074b73e6797e3e276be36b350..93bdf6712a3dbcdb16eb474fe78e2605d860dac9 100644 --- a/tests/runtime/common/object_factory_test.cpp +++ b/tests/runtime/common/object_factory_test.cpp @@ -70,21 +70,21 @@ JSHandle GetGlobal(JSThread *thread) TEST_F(ObjectFactoryTest, DISABLED_NewJSObjectByConstructor) // NOTE(vpukhov) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle obj_fun = GetGlobal(thread_)->GetObjectFunction(); + JSHandle objFun = GetGlobal(thread_)->GetObjectFunction(); // check mem alloc - JSHandle new_obj = factory->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); - JSHandle new_obj_cls(thread_, new_obj->GetJSHClass()); - EXPECT_TRUE(*new_obj != nullptr); - EXPECT_TRUE(*new_obj_cls != nullptr); + JSHandle newObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle newObjCls(thread_, newObj->GetJSHClass()); + EXPECT_TRUE(*newObj != nullptr); + EXPECT_TRUE(*newObjCls != nullptr); // check feild - EXPECT_EQ(new_obj->GetProperties(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); - EXPECT_EQ(new_obj->GetElements(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); - EXPECT_TRUE(JSTaggedValue(*new_obj).IsECMAObject()); + EXPECT_EQ(newObj->GetProperties(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); + EXPECT_EQ(newObj->GetElements(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); + EXPECT_TRUE(JSTaggedValue(*newObj).IsECMAObject()); // check jshclass - JSHClass *cls = *new_obj_cls; + JSHClass *cls = *newObjCls; EXPECT_TRUE(cls->GetObjectSize() == JSObject::SIZE + JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS * JSTaggedValue::TaggedTypeSize()); EXPECT_TRUE(cls->GetPrototype() == GetGlobal(thread_)->GetObjectFunctionPrototype().GetTaggedValue()); @@ -94,7 +94,7 @@ TEST_F(ObjectFactoryTest, DISABLED_NewJSObjectByConstructor) // NOTE(vpukhov) auto *prototype = cls->GetPrototype().GetTaggedObject(); thread_->GetEcmaVM()->CollectGarbage(); // CompressGC not the same - EXPECT_TRUE(prototype != new_obj_cls->GetPrototype().GetTaggedObject()); + EXPECT_TRUE(prototype != newObjCls->GetPrototype().GetTaggedObject()); } TEST_F(ObjectFactoryTest, NewJSFunction) @@ -103,20 +103,20 @@ TEST_F(ObjectFactoryTest, NewJSFunction) JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); // check mem alloc - JSHandle new_fun = factory->NewJSFunction(env); - JSHandle new_fun_cls(thread_, new_fun->GetJSHClass()); - EXPECT_TRUE(*new_fun != nullptr); - EXPECT_TRUE(*new_fun_cls != nullptr); + JSHandle newFun = factory->NewJSFunction(env); + JSHandle newFunCls(thread_, newFun->GetJSHClass()); + EXPECT_TRUE(*newFun != nullptr); + EXPECT_TRUE(*newFunCls != nullptr); // check feild - EXPECT_EQ(new_fun->GetProperties(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); - EXPECT_EQ(new_fun->GetElements(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); - EXPECT_EQ(new_fun->GetProtoOrDynClass(), JSTaggedValue::Hole()); - EXPECT_EQ(new_fun->GetHomeObject(), JSTaggedValue::Undefined()); - EXPECT_TRUE(JSTaggedValue(*new_fun).IsJSFunction()); + EXPECT_EQ(newFun->GetProperties(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); + EXPECT_EQ(newFun->GetElements(), GetGlobal(thread_)->GetEmptyArray().GetTaggedValue()); + EXPECT_EQ(newFun->GetProtoOrDynClass(), JSTaggedValue::Hole()); + EXPECT_EQ(newFun->GetHomeObject(), JSTaggedValue::Undefined()); + EXPECT_TRUE(JSTaggedValue(*newFun).IsJSFunction()); // check jshclass - JSHClass *cls = *new_fun_cls; + JSHClass *cls = *newFunCls; EXPECT_TRUE(cls->GetObjectSize() == JSFunction::SIZE + JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS * JSTaggedValue::TaggedTypeSize()); EXPECT_TRUE(cls->GetPrototype() == GetGlobal(thread_)->GetFunctionPrototype().GetTaggedValue()); @@ -131,16 +131,16 @@ TEST_F(ObjectFactoryTest, NewJSBoundFunction) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // test prepare - JSHandle fun_fun(GetGlobal(thread_)->GetObjectFunction()); + JSHandle funFun(GetGlobal(thread_)->GetObjectFunction()); JSHandle bound(thread_, GetGlobal(thread_)->GetObjectFunctionPrototype().GetTaggedValue()); const JSHandle array(GetGlobal(thread_)->GetEmptyArray()); // check mem alloc - JSHandle target_func(fun_fun); - JSHandle new_bound_fun = factory->NewJSBoundFunction(target_func, bound, array); - JSHandle new_bound_fun_cls(thread_, new_bound_fun->GetJSHClass()); - EXPECT_TRUE(*new_bound_fun != nullptr); - EXPECT_TRUE(*new_bound_fun_cls != nullptr); + JSHandle targetFunc(funFun); + JSHandle newBoundFun = factory->NewJSBoundFunction(targetFunc, bound, array); + JSHandle newBoundFunCls(thread_, newBoundFun->GetJSHClass()); + EXPECT_TRUE(*newBoundFun != nullptr); + EXPECT_TRUE(*newBoundFunCls != nullptr); } TEST_F(ObjectFactoryTest, NewJSPrimitiveRef) @@ -148,16 +148,16 @@ TEST_F(ObjectFactoryTest, NewJSPrimitiveRef) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // test prepare - JSHandle number_fun(GetGlobal(thread_)->GetNumberFunction()); + JSHandle numberFun(GetGlobal(thread_)->GetNumberFunction()); JSHandle primitive(thread_, JSTaggedValue(1)); // check mem alloc - JSHandle new_primitive = factory->NewJSPrimitiveRef(number_fun, primitive); - JSHandle new_primitive_cls(thread_, new_primitive->GetJSHClass()); - EXPECT_TRUE(*new_primitive != nullptr); - EXPECT_TRUE(*new_primitive_cls != nullptr); + JSHandle newPrimitive = factory->NewJSPrimitiveRef(numberFun, primitive); + JSHandle newPrimitiveCls(thread_, newPrimitive->GetJSHClass()); + EXPECT_TRUE(*newPrimitive != nullptr); + EXPECT_TRUE(*newPrimitiveCls != nullptr); - EXPECT_TRUE(new_primitive->GetValue() == JSTaggedValue(1)); + EXPECT_TRUE(newPrimitive->GetValue() == JSTaggedValue(1)); } TEST_F(ObjectFactoryTest, NewLexicalEnv) @@ -165,10 +165,10 @@ TEST_F(ObjectFactoryTest, NewLexicalEnv) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // check mem alloc - JSHandle new_lexical_env = factory->NewLexicalEnv(0); - JSHandle new_lexical_env_cls(thread_, new_lexical_env->GetClass()); - EXPECT_TRUE(*new_lexical_env != nullptr); - EXPECT_TRUE(*new_lexical_env_cls != nullptr); + JSHandle newLexicalEnv = factory->NewLexicalEnv(0); + JSHandle newLexicalEnvCls(thread_, newLexicalEnv->GetClass()); + EXPECT_TRUE(*newLexicalEnv != nullptr); + EXPECT_TRUE(*newLexicalEnvCls != nullptr); } TEST_F(ObjectFactoryTest, NewJSArray) @@ -176,9 +176,9 @@ TEST_F(ObjectFactoryTest, NewJSArray) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // check mem alloc - JSHandle new_js_aarray = factory->NewJSArray(); - JSHandle new_js_array_cls(thread_, new_js_aarray->GetJSHClass()); - EXPECT_TRUE(*new_js_aarray != nullptr); - EXPECT_TRUE(*new_js_array_cls != nullptr); + JSHandle newJsAarray = factory->NewJSArray(); + JSHandle newJsArrayCls(thread_, newJsAarray->GetJSHClass()); + EXPECT_TRUE(*newJsAarray != nullptr); + EXPECT_TRUE(*newJsArrayCls != nullptr); } } // namespace panda::test diff --git a/tests/runtime/common/separate_jsvm_test.cpp b/tests/runtime/common/separate_jsvm_test.cpp index addf830d7f801454908af4dd65c29b8941252dad..685b8fb0794ac8391ef10eaac67e47373bdef415 100644 --- a/tests/runtime/common/separate_jsvm_test.cpp +++ b/tests/runtime/common/separate_jsvm_test.cpp @@ -56,24 +56,24 @@ public: options.SetLoadRuntimes({"ecmascript"}); options.SetRunGcInPlace(true); options.SetGcType("g1-gc"); - EcmaVM *ecma_vm = EcmaVM::Create(options); - ecma_vm->StartGC(); - return ecma_vm; + EcmaVM *ecmaVm = EcmaVM::Create(options); + ecmaVm->StartGC(); + return ecmaVm; } }; TEST_F(SepareteJSVMTest, CreateInstance) { std::function func([this]() { - auto ecma_vm = SepareteJSVMTest::CreateJSVM(); - ASSERT_TRUE(ecma_vm != nullptr); + auto ecmaVm = SepareteJSVMTest::CreateJSVM(); + ASSERT_TRUE(ecmaVm != nullptr); { - auto *thread = ecma_vm->GetAssociatedJSThread(); + auto *thread = ecmaVm->GetAssociatedJSThread(); ScopedManagedCodeThread s(thread); [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread); - JSHandle global_env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle dynclass = global_env->GetObjectFunction(); + JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle dynclass = globalEnv->GetObjectFunction(); JSHandle jsobject = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(dynclass), dynclass); JSHandle jsobject2 = @@ -83,12 +83,12 @@ TEST_F(SepareteJSVMTest, CreateInstance) EXPECT_TRUE(!jsobject->IsCallable()); } - EcmaVM::Destroy(ecma_vm); + EcmaVM::Destroy(ecmaVm); }); - std::thread vm_t1(func); + std::thread vmT1(func); - vm_t1.join(); + vmT1.join(); } } // namespace panda::test diff --git a/tests/runtime/common/symbol_table_test.cpp b/tests/runtime/common/symbol_table_test.cpp index fdf684c3dc2d23748ff161327b2f3e7941961bef..05aad7cff602de22ddccdc0a70a8f1e533eb2bd3 100644 --- a/tests/runtime/common/symbol_table_test.cpp +++ b/tests/runtime/common/symbol_table_test.cpp @@ -91,17 +91,17 @@ TEST_F(SymbolTableTest, IsMatch) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle symbol_table_string = factory->NewFromCanBeCompressString("name"); - JSTaggedValue symbol_table_other = symbol_table_string.GetTaggedValue(); + JSHandle symbolTableString = factory->NewFromCanBeCompressString("name"); + JSTaggedValue symbolTableOther = symbolTableString.GetTaggedValue(); - JSTaggedValue symbol_table_name1 = JSTaggedValue::Hole(); - EXPECT_EQ(SymbolTable::IsMatch(symbol_table_name1, symbol_table_other), false); + JSTaggedValue symbolTableName1 = JSTaggedValue::Hole(); + EXPECT_EQ(SymbolTable::IsMatch(symbolTableName1, symbolTableOther), false); - JSTaggedValue symbol_table_name2 = JSTaggedValue::Undefined(); - EXPECT_EQ(SymbolTable::IsMatch(symbol_table_name2, symbol_table_other), false); + JSTaggedValue symbolTableName2 = JSTaggedValue::Undefined(); + EXPECT_EQ(SymbolTable::IsMatch(symbolTableName2, symbolTableOther), false); - JSTaggedValue symbol_table_name3 = symbol_table_string.GetTaggedValue(); - EXPECT_EQ(SymbolTable::IsMatch(symbol_table_name3, symbol_table_other), true); + JSTaggedValue symbolTableName3 = symbolTableString.GetTaggedValue(); + EXPECT_EQ(SymbolTable::IsMatch(symbolTableName3, symbolTableOther), true); } /* @@ -116,24 +116,24 @@ TEST_F(SymbolTableTest, Hash_Utf8) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // test obj is not string - JSHandle js_ob_ject(factory->NewEmptyJSObject()); - EXPECT_EQ(SymbolTable::Hash(js_ob_ject.GetTaggedValue()), JSSymbol::ComputeHash()); + JSHandle jsObJect(factory->NewEmptyJSObject()); + EXPECT_EQ(SymbolTable::Hash(jsObJect.GetTaggedValue()), JSSymbol::ComputeHash()); // the CompressedStringsEnabled must be true bool flag = EcmaString::GetCompressedStringsEnabled(); EXPECT_EQ(flag, true); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - uint8_t utf8_array_name1[4] = {1, 2, 3}; // The last element is "\0" - uint32_t utf8_array_name_len1 = sizeof(utf8_array_name1) - 1; - JSHandle name_string_utf8_obj1 = factory->NewFromUtf8(utf8_array_name1, utf8_array_name_len1); - EXPECT_EQ(SymbolTable::Hash(name_string_utf8_obj1.GetTaggedValue()), 1026); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 + uint8_t utf8ArrayName1[4] = {1, 2, 3}; // The last element is "\0" + uint32_t utf8ArrayNameLen1 = sizeof(utf8ArrayName1) - 1; + JSHandle nameStringUtf8Obj1 = factory->NewFromUtf8(utf8ArrayName1, utf8ArrayNameLen1); + EXPECT_EQ(SymbolTable::Hash(nameStringUtf8Obj1.GetTaggedValue()), 1026); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 // NOLINTNEXTLINE(modernize-avoid-c-arrays) - uint8_t utf8_array_name2[] = "key"; - uint32_t utf8_array_name_len2 = sizeof(utf8_array_name2) - 1; - JSHandle name_string_utf8_obj2 = factory->NewFromUtf8(utf8_array_name2, utf8_array_name_len2); - EXPECT_EQ(SymbolTable::Hash(name_string_utf8_obj2.GetTaggedValue()), 106079); + uint8_t utf8ArrayName2[] = "key"; + uint32_t utf8ArrayNameLen2 = sizeof(utf8ArrayName2) - 1; + JSHandle nameStringUtf8Obj2 = factory->NewFromUtf8(utf8ArrayName2, utf8ArrayNameLen2); + EXPECT_EQ(SymbolTable::Hash(nameStringUtf8Obj2.GetTaggedValue()), 106079); } /* @@ -149,17 +149,17 @@ TEST_F(SymbolTableTest, Hash_Utf16) ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - uint16_t utf16_array_name1[] = {1, 2, 3}; - uint32_t utf16_array_name_len1 = sizeof(utf16_array_name1) / sizeof(utf16_array_name1[0]); - JSHandle name_string_utf16_obj1 = factory->NewFromUtf16(utf16_array_name1, utf16_array_name_len1); - EXPECT_EQ(SymbolTable::Hash(name_string_utf16_obj1.GetTaggedValue()), + uint16_t utf16ArrayName1[] = {1, 2, 3}; + uint32_t utf16ArrayNameLen1 = sizeof(utf16ArrayName1) / sizeof(utf16ArrayName1[0]); + JSHandle nameStringUtf16Obj1 = factory->NewFromUtf16(utf16ArrayName1, utf16ArrayNameLen1); + EXPECT_EQ(SymbolTable::Hash(nameStringUtf16Obj1.GetTaggedValue()), 1026); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 // NOLINTNEXTLINE(modernize-avoid-c-arrays) - uint16_t utf16_array_name2[] = {0, 1, 2}; - uint32_t utf16_array_name_len2 = sizeof(utf16_array_name2) / sizeof(utf16_array_name2[0]); - JSHandle name_string_utf16_obj2 = factory->NewFromUtf16(utf16_array_name2, utf16_array_name_len2); - EXPECT_EQ(SymbolTable::Hash(name_string_utf16_obj2.GetTaggedValue()), 33); // 33 = (0 << 5 - 0 + 1) << 5 - 1 + 2 + uint16_t utf16ArrayName2[] = {0, 1, 2}; + uint32_t utf16ArrayNameLen2 = sizeof(utf16ArrayName2) / sizeof(utf16ArrayName2[0]); + JSHandle nameStringUtf16Obj2 = factory->NewFromUtf16(utf16ArrayName2, utf16ArrayNameLen2); + EXPECT_EQ(SymbolTable::Hash(nameStringUtf16Obj2.GetTaggedValue()), 33); // 33 = (0 << 5 - 0 + 1) << 5 - 1 + 2 } /* @@ -173,13 +173,13 @@ TEST_F(SymbolTableTest, Hash_Utf16) */ TEST_F(SymbolTableTest, Create) { - int number_of_elements = SymbolTable::DEFAULT_ELEMENTS_NUMBER; + int numberOfElements = SymbolTable::DEFAULT_ELEMENTS_NUMBER; // the CompressedStringsEnabled must be true bool flag = EcmaString::GetCompressedStringsEnabled(); EXPECT_EQ(flag, true); - JSHandle symbol_table = SymbolTable::Create(thread_, number_of_elements); - EXPECT_TRUE(*symbol_table != nullptr); + JSHandle symbolTable = SymbolTable::Create(thread_, numberOfElements); + EXPECT_TRUE(*symbolTable != nullptr); } /* @@ -193,29 +193,29 @@ TEST_F(SymbolTableTest, Create) TEST_F(SymbolTableTest, ContainsKey) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle symbol_table_string_key1 = factory->NewFromCanBeCompressString("key"); - JSHandle symbol_table_string_key2 = factory->NewFromCanBeCompressString("key1"); - JSHandle symbol_table_string_key3 = factory->NewFromCanBeCompressString("value"); + JSHandle symbolTableStringKey1 = factory->NewFromCanBeCompressString("key"); + JSHandle symbolTableStringKey2 = factory->NewFromCanBeCompressString("key1"); + JSHandle symbolTableStringKey3 = factory->NewFromCanBeCompressString("value"); - int number_of_elements = 2; - JSHandle symbol_table = SymbolTable::Create(thread_, number_of_elements); - EXPECT_EQ(symbol_table->ContainsKey(thread_, symbol_table_string_key1.GetTaggedValue()), false); + int numberOfElements = 2; + JSHandle symbolTable = SymbolTable::Create(thread_, numberOfElements); + EXPECT_EQ(symbolTable->ContainsKey(thread_, symbolTableStringKey1.GetTaggedValue()), false); - symbol_table->SetKey(thread_, 1, JSTaggedValue::Hole()); - EXPECT_EQ(symbol_table->ContainsKey(thread_, symbol_table_string_key1.GetTaggedValue()), false); + symbolTable->SetKey(thread_, 1, JSTaggedValue::Hole()); + EXPECT_EQ(symbolTable->ContainsKey(thread_, symbolTableStringKey1.GetTaggedValue()), false); - symbol_table->SetKey(thread_, 1, JSTaggedValue::Undefined()); - EXPECT_EQ(symbol_table->ContainsKey(thread_, symbol_table_string_key1.GetTaggedValue()), false); + symbolTable->SetKey(thread_, 1, JSTaggedValue::Undefined()); + EXPECT_EQ(symbolTable->ContainsKey(thread_, symbolTableStringKey1.GetTaggedValue()), false); - symbol_table->SetKey(thread_, 1, symbol_table_string_key1.GetTaggedValue()); - EXPECT_EQ(symbol_table->ContainsKey(thread_, symbol_table_string_key1.GetTaggedValue()), true); + symbolTable->SetKey(thread_, 1, symbolTableStringKey1.GetTaggedValue()); + EXPECT_EQ(symbolTable->ContainsKey(thread_, symbolTableStringKey1.GetTaggedValue()), true); // the key value has numbers - symbol_table->SetKey(thread_, 1, symbol_table_string_key2.GetTaggedValue()); - EXPECT_EQ(symbol_table->ContainsKey(thread_, symbol_table_string_key2.GetTaggedValue()), false); + symbolTable->SetKey(thread_, 1, symbolTableStringKey2.GetTaggedValue()); + EXPECT_EQ(symbolTable->ContainsKey(thread_, symbolTableStringKey2.GetTaggedValue()), false); - symbol_table->SetKey(thread_, 1, symbol_table_string_key3.GetTaggedValue()); - EXPECT_EQ(symbol_table->ContainsKey(thread_, symbol_table_string_key3.GetTaggedValue()), true); + symbolTable->SetKey(thread_, 1, symbolTableStringKey3.GetTaggedValue()); + EXPECT_EQ(symbolTable->ContainsKey(thread_, symbolTableStringKey3.GetTaggedValue()), true); } /* @@ -229,19 +229,19 @@ TEST_F(SymbolTableTest, ContainsKey) TEST_F(SymbolTableTest, GetSymbol) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - int number_of_elements = 2; + int numberOfElements = 2; - JSHandle symbol_table_string_key = factory->NewFromCanBeCompressString("key"); - JSHandle symbol_table = SymbolTable::Create(thread_, number_of_elements); + JSHandle symbolTableStringKey = factory->NewFromCanBeCompressString("key"); + JSHandle symbolTable = SymbolTable::Create(thread_, numberOfElements); - symbol_table->SetKey(thread_, 1, symbol_table_string_key.GetTaggedValue()); - EXPECT_EQ(symbol_table->GetSymbol(symbol_table_string_key.GetTaggedValue()), JSTaggedValue::Undefined()); + symbolTable->SetKey(thread_, 1, symbolTableStringKey.GetTaggedValue()); + EXPECT_EQ(symbolTable->GetSymbol(symbolTableStringKey.GetTaggedValue()), JSTaggedValue::Undefined()); - symbol_table->SetValue(thread_, 0, JSTaggedValue(1)); - EXPECT_EQ(symbol_table->GetSymbol(symbol_table_string_key.GetTaggedValue()), JSTaggedValue::Undefined()); + symbolTable->SetValue(thread_, 0, JSTaggedValue(1)); + EXPECT_EQ(symbolTable->GetSymbol(symbolTableStringKey.GetTaggedValue()), JSTaggedValue::Undefined()); - symbol_table->SetValue(thread_, 1, JSTaggedValue(1)); - EXPECT_EQ(symbol_table->GetSymbol(symbol_table_string_key.GetTaggedValue()).GetInt(), 1); + symbolTable->SetValue(thread_, 1, JSTaggedValue(1)); + EXPECT_EQ(symbolTable->GetSymbol(symbolTableStringKey.GetTaggedValue()).GetInt(), 1); } /* @@ -257,26 +257,26 @@ TEST_F(SymbolTableTest, GetSymbol) TEST_F(SymbolTableTest, FindSymbol) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle symbol_table_string_key1(factory->NewFromCanBeCompressString("key")); - JSHandle symbol_table_string_key2(factory->NewFromCanBeCompressString("key1")); + JSHandle symbolTableStringKey1(factory->NewFromCanBeCompressString("key")); + JSHandle symbolTableStringKey2(factory->NewFromCanBeCompressString("key1")); - int number_of_elements = 2; - JSHandle handle_symbol = factory->NewJSSymbol(); - JSHandle symbol_table = SymbolTable::Create(thread_, number_of_elements); + int numberOfElements = 2; + JSHandle handleSymbol = factory->NewJSSymbol(); + JSHandle symbolTable = SymbolTable::Create(thread_, numberOfElements); - JSTaggedValue result_value1 = symbol_table->FindSymbol(thread_, handle_symbol.GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue(result_value1, JSTaggedValue::Undefined()), true); + JSTaggedValue resultValue1 = symbolTable->FindSymbol(thread_, handleSymbol.GetTaggedValue()); + EXPECT_EQ(JSTaggedValue::SameValue(resultValue1, JSTaggedValue::Undefined()), true); - handle_symbol->SetDescription(thread_, symbol_table_string_key1.GetTaggedValue()); - JSTaggedValue result_value2 = symbol_table->FindSymbol(thread_, handle_symbol.GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue(result_value2, JSTaggedValue::Undefined()), true); + handleSymbol->SetDescription(thread_, symbolTableStringKey1.GetTaggedValue()); + JSTaggedValue resultValue2 = symbolTable->FindSymbol(thread_, handleSymbol.GetTaggedValue()); + EXPECT_EQ(JSTaggedValue::SameValue(resultValue2, JSTaggedValue::Undefined()), true); - symbol_table->SetKey(thread_, 1, symbol_table_string_key1.GetTaggedValue()); - JSTaggedValue result_value3 = symbol_table->FindSymbol(thread_, handle_symbol.GetTaggedValue()); - EXPECT_EQ(result_value3.GetRawData() == symbol_table_string_key1.GetTaggedValue().GetRawData(), true); + symbolTable->SetKey(thread_, 1, symbolTableStringKey1.GetTaggedValue()); + JSTaggedValue resultValue3 = symbolTable->FindSymbol(thread_, handleSymbol.GetTaggedValue()); + EXPECT_EQ(resultValue3.GetRawData() == symbolTableStringKey1.GetTaggedValue().GetRawData(), true); - symbol_table->SetKey(thread_, 1, symbol_table_string_key2.GetTaggedValue()); - JSTaggedValue result_value4 = symbol_table->FindSymbol(thread_, handle_symbol.GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue(result_value4, JSTaggedValue::Undefined()), true); + symbolTable->SetKey(thread_, 1, symbolTableStringKey2.GetTaggedValue()); + JSTaggedValue resultValue4 = symbolTable->FindSymbol(thread_, handleSymbol.GetTaggedValue()); + EXPECT_EQ(JSTaggedValue::SameValue(resultValue4, JSTaggedValue::Undefined()), true); } } // namespace panda::test diff --git a/tests/runtime/common/tagged_value_test.cpp b/tests/runtime/common/tagged_value_test.cpp index d1370d21b852a9c7aba44947462ba9517f4aca25..50433087ececcd17179941036275563f06294905 100644 --- a/tests/runtime/common/tagged_value_test.cpp +++ b/tests/runtime/common/tagged_value_test.cpp @@ -67,14 +67,14 @@ TEST_F(JSTaggedValueTest, Double) ASSERT_DOUBLE_EQ(td.GetDouble(), d); double nan = std::nan(""); - JSTaggedValue t_nan(nan); - EXPECT_EQ(true, t_nan.IsDouble()); - EXPECT_EQ(false, t_nan.IsInt()); - EXPECT_EQ(false, t_nan.IsObject()); - EXPECT_EQ(ReinterpretDoubleToTaggedType(t_nan.GetDouble()), ReinterpretDoubleToTaggedType(nan)); - - double pure_na_n = ReinterpretTaggedTypeToDouble(JSTaggedValue::TAG_INT - JSTaggedValue::DOUBLE_ENCODE_OFFSET); - EXPECT_EQ(true, JSTaggedValue::IsImpureNaN(pure_na_n)); + JSTaggedValue tNan(nan); + EXPECT_EQ(true, tNan.IsDouble()); + EXPECT_EQ(false, tNan.IsInt()); + EXPECT_EQ(false, tNan.IsObject()); + EXPECT_EQ(ReinterpretDoubleToTaggedType(tNan.GetDouble()), ReinterpretDoubleToTaggedType(nan)); + + double pureNaN = ReinterpretTaggedTypeToDouble(JSTaggedValue::TAG_INT - JSTaggedValue::DOUBLE_ENCODE_OFFSET); + EXPECT_EQ(true, JSTaggedValue::IsImpureNaN(pureNaN)); } TEST_F(JSTaggedValueTest, Int) @@ -130,32 +130,32 @@ TEST_F(JSTaggedValueTest, ToPrimitive) { JSTaggedValue result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result.GetInt(), 100); - JSTaggedValue double_v((double)100.0); - result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, double_v)); + JSTaggedValue doubleV((double)100.0); + result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, doubleV)); EXPECT_EQ(result.GetDouble(), (double)100.0); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, undefinedV)); EXPECT_TRUE(result.IsUndefined()); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, holeV)); EXPECT_TRUE(result.IsHole()); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, nullV)); EXPECT_TRUE(result.IsNull()); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, falseV)); EXPECT_TRUE(result.IsFalse()); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToPrimitive(thread_, JSHandle(thread_, trueV)); EXPECT_TRUE(result.IsTrue()); } @@ -184,161 +184,161 @@ TEST_F(JSTaggedValueTest, ToNumber) { JSTaggedNumber result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result.GetNumber(), 100); - JSTaggedValue double_v((double)100.0); - result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, double_v)); + JSTaggedValue doubleV((double)100.0); + result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, doubleV)); EXPECT_EQ(result.GetNumber(), (double)100.0); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, undefinedV)); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, holeV)); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToNumber(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result.GetNumber(), 1); - JSHandle string_v0(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 1234 ")); - result = JSTaggedValue::ToNumber(thread_, string_v0); + JSHandle stringV0(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 1234 ")); + result = JSTaggedValue::ToNumber(thread_, stringV0); EXPECT_EQ(result.GetNumber(), 1234); - JSHandle string_v1(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0b1010 ")); - result = JSTaggedValue::ToNumber(thread_, string_v1); + JSHandle stringV1(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0b1010 ")); + result = JSTaggedValue::ToNumber(thread_, stringV1); EXPECT_EQ(result.GetNumber(), 10); - JSHandle string_v2(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0O11 ")); - result = JSTaggedValue::ToNumber(thread_, string_v2); + JSHandle stringV2(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0O11 ")); + result = JSTaggedValue::ToNumber(thread_, stringV2); EXPECT_EQ(result.GetNumber(), 9); - JSHandle string_v3(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0x2d ")); - result = JSTaggedValue::ToNumber(thread_, string_v3); + JSHandle stringV3(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0x2d ")); + result = JSTaggedValue::ToNumber(thread_, stringV3); EXPECT_EQ(result.GetNumber(), 45); - JSHandle string_v4(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0.000001 ")); - result = JSTaggedValue::ToNumber(thread_, string_v4); + JSHandle stringV4(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0.000001 ")); + result = JSTaggedValue::ToNumber(thread_, stringV4); EXPECT_EQ(result.GetNumber(), 0.000001); - JSHandle string_v5(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 1.23 ")); - result = JSTaggedValue::ToNumber(thread_, string_v5); + JSHandle stringV5(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 1.23 ")); + result = JSTaggedValue::ToNumber(thread_, stringV5); EXPECT_EQ(result.GetNumber(), 1.23); - JSHandle string_v6(thread_->GetEcmaVM()->GetFactory()->NewFromString(" -1.23e2 ")); - result = JSTaggedValue::ToNumber(thread_, string_v6); + JSHandle stringV6(thread_->GetEcmaVM()->GetFactory()->NewFromString(" -1.23e2 ")); + result = JSTaggedValue::ToNumber(thread_, stringV6); EXPECT_EQ(result.GetNumber(), -123); - JSHandle string_v7(thread_->GetEcmaVM()->GetFactory()->NewFromString(" -123e-2")); - result = JSTaggedValue::ToNumber(thread_, string_v7); + JSHandle stringV7(thread_->GetEcmaVM()->GetFactory()->NewFromString(" -123e-2")); + result = JSTaggedValue::ToNumber(thread_, stringV7); EXPECT_EQ(result.GetNumber(), -1.23); - JSHandle string_v8(thread_->GetEcmaVM()->GetFactory()->NewFromString(" Infinity ")); - result = JSTaggedValue::ToNumber(thread_, string_v8); + JSHandle stringV8(thread_->GetEcmaVM()->GetFactory()->NewFromString(" Infinity ")); + result = JSTaggedValue::ToNumber(thread_, stringV8); EXPECT_TRUE(std::isinf(result.GetNumber())); - JSHandle string_v9(thread_->GetEcmaVM()->GetFactory()->NewFromString("100e307")); - result = JSTaggedValue::ToNumber(thread_, string_v9); + JSHandle stringV9(thread_->GetEcmaVM()->GetFactory()->NewFromString("100e307")); + result = JSTaggedValue::ToNumber(thread_, stringV9); EXPECT_TRUE(std::isinf(result.GetNumber())); - JSHandle string_v10(thread_->GetEcmaVM()->GetFactory()->NewFromString(" .")); - result = JSTaggedValue::ToNumber(thread_, string_v10); + JSHandle stringV10(thread_->GetEcmaVM()->GetFactory()->NewFromString(" .")); + result = JSTaggedValue::ToNumber(thread_, stringV10); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v11(thread_->GetEcmaVM()->GetFactory()->NewFromString("12e+")); - result = JSTaggedValue::ToNumber(thread_, string_v11); + JSHandle stringV11(thread_->GetEcmaVM()->GetFactory()->NewFromString("12e+")); + result = JSTaggedValue::ToNumber(thread_, stringV11); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v12(thread_->GetEcmaVM()->GetFactory()->NewFromString(".e3")); - result = JSTaggedValue::ToNumber(thread_, string_v12); + JSHandle stringV12(thread_->GetEcmaVM()->GetFactory()->NewFromString(".e3")); + result = JSTaggedValue::ToNumber(thread_, stringV12); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v13(thread_->GetEcmaVM()->GetFactory()->NewFromString("23eE")); - result = JSTaggedValue::ToNumber(thread_, string_v13); + JSHandle stringV13(thread_->GetEcmaVM()->GetFactory()->NewFromString("23eE")); + result = JSTaggedValue::ToNumber(thread_, stringV13); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v14(thread_->GetEcmaVM()->GetFactory()->NewFromString("a")); - result = JSTaggedValue::ToNumber(thread_, string_v14); + JSHandle stringV14(thread_->GetEcmaVM()->GetFactory()->NewFromString("a")); + result = JSTaggedValue::ToNumber(thread_, stringV14); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v15(thread_->GetEcmaVM()->GetFactory()->NewFromString("0o12e3")); - result = JSTaggedValue::ToNumber(thread_, string_v15); + JSHandle stringV15(thread_->GetEcmaVM()->GetFactory()->NewFromString("0o12e3")); + result = JSTaggedValue::ToNumber(thread_, stringV15); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v16(thread_->GetEcmaVM()->GetFactory()->NewFromString("0x12.3")); - result = JSTaggedValue::ToNumber(thread_, string_v16); + JSHandle stringV16(thread_->GetEcmaVM()->GetFactory()->NewFromString("0x12.3")); + result = JSTaggedValue::ToNumber(thread_, stringV16); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v17(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 12.4.")); - result = JSTaggedValue::ToNumber(thread_, string_v17); + JSHandle stringV17(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 12.4.")); + result = JSTaggedValue::ToNumber(thread_, stringV17); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v18(thread_->GetEcmaVM()->GetFactory()->NewFromString("123test")); - result = JSTaggedValue::ToNumber(thread_, string_v18); + JSHandle stringV18(thread_->GetEcmaVM()->GetFactory()->NewFromString("123test")); + result = JSTaggedValue::ToNumber(thread_, stringV18); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v19(thread_->GetEcmaVM()->GetFactory()->NewFromString("123test")); - result = JSTaggedValue::ToNumber(thread_, string_v19); + JSHandle stringV19(thread_->GetEcmaVM()->GetFactory()->NewFromString("123test")); + result = JSTaggedValue::ToNumber(thread_, stringV19); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v20(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0b ")); - result = JSTaggedValue::ToNumber(thread_, string_v20); + JSHandle stringV20(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0b ")); + result = JSTaggedValue::ToNumber(thread_, stringV20); EXPECT_TRUE(std::isnan(result.GetNumber())); - JSHandle string_v21(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0b0000 ")); - result = JSTaggedValue::ToNumber(thread_, string_v21); + JSHandle stringV21(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0b0000 ")); + result = JSTaggedValue::ToNumber(thread_, stringV21); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v22(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0o0000 ")); - result = JSTaggedValue::ToNumber(thread_, string_v22); + JSHandle stringV22(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0o0000 ")); + result = JSTaggedValue::ToNumber(thread_, stringV22); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v23(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0X0000 ")); - result = JSTaggedValue::ToNumber(thread_, string_v23); + JSHandle stringV23(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0X0000 ")); + result = JSTaggedValue::ToNumber(thread_, stringV23); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v24(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 000.00000 ")); - result = JSTaggedValue::ToNumber(thread_, string_v24); + JSHandle stringV24(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 000.00000 ")); + result = JSTaggedValue::ToNumber(thread_, stringV24); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v25(thread_->GetEcmaVM()->GetFactory()->NewFromString("")); - result = JSTaggedValue::ToNumber(thread_, string_v25); + JSHandle stringV25(thread_->GetEcmaVM()->GetFactory()->NewFromString("")); + result = JSTaggedValue::ToNumber(thread_, stringV25); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v26(thread_->GetEcmaVM()->GetFactory()->NewFromString(" ")); - result = JSTaggedValue::ToNumber(thread_, string_v26); + JSHandle stringV26(thread_->GetEcmaVM()->GetFactory()->NewFromString(" ")); + result = JSTaggedValue::ToNumber(thread_, stringV26); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v27(thread_->GetEcmaVM()->GetFactory()->NewFromString("0")); - result = JSTaggedValue::ToNumber(thread_, string_v27); + JSHandle stringV27(thread_->GetEcmaVM()->GetFactory()->NewFromString("0")); + result = JSTaggedValue::ToNumber(thread_, stringV27); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v28(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0 ")); - result = JSTaggedValue::ToNumber(thread_, string_v28); + JSHandle stringV28(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 0 ")); + result = JSTaggedValue::ToNumber(thread_, stringV28); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v29(thread_->GetEcmaVM()->GetFactory()->NewFromString("00000000")); - result = JSTaggedValue::ToNumber(thread_, string_v29); + JSHandle stringV29(thread_->GetEcmaVM()->GetFactory()->NewFromString("00000000")); + result = JSTaggedValue::ToNumber(thread_, stringV29); EXPECT_EQ(result.GetNumber(), 0); - JSHandle string_v30(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 00000000 ")); - result = JSTaggedValue::ToNumber(thread_, string_v30); + JSHandle stringV30(thread_->GetEcmaVM()->GetFactory()->NewFromString(" 00000000 ")); + result = JSTaggedValue::ToNumber(thread_, stringV30); EXPECT_EQ(result.GetNumber(), 0); thread_->ClearException(); - JSHandle symbol_v1(thread_->GetEcmaVM()->GetFactory()->NewJSSymbol()); - JSTaggedValue::ToNumber(thread_, symbol_v1); + JSHandle symbolV1(thread_->GetEcmaVM()->GetFactory()->NewJSSymbol()); + JSTaggedValue::ToNumber(thread_, symbolV1); EXPECT_TRUE(thread_->HasPendingException()); EXPECT_TRUE(thread_->GetException().IsJSError()); } @@ -347,36 +347,36 @@ TEST_F(JSTaggedValueTest, ToInteger) { JSTaggedNumber result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result.GetNumber(), 100); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result.GetNumber(), (double)100.0); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result.GetNumber(), (double)100); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToInteger(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result.GetNumber(), 1); } @@ -384,51 +384,51 @@ TEST_F(JSTaggedValueTest, ToInt32) { int32_t result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result, 100); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result, 100); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result, 100); - double input_1 = (static_cast(UINT32_MAX) + 1) + 12345; - JSTaggedValue double_v3(input_1); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, double_v3)); + double input1 = (static_cast(UINT32_MAX) + 1) + 12345; + JSTaggedValue doubleV3(input1); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result, 12345); - double input_2 = 100 * (static_cast(UINT32_MAX) + 1) + 23456; - JSTaggedValue double_v4(input_2); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, double_v4)); + double input2 = 100 * (static_cast(UINT32_MAX) + 1) + 23456; + JSTaggedValue doubleV4(input2); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result, 23456); - double input_3 = 100 * (static_cast(UINT32_MAX) + 1) + INT32_MAX + 1 + 23456; - JSTaggedValue double_v5(input_3); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, double_v5)); + double input3 = 100 * (static_cast(UINT32_MAX) + 1) + INT32_MAX + 1 + 23456; + JSTaggedValue doubleV5(input3); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, doubleV5)); EXPECT_EQ(result, 23456 - static_cast(INT32_MAX) - 1); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result, 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result, 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result, 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result, 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToInt32(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result, 1); } @@ -436,51 +436,51 @@ TEST_F(JSTaggedValueTest, ToUint32) { uint32_t result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result, 100); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result, 100); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result, 100); - double input_1 = (static_cast(UINT32_MAX) + 1) + 12345; - JSTaggedValue double_v3(input_1); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, double_v3)); + double input1 = (static_cast(UINT32_MAX) + 1) + 12345; + JSTaggedValue doubleV3(input1); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result, 12345); - double input_2 = 100 * (static_cast(UINT32_MAX) + 1) + 23456; - JSTaggedValue double_v4(input_2); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, double_v4)); + double input2 = 100 * (static_cast(UINT32_MAX) + 1) + 23456; + JSTaggedValue doubleV4(input2); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result, 23456); - double input_3 = 100 * (static_cast(UINT32_MAX) + 1) + INT32_MAX + 1 + 23456; - JSTaggedValue double_v5(input_3); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, double_v5)); + double input3 = 100 * (static_cast(UINT32_MAX) + 1) + INT32_MAX + 1 + 23456; + JSTaggedValue doubleV5(input3); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, doubleV5)); EXPECT_EQ(result, static_cast(INT32_MAX) + 1 + 23456); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result, 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result, 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result, 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result, 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToUint32(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result, 1); } @@ -488,51 +488,51 @@ TEST_F(JSTaggedValueTest, ToInt16) { int32_t result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result, 100); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result, 100); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result, 100); - double input_1 = (static_cast(UINT16_MAX) + 1) + 12345; - JSTaggedValue double_v3(input_1); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, double_v3)); + double input1 = (static_cast(UINT16_MAX) + 1) + 12345; + JSTaggedValue doubleV3(input1); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result, 12345); - double input_2 = 100 * (static_cast(UINT16_MAX) + 1) + 23456; - JSTaggedValue double_v4(input_2); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, double_v4)); + double input2 = 100 * (static_cast(UINT16_MAX) + 1) + 23456; + JSTaggedValue doubleV4(input2); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result, 23456); - double input_3 = 100 * (static_cast(UINT16_MAX) + 1) + INT16_MAX + 1 + 23456; - JSTaggedValue double_v5(input_3); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, double_v5)); + double input3 = 100 * (static_cast(UINT16_MAX) + 1) + INT16_MAX + 1 + 23456; + JSTaggedValue doubleV5(input3); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, doubleV5)); EXPECT_EQ(result, 23456 - static_cast(INT16_MAX) - 1); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result, 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result, 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result, 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result, 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToInt16(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result, 1); } @@ -540,51 +540,51 @@ TEST_F(JSTaggedValueTest, ToUint16) { uint32_t result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result, 100); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result, 100); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result, 100); - double input_1 = (static_cast(UINT16_MAX) + 1) + 12345; - JSTaggedValue double_v3(input_1); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, double_v3)); + double input1 = (static_cast(UINT16_MAX) + 1) + 12345; + JSTaggedValue doubleV3(input1); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result, 12345); - double input_2 = 100 * (static_cast(UINT16_MAX) + 1) + 23456; - JSTaggedValue double_v4(input_2); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, double_v4)); + double input2 = 100 * (static_cast(UINT16_MAX) + 1) + 23456; + JSTaggedValue doubleV4(input2); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result, 23456); - double input_3 = 100 * (static_cast(UINT16_MAX) + 1) + INT16_MAX + 1 + 23456; - JSTaggedValue double_v5(input_3); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, double_v5)); + double input3 = 100 * (static_cast(UINT16_MAX) + 1) + INT16_MAX + 1 + 23456; + JSTaggedValue doubleV5(input3); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, doubleV5)); EXPECT_EQ(result, static_cast(INT16_MAX) + 1 + 23456); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result, 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result, 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result, 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result, 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToUint16(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result, 1); } @@ -592,51 +592,51 @@ TEST_F(JSTaggedValueTest, ToInt8) { int32_t result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result, 100); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result, 100); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result, 100); - double input_1 = (static_cast(UINT8_MAX) + 1) + 45; - JSTaggedValue double_v3(input_1); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, double_v3)); + double input1 = (static_cast(UINT8_MAX) + 1) + 45; + JSTaggedValue doubleV3(input1); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result, 45); - double input_2 = 100 * (static_cast(UINT8_MAX) + 1) + 56; - JSTaggedValue double_v4(input_2); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, double_v4)); + double input2 = 100 * (static_cast(UINT8_MAX) + 1) + 56; + JSTaggedValue doubleV4(input2); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result, 56); - double input_3 = 100 * (static_cast(UINT8_MAX) + 1) + INT8_MAX + 1 + 23; - JSTaggedValue double_v5(input_3); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, double_v5)); + double input3 = 100 * (static_cast(UINT8_MAX) + 1) + INT8_MAX + 1 + 23; + JSTaggedValue doubleV5(input3); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, doubleV5)); EXPECT_EQ(result, 23 - static_cast(INT8_MAX) - 1); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result, 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result, 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result, 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result, 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToInt8(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result, 1); } @@ -644,51 +644,51 @@ TEST_F(JSTaggedValueTest, ToUint8) { uint32_t result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result, 100); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result, 100); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result, 100); - double input_1 = (static_cast(UINT8_MAX) + 1) + 34; - JSTaggedValue double_v3(input_1); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, double_v3)); + double input1 = (static_cast(UINT8_MAX) + 1) + 34; + JSTaggedValue doubleV3(input1); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result, 34); - double input_2 = 100 * (static_cast(UINT8_MAX) + 1) + 45; - JSTaggedValue double_v4(input_2); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, double_v4)); + double input2 = 100 * (static_cast(UINT8_MAX) + 1) + 45; + JSTaggedValue doubleV4(input2); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result, 45); - double input_3 = 100 * (static_cast(UINT8_MAX) + 1) + INT8_MAX + 1 + 56; - JSTaggedValue double_v5(input_3); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, double_v5)); + double input3 = 100 * (static_cast(UINT8_MAX) + 1) + INT8_MAX + 1 + 56; + JSTaggedValue doubleV5(input3); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, doubleV5)); EXPECT_EQ(result, static_cast(INT8_MAX) + 1 + 56); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result, 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result, 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result, 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result, 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToUint8(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result, 1); } @@ -696,56 +696,56 @@ TEST_F(JSTaggedValueTest, ToUint8Clamp) { uint32_t result; - JSTaggedValue int_v1(-100); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, int_v1)); + JSTaggedValue intV1(-100); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, intV1)); EXPECT_EQ(result, 0); - JSTaggedValue int_v2(100); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, int_v2)); + JSTaggedValue intV2(100); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, intV2)); EXPECT_EQ(result, 100); - JSTaggedValue int_v3(300); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, int_v3)); + JSTaggedValue intV3(300); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, intV3)); EXPECT_EQ(result, 255); - JSTaggedValue double_v1((double)-100.123); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)-100.123); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result, 0); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result, 100); - JSTaggedValue double_v3((double)100.55); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, double_v3)); + JSTaggedValue doubleV3((double)100.55); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result, 101); - JSTaggedValue double_v4((double)99.9); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, double_v4)); + JSTaggedValue doubleV4((double)99.9); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result, 100); - JSTaggedValue double_v5((double)300.5); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, double_v5)); + JSTaggedValue doubleV5((double)300.5); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, doubleV5)); EXPECT_EQ(result, 255); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result, 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result, 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result, 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result, 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToUint8Clamp(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result, 1); } @@ -758,60 +758,60 @@ TEST_F(JSTaggedValueTest, ToPropertyKey) EXPECT_TRUE(key == result); } -void CheckOkString(JSThread *thread, const JSHandle &tagged, PandaString &right_c_str) +void CheckOkString(JSThread *thread, const JSHandle &tagged, PandaString &rightCStr) { JSHandle result = JSTaggedValue::ToString(thread, tagged); - JSHandle right_string = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(right_c_str); + JSHandle rightString = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(rightCStr); EXPECT_TRUE(EcmaString::StringsAreEqual(EcmaString::Cast(result.GetObject()), - EcmaString::Cast(right_string.GetObject()))); + EcmaString::Cast(rightString.GetObject()))); } TEST_F(JSTaggedValueTest, ToString) { - PandaString right_c_str; - CheckOkString(thread_, JSHandle(thread_, JSTaggedValue()), right_c_str); + PandaString rightCStr; + CheckOkString(thread_, JSHandle(thread_, JSTaggedValue()), rightCStr); - right_c_str = "undefined"; - CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::Undefined()), right_c_str); + rightCStr = "undefined"; + CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::Undefined()), rightCStr); - right_c_str = "null"; - CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::Null()), right_c_str); + rightCStr = "null"; + CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::Null()), rightCStr); - right_c_str = "true"; - CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::True()), right_c_str); + rightCStr = "true"; + CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::True()), rightCStr); - right_c_str = "false"; - CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::False()), right_c_str); + rightCStr = "false"; + CheckOkString(thread_, JSHandle(thread_, JSTaggedValue::False()), rightCStr); - right_c_str = "hello world"; + rightCStr = "hello world"; CheckOkString(thread_, - JSHandle(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(right_c_str)), - right_c_str); + JSHandle(thread_->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(rightCStr)), + rightCStr); double num = 1; - auto number_num = JSTaggedNumber(num); - right_c_str = "1"; - CheckOkString(thread_, JSHandle(thread_, number_num), right_c_str); + auto numberNum = JSTaggedNumber(num); + rightCStr = "1"; + CheckOkString(thread_, JSHandle(thread_, numberNum), rightCStr); num = 1.23; - number_num = JSTaggedNumber(num); - right_c_str = "1.23"; - CheckOkString(thread_, JSHandle(thread_, number_num), right_c_str); + numberNum = JSTaggedNumber(num); + rightCStr = "1.23"; + CheckOkString(thread_, JSHandle(thread_, numberNum), rightCStr); - int num_int = 2; - JSHandle value1(thread_, JSTaggedValue(num_int)); - right_c_str = "2"; - CheckOkString(thread_, JSHandle::Cast(JSTaggedValue::ToObject(thread_, value1)), right_c_str); + int numInt = 2; + JSHandle value1(thread_, JSTaggedValue(numInt)); + rightCStr = "2"; + CheckOkString(thread_, JSHandle::Cast(JSTaggedValue::ToObject(thread_, value1)), rightCStr); num = 1.23; JSHandle value2(thread_, JSTaggedValue(num)); - right_c_str = "1.23"; - CheckOkString(thread_, JSHandle::Cast(JSTaggedValue::ToObject(thread_, value2)), right_c_str); + rightCStr = "1.23"; + CheckOkString(thread_, JSHandle::Cast(JSTaggedValue::ToObject(thread_, value2)), rightCStr); - bool value_bool = true; - JSHandle value3(thread_, JSTaggedValue(value_bool)); - right_c_str = "true"; - CheckOkString(thread_, JSHandle::Cast(JSTaggedValue::ToObject(thread_, value3)), right_c_str); + bool valueBool = true; + JSHandle value3(thread_, JSTaggedValue(valueBool)); + rightCStr = "true"; + CheckOkString(thread_, JSHandle::Cast(JSTaggedValue::ToObject(thread_, value3)), rightCStr); } TEST_F(JSTaggedValueTest, CanonicalNumericIndexString) @@ -819,16 +819,16 @@ TEST_F(JSTaggedValueTest, CanonicalNumericIndexString) JSTaggedValue result; JSHandle str = thread_->GetEcmaVM()->GetFactory()->NewFromString("-0"); - JSTaggedValue tmp_str = str.GetTaggedValue(); - result = JSTaggedValue::CanonicalNumericIndexString(thread_, JSHandle(thread_, tmp_str)); + JSTaggedValue tmpStr = str.GetTaggedValue(); + result = JSTaggedValue::CanonicalNumericIndexString(thread_, JSHandle(thread_, tmpStr)); EXPECT_EQ(result.GetDouble(), -0.0); - JSTaggedValue tmp_int(1); - result = JSTaggedValue::CanonicalNumericIndexString(thread_, JSHandle(thread_, tmp_int)); + JSTaggedValue tmpInt(1); + result = JSTaggedValue::CanonicalNumericIndexString(thread_, JSHandle(thread_, tmpInt)); EXPECT_TRUE(result.IsUndefined()); - JSTaggedValue tmp_double((double)100.0); - result = JSTaggedValue::CanonicalNumericIndexString(thread_, JSHandle(thread_, tmp_double)); + JSTaggedValue tmpDouble((double)100.0); + result = JSTaggedValue::CanonicalNumericIndexString(thread_, JSHandle(thread_, tmpDouble)); EXPECT_TRUE(result.IsUndefined()); } @@ -874,70 +874,70 @@ TEST_F(JSTaggedValueTest, ToObject) // JSObject(include all types of objects inherited from JSObject) -> JSObject EcmaVM *ecma = thread_->GetEcmaVM(); - JSHandle object_fun = ecma->GetGlobalEnv()->GetObjectFunction(); - JSHandle js_obj = factory->NewJSObjectByConstructor(JSHandle(object_fun), object_fun); - JSHandle value(js_obj); - EXPECT_EQ(*JSTaggedValue::ToObject(thread_, value), *js_obj); + JSHandle objectFun = ecma->GetGlobalEnv()->GetObjectFunction(); + JSHandle jsObj = factory->NewJSObjectByConstructor(JSHandle(objectFun), objectFun); + JSHandle value(jsObj); + EXPECT_EQ(*JSTaggedValue::ToObject(thread_, value), *jsObj); } TEST_F(JSTaggedValueTest, ToLength) { JSTaggedNumber result; - JSTaggedValue int_v(100); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, int_v)); + JSTaggedValue intV(100); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, intV)); EXPECT_EQ(result.GetNumber(), 100); - JSTaggedValue int_v2(-1); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, int_v2)); + JSTaggedValue intV2(-1); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, intV2)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue double_v1((double)100.0); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, double_v1)); + JSTaggedValue doubleV1((double)100.0); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, doubleV1)); EXPECT_EQ(result.GetNumber(), (double)100.0); - JSTaggedValue double_v2((double)100.123); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, double_v2)); + JSTaggedValue doubleV2((double)100.123); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, doubleV2)); EXPECT_EQ(result.GetNumber(), (double)100); - JSTaggedValue double_v3((double)-1.0); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, double_v3)); + JSTaggedValue doubleV3((double)-1.0); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, doubleV3)); EXPECT_EQ(result.GetNumber(), (double)0); - JSTaggedValue double_v4((double)9007199254740992); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, double_v4)); + JSTaggedValue doubleV4((double)9007199254740992); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, doubleV4)); EXPECT_EQ(result.GetNumber(), (double)9007199254740991); - JSTaggedValue undefined_v = JSTaggedValue::Undefined(); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, undefined_v)); + JSTaggedValue undefinedV = JSTaggedValue::Undefined(); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, undefinedV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue hole_v = JSTaggedValue::Hole(); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, hole_v)); + JSTaggedValue holeV = JSTaggedValue::Hole(); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, holeV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue null_v = JSTaggedValue::Null(); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, null_v)); + JSTaggedValue nullV = JSTaggedValue::Null(); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, nullV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue false_v = JSTaggedValue::False(); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, false_v)); + JSTaggedValue falseV = JSTaggedValue::False(); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, falseV)); EXPECT_EQ(result.GetNumber(), 0); - JSTaggedValue true_v = JSTaggedValue::True(); - result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, true_v)); + JSTaggedValue trueV = JSTaggedValue::True(); + result = JSTaggedValue::ToLength(thread_, JSHandle(thread_, trueV)); EXPECT_EQ(result.GetNumber(), 1); } TEST_F(JSTaggedValueTest, IsArray) { EcmaVM *ecma = thread_->GetEcmaVM(); - JSHandle object_fun = ecma->GetGlobalEnv()->GetArrayFunction(); + JSHandle objectFun = ecma->GetGlobalEnv()->GetArrayFunction(); - JSHandle js_obj = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(object_fun), object_fun); + JSHandle jsObj = + thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objectFun), objectFun); - ASSERT_TRUE(js_obj->IsJSArray()); + ASSERT_TRUE(jsObj->IsJSArray()); ASSERT_FALSE(JSTaggedValue(1).IsArray(thread_)); ASSERT_FALSE(thread_->GetEcmaVM()->GetFactory()->NewFromString("test").GetTaggedValue().IsArray(thread_)); @@ -946,17 +946,17 @@ TEST_F(JSTaggedValueTest, IsArray) TEST_F(JSTaggedValueTest, IsCallable_IsConstructor_IsExtensible) { JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle js_function = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env); - JSHClass *js_hclass = js_function->GetJSHClass(); - ASSERT_TRUE(js_function->IsCallable()); - js_hclass->SetConstructor(true); - ASSERT_TRUE(js_function->IsConstructor()); - js_hclass->SetConstructor(false); - ASSERT_FALSE(js_function->IsConstructor()); - js_hclass->SetExtensible(true); - ASSERT_TRUE(js_function->IsExtensible()); - js_hclass->SetExtensible(false); - ASSERT_FALSE(js_function->IsExtensible()); + JSHandle jsFunction = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env); + JSHClass *jsHclass = jsFunction->GetJSHClass(); + ASSERT_TRUE(jsFunction->IsCallable()); + jsHclass->SetConstructor(true); + ASSERT_TRUE(jsFunction->IsConstructor()); + jsHclass->SetConstructor(false); + ASSERT_FALSE(jsFunction->IsConstructor()); + jsHclass->SetExtensible(true); + ASSERT_TRUE(jsFunction->IsExtensible()); + jsHclass->SetExtensible(false); + ASSERT_FALSE(jsFunction->IsExtensible()); ASSERT_FALSE(JSTaggedValue(1).IsExtensible(thread_)); ASSERT_FALSE(JSTaggedValue(1).IsConstructor()); ASSERT_FALSE(JSTaggedValue(1).IsCallable()); @@ -997,19 +997,18 @@ TEST_F(JSTaggedValueTest, IsRegExp) TEST_F(JSTaggedValueTest, SameValue) { EcmaVM *ecma = thread_->GetEcmaVM(); - JSHandle object_fun = ecma->GetGlobalEnv()->GetObjectFunction(); + JSHandle objectFun = ecma->GetGlobalEnv()->GetObjectFunction(); - JSHandle js_obj = - ecma->GetFactory()->NewJSObjectByConstructor(JSHandle(object_fun), object_fun); + JSHandle jsObj = ecma->GetFactory()->NewJSObjectByConstructor(JSHandle(objectFun), objectFun); // not same type ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue::False())); ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1.0), JSTaggedValue::True())); ASSERT_FALSE( JSTaggedValue::SameValue(JSTaggedValue(1), ecma->GetFactory()->NewFromString("test").GetTaggedValue())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue(*js_obj))); + ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue(*jsObj))); JSHandle test(ecma->GetFactory()->NewFromString("test")); - ASSERT_FALSE(JSTaggedValue::SameValue(test.GetTaggedValue(), JSTaggedValue(*js_obj))); + ASSERT_FALSE(JSTaggedValue::SameValue(test.GetTaggedValue(), JSTaggedValue(*jsObj))); // number compare ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue(1))); @@ -1036,7 +1035,7 @@ TEST_F(JSTaggedValueTest, SameValue) ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue::True(), JSTaggedValue::False())); // js object compare - ASSERT_TRUE(JSTaggedValue::SameValue(js_obj.GetTaggedValue(), js_obj.GetTaggedValue())); + ASSERT_TRUE(JSTaggedValue::SameValue(jsObj.GetTaggedValue(), jsObj.GetTaggedValue())); // undefined or null compare ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue::Undefined(), JSTaggedValue::Undefined())); @@ -1128,19 +1127,19 @@ TEST_F(JSTaggedValueTest, Equal) JSHandle test1(thread_->GetEcmaVM()->GetFactory()->NewFromString("test1")); JSHandle empty(thread_->GetEcmaVM()->GetFactory()->NewFromString("")); JSHandle char0(thread_->GetEcmaVM()->GetFactory()->NewFromString("0")); - JSHandle char0_point_0(thread_->GetEcmaVM()->GetFactory()->NewFromString("0.0")); + JSHandle char0Point0(thread_->GetEcmaVM()->GetFactory()->NewFromString("0.0")); JSHandle char1(thread_->GetEcmaVM()->GetFactory()->NewFromString("1")); - JSHandle char1_point_0(thread_->GetEcmaVM()->GetFactory()->NewFromString("1.0")); - JSHandle char_1(thread_->GetEcmaVM()->GetFactory()->NewFromString("-1")); - JSHandle char_0_point_0(thread_->GetEcmaVM()->GetFactory()->NewFromString("-0.0")); - JSHandle char_0_point_1(thread_->GetEcmaVM()->GetFactory()->NewFromString("-0.1")); + JSHandle char1Point0(thread_->GetEcmaVM()->GetFactory()->NewFromString("1.0")); + JSHandle charm1(thread_->GetEcmaVM()->GetFactory()->NewFromString("-1")); + JSHandle charm0Point0(thread_->GetEcmaVM()->GetFactory()->NewFromString("-0.0")); + JSHandle char0Point1(thread_->GetEcmaVM()->GetFactory()->NewFromString("-0.1")); ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(0)), char0)); ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(0.0)), char0)); ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(1.0)), char1)); - ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(-1.0)), char_1)); - ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(0.0)), char_0_point_0)); - ASSERT_FALSE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(0.0)), char_0_point_1)); + ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(-1.0)), charm1)); + ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(0.0)), charm0Point0)); + ASSERT_FALSE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue(0.0)), char0Point1)); // string compare ASSERT_TRUE(JSTaggedValue::Equal(thread_, test, test)); @@ -1187,9 +1186,9 @@ TEST_F(JSTaggedValueTest, Equal) ASSERT_FALSE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::False()), JSHandle(thread_, JSTaggedValue(1.0)))); ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::False()), char0)); - ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::False()), char0_point_0)); + ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::False()), char0Point0)); ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::True()), char1)); - ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::True()), char1_point_0)); + ASSERT_TRUE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::True()), char1Point0)); ASSERT_FALSE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::True()), char0)); ASSERT_FALSE(JSTaggedValue::Equal(thread_, JSHandle(thread_, JSTaggedValue::False()), char1)); } diff --git a/tests/runtime/common/test_helper.cpp b/tests/runtime/common/test_helper.cpp index 5b0958eb4b17dce1b450636d33e6027dde415179..9162921e7c9e9dc42c25439d4dbd7830c3e925f3 100644 --- a/tests/runtime/common/test_helper.cpp +++ b/tests/runtime/common/test_helper.cpp @@ -21,43 +21,43 @@ using panda::ecmascript::EcmaRuntimeCallInfo; using panda::ecmascript::JSTaggedValue; using panda::ecmascript::JSThread; -thread_local bool TestHelper::is_leaf_ = true; +thread_local bool TestHelper::isLeaf_ = true; // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) -ecmascript::JSHandle TestHelper::method_function_ {}; +ecmascript::JSHandle TestHelper::methodFunction_ {}; -std::unique_ptr TestHelper::CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue new_tgt, - ArraySizeT argv_length) +std::unique_ptr TestHelper::CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue newTgt, + ArraySizeT argvLength) { auto method = thread->GetEcmaVM()->GetMethodForNativeFunction(nullptr); - if (is_leaf_ && thread->GetCurrentFrame() != nullptr) { + if (isLeaf_ && thread->GetCurrentFrame() != nullptr) { method->ExitNativeMethodFrame(thread); } - is_leaf_ = true; + isLeaf_ = true; - const uint8_t test_decoded_size = 2; + const uint8_t testDecodedSize = 2; // argvLength includes number of int64_t to store value and tag of function, 'this' and call args // It doesn't include new.target argument - uint32_t num_actual_args = argv_length / test_decoded_size + 1; + uint32_t numActualArgs = argvLength / testDecodedSize + 1; std::vector args; - for (size_t i = 0; i < num_actual_args; ++i) { + for (size_t i = 0; i < numActualArgs; ++i) { args.emplace_back(JSTaggedValue::VALUE_UNDEFINED); } Frame *frame = - method->EnterNativeMethodFrame(thread, 0, num_actual_args, args.data()); + method->EnterNativeMethodFrame(thread, 0, numActualArgs, args.data()); - auto call_info = std::make_unique(thread, num_actual_args, - reinterpret_cast(&frame->GetVReg(0))); + auto callInfo = std::make_unique(thread, numActualArgs, + reinterpret_cast(&frame->GetVReg(0))); - call_info->SetFunction(method_function_.GetTaggedValue()); - call_info->SetNewTarget(new_tgt); - return call_info; + callInfo->SetFunction(methodFunction_.GetTaggedValue()); + callInfo->SetNewTarget(newTgt); + return callInfo; } Frame *TestHelper::SetupFrame(JSThread *thread, [[maybe_unused]] EcmaRuntimeCallInfo *info) { - is_leaf_ = false; + isLeaf_ = false; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) ASSERT((void *)info->GetArgAddress(0) == &thread->GetCurrentFrame()->GetVReg(0)); return thread->GetCurrentFrame()->GetPrevFrame(); @@ -65,7 +65,7 @@ Frame *TestHelper::SetupFrame(JSThread *thread, [[maybe_unused]] EcmaRuntimeCall void TestHelper::TearDownFrame([[maybe_unused]] JSThread *thread, [[maybe_unused]] Frame *prev) { - is_leaf_ = true; + isLeaf_ = true; auto frame = thread->GetCurrentFrame(); while (frame != nullptr && frame->GetPrevFrame() != prev) { Method::ExitNativeMethodFrame(thread); diff --git a/tests/runtime/common/test_helper.h b/tests/runtime/common/test_helper.h index 9fccc2dcad6411be1d87d5e94608bc81464b3e94..42ab1573e9775c881ac6422165ad894325d07465 100644 --- a/tests/runtime/common/test_helper.h +++ b/tests/runtime/common/test_helper.h @@ -36,13 +36,13 @@ using panda::ecmascript::JSThread; class TestHelper { public: - static std::unique_ptr CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue new_tgt, - ArraySizeT argv_length); + static std::unique_ptr CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue newTgt, + ArraySizeT argvLength); static Frame *SetupFrame(JSThread *thread, [[maybe_unused]] EcmaRuntimeCallInfo *info); static void TearDownFrame([[maybe_unused]] JSThread *thread, [[maybe_unused]] Frame *prev); static inline void CreateEcmaVMWithScope(PandaVM *&instance, JSThread *&thread, EcmaHandleScope *&scope, - bool enter_managed_code = true) + bool enterManagedCode = true) { RuntimeOptions options; #if defined(ICU_PATH) @@ -53,28 +53,28 @@ public: options.SetLoadRuntimes({"ecmascript"}); options.SetRunGcInPlace(true); options.SetExplicitConcurrentGcEnabled(false); - static EcmaLanguageContext lc_ecma; - [[maybe_unused]] bool success = Runtime::Create(options, {&lc_ecma}); + static EcmaLanguageContext lcEcma; + [[maybe_unused]] bool success = Runtime::Create(options, {&lcEcma}); ASSERT_TRUE(success) << "Cannot create Runtime"; instance = Runtime::GetCurrent()->GetPandaVM(); ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM"; thread = EcmaVM::Cast(instance)->GetAssociatedJSThread(); scope = new EcmaHandleScope(thread); - EcmaVM *ecma_vm = thread->GetEcmaVM(); - auto global_env = ecma_vm->GetGlobalEnv(); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + auto globalEnv = ecmaVm->GetGlobalEnv(); { ScopedManagedCodeThread s(thread); - method_function_ = ecma_vm->GetFactory()->NewJSFunction(global_env); + methodFunction_ = ecmaVm->GetFactory()->NewJSFunction(globalEnv); } - if (enter_managed_code) { + if (enterManagedCode) { thread->ManagedCodeBegin(); } } - static inline void DestroyEcmaVMWithScope(PandaVM *instance, EcmaHandleScope *scope, bool exit_managed_code = true) + static inline void DestroyEcmaVMWithScope(PandaVM *instance, EcmaHandleScope *scope, bool exitManagedCode = true) { auto thread = EcmaVM::Cast(instance)->GetAssociatedJSThread(); - if (exit_managed_code) { + if (exitManagedCode) { thread->ManagedCodeEnd(); } delete scope; @@ -85,8 +85,8 @@ public: } private: - static thread_local bool is_leaf_; - static ecmascript::JSHandle method_function_; + static thread_local bool isLeaf_; + static ecmascript::JSHandle methodFunction_; }; } // namespace panda::test diff --git a/tests/runtime/mem/g1gc_barrier_test.cpp b/tests/runtime/mem/g1gc_barrier_test.cpp index 446aee0c24ae0a766307e6246a9f6276061161d8..3036dca264623bd9cc069260d13c110523535dc5 100644 --- a/tests/runtime/mem/g1gc_barrier_test.cpp +++ b/tests/runtime/mem/g1gc_barrier_test.cpp @@ -22,7 +22,7 @@ public: NO_MOVE_SEMANTIC(G1GCBarrierTest); // NOLINTNEXTLINE(readability-magic-numbers) - explicit G1GCBarrierTest(size_t promotion_region_alive_rate = 100) + explicit G1GCBarrierTest(size_t promotionRegionAliveRate = 100) { RuntimeOptions options; options.SetLoadRuntimes({"ecmascript"}); @@ -30,7 +30,7 @@ public: options.SetRunGcInPlace(true); options.SetCompilerEnableJit(false); options.SetGcWorkersCount(0); - options.SetG1PromotionRegionAliveRate(promotion_region_alive_rate); + options.SetG1PromotionRegionAliveRate(promotionRegionAliveRate); options.SetGcTriggerType("debug-never"); options.SetShouldLoadBootPandaFiles(false); options.SetShouldInitializeIntrinsics(false); @@ -39,9 +39,9 @@ public: Runtime::Create(options); thread = JSThread::GetCurrent(); - const GlobalEnvConstants *global_const = thread->GlobalConstants(); - string_class_ = JSHClass::Cast(global_const->GetStringClass().GetTaggedObject()); - array_class_ = JSHClass::Cast(global_const->GetArrayClass().GetTaggedObject()); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + stringClass_ = JSHClass::Cast(globalConst->GetStringClass().GetTaggedObject()); + arrayClass_ = JSHClass::Cast(globalConst->GetArrayClass().GetTaggedObject()); } ~G1GCBarrierTest() override @@ -58,9 +58,9 @@ public: TaggedArray *AllocArray(size_t length) { size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); - mem::HeapManager *heap_manager = thread->GetVM()->GetHeapManager(); + mem::HeapManager *heapManager = thread->GetVM()->GetHeapManager(); auto *array = reinterpret_cast( - heap_manager->AllocateObject(array_class_->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread)); + heapManager->AllocateObject(arrayClass_->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread)); array->SetLength(length); return array; } @@ -69,8 +69,8 @@ public: JSThread *thread; private: - JSHClass *array_class_; - JSHClass *string_class_; + JSHClass *arrayClass_; + JSHClass *stringClass_; }; class ConcurrentMarkListener : public mem::GCListener { @@ -79,9 +79,9 @@ public: NO_MOVE_SEMANTIC(ConcurrentMarkListener); ~ConcurrentMarkListener() override = default; - ConcurrentMarkListener(G1GCBarrierTest *cur_test, JSHandle arr, JSHandle obj, - JSHandle cur_replacement) - : test_(cur_test), array_(arr), object_(obj), replacement_(cur_replacement) + ConcurrentMarkListener(G1GCBarrierTest *curTest, JSHandle arr, JSHandle obj, + JSHandle curReplacement) + : test_(curTest), array_(arr), object_(obj), replacement_(curReplacement) { } @@ -90,22 +90,22 @@ public: if (phase != mem::GCPhase::GC_PHASE_MARK) { return; } - has_concurrent_mark = true; + hasConcurrentMark = true; JSThread *thread = test_->thread; array_->Set(thread, 0, JSTaggedValue::Undefined()); array_->Set(thread, 1, replacement_.GetTaggedValue()); - PandaVector *pre_buff = thread->GetPreBuff(); - EXPECT_TRUE(pre_buff != nullptr); - if (pre_buff == nullptr) { + PandaVector *preBuff = thread->GetPreBuff(); + EXPECT_TRUE(preBuff != nullptr); + if (preBuff == nullptr) { return; } - EXPECT_EQ(1U, pre_buff->size()); - EXPECT_EQ(object_.GetObject(), pre_buff->front()); + EXPECT_EQ(1U, preBuff->size()); + EXPECT_EQ(object_.GetObject(), preBuff->front()); } // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) - bool has_concurrent_mark = false; + bool hasConcurrentMark = false; private: G1GCBarrierTest *test_; @@ -133,7 +133,7 @@ TEST_F(G1GCBarrierTest, TestPreBarrier) GCTask task(GCTaskCause::HEAP_USAGE_THRESHOLD_CAUSE); // trigger concurrent marking task.Run(*gc); } - ASSERT_TRUE(listener.has_concurrent_mark); + ASSERT_TRUE(listener.hasConcurrentMark); } class G1GCClassCollectionTest : public testing::TestWithParam { @@ -166,10 +166,10 @@ public: JSHandle AllocClass() { - const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHClass *root_hclass = JSHClass::Cast(global_const->GetHClassClass().GetTaggedObject()); - return factory->NewEcmaDynClass(root_hclass, 0, JSType::JS_OBJECT); + JSHClass *rootHclass = JSHClass::Cast(globalConst->GetHClassClass().GetTaggedObject()); + return factory->NewEcmaDynClass(rootHclass, 0, JSType::JS_OBJECT); } mem::ObjectAllocatorG1<> *GetAllocator() @@ -190,9 +190,9 @@ TEST_P(G1GCClassCollectionTest, TestCollectClasses) JSHClass *hclass = nullptr; { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle hclass_handle = AllocClass(); + JSHandle hclassHandle = AllocClass(); // JSHClass is allocated in the non-movable space so we can use raw pointer safe - hclass = hclass_handle.GetObject(); + hclass = hclassHandle.GetObject(); } ASSERT_NE(nullptr, hclass); mem::Region *region = mem::ObjectToRegion(hclass); diff --git a/tests/runtime/mem/object_helpers_test.cpp b/tests/runtime/mem/object_helpers_test.cpp index 17ca4613449b8049b1445cc33a59b2afbff8f6d0..29bc10abca74caaa414dea8a7aab42032afdd395 100644 --- a/tests/runtime/mem/object_helpers_test.cpp +++ b/tests/runtime/mem/object_helpers_test.cpp @@ -35,20 +35,20 @@ public: options.SetLoadRuntimes({"ecmascript"}); options.SetGcType("epsilon"); options.SetGcTriggerType("debug-never"); - auto exec_path = panda::os::file::File::GetExecutablePath(); - std::string panda_std_lib = - exec_path.Value() + Separator() + ".." + Separator() + "pandastdlib" + Separator() + "pandastdlib.bin"; - options.SetBootPandaFiles({panda_std_lib}); + auto execPath = panda::os::file::File::GetExecutablePath(); + std::string pandaStdLib = + execPath.Value() + Separator() + ".." + Separator() + "pandastdlib" + Separator() + "pandastdlib.bin"; + options.SetBootPandaFiles({pandaStdLib}); Runtime::Create(options); vm_ = EcmaVM::Cast(Runtime::GetCurrent()->GetPandaVM()); thread_ = vm_->GetAssociatedJSThread(); factory_ = vm_->GetFactory(); - handle_scope_ = new EcmaHandleScope(thread_); + handleScope_ = new EcmaHandleScope(thread_); vm_->GetMutatorLock()->ReadLock(); - initial_dyn_class_ = factory_->NewEcmaDynClassClass(nullptr, JSHClass::SIZE, JSType::HCLASS); - JSHClass *dynclass = reinterpret_cast(initial_dyn_class_.GetTaggedValue().GetTaggedObject()); + initialDynClass_ = factory_->NewEcmaDynClassClass(nullptr, JSHClass::SIZE, JSType::HCLASS); + JSHClass *dynclass = reinterpret_cast(initialDynClass_.GetTaggedValue().GetTaggedObject()); dynclass->SetClass(dynclass); dynclass->GetHClass()->SetNativeFieldMask(JSHClass::NATIVE_FIELDS_MASK); } @@ -56,13 +56,13 @@ public: ~DynamicObjectHelpersTest() override { vm_->GetMutatorLock()->Unlock(); - delete handle_scope_; + delete handleScope_; Runtime::Destroy(); } JSHandle NewDynClass() { - return factory_->CreateDynClass(*initial_dyn_class_, JSType::HCLASS, HClass::HCLASS); + return factory_->CreateDynClass(*initialDynClass_, JSType::HCLASS, HClass::HCLASS); } protected: @@ -72,15 +72,15 @@ protected: ObjectFactory *factory_ {}; private: - EcmaHandleScope *handle_scope_ {}; + EcmaHandleScope *handleScope_ {}; EcmaVM *vm_ {}; - JSHandle initial_dyn_class_; + JSHandle initialDynClass_; }; TEST_F(DynamicObjectHelpersTest, TestDynClass) { - JSHandle dyn_class = NewDynClass(); - JSHClass *hclass = *dyn_class; + JSHandle dynClass = NewDynClass(); + JSHClass *hclass = *dynClass; JSHandle proto = factory_->NewEmptyJSObject(); hclass->SetProto(thread_, proto); @@ -90,37 +90,37 @@ TEST_F(DynamicObjectHelpersTest, TestDynClass) hclass->SetTransitions(thread_, transitions); JSHandle parent = factory_->NewEmptyJSObject(); hclass->SetParent(thread_, parent); - JSHandle proto_changed_cell = factory_->NewEmptyJSObject(); - hclass->SetProtoChangeMarker(thread_, proto_changed_cell); - JSHandle proto_change_details = factory_->NewEmptyJSObject(); - hclass->SetProtoChangeDetails(thread_, proto_change_details); - JSHandle enum_cache = factory_->NewEmptyJSObject(); - hclass->SetEnumCache(thread_, enum_cache); - - PandaVector> objects_seen = { + JSHandle protoChangedCell = factory_->NewEmptyJSObject(); + hclass->SetProtoChangeMarker(thread_, protoChangedCell); + JSHandle protoChangeDetails = factory_->NewEmptyJSObject(); + hclass->SetProtoChangeDetails(thread_, protoChangeDetails); + JSHandle enumCache = factory_->NewEmptyJSObject(); + hclass->SetEnumCache(thread_, enumCache); + + PandaVector> objectsSeen = { {proto.GetObject(), JSHClass::GetProtoOffset()}, {attributes.GetObject(), JSHClass::GetLayoutOffset()}, {transitions.GetObject(), JSHClass::GetTransitionsOffset()}, {parent.GetObject(), JSHClass::GetParentOffset()}, - {proto_changed_cell.GetObject(), JSHClass::GetProtoChangeMarkerOffset()}, - {proto_change_details.GetObject(), JSHClass::GetProtoChangeDetailsOffset()}, - {enum_cache.GetObject(), JSHClass::GetEnumCacheOffset()}}; - auto handler = [&objects_seen]([[maybe_unused]] ObjectHeader *obj, ObjectHeader *field, uint32_t offset, - [[maybe_unused]] bool is_volatile) { + {protoChangedCell.GetObject(), JSHClass::GetProtoChangeMarkerOffset()}, + {protoChangeDetails.GetObject(), JSHClass::GetProtoChangeDetailsOffset()}, + {enumCache.GetObject(), JSHClass::GetEnumCacheOffset()}}; + auto handler = [&objectsSeen]([[maybe_unused]] ObjectHeader *obj, ObjectHeader *field, uint32_t offset, + [[maybe_unused]] bool isVolatile) { auto it = - std::find_if(objects_seen.begin(), objects_seen.end(), + std::find_if(objectsSeen.begin(), objectsSeen.end(), [field](const std::pair &entry) { return entry.first == field; }); - EXPECT_NE(objects_seen.end(), it); - if (it != objects_seen.end()) { + EXPECT_NE(objectsSeen.end(), it); + if (it != objectsSeen.end()) { EXPECT_NE(nullptr, it->first); EXPECT_EQ(it->second, offset); it->first = nullptr; } return true; }; - mem::GCDynamicObjectHelpers::TraverseAllObjectsWithInfo(dyn_class.GetObject(), handler); + mem::GCDynamicObjectHelpers::TraverseAllObjectsWithInfo(dynClass.GetObject(), handler); size_t count = 0; - for (auto entry : objects_seen) { + for (auto entry : objectsSeen) { ASSERT_EQ(nullptr, entry.first) << "Object " << count << " was not seen"; ++count; } @@ -135,11 +135,11 @@ TEST_F(DynamicObjectHelpersTest, TestDynObject) JSHandle(thread_, value.GetTaggedValue())); PandaQueue queue; - bool value_seen = false; - auto handler = [&value, &value_seen, &queue]([[maybe_unused]] ObjectHeader *obj, ObjectHeader *field, - [[maybe_unused]] uint32_t offset, [[maybe_unused]] bool is_volatile) { + bool valueSeen = false; + auto handler = [&value, &valueSeen, &queue]([[maybe_unused]] ObjectHeader *obj, ObjectHeader *field, + [[maybe_unused]] uint32_t offset, [[maybe_unused]] bool isVolatile) { if (field == value.GetObject()) { - value_seen = true; + valueSeen = true; } else { queue.push(field); } @@ -151,7 +151,7 @@ TEST_F(DynamicObjectHelpersTest, TestDynObject) queue.pop(); mem::GCDynamicObjectHelpers::TraverseAllObjectsWithInfo(front, handler); } - ASSERT_TRUE(value_seen); + ASSERT_TRUE(valueSeen); } TEST_F(DynamicObjectHelpersTest, TestDynArray) @@ -162,11 +162,11 @@ TEST_F(DynamicObjectHelpersTest, TestDynArray) JSHandle(thread_, value.GetTaggedValue())); PandaQueue queue; - bool value_seen = false; - auto handler = [&value, &value_seen, &queue]([[maybe_unused]] ObjectHeader *obj, ObjectHeader *field, - [[maybe_unused]] uint32_t offset, [[maybe_unused]] bool is_volatile) { + bool valueSeen = false; + auto handler = [&value, &valueSeen, &queue]([[maybe_unused]] ObjectHeader *obj, ObjectHeader *field, + [[maybe_unused]] uint32_t offset, [[maybe_unused]] bool isVolatile) { if (field == value.GetObject()) { - value_seen = true; + valueSeen = true; } else { queue.push(field); } @@ -178,7 +178,7 @@ TEST_F(DynamicObjectHelpersTest, TestDynArray) queue.pop(); mem::GCDynamicObjectHelpers::TraverseAllObjectsWithInfo(front, handler); } - ASSERT_TRUE(value_seen); + ASSERT_TRUE(valueSeen); } } // namespace panda::ecmascript diff --git a/tests/runtime/mem/weak_containers_test.cpp b/tests/runtime/mem/weak_containers_test.cpp index ef968ab52799e49170c045d438e52280065facac..07f5fdca0a3904768a26cd5dcfcb8d6a33c9f817 100644 --- a/tests/runtime/mem/weak_containers_test.cpp +++ b/tests/runtime/mem/weak_containers_test.cpp @@ -82,48 +82,48 @@ Local GetContainerSize(EcmaVM *vm, Local /*unused*/, con LOG_ECMA(FATAL) << "Argument is not weak container"; } if (hclass->IsJSWeakMap()) { - auto *weak_map = JSWeakMap::Cast(value->GetHeapObject()); - return IntegerRef::New(vm, weak_map->GetSize()); + auto *weakMap = JSWeakMap::Cast(value->GetHeapObject()); + return IntegerRef::New(vm, weakMap->GetSize()); } if (hclass->IsJSWeakSet()) { - auto *weak_set = JSWeakSet::Cast(value->GetHeapObject()); - return IntegerRef::New(vm, weak_set->GetSize()); + auto *weakSet = JSWeakSet::Cast(value->GetHeapObject()); + return IntegerRef::New(vm, weakSet->GetSize()); } UNREACHABLE(); } -bool RegisterFunction(EcmaVM *vm, Local &global_object, panda::FunctionCallback callback, const char *name) +bool RegisterFunction(EcmaVM *vm, Local &globalObject, panda::FunctionCallback callback, const char *name) { - Local function_ref = FunctionRef::New(vm, callback, nullptr); - if (function_ref.IsEmpty()) { + Local functionRef = FunctionRef::New(vm, callback, nullptr); + if (functionRef.IsEmpty()) { return false; } Local key = StringRef::NewFromUtf8(vm, name); - bool result = global_object->Set(vm, key, function_ref); + bool result = globalObject->Set(vm, key, functionRef); return result; } TEST_F(WeakContainersTests, WeakContainers) { // NOLINTNEXTLINE(modernize-avoid-c-arrays) - const char main_func[] = "_GLOBAL::func_main_0"; - JSExecutionScope execution_scope(vm_); + const char mainFunc[] = "_GLOBAL::func_main_0"; + JSExecutionScope executionScope(vm_); LocalScope scope(vm_); - Local global_object = JSNApi::GetGlobalObject(vm_); + Local globalObject = JSNApi::GetGlobalObject(vm_); - ASSERT_TRUE(RegisterFunction(vm_, global_object, RunGC, "collectGarbage")); - ASSERT_TRUE(RegisterFunction(vm_, global_object, GetContainerSize, "getContainerSize")); + ASSERT_TRUE(RegisterFunction(vm_, globalObject, RunGC, "collectGarbage")); + ASSERT_TRUE(RegisterFunction(vm_, globalObject, GetContainerSize, "getContainerSize")); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - const char file_name[] = "weakContainers.abc"; - bool ret2 = JSNApi::Execute(vm_, file_name, main_func); + const char fileName[] = "weakContainers.abc"; + bool ret2 = JSNApi::Execute(vm_, fileName, mainFunc); ASSERT_EQ(ret2, true); Local exception = JSNApi::GetUncaughtException(vm_); if (!exception.IsEmpty() && !exception->IsHole()) { - Local msg_key = StringRef::NewFromUtf8(vm_, "message"); - auto msg = exception->Get(vm_, msg_key)->ToString(vm_); + Local msgKey = StringRef::NewFromUtf8(vm_, "message"); + auto msg = exception->Get(vm_, msgKey)->ToString(vm_); FAIL() << msg->ToString(); } } diff --git a/tests/runtime/napi/jsnapi_tests.cpp b/tests/runtime/napi/jsnapi_tests.cpp index bf491f726dfac48c3e8bfddd0d3c4abb014aba90..cffd20ebb9b892451bb552cf12e2da7536eb66f4 100644 --- a/tests/runtime/napi/jsnapi_tests.cpp +++ b/tests/runtime/napi/jsnapi_tests.cpp @@ -66,9 +66,8 @@ public: { ScopedManagedCodeThread scope(thread_); auto factory = vm_->GetFactory(); - JSHandle ctor_handle = JSNApiHelper::ToJSHandle(ctor); - JSHandle obj = - factory->NewJSObjectByConstructor(JSHandle::Cast(ctor_handle), ctor_handle); + JSHandle ctorHandle = JSNApiHelper::ToJSHandle(ctor); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle::Cast(ctorHandle), ctorHandle); return JSNApiHelper::ToLocal(JSHandle(obj)); } @@ -76,8 +75,8 @@ public: { ScopedManagedCodeThread scope(thread_); auto factory = vm_->GetFactory(); - JSHandle proto_func = factory->NewJSFunctionByDynClass(method, hclass); - return JSNApiHelper::ToLocal(JSHandle(proto_func)); + JSHandle protoFunc = factory->NewJSFunctionByDynClass(method, hclass); + return JSNApiHelper::ToLocal(JSHandle(protoFunc)); } Local GetMethod(Local obj, Local key) @@ -109,16 +108,16 @@ void ThreadCheck(const EcmaVM *vm) TEST_F(JSNApiTests, GetGlobalObject) { LocalScope scope(vm_); - Local global_object = JSNApi::GetGlobalObject(vm_); - ASSERT_FALSE(global_object.IsEmpty()); - ASSERT_TRUE(global_object->IsObject()); + Local globalObject = JSNApi::GetGlobalObject(vm_); + ASSERT_FALSE(globalObject.IsEmpty()); + ASSERT_TRUE(globalObject->IsObject()); } TEST_F(JSNApiTests, ThreadIdCheck) { EXPECT_TRUE(vm_->GetAssociatedJSThread()->GetId() == os::thread::GetCurrentThreadId()); - std::thread test_thread(ThreadCheck, vm_); - test_thread.join(); + std::thread testThread(ThreadCheck, vm_); + testThread.join(); } TEST_F(JSNApiTests, RegisterFunction) @@ -137,50 +136,50 @@ TEST_F(JSNApiTests, RegisterFunction) TEST_F(JSNApiTests, GetProperty) { LocalScope scope(vm_); - Local global_object = JSNApi::GetGlobalObject(vm_); - ASSERT_FALSE(global_object.IsEmpty()); - ASSERT_TRUE(global_object->IsObject()); + Local globalObject = JSNApi::GetGlobalObject(vm_); + ASSERT_FALSE(globalObject.IsEmpty()); + ASSERT_TRUE(globalObject->IsObject()); Local key = StringRef::NewFromUtf8(vm_, "Number"); - Local property = global_object->Get(vm_, key); + Local property = globalObject->Get(vm_, key); ASSERT_TRUE(property->IsFunction()); } TEST_F(JSNApiTests, SetProperty) { LocalScope scope(vm_); - Local global_object = JSNApi::GetGlobalObject(vm_); - ASSERT_FALSE(global_object.IsEmpty()); - ASSERT_TRUE(global_object->IsObject()); + Local globalObject = JSNApi::GetGlobalObject(vm_); + ASSERT_FALSE(globalObject.IsEmpty()); + ASSERT_TRUE(globalObject->IsObject()); Local property = ArrayRef::New(vm_, 3); // 3 : length ASSERT_TRUE(property->IsArray(vm_)); ASSERT_EQ(property->Length(vm_), 3); // 3 : test case of input Local key = StringRef::NewFromUtf8(vm_, "Test"); - bool result = global_object->Set(vm_, key, property); + bool result = globalObject->Set(vm_, key, property); ASSERT_TRUE(result); - Local property_get = global_object->Get(vm_, key); - ASSERT_TRUE(property_get->IsArray(vm_)); - ASSERT_EQ(Local(property_get)->Length(vm_), 3); // 3 : test case of input + Local propertyGet = globalObject->Get(vm_, key); + ASSERT_TRUE(propertyGet->IsArray(vm_)); + ASSERT_EQ(Local(propertyGet)->Length(vm_), 3); // 3 : test case of input } TEST_F(JSNApiTests, JsonParser) { LocalScope scope(vm_); - Local global_object = JSNApi::GetGlobalObject(vm_); - ASSERT_FALSE(global_object.IsEmpty()); - ASSERT_TRUE(global_object->IsObject()); + Local globalObject = JSNApi::GetGlobalObject(vm_); + ASSERT_FALSE(globalObject.IsEmpty()); + ASSERT_TRUE(globalObject->IsObject()); const char *const test {R"({"orientation": "portrait"})"}; - Local json_string = StringRef::NewFromUtf8(vm_, test); + Local jsonString = StringRef::NewFromUtf8(vm_, test); - Local result = JSON::Parse(vm_, json_string); + Local result = JSON::Parse(vm_, jsonString); ASSERT_TRUE(result->IsObject()); - Local key_string = StringRef::NewFromUtf8(vm_, "orientation"); - Local property = Local(result)->Get(vm_, key_string); + Local keyString = StringRef::NewFromUtf8(vm_, "orientation"); + Local property = Local(result)->Get(vm_, keyString); ASSERT_TRUE(property->IsString()); } @@ -208,12 +207,12 @@ TEST_F(JSNApiTests, TypeOf) { LocalScope scope(vm_); Local origin = StringRef::NewFromUtf8(vm_, "1"); - Local type_string = origin->Typeof(vm_); - ASSERT_EQ(type_string->ToString(), "string"); + Local typeString = origin->Typeof(vm_); + ASSERT_EQ(typeString->ToString(), "string"); Local target = NumberRef::New(vm_, 1); - type_string = target->Typeof(vm_); - ASSERT_EQ(type_string->ToString(), "number"); + typeString = target->Typeof(vm_); + ASSERT_EQ(typeString->ToString(), "number"); } TEST_F(JSNApiTests, Symbol) @@ -230,11 +229,11 @@ TEST_F(JSNApiTests, StringUtf8_001) { LocalScope scope(vm_); std::string test = "Hello world"; - Local test_string = StringRef::NewFromUtf8(vm_, test.c_str()); + Local testString = StringRef::NewFromUtf8(vm_, test.c_str()); - EXPECT_TRUE(test_string->Utf8Length() == 12); // 12 : length of testString("Hello World") - char buffer[12]; // 12 : length of testString - EXPECT_TRUE(test_string->WriteUtf8(buffer, 12) == 12); // 12 : length of testString("Hello World") + EXPECT_TRUE(testString->Utf8Length() == 12); // 12 : length of testString("Hello World") + char buffer[12]; // 12 : length of testString + EXPECT_TRUE(testString->WriteUtf8(buffer, 12) == 12); // 12 : length of testString("Hello World") std::string res(buffer); ASSERT_EQ(res, test); } @@ -243,11 +242,11 @@ TEST_F(JSNApiTests, StringUtf8_002) { LocalScope scope(vm_); std::string test = "年"; - Local test_string = StringRef::NewFromUtf8(vm_, test.c_str()); + Local testString = StringRef::NewFromUtf8(vm_, test.c_str()); - EXPECT_TRUE(test_string->Utf8Length() == 4); // 4 : length of testString("年") - char buffer[4]; // 4 : length of testString - EXPECT_TRUE(test_string->WriteUtf8(buffer, 4) == 4); // 4 : length of testString("年") + EXPECT_TRUE(testString->Utf8Length() == 4); // 4 : length of testString("年") + char buffer[4]; // 4 : length of testString + EXPECT_TRUE(testString->WriteUtf8(buffer, 4) == 4); // 4 : length of testString("年") std::string res(buffer); ASSERT_EQ(res, test); } @@ -255,25 +254,25 @@ TEST_F(JSNApiTests, StringUtf8_002) TEST_F(JSNApiTests, ToType) { LocalScope scope(vm_); - Local to_string = StringRef::NewFromUtf8(vm_, "-123.3"); - Local to_value(to_string); + Local toString = StringRef::NewFromUtf8(vm_, "-123.3"); + Local toValue(toString); - ASSERT_EQ(to_string->ToNumber(vm_)->Value(), -123.3); // -123 : test case of input - ASSERT_EQ(to_string->ToBoolean(vm_)->Value(), true); - ASSERT_EQ(to_value->ToString(vm_)->ToString(), "-123.3"); - ASSERT_TRUE(to_value->ToObject(vm_)->IsObject()); + ASSERT_EQ(toString->ToNumber(vm_)->Value(), -123.3); // -123 : test case of input + ASSERT_EQ(toString->ToBoolean(vm_)->Value(), true); + ASSERT_EQ(toValue->ToString(vm_)->ToString(), "-123.3"); + ASSERT_TRUE(toValue->ToObject(vm_)->IsObject()); } TEST_F(JSNApiTests, TypeValue) { LocalScope scope(vm_); - Local to_string = StringRef::NewFromUtf8(vm_, "-123"); - Local to_value(to_string); + Local toString = StringRef::NewFromUtf8(vm_, "-123"); + Local toValue(toString); - ASSERT_EQ(to_string->Int32Value(vm_), -123); // -123 : test case of input - ASSERT_EQ(to_string->BooleaValue(), true); - ASSERT_EQ(to_string->Uint32Value(vm_), 4294967173); // 4294967173 : test case of input - ASSERT_EQ(to_string->IntegerValue(vm_), -123); // -123 : test case of input + ASSERT_EQ(toString->Int32Value(vm_), -123); // -123 : test case of input + ASSERT_EQ(toString->BooleaValue(), true); + ASSERT_EQ(toString->Uint32Value(vm_), 4294967173); // 4294967173 : test case of input + ASSERT_EQ(toString->IntegerValue(vm_), -123); // -123 : test case of input } TEST_F(JSNApiTests, DefineProperty) @@ -318,12 +317,12 @@ TEST_F(JSNApiTests, GetProtoType) { LocalScope scope(vm_); Local function = FunctionRef::New(vm_, nullptr, nullptr); - Local proto_type = function->GetPrototype(vm_); - ASSERT_TRUE(proto_type->IsObject()); + Local protoType = function->GetPrototype(vm_); + ASSERT_TRUE(protoType->IsObject()); Local object = ObjectRef::New(vm_); - proto_type = object->GetPrototype(vm_); - ASSERT_TRUE(proto_type->IsObject()); + protoType = object->GetPrototype(vm_); + ASSERT_TRUE(protoType->IsObject()); } void CheckReject(EcmaVM * /*unused*/, Local /*unused*/, const Local argv[], int32_t length, @@ -336,11 +335,11 @@ void CheckReject(EcmaVM * /*unused*/, Local /*unused*/, const Local< ASSERT_EQ(Local(reason)->ToString(), "Reject"); } -Local RejectCallback(EcmaVM *vm, Local this_arg, const Local argv[], int32_t length, +Local RejectCallback(EcmaVM *vm, Local thisArg, const Local argv[], int32_t length, void *data) { LocalScope scope(vm); - CheckReject(vm, this_arg, argv, length, data); + CheckReject(vm, thisArg, argv, length, data); return JSValueRef::Undefined(vm); } @@ -351,9 +350,9 @@ TEST_F(JSNApiTests, PromiseCatch) Local promise = capability->GetPromise(vm_); Local reject = FunctionRef::New(vm_, RejectCallback, nullptr); - Local catch_promise = promise->Catch(vm_, reject); + Local catchPromise = promise->Catch(vm_, reject); ASSERT_TRUE(promise->IsPromise()); - ASSERT_TRUE(catch_promise->IsPromise()); + ASSERT_TRUE(catchPromise->IsPromise()); Local reason = StringRef::NewFromUtf8(vm_, "Reject"); ASSERT_TRUE(capability->Reject(vm_, reason)); @@ -371,11 +370,11 @@ void CheckResolve(EcmaVM * /*unused*/, Local /*unused*/, const Local ASSERT_EQ(Local(value)->Value(), 300.3); // 300.3 : test case of input } -Local ResolvedCallback(EcmaVM *vm, Local this_arg, const Local argv[], +Local ResolvedCallback(EcmaVM *vm, Local thisArg, const Local argv[], int32_t length, void *data) { LocalScope scope(vm); - CheckResolve(vm, this_arg, argv, length, data); + CheckResolve(vm, thisArg, argv, length, data); return JSValueRef::Undefined(vm); } @@ -387,9 +386,9 @@ TEST_F(JSNApiTests, PromiseThen) Local promise = capability->GetPromise(vm_); Local resolve = FunctionRef::New(vm_, ResolvedCallback, nullptr); Local reject = FunctionRef::New(vm_, RejectCallback, nullptr); - Local then_promise = promise->Then(vm_, resolve, reject); + Local thenPromise = promise->Then(vm_, resolve, reject); ASSERT_TRUE(promise->IsPromise()); - ASSERT_TRUE(then_promise->IsPromise()); + ASSERT_TRUE(thenPromise->IsPromise()); Local value = NumberRef::New(vm_, 300.3); // 300.3 : test case of input ASSERT_TRUE(capability->Resolve(vm_, value)); @@ -401,10 +400,10 @@ TEST_F(JSNApiTests, Constructor) LocalScope scope(vm_); Local object = JSNApi::GetGlobalObject(vm_); Local key = StringRef::NewFromUtf8(vm_, "Number"); - Local number_constructor = object->Get(vm_, key); + Local numberConstructor = object->Get(vm_, key); Local argv[1]; argv[0] = NumberRef::New(vm_, 1.3); // 1.3 : test case of input - Local result = number_constructor->Constructor(vm_, argv, 1); + Local result = numberConstructor->Constructor(vm_, argv, 1); ASSERT_TRUE(result->IsObject()); ASSERT_EQ(result->ToNumber(vm_)->Value(), 1.3); // 1.3 : size of arguments } @@ -413,203 +412,203 @@ TEST_F(JSNApiTests, ArrayBuffer) { LocalScope scope(vm_); const int32_t length = 15; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); - ASSERT_EQ(array_buffer->ByteLength(vm_), length); - ASSERT_NE(array_buffer->GetBuffer(), nullptr); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); + ASSERT_EQ(arrayBuffer->ByteLength(vm_), length); + ASSERT_NE(arrayBuffer->GetBuffer(), nullptr); JSNApi::TriggerGC(vm_); } TEST_F(JSNApiTests, ArrayBufferWithBuffer) { - static bool is_free = false; + static bool isFree = false; struct Data { int32_t length; }; const int32_t length = 15; Data *data = new Data(); data->length = length; - Deleter deleter = [](void *buffer, void *data_ptr) -> void { + Deleter deleter = [](void *buffer, void *dataPtr) -> void { delete[] reinterpret_cast(buffer); - Data *current_data = reinterpret_cast(data_ptr); - ASSERT_EQ(current_data->length, 15); // 5 : size of arguments - delete current_data; - is_free = true; + Data *currentData = reinterpret_cast(dataPtr); + ASSERT_EQ(currentData->length, 15); // 5 : size of arguments + delete currentData; + isFree = true; }; { LocalScope scope(vm_); auto *buffer = new uint8_t[length](); - Local array_buffer = ArrayBufferRef::New(vm_, buffer, length, deleter, data); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); - ASSERT_EQ(array_buffer->ByteLength(vm_), length); - ASSERT_EQ(array_buffer->GetBuffer(), buffer); + Local arrayBuffer = ArrayBufferRef::New(vm_, buffer, length, deleter, data); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); + ASSERT_EQ(arrayBuffer->ByteLength(vm_), length); + ASSERT_EQ(arrayBuffer->GetBuffer(), buffer); } JSNApi::TriggerGC(vm_); - ASSERT_TRUE(is_free); + ASSERT_TRUE(isFree); } TEST_F(JSNApiTests, DataView) { LocalScope scope(vm_); const int32_t length = 15; - Local array_buffer = ArrayBufferRef::New(vm_, length); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); JSNApi::TriggerGC(vm_); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 5 : offset of byte, 7 : length - Local data_view = DataViewRef::New(vm_, array_buffer, 5, 7); - ASSERT_TRUE(data_view->IsDataView()); - ASSERT_EQ(data_view->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); - ASSERT_EQ(data_view->ByteLength(), 7); // 7 : size of arguments - ASSERT_EQ(data_view->ByteOffset(), 5); // 5 : size of arguments + Local dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7); + ASSERT_TRUE(dataView->IsDataView()); + ASSERT_EQ(dataView->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); + ASSERT_EQ(dataView->ByteLength(), 7); // 7 : size of arguments + ASSERT_EQ(dataView->ByteOffset(), 5); // 5 : size of arguments // 5 : offset of byte, 11 : length - data_view = DataViewRef::New(vm_, array_buffer, 5, 11); - ASSERT_TRUE(data_view->IsException()); + dataView = DataViewRef::New(vm_, arrayBuffer, 5, 11); + ASSERT_TRUE(dataView->IsException()); } TEST_F(JSNApiTests, Int8Array) { LocalScope scope(vm_); const int32_t length = 15; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 5 : offset of byte, 6 : length - Local typed_array = Int8ArrayRef::New(vm_, array_buffer, 5, 6); - ASSERT_TRUE(typed_array->IsInt8Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 6); // 6 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 5); // 5 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6); + ASSERT_TRUE(typedArray->IsInt8Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 6); // 6 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 5); // 5 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Uint8Array) { LocalScope scope(vm_); const int32_t length = 15; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 5 : offset of byte, 6 : length - Local typed_array = Uint8ArrayRef::New(vm_, array_buffer, 5, 6); - ASSERT_TRUE(typed_array->IsUint8Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 6); // 6 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 5); // 5 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Uint8ArrayRef::New(vm_, arrayBuffer, 5, 6); + ASSERT_TRUE(typedArray->IsUint8Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 6); // 6 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 5); // 5 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Uint8ClampedArray) { LocalScope scope(vm_); const int32_t length = 15; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 5 : offset of byte, 6 : length - Local typed_array = Uint8ClampedArrayRef::New(vm_, array_buffer, 5, 6); - ASSERT_TRUE(typed_array->IsUint8ClampedArray()); - ASSERT_EQ(typed_array->ByteLength(vm_), 6); // 6 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 5); // 5 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Uint8ClampedArrayRef::New(vm_, arrayBuffer, 5, 6); + ASSERT_TRUE(typedArray->IsUint8ClampedArray()); + ASSERT_EQ(typedArray->ByteLength(vm_), 6); // 6 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 5); // 5 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Int16Array) { LocalScope scope(vm_); const int32_t length = 30; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 4 : offset of byte, 6 : length - Local typed_array = Int16ArrayRef::New(vm_, array_buffer, 4, 6); - ASSERT_TRUE(typed_array->IsInt16Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 12); // 12 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 4); // 4 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Int16ArrayRef::New(vm_, arrayBuffer, 4, 6); + ASSERT_TRUE(typedArray->IsInt16Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 12); // 12 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 4); // 4 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Uint16Array) { LocalScope scope(vm_); const int32_t length = 30; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 4 : offset of byte, 6 : length - Local typed_array = Uint16ArrayRef::New(vm_, array_buffer, 4, 6); - ASSERT_TRUE(typed_array->IsUint16Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 12); // 12 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 4); // 4 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Uint16ArrayRef::New(vm_, arrayBuffer, 4, 6); + ASSERT_TRUE(typedArray->IsUint16Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 12); // 12 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 4); // 4 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Uint32Array) { LocalScope scope(vm_); const int32_t length = 30; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 4 : offset of byte, 6 : length - Local typed_array = Uint32ArrayRef::New(vm_, array_buffer, 4, 6); - ASSERT_TRUE(typed_array->IsUint32Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 24); // 24 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 4); // 4 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Uint32ArrayRef::New(vm_, arrayBuffer, 4, 6); + ASSERT_TRUE(typedArray->IsUint32Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 24); // 24 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 4); // 4 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Int32Array) { LocalScope scope(vm_); const int32_t length = 30; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 4 : offset of byte, 6 : length - Local typed_array = Int32ArrayRef::New(vm_, array_buffer, 4, 6); - ASSERT_TRUE(typed_array->IsInt32Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 24); // 24 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 4); // 4 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Int32ArrayRef::New(vm_, arrayBuffer, 4, 6); + ASSERT_TRUE(typedArray->IsInt32Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 24); // 24 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 4); // 4 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Float32Array) { LocalScope scope(vm_); const int32_t length = 30; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 4 : offset of byte, 6 : length - Local typed_array = Float32ArrayRef::New(vm_, array_buffer, 4, 6); - ASSERT_TRUE(typed_array->IsFloat32Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 24); // 24 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 4); // 4 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Float32ArrayRef::New(vm_, arrayBuffer, 4, 6); + ASSERT_TRUE(typedArray->IsFloat32Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 24); // 24 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 4); // 4 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Float64Array) { LocalScope scope(vm_); const int32_t length = 57; - Local array_buffer = ArrayBufferRef::New(vm_, length); - ASSERT_TRUE(array_buffer->IsArrayBuffer()); + Local arrayBuffer = ArrayBufferRef::New(vm_, length); + ASSERT_TRUE(arrayBuffer->IsArrayBuffer()); // 8 : offset of byte, 6 : length - Local typed_array = Float64ArrayRef::New(vm_, array_buffer, 8, 6); - ASSERT_TRUE(typed_array->IsFloat64Array()); - ASSERT_EQ(typed_array->ByteLength(vm_), 48); // 48 : length of bytes - ASSERT_EQ(typed_array->ByteOffset(vm_), 8); // 8 : offset of byte - ASSERT_EQ(typed_array->ArrayLength(vm_), 6); // 6 : length of array - ASSERT_EQ(typed_array->GetArrayBuffer(vm_)->GetBuffer(), array_buffer->GetBuffer()); + Local typedArray = Float64ArrayRef::New(vm_, arrayBuffer, 8, 6); + ASSERT_TRUE(typedArray->IsFloat64Array()); + ASSERT_EQ(typedArray->ByteLength(vm_), 48); // 48 : length of bytes + ASSERT_EQ(typedArray->ByteOffset(vm_), 8); // 8 : offset of byte + ASSERT_EQ(typedArray->ArrayLength(vm_), 6); // 6 : length of array + ASSERT_EQ(typedArray->GetArrayBuffer(vm_)->GetBuffer(), arrayBuffer->GetBuffer()); } TEST_F(JSNApiTests, Error) @@ -673,63 +672,61 @@ TEST_F(JSNApiTests, InheritPrototype_001) JSHandle env = vm_->GetGlobalEnv(); // new with Builtins::Set Prototype JSHandle set = env->GetSetFunction(); - Local set_local = JSNApiHelper::ToLocal(set); + Local setLocal = JSNApiHelper::ToLocal(set); // new with Builtins::Map Prototype JSHandle map = env->GetMapFunction(); - Local map_local = JSNApiHelper::ToLocal(map); - JSHandle set_prototype(thread_, JSHandle::Cast(set)->GetFunctionPrototype()); - JSHandle map_prototype(thread_, JSHandle::Cast(map)->GetFunctionPrototype()); - JSHandle map_prototype_proto(thread_, - JSHandle::Cast(map_prototype)->GetPrototype(thread_)); - bool same = JSTaggedValue::SameValue(set_prototype, map_prototype_proto); + Local mapLocal = JSNApiHelper::ToLocal(map); + JSHandle setPrototype(thread_, JSHandle::Cast(set)->GetFunctionPrototype()); + JSHandle mapPrototype(thread_, JSHandle::Cast(map)->GetFunctionPrototype()); + JSHandle mapPrototypeProto(thread_, JSHandle::Cast(mapPrototype)->GetPrototype(thread_)); + bool same = JSTaggedValue::SameValue(setPrototype, mapPrototypeProto); // before inherit, map.Prototype.__proto__ should be different from set.Prototype ASSERT_FALSE(same); // before inherit, map.__proto__ should be different from set - JSHandle map_proto(thread_, JSHandle::Cast(map)->GetPrototype(thread_)); - bool same1 = JSTaggedValue::SameValue(set, map_proto); + JSHandle mapProto(thread_, JSHandle::Cast(map)->GetPrototype(thread_)); + bool same1 = JSTaggedValue::SameValue(set, mapProto); ASSERT_FALSE(same1); // Set property to Set Function - Local default_string = + Local defaultString = JSNApiHelper::ToLocal(thread_->GlobalConstants()->GetHandledDefaultString()); { - PropertyAttribute attr(default_string, true, true, true); - ASSERT_TRUE(set_local->DefineProperty(vm_, default_string, attr)); + PropertyAttribute attr(defaultString, true, true, true); + ASSERT_TRUE(setLocal->DefineProperty(vm_, defaultString, attr)); } Local func = JSNApiHelper::ToLocal(env->GetTypedArrayFunction()); - Local property1_string = StringRef::NewFromUtf8(vm_, "property1"); + Local property1String = StringRef::NewFromUtf8(vm_, "property1"); { PropertyAttribute attr(func, true, true, true); - ASSERT_TRUE(set_local->DefineProperty(vm_, property1_string, attr)); + ASSERT_TRUE(setLocal->DefineProperty(vm_, property1String, attr)); } - map_local->Inherit(vm_, set_local); - JSHandle son_handle = JSNApiHelper::ToJSHandle(map_local); - JSHandle son_prototype(thread_, JSHandle::Cast(son_handle)->GetFunctionPrototype()); - JSHandle son_prototype_proto(thread_, - JSHandle::Cast(son_prototype)->GetPrototype(thread_)); - bool same2 = JSTaggedValue::SameValue(set_prototype, son_prototype_proto); + mapLocal->Inherit(vm_, setLocal); + JSHandle sonHandle = JSNApiHelper::ToJSHandle(mapLocal); + JSHandle sonPrototype(thread_, JSHandle::Cast(sonHandle)->GetFunctionPrototype()); + JSHandle sonPrototypeProto(thread_, JSHandle::Cast(sonPrototype)->GetPrototype(thread_)); + bool same2 = JSTaggedValue::SameValue(setPrototype, sonPrototypeProto); ASSERT_TRUE(same2); - JSHandle son_proto(thread_, JSHandle::Cast(map)->GetPrototype(thread_)); - bool same3 = JSTaggedValue::SameValue(set, son_proto); + JSHandle sonProto(thread_, JSHandle::Cast(map)->GetPrototype(thread_)); + bool same3 = JSTaggedValue::SameValue(set, sonProto); ASSERT_TRUE(same3); // son = new Son(), Son() inherit from Parent(), Test whether son.InstanceOf(Parent) is true - Local son_obj = NewObjectByConstructor(map_local); - bool is_instance = son_obj->InstanceOf(vm_, set_local); - ASSERT_TRUE(is_instance); + Local sonObj = NewObjectByConstructor(mapLocal); + bool isInstance = sonObj->InstanceOf(vm_, setLocal); + ASSERT_TRUE(isInstance); // Test whether son Function can access to property of parent Function - Local res = map_local->Get(vm_, default_string); - ASSERT_TRUE(default_string->IsStrictEquals(vm_, res)); - Local res1 = map_local->Get(vm_, property1_string); + Local res = mapLocal->Get(vm_, defaultString); + ASSERT_TRUE(defaultString->IsStrictEquals(vm_, res)); + Local res1 = mapLocal->Get(vm_, property1String); ASSERT_TRUE(func->IsStrictEquals(vm_, res1)); // new with empty Function Constructor Local son1 = FunctionRef::New(vm_, FunctionCallback, nullptr); - son1->Inherit(vm_, map_local); - JSHandle son1_handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(son1)); - ASSERT_TRUE(son1_handle->HasFunctionPrototype()); + son1->Inherit(vm_, mapLocal); + JSHandle son1Handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(son1)); + ASSERT_TRUE(son1Handle->HasFunctionPrototype()); } TEST_F(JSNApiTests, InheritPrototype_002) @@ -737,28 +734,28 @@ TEST_F(JSNApiTests, InheritPrototype_002) LocalScope scope(vm_); JSHandle env = vm_->GetGlobalEnv(); // new with Builtins::weakSet Prototype - JSHandle weak_set = env->GetWeakSetFunction(); - Local weak_set_local = JSNApiHelper::ToLocal(weak_set); + JSHandle weakSet = env->GetWeakSetFunction(); + Local weakSetLocal = JSNApiHelper::ToLocal(weakSet); // new with Builtins::weakMap Prototype - JSHandle weak_map = env->GetWeakMapFunction(); - Local weak_map_local = JSNApiHelper::ToLocal(weak_map); + JSHandle weakMap = env->GetWeakMapFunction(); + Local weakMapLocal = JSNApiHelper::ToLocal(weakMap); - weak_map_local->Inherit(vm_, weak_set_local); + weakMapLocal->Inherit(vm_, weakSetLocal); - Local property1_string = StringRef::NewFromUtf8(vm_, "property1"); + Local property1String = StringRef::NewFromUtf8(vm_, "property1"); Local func = JSNApiHelper::ToLocal(env->GetArrayFunction()); { PropertyAttribute attr(func, true, true, true); - ASSERT_TRUE(weak_map_local->DefineProperty(vm_, property1_string, attr)); + ASSERT_TRUE(weakMapLocal->DefineProperty(vm_, property1String, attr)); } - Local son_obj = NewObjectByConstructor(weak_map_local); + Local sonObj = NewObjectByConstructor(weakMapLocal); - Local father_obj = NewObjectByConstructor(weak_set_local); + Local fatherObj = NewObjectByConstructor(weakSetLocal); - Local son_method = GetMethod(son_obj, property1_string); - Local father_method = GetMethod(father_obj, property1_string); - ASSERT_TRUE(son_method->IsStrictEquals(vm_, father_method)); + Local sonMethod = GetMethod(sonObj, property1String); + Local fatherMethod = GetMethod(fatherObj, property1String); + ASSERT_TRUE(sonMethod->IsStrictEquals(vm_, fatherMethod)); } TEST_F(JSNApiTests, InheritPrototype_003) @@ -766,39 +763,39 @@ TEST_F(JSNApiTests, InheritPrototype_003) LocalScope scope(vm_); JSHandle env = vm_->GetGlobalEnv(); - JSMethod *invoke_self = + JSMethod *invokeSelf = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionPrototypeInvokeSelf)); // father type - Local proto_local = - NewFunctionByHClass(JSHandle::Cast(env->GetFunctionClassWithProto()), invoke_self); + Local protoLocal = + NewFunctionByHClass(JSHandle::Cast(env->GetFunctionClassWithProto()), invokeSelf); // son type - Local no_proto_local = - NewFunctionByHClass(JSHandle::Cast(env->GetFunctionClassWithoutProto()), invoke_self); + Local noProtoLocal = + NewFunctionByHClass(JSHandle::Cast(env->GetFunctionClassWithoutProto()), invokeSelf); - JSHandle son_handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(no_proto_local)); - EXPECT_FALSE(son_handle->HasFunctionPrototype()); + JSHandle sonHandle = JSHandle::Cast(JSNApiHelper::ToJSHandle(noProtoLocal)); + EXPECT_FALSE(sonHandle->HasFunctionPrototype()); - Local default_string = + Local defaultString = JSNApiHelper::ToLocal(thread_->GlobalConstants()->GetHandledDefaultString()); { - PropertyAttribute attr(default_string, true, true, true); - proto_local->DefineProperty(vm_, default_string, attr); + PropertyAttribute attr(defaultString, true, true, true); + protoLocal->DefineProperty(vm_, defaultString, attr); } - no_proto_local->Inherit(vm_, proto_local); - JSHandle son1_handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(no_proto_local)); - EXPECT_TRUE(son1_handle->HasFunctionPrototype()); + noProtoLocal->Inherit(vm_, protoLocal); + JSHandle son1Handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(noProtoLocal)); + EXPECT_TRUE(son1Handle->HasFunctionPrototype()); - Local res = no_proto_local->Get(vm_, default_string); - EXPECT_TRUE(default_string->IsStrictEquals(vm_, res)); + Local res = noProtoLocal->Get(vm_, defaultString); + EXPECT_TRUE(defaultString->IsStrictEquals(vm_, res)); - Local property_string = StringRef::NewFromUtf8(vm_, "property"); + Local propertyString = StringRef::NewFromUtf8(vm_, "property"); Local func = JSNApiHelper::ToLocal(env->GetArrayFunction()); { PropertyAttribute attr(func, true, true, true); - proto_local->DefineProperty(vm_, property_string, attr); + protoLocal->DefineProperty(vm_, propertyString, attr); } - Local res1 = no_proto_local->Get(vm_, property_string); + Local res1 = noProtoLocal->Get(vm_, propertyString); EXPECT_TRUE(func->IsStrictEquals(vm_, res1)); } @@ -808,62 +805,61 @@ TEST_F(JSNApiTests, DISABLED_InheritPrototype_004) // NOTE(vpukhov) JSHandle env = vm_->GetGlobalEnv(); auto factory = vm_->GetFactory(); - JSHandle weak_set = env->GetWeakSetFunction(); - JSHandle delete_string(factory->NewFromCanBeCompressString("delete")); - JSHandle add_string(factory->NewFromCanBeCompressString("add")); - JSHandle default_string = thread_->GlobalConstants()->GetHandledDefaultString(); - JSHandle delete_method = JSObject::GetMethod(thread_, weak_set, delete_string); - JSHandle add_method = JSObject::GetMethod(thread_, weak_set, add_string); + JSHandle weakSet = env->GetWeakSetFunction(); + JSHandle deleteString(factory->NewFromCanBeCompressString("delete")); + JSHandle addString(factory->NewFromCanBeCompressString("add")); + JSHandle defaultString = thread_->GlobalConstants()->GetHandledDefaultString(); + JSHandle deleteMethod = JSObject::GetMethod(thread_, weakSet, deleteString); + JSHandle addMethod = JSObject::GetMethod(thread_, weakSet, addString); - JSMethod *invoke_self = + JSMethod *invokeSelf = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionPrototypeInvokeSelf)); JSMethod *ctor = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionConstructor)); - JSHandle proto_dynclass = JSHandle::Cast(env->GetFunctionClassWithProto()); - JSHandle func_func_prototype = factory->NewJSFunctionByDynClass(invoke_self, proto_dynclass); + JSHandle protoDynclass = JSHandle::Cast(env->GetFunctionClassWithProto()); + JSHandle funcFuncPrototype = factory->NewJSFunctionByDynClass(invokeSelf, protoDynclass); // add method in funcPrototype - PropertyDescriptor desc = PropertyDescriptor(thread_, delete_method); - JSObject::DefineOwnProperty(thread_, JSHandle::Cast(func_func_prototype), delete_string, desc); - JSHandle func_func_prototype_value(func_func_prototype); + PropertyDescriptor desc = PropertyDescriptor(thread_, deleteMethod); + JSObject::DefineOwnProperty(thread_, JSHandle::Cast(funcFuncPrototype), deleteString, desc); + JSHandle funcFuncPrototypeValue(funcFuncPrototype); - JSHandle func_func_proto_intance_dynclass = - factory->CreateDynClass(JSType::JS_FUNCTION, func_func_prototype_value); + JSHandle funcFuncProtoIntanceDynclass = + factory->CreateDynClass(JSType::JS_FUNCTION, funcFuncPrototypeValue); // new with NewJSFunctionByDynClass::function DynClass - JSHandle proto_func = - factory->NewJSFunctionByDynClass(ctor, func_func_proto_intance_dynclass, FunctionKind::BUILTIN_CONSTRUCTOR); - EXPECT_TRUE(*proto_func != nullptr); + JSHandle protoFunc = + factory->NewJSFunctionByDynClass(ctor, funcFuncProtoIntanceDynclass, FunctionKind::BUILTIN_CONSTRUCTOR); + EXPECT_TRUE(*protoFunc != nullptr); // add method in funcnction - PropertyDescriptor desc1 = PropertyDescriptor(thread_, add_method); - JSObject::DefineOwnProperty(thread_, JSHandle::Cast(proto_func), add_string, desc1); - JSObject::DefineOwnProperty(thread_, JSHandle::Cast(proto_func), delete_string, desc); + PropertyDescriptor desc1 = PropertyDescriptor(thread_, addMethod); + JSObject::DefineOwnProperty(thread_, JSHandle::Cast(protoFunc), addString, desc1); + JSObject::DefineOwnProperty(thread_, JSHandle::Cast(protoFunc), deleteString, desc); // father type - Local proto_local = JSNApiHelper::ToLocal(JSHandle(proto_func)); + Local protoLocal = JSNApiHelper::ToLocal(JSHandle(protoFunc)); - JSHandle no_proto_dynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); - JSHandle func_func_no_proto_prototype = - factory->NewJSFunctionByDynClass(invoke_self, no_proto_dynclass); - JSHandle func_func_no_proto_prototype_value(func_func_no_proto_prototype); + JSHandle noProtoDynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); + JSHandle funcFuncNoProtoPrototype = factory->NewJSFunctionByDynClass(invokeSelf, noProtoDynclass); + JSHandle funcFuncNoProtoPrototypeValue(funcFuncNoProtoPrototype); - JSHandle func_func_no_proto_proto_intance_dynclass = - factory->CreateDynClass(JSType::JS_FUNCTION, func_func_no_proto_prototype_value); + JSHandle funcFuncNoProtoProtoIntanceDynclass = + factory->CreateDynClass(JSType::JS_FUNCTION, funcFuncNoProtoPrototypeValue); // new with NewJSFunctionByDynClass::function DynClass - JSHandle no_proto_func = factory->NewJSFunctionByDynClass( - ctor, func_func_no_proto_proto_intance_dynclass, FunctionKind::BUILTIN_CONSTRUCTOR); - EXPECT_TRUE(*no_proto_func != nullptr); + JSHandle noProtoFunc = + factory->NewJSFunctionByDynClass(ctor, funcFuncNoProtoProtoIntanceDynclass, FunctionKind::BUILTIN_CONSTRUCTOR); + EXPECT_TRUE(*noProtoFunc != nullptr); // set property that has same key with fater type - PropertyDescriptor desc2 = PropertyDescriptor(thread_, default_string); - JSObject::DefineOwnProperty(thread_, JSHandle::Cast(no_proto_func), add_string, desc2); + PropertyDescriptor desc2 = PropertyDescriptor(thread_, defaultString); + JSObject::DefineOwnProperty(thread_, JSHandle::Cast(noProtoFunc), addString, desc2); // son type - Local no_proto_local = JSNApiHelper::ToLocal(JSHandle(no_proto_func)); + Local noProtoLocal = JSNApiHelper::ToLocal(JSHandle(noProtoFunc)); - no_proto_local->Inherit(vm_, proto_local); + noProtoLocal->Inherit(vm_, protoLocal); - JSHandle son_handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(no_proto_local)); - OperationResult res = JSObject::GetProperty(thread_, JSHandle::Cast(son_handle), delete_string); - EXPECT_EQ(JSTaggedValue::SameValue(delete_method, res.GetValue()), true); + JSHandle sonHandle = JSHandle::Cast(JSNApiHelper::ToJSHandle(noProtoLocal)); + OperationResult res = JSObject::GetProperty(thread_, JSHandle::Cast(sonHandle), deleteString); + EXPECT_EQ(JSTaggedValue::SameValue(deleteMethod, res.GetValue()), true); // test if the property value changed after inherit - OperationResult res1 = JSObject::GetProperty(thread_, JSHandle::Cast(son_handle), add_string); - EXPECT_EQ(JSTaggedValue::SameValue(default_string, res1.GetValue()), true); + OperationResult res1 = JSObject::GetProperty(thread_, JSHandle::Cast(sonHandle), addString); + EXPECT_EQ(JSTaggedValue::SameValue(defaultString, res1.GetValue()), true); } TEST_F(JSNApiTests, ClassFunction) @@ -871,11 +867,11 @@ TEST_F(JSNApiTests, ClassFunction) LocalScope scope(vm_); Local cls = FunctionRef::NewClassFunction(vm_, nullptr, nullptr, nullptr); - JSHandle cls_obj = JSNApiHelper::ToJSHandle(Local(cls)); - ASSERT_TRUE(cls_obj->IsClassConstructor()); + JSHandle clsObj = JSNApiHelper::ToJSHandle(Local(cls)); + ASSERT_TRUE(clsObj->IsClassConstructor()); JSTaggedValue accessor = - JSHandle(cls_obj)->GetPropertyInlinedProps(JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX); + JSHandle(clsObj)->GetPropertyInlinedProps(JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX); ASSERT_TRUE(accessor.IsInternalAccessor()); } } // namespace panda::test diff --git a/tests/runtime/regexp/regexp_test.cpp b/tests/runtime/regexp/regexp_test.cpp index 429baacfcbed49dd26a3cae0ee1dcb0af489b074..74838f93a1db91ee0bace1980ae12f2bc4c05d87 100644 --- a/tests/runtime/regexp/regexp_test.cpp +++ b/tests/runtime/regexp/regexp_test.cpp @@ -71,8 +71,8 @@ TEST_F(RegExpTest, ParseAndExec1) PandaString source("ab"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("abc"); @@ -93,8 +93,8 @@ TEST_F(RegExpTest, ParseAndExec2) PandaString source("(((ab)|(cd)|(de))|((ef)|(gh)|(jk)))"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("cabd"); @@ -124,8 +124,8 @@ TEST_F(RegExpTest, ParseAndExec3) PandaString source("(aa|aabaac|ba|b|c)*"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("aabaac"); @@ -148,8 +148,8 @@ TEST_F(RegExpTest, ParseAndExec4) PandaString source("a*"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("aabaac"); @@ -170,8 +170,8 @@ TEST_F(RegExpTest, ParseAndExec5) PandaString source("a?"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("b"); @@ -192,8 +192,8 @@ TEST_F(RegExpTest, ParseAndExec6) PandaString source("(z)((a+)?(b+)?(c))*"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("zaacbbbcac"); @@ -223,8 +223,8 @@ TEST_F(RegExpTest, ParseAndExec7) PandaString source("^abc"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 4); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("ab\nabc"); @@ -245,8 +245,8 @@ TEST_F(RegExpTest, ParseAndExec8) PandaString source("abc$"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 4); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("ab\nabc"); @@ -267,8 +267,8 @@ TEST_F(RegExpTest, ParseAndExec9) PandaString source("er\\B"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("erv"); @@ -289,8 +289,8 @@ TEST_F(RegExpTest, ParseAndExec10) PandaString source("d\\b"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("bad good"); @@ -311,8 +311,8 @@ TEST_F(RegExpTest, ParseAndExec11) PandaString source("."); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("\na"); @@ -333,8 +333,8 @@ TEST_F(RegExpTest, ParseAndExec12) PandaString source("."); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 8); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("\n"); @@ -355,8 +355,8 @@ TEST_F(RegExpTest, ParseAndExec13) PandaString source("abc"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 4); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("\naabc"); @@ -377,8 +377,8 @@ TEST_F(RegExpTest, ParseAndExec14) PandaString source("abc"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 4); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("\nbbabc"); @@ -399,8 +399,8 @@ TEST_F(RegExpTest, ParseAndExec15) PandaString source("a(?=a)"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("aabc"); @@ -421,8 +421,8 @@ TEST_F(RegExpTest, ParseAndExec16) PandaString source("abc"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("ABC"); @@ -443,8 +443,8 @@ TEST_F(RegExpTest, ParseAndExec17) PandaString source("a\\n"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("a\n"); @@ -464,8 +464,8 @@ TEST_F(RegExpTest, ParseAndExec18) PandaString source("a(?=a)"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("ababc"); @@ -481,8 +481,8 @@ TEST_F(RegExpTest, ParseAndExec19) PandaString source("a(?!a)"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("ababc"); @@ -503,8 +503,8 @@ TEST_F(RegExpTest, ParseAndExec20) PandaString source("(?=(a+))"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("baaabac"); @@ -527,8 +527,8 @@ TEST_F(RegExpTest, ParseAndExec21) PandaString source("a(?=a(?=b))"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("caab"); @@ -549,8 +549,8 @@ TEST_F(RegExpTest, ParseAndExec22) PandaString source(".+:"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("aaaa:aa"); @@ -571,8 +571,8 @@ TEST_F(RegExpTest, ParseAndExec23) PandaString source("a(?<=a(?(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("caab"); @@ -592,8 +592,8 @@ TEST_F(RegExpTest, ParseAndExec24) PandaString source("a(?<=ab(?(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("caab"); @@ -609,8 +609,8 @@ TEST_F(RegExpTest, ParseAndExec25) PandaString source("(?<=(ab))"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("cabab"); @@ -633,8 +633,8 @@ TEST_F(RegExpTest, ParseAndExec26) PandaString source("[a-z]"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("A"); @@ -655,8 +655,8 @@ TEST_F(RegExpTest, ParseAndExec27) PandaString source("[^a-b]"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("Z"); @@ -677,8 +677,8 @@ TEST_F(RegExpTest, ParseAndExec28) PandaString source("\\s"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("\n"); @@ -699,8 +699,8 @@ TEST_F(RegExpTest, ParseAndExec29) PandaString source("()|"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input; @@ -722,8 +722,8 @@ TEST_F(RegExpTest, ParseAndExec30) PandaString source("|()"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input; @@ -745,8 +745,8 @@ TEST_F(RegExpTest, ParseAndExec31) PandaString source("a(a|b)\\1"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("aabb"); bool ret = @@ -767,8 +767,8 @@ TEST_F(RegExpTest, ParseAndExec32) PandaString source("(a(a|b))\\2"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("aabb"); bool ret = @@ -791,8 +791,8 @@ TEST_F(RegExpTest, ParseAndExec33) PandaString source("qya+"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("qyqya"); bool ret = @@ -811,8 +811,8 @@ TEST_F(RegExpTest, ParseAndExec34) PandaString source("qy(?=\\s+)"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("qyqy "); bool ret = @@ -831,8 +831,8 @@ TEST_F(RegExpTest, ParseAndExec35) PandaString source(R"((\d{4})-(\d{2})-(\d{2}))"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("xx2021-01-09"); bool ret = @@ -857,8 +857,8 @@ TEST_F(RegExpTest, ParseAndExec36) PandaString source("quick\\s(brown).+?(jumps)"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("The Quick Brown Fox Jumps Over The Lazy Dog"); bool ret = @@ -881,8 +881,8 @@ TEST_F(RegExpTest, ParseAndExec37) PandaString source("(ab){1,2}?c"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("abABc"); bool ret = @@ -903,8 +903,8 @@ TEST_F(RegExpTest, ParseAndExec38) PandaString source("^(([a-z]+)*[a-z]\\.)+[a-z]{2,}$"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("www.netscape.com"); bool ret = @@ -927,8 +927,8 @@ TEST_F(RegExpTest, ParseAndExec39) PandaString source("(a*)b\\1+"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("baaaac"); bool ret = @@ -949,8 +949,8 @@ TEST_F(RegExpTest, ParseAndExec40) PandaString source("a*?"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("ab"); bool ret = @@ -969,8 +969,8 @@ TEST_F(RegExpTest, ParseAndExec41) PandaString source("(.*?)a(?!(a+)b\\2c)\\2(.*)"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("baaabaac"); bool ret = @@ -994,8 +994,8 @@ TEST_F(RegExpTest, ParseAndExec42) PandaString source("[a-c\\d]+"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("\n\n\\abc324234"); bool ret = @@ -1014,8 +1014,8 @@ TEST_F(RegExpTest, ParseAndExec43) PandaString source("[\\d][\n][^\\d]"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("line1\nline2"); bool ret = @@ -1034,8 +1034,8 @@ TEST_F(RegExpTest, ParseAndExec44) PandaString source(".[\b]."); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("abc\bdef"); bool ret = @@ -1054,8 +1054,8 @@ TEST_F(RegExpTest, ParseAndExec45) PandaString source("[^\b]+"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("easy\bto\u0008ride"); bool ret = @@ -1074,8 +1074,8 @@ TEST_F(RegExpTest, ParseAndExec46) PandaString source("([\\S]+([ \t]+[\\S]+)*)[ \t]*=[ \t]*[\\S]+"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("Course_Creator = Test"); bool ret = @@ -1098,8 +1098,8 @@ TEST_F(RegExpTest, ParseAndExec47) PandaString source("[^o]t\\b"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("pilOt\nsoviet robot\topenoffice"); bool ret = @@ -1118,8 +1118,8 @@ TEST_F(RegExpTest, ParseAndExec49) PandaString source("(a(b)\\4(5)(5))"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("ab55"); bool ret = @@ -1171,8 +1171,8 @@ TEST_F(RegExpTest, ParseAndExec51) PandaString source("\\u0000"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; // NOLINTNEXTLINE(bugprone-string-literal-with-embedded-nul) std::u16string input(u"\u0000"); @@ -1190,8 +1190,8 @@ TEST_F(RegExpTest, ParseAndExec52) PandaString source("(aa).+\\1"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("aabcdaabcd"); bool ret = @@ -1212,8 +1212,8 @@ TEST_F(RegExpTest, ParseAndExec53) PandaString source("\\x01"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; std::u16string input(u"\u0001"); bool ret = executor.Execute(reinterpret_cast(input.c_str()), 0, input.length(), @@ -1231,8 +1231,8 @@ TEST_F(RegExpTest, ParseAndExec54) PandaString source("\\bot"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("pilot\nsoviet robot\topenoffice"); bool ret = executor.Execute(reinterpret_cast(input.c_str()), 0, input.length(), @@ -1247,8 +1247,8 @@ TEST_F(RegExpTest, ParseAndExec55) PandaString source("e\\b"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("c\u0065"); bool ret = executor.Execute(reinterpret_cast(input.c_str()), 0, input.length(), @@ -1267,8 +1267,8 @@ TEST_F(RegExpTest, ParseAndExec56) PandaString source("a啊"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; std::u16string input(u"a啊"); bool ret = executor.Execute(reinterpret_cast(input.c_str()), 0, input.length(), @@ -1286,8 +1286,8 @@ TEST_F(RegExpTest, ParseAndExec57) PandaString source("\\udf06"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 16); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; // NOLINTNEXTLINE(modernize-avoid-c-arrays) char16_t data[] = {0xd834, 0xdf06}; @@ -1302,8 +1302,8 @@ TEST_F(RegExpTest, ParseAndExec58) PandaString source("\\udf06"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; // NOLINTNEXTLINE(modernize-avoid-c-arrays) char16_t data[] = {0xd834, 0xdf06}; @@ -1324,8 +1324,8 @@ TEST_F(RegExpTest, ParseAndExec59) PandaString source("\\v"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 0); parser.Parse(); - bool parse_result = parser.IsError(); - ASSERT_FALSE(parse_result); + bool parseResult = parser.IsError(); + ASSERT_FALSE(parseResult); RegExpExecutor executor; PandaString input("\u000B"); diff --git a/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h b/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h index dffd9e6bf0296bb71a00916e9cbbd75ea1f6faac..b6ad078f83e9bc0de9944584c61508ec22225baa 100644 --- a/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h +++ b/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h @@ -23,9 +23,9 @@ class JsBreakpointTest : public ApiTest { public: JsBreakpointTest() { - vm_start = [this] { + vmStart = [this] { // NOLINTNEXTLINE(readability-magic-numbers) - location_ = TestUtil::GetLocation("Sample.js", 22, panda_file_.c_str()); + location_ = TestUtil::GetLocation("Sample.js", 22, pandaFile_.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); return true; }; @@ -33,36 +33,36 @@ public: breakpoint = [this](PtThread, Method *, const PtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); - ++breakpoint_counter_; + ++breakpointCounter_; return true; }; - load_module = [this](std::string_view module_name) { - if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { + loadModule = [this](std::string_view moduleName) { + if (moduleName.find(pandaFile_.c_str()) == std::string_view::npos) { return true; } - ASSERT_SUCCESS(debug_interface->SetBreakpoint(location_)); - auto error = debug_interface->SetBreakpoint(location_); + ASSERT_SUCCESS(debugInterface->SetBreakpoint(location_)); + auto error = debugInterface->SetBreakpoint(location_); ASSERT_FALSE(!error); return true; }; - vm_death = [this]() { - ASSERT_EQ(breakpoint_counter_, 2U); + vmDeath = [this]() { + ASSERT_EQ(breakpointCounter_, 2U); return true; }; } std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/Sample.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; + std::string pandaFile_ = "js/Sample.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; PtLocation location_ {nullptr, PtLocation::EntityId(0), 0}; - size_t breakpoint_counter_ = 0; + size_t breakpointCounter_ = 0; }; inline std::unique_ptr GetJsBreakpointTest() diff --git a/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h b/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h index ac471c618a5b91de47eb32e03644d3405a37ced5..aa93bab5766187fdf4fde450852a21aebdb8200a 100644 --- a/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h +++ b/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h @@ -23,24 +23,24 @@ class JsEnumerateFrameTest : public ApiTest { public: JsEnumerateFrameTest() { - vm_death = [this]() { - ASSERT_EQ(count_frames_, 9U); + vmDeath = [this]() { + ASSERT_EQ(countFrames_, 9U); return true; }; - method_exit = [this](PtThread thread, Method *method, bool, VRegValue) { + methodExit = [this](PtThread thread, Method *method, bool, VRegValue) { if (method->GetFullName() == "_GLOBAL::func_method3_3") { - ASSERT_EQ(count_frames_, 0U); - debug_interface->EnumerateFrames(thread, callback_); - ASSERT_EQ(count_frames_, 4U); + ASSERT_EQ(countFrames_, 0U); + debugInterface->EnumerateFrames(thread, callback_); + ASSERT_EQ(countFrames_, 4U); } else if (method->GetFullName() == "_GLOBAL::func_method2_2") { - ASSERT_EQ(count_frames_, 4U); - debug_interface->EnumerateFrames(thread, callback_); - ASSERT_EQ(count_frames_, 7U); + ASSERT_EQ(countFrames_, 4U); + debugInterface->EnumerateFrames(thread, callback_); + ASSERT_EQ(countFrames_, 7U); } else if (method->GetFullName() == "_GLOBAL::func_method1_1") { - ASSERT_EQ(count_frames_, 7U); - debug_interface->EnumerateFrames(thread, callback_); - ASSERT_EQ(count_frames_, 9U); + ASSERT_EQ(countFrames_, 7U); + debugInterface->EnumerateFrames(thread, callback_); + ASSERT_EQ(countFrames_, 9U); } return true; }; @@ -48,17 +48,17 @@ public: std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/GetFrame.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; - size_t count_frames_ = 0; + std::string pandaFile_ = "js/GetFrame.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + size_t countFrames_ = 0; - std::function callback_ {[this](const PtFrame &debug_frame) { - this->count_frames_++; - return debug_frame.GetArgumentNum() != 1; + std::function callback_ {[this](const PtFrame &debugFrame) { + this->countFrames_++; + return debugFrame.GetArgumentNum() != 1; }}; }; diff --git a/tests/runtime/tooling/api_tests/js/js_exception_events_test.h b/tests/runtime/tooling/api_tests/js/js_exception_events_test.h index 93ab82a8cd635df3b45caa7679e12359fd7c8583..1ed6b191b5d7fccbeceeaddb9cc80b2d1d6bf1dd 100644 --- a/tests/runtime/tooling/api_tests/js/js_exception_events_test.h +++ b/tests/runtime/tooling/api_tests/js/js_exception_events_test.h @@ -24,61 +24,61 @@ class JsExceptionEventTest : public ApiTest { public: JsExceptionEventTest() { - vm_death = [this]() { - ASSERT_EQ(exception_counter_, 1U); - ASSERT_EQ(exception_catch_counter_, 1U); + vmDeath = [this]() { + ASSERT_EQ(exceptionCounter_, 1U); + ASSERT_EQ(exceptionCatchCounter_, 1U); return true; }; - method_entry = [this](PtThread thread, Method *method) { + methodEntry = [this](PtThread thread, Method *method) { if (method->GetFullName() == "_GLOBAL::func_main_0") { - ASSERT_TRUE(thread_id_ == PtThread::NONE.GetId()); - thread_id_ = thread.GetId(); + ASSERT_TRUE(threadId_ == PtThread::NONE.GetId()); + threadId_ = thread.GetId(); } return true; }; - method_exit = [this](PtThread, Method *method, bool, VRegValue) { + methodExit = [this](PtThread, Method *method, bool, VRegValue) { if (method->GetFullName() == "_GLOBAL::func_main_0") { - thread_id_ = PtThread::NONE.GetId(); + threadId_ = PtThread::NONE.GetId(); } return true; }; exception = [this](PtThread thread, Method *, const PtLocation &, ObjectHeader *, Method *, - const PtLocation &catch_location) { - if (thread_id_ != thread.GetId()) { + const PtLocation &catchLocation) { + if (threadId_ != thread.GetId()) { return true; } - ++exception_counter_; - catch_location_ = catch_location; + ++exceptionCounter_; + catchLocation_ = catchLocation; return true; }; - exception_catch = [this](PtThread thread, Method *, const PtLocation &location, ObjectHeader *) { - if (thread_id_ != thread.GetId()) { + exceptionCatch = [this](PtThread thread, Method *, const PtLocation &location, ObjectHeader *) { + if (threadId_ != thread.GetId()) { return true; } - ASSERT_LOCATION_EQ(location, catch_location_); - ++exception_catch_counter_; + ASSERT_LOCATION_EQ(location, catchLocation_); + ++exceptionCatchCounter_; return true; }; } std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/ExceptionTest.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; - size_t exception_counter_ = 0; - size_t exception_catch_counter_ = 0; - uint32_t thread_id_ = PtThread::NONE.GetId(); - PtLocation catch_location_ {nullptr, PtLocation::EntityId(0), 0}; + std::string pandaFile_ = "js/ExceptionTest.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + size_t exceptionCounter_ = 0; + size_t exceptionCatchCounter_ = 0; + uint32_t threadId_ = PtThread::NONE.GetId(); + PtLocation catchLocation_ {nullptr, PtLocation::EntityId(0), 0}; }; inline std::unique_ptr GetJsExceptionEventTest() diff --git a/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h b/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h index 20cf10025a987a3e97624901d8837f046bef2fba..bdcf8e1e8b237983a38c69ce0c9139f112c6a129 100644 --- a/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h +++ b/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h @@ -23,16 +23,16 @@ class JsFramePopTest : public ApiTest { public: JsFramePopTest() { - vm_start = [this] { + vmStart = [this] { // NOLINTNEXTLINE(readability-magic-numbers) - location_ = TestUtil::GetLocation("FramePop.js", 33, panda_file_.c_str()); + location_ = TestUtil::GetLocation("FramePop.js", 33, pandaFile_.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); return true; }; - vm_death = [this] { - ASSERT_EQ(breakpoint_counter_, 2U); - ASSERT_EQ(frame_pop_counter_, 2U); + vmDeath = [this] { + ASSERT_EQ(breakpointCounter_, 2U); + ASSERT_EQ(framePopCounter_, 2U); return true; }; @@ -55,53 +55,53 @@ public: breakpoint = [this](PtThread thread, Method *, const PtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); - ++breakpoint_counter_; + ++breakpointCounter_; TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, thread, location); - if (breakpoint_counter_ == 1) { - ASSERT_SUCCESS(debug_interface->NotifyFramePop(thread, 0)); - ASSERT_SUCCESS(debug_interface->NotifyFramePop(thread, 2)); + if (breakpointCounter_ == 1) { + ASSERT_SUCCESS(debugInterface->NotifyFramePop(thread, 0)); + ASSERT_SUCCESS(debugInterface->NotifyFramePop(thread, 2)); } return true; }; - load_module = [this](std::string_view module_name) { - if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { + loadModule = [this](std::string_view moduleName) { + if (moduleName.find(pandaFile_.c_str()) == std::string_view::npos) { return true; } - ASSERT_SUCCESS(debug_interface->SetBreakpoint(location_)); + ASSERT_SUCCESS(debugInterface->SetBreakpoint(location_)); return true; }; - frame_pop = [this](PtThread thread_id, Method *method, bool was_popped_by_exception) { - auto method_name = method->GetFullName(); - if (method_name == "_GLOBAL::func_frame0_4") { - ASSERT_EQ(frame_pop_counter_, 0U); - } else if (method_name == "_GLOBAL::func_frame2_2") { - ASSERT_EQ(frame_pop_counter_, 1U); + framePop = [this](PtThread threadId, Method *method, bool wasPoppedByException) { + auto methodName = method->GetFullName(); + if (methodName == "_GLOBAL::func_frame0_4") { + ASSERT_EQ(framePopCounter_, 0U); + } else if (methodName == "_GLOBAL::func_frame2_2") { + ASSERT_EQ(framePopCounter_, 1U); } else { // Not expected frame pop return false; } - ASSERT_NE(thread_id.GetId(), PtThread::NONE.GetId()); - ASSERT_EQ(was_popped_by_exception, false); - ++frame_pop_counter_; + ASSERT_NE(threadId.GetId(), PtThread::NONE.GetId()); + ASSERT_EQ(wasPoppedByException, false); + ++framePopCounter_; return true; }; } std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/FramePop.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; + std::string pandaFile_ = "js/FramePop.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; PtLocation location_ {nullptr, PtLocation::EntityId(0), 0}; - size_t breakpoint_counter_ = 0; - size_t frame_pop_counter_ = 0; - PtMethod pop_method_ {nullptr}; + size_t breakpointCounter_ = 0; + size_t framePopCounter_ = 0; + PtMethod popMethod_ {nullptr}; }; inline std::unique_ptr GetJsFramePopTest() diff --git a/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h b/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h index fac06bf9c0cdba95821072df5f6ea7858d38a045..81e40a9a04d0bfb2bb6200e4b1d49704b1360bb5 100644 --- a/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h +++ b/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h @@ -23,28 +23,28 @@ class JsCurrentFrameTest : public ApiTest { public: JsCurrentFrameTest() { - vm_death = [this]() { + vmDeath = [this]() { ASSERT_EQ(entry_, 111U); return true; }; - method_exit = [this](PtThread thread, Method *method, bool, VRegValue) { + methodExit = [this](PtThread thread, Method *method, bool, VRegValue) { if (method->GetFullName() == "_GLOBAL::func_method3_3") { ASSERT_EQ(entry_, 0U); entry_++; - auto frme = debug_interface->GetCurrentFrame(thread); + auto frme = debugInterface->GetCurrentFrame(thread); ASSERT_EQ((*frme)->GetMethod(), method); } else if (method->GetFullName() == "_GLOBAL::func_method2_2") { ASSERT_EQ(entry_, 1U); // NOLINTNEXTLINE(readability-magic-numbers) entry_ += 10; - auto frme = debug_interface->GetCurrentFrame(thread); + auto frme = debugInterface->GetCurrentFrame(thread); ASSERT_EQ((*frme)->GetMethod(), method); } else if (method->GetFullName() == "_GLOBAL::func_method1_1") { ASSERT_EQ(entry_, 11U); // NOLINTNEXTLINE(readability-magic-numbers) entry_ += 100U; - auto frme = debug_interface->GetCurrentFrame(thread); + auto frme = debugInterface->GetCurrentFrame(thread); ASSERT_EQ((*frme)->GetMethod(), method); } return true; @@ -53,12 +53,12 @@ public: std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/GetFrame.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; + std::string pandaFile_ = "js/GetFrame.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; size_t entry_ = 0; }; diff --git a/tests/runtime/tooling/api_tests/js/js_get_variable_test.h b/tests/runtime/tooling/api_tests/js/js_get_variable_test.h index 2ecc7d70bfd16c163d228e82391d61e0119a10d5..24ce68000fb5528845305f4ff35179dabb673c56 100644 --- a/tests/runtime/tooling/api_tests/js/js_get_variable_test.h +++ b/tests/runtime/tooling/api_tests/js/js_get_variable_test.h @@ -30,20 +30,20 @@ class JsGetVariableTest : public ApiTest { public: JsGetVariableTest() { - vm_death = [this]() { - const int expected_count = 1; - ASSERT_EQ(count_checker_, expected_count); + vmDeath = [this]() { + const int expectedCount = 1; + ASSERT_EQ(countChecker_, expectedCount); return true; }; - load_module = [this](std::string_view module_name) { - if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { + loadModule = [this](std::string_view moduleName) { + if (moduleName.find(pandaFile_.c_str()) == std::string_view::npos) { return true; } // NOLINTNEXTLINE(readability-magic-numbers) - auto location = TestUtil::GetLocation("GetVariable.js", 19, panda_file_.c_str()); // getVariable + auto location = TestUtil::GetLocation("GetVariable.js", 19, pandaFile_.c_str()); // getVariable ASSERT_TRUE(location.GetMethodId().IsValid()); - ASSERT_SUCCESS(debug_interface->SetBreakpoint(location)); + ASSERT_SUCCESS(debugInterface->SetBreakpoint(location)); return true; }; @@ -55,13 +55,13 @@ public: std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } bool CheckSetValues(PtThread thread, Method *method, uint32_t offset) { // NOLINTNEXTLINE(modernize-avoid-c-arrays) - std::function checkers_list[] = { + std::function checkersList[] = { [&](JSTaggedValue value) { // boolean: false ASSERT_EQ(value.GetRawData(), JSTaggedValue::VALUE_FALSE); return true; @@ -87,32 +87,32 @@ public: return true; }, [&](JSTaggedValue value) { // String: "new_string" - PandaString checked_value; + PandaString checkedValue; ASSERT_TRUE(value.IsHeapObject()); - auto vreg_value = ecmascript::PtEcmaScriptExtension::TaggedValueToVRegValue(value); - ASSERT_TRUE(ecmascript::JSTestApi::VRegValueToString(vreg_value, &checked_value)); + auto vregValue = ecmascript::PtEcmaScriptExtension::TaggedValueToVRegValue(value); + ASSERT_TRUE(ecmascript::JSTestApi::VRegValueToString(vregValue, &checkedValue)); // NOLINTNEXTLINE(readability-string-compare) - ASSERT_TRUE(checked_value.compare("new_string") == 0); + ASSERT_TRUE(checkedValue.compare("new_string") == 0); return true; }}; - ++count_checker_; - uint32_t frame_depth = 0; - int32_t arg_number = TestUtil::GetValueRegister(method, "bl1", offset); - for (const auto &checker : checkers_list) { - VRegValue vreg_value; - ASSERT_SUCCESS(debug_interface->GetVariable(thread, frame_depth, arg_number++, &vreg_value)); - ASSERT_TRUE(checker(ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(vreg_value))); + ++countChecker_; + uint32_t frameDepth = 0; + int32_t argNumber = TestUtil::GetValueRegister(method, "bl1", offset); + for (const auto &checker : checkersList) { + VRegValue vregValue; + ASSERT_SUCCESS(debugInterface->GetVariable(thread, frameDepth, argNumber++, &vregValue)); + ASSERT_TRUE(checker(ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(vregValue))); } return true; } private: - std::string panda_file_ = "js/GetVariable.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; + std::string pandaFile_ = "js/GetVariable.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; - int count_checker_ = 0; + int countChecker_ = 0; }; inline std::unique_ptr GetJsGetVariableTest() diff --git a/tests/runtime/tooling/api_tests/js/js_method_event_test.h b/tests/runtime/tooling/api_tests/js/js_method_event_test.h index 7a450f9429344ad49cc5b00a6ad8507d64941024..470a93734c5d273375f6a1e18add11f3640d814d 100644 --- a/tests/runtime/tooling/api_tests/js/js_method_event_test.h +++ b/tests/runtime/tooling/api_tests/js/js_method_event_test.h @@ -23,35 +23,35 @@ class JsMethodEventTest : public ApiTest { public: JsMethodEventTest() { - vm_death = [this]() { - ASSERT_EQ(method_entry_exit_count_, 0); - ASSERT_NE(method_entry_count_, 0); + vmDeath = [this]() { + ASSERT_EQ(methodEntryExitCount_, 0); + ASSERT_NE(methodEntryCount_, 0); return true; }; - method_entry = [this](PtThread, Method *) { - method_entry_exit_count_++; - method_entry_count_++; + methodEntry = [this](PtThread, Method *) { + methodEntryExitCount_++; + methodEntryCount_++; return true; }; - method_exit = [this](PtThread, Method *, bool, VRegValue) { - method_entry_exit_count_--; + methodExit = [this](PtThread, Method *, bool, VRegValue) { + methodEntryExitCount_--; return true; }; } std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/Sample.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; + std::string pandaFile_ = "js/Sample.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; - int method_entry_exit_count_ = 0; - int method_entry_count_ = 0; + int methodEntryExitCount_ = 0; + int methodEntryCount_ = 0; }; inline std::unique_ptr GetJsMethodEventTest() diff --git a/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h b/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h index 0f53770cbfb9911dd9c2cacf6b76a8619ad9f0ea..bb1f60c390b3f85066fea77b644e6df5e7bf8dff 100644 --- a/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h +++ b/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h @@ -26,9 +26,9 @@ class JsRestartFrameTest : public ApiTest { public: JsRestartFrameTest() { - vm_start = [this] { + vmStart = [this] { // NOLINTNEXTLINE(readability-magic-numbers) - location_ = TestUtil::GetLocation("RestartFrame.js", 35, panda_file_.c_str()); + location_ = TestUtil::GetLocation("RestartFrame.js", 35, pandaFile_.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); return true; }; @@ -36,41 +36,41 @@ public: breakpoint = [this](PtThread thread, Method *, const PtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); - ++breakpoint_counter_; + ++breakpointCounter_; TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, thread, location); - if (breakpoint_counter_ == 1) { - ASSERT_SUCCESS(debug_interface->RestartFrame(thread, 2)); + if (breakpointCounter_ == 1) { + ASSERT_SUCCESS(debugInterface->RestartFrame(thread, 2)); } - if (breakpoint_counter_ == 2) { - ASSERT_SUCCESS(debug_interface->RestartFrame(thread, 0)); + if (breakpointCounter_ == 2) { + ASSERT_SUCCESS(debugInterface->RestartFrame(thread, 0)); } return true; }; - load_module = [this](std::string_view module_name) { - if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { + loadModule = [this](std::string_view moduleName) { + if (moduleName.find(pandaFile_.c_str()) == std::string_view::npos) { return true; } - ASSERT_SUCCESS(debug_interface->SetBreakpoint(location_)); + ASSERT_SUCCESS(debugInterface->SetBreakpoint(location_)); return true; }; - method_entry = [this](PtThread, Method *) { - ++entry_exit_counter_; + methodEntry = [this](PtThread, Method *) { + ++entryExitCounter_; return true; }; - method_exit = [this](PtThread, Method *method, bool, VRegValue val) { - auto module_name = method->GetFullName(); - if (module_name == "_GLOBAL::func_2") { + methodExit = [this](PtThread, Method *method, bool, VRegValue val) { + auto moduleName = method->GetFullName(); + if (moduleName == "_GLOBAL::func_2") { // Force exit always zero - auto tagged_value = ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(val); - if (tagged_value.IsInt()) { - result_ = tagged_value.GetInt(); + auto taggedValue = ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(val); + if (taggedValue.IsInt()) { + result_ = taggedValue.GetInt(); } } - --entry_exit_counter_; + --entryExitCounter_; return true; }; @@ -88,7 +88,7 @@ public: return true; }; - vm_death = [this] { + vmDeath = [this] { // result_ indicate count of calls // frame0 +1 // frame1 +10 @@ -96,8 +96,8 @@ public: // frame3 +1000 +100000 // frame4 +10000 +100000 ASSERT_EQ(result_, 322311); - ASSERT_EQ(entry_exit_counter_, 0U); - ASSERT_EQ(breakpoint_counter_, 3U); + ASSERT_EQ(entryExitCounter_, 0U); + ASSERT_EQ(breakpointCounter_, 3U); return true; }; @@ -105,15 +105,15 @@ public: std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/RestartFrame.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; + std::string pandaFile_ = "js/RestartFrame.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; PtLocation location_ {nullptr, PtLocation::EntityId(0), 0}; - size_t breakpoint_counter_ = 0; - size_t entry_exit_counter_ = 0; + size_t breakpointCounter_ = 0; + size_t entryExitCounter_ = 0; int64_t result_ = 0; }; diff --git a/tests/runtime/tooling/api_tests/js/js_set_notification_test.h b/tests/runtime/tooling/api_tests/js/js_set_notification_test.h index 800a7a1568eae1bb14ed2ebce1220d4f3ee8808e..01d476c8bb81452d3396f8c3012b81a78bee9697 100644 --- a/tests/runtime/tooling/api_tests/js/js_set_notification_test.h +++ b/tests/runtime/tooling/api_tests/js/js_set_notification_test.h @@ -24,21 +24,21 @@ class JsSetNotificationTest : public ApiTest { public: JsSetNotificationTest() { - vm_death = [this]() { + vmDeath = [this]() { ASSERT_EQ(nn_, 5); ASSERT_EQ(entry_, 3); ASSERT_EQ(exit_, 5); return true; }; - method_entry = [this](PtThread /* thread */, Method *method) { + methodEntry = [this](PtThread /* thread */, Method *method) { if (method->GetFullName() == "_GLOBAL::func__2") { ++entry_; } return true; }; - method_exit = [this](PtThread thread, Method *method, bool, VRegValue) { + methodExit = [this](PtThread thread, Method *method, bool, VRegValue) { if (method->GetFullName() == "_GLOBAL::func__2") { ++exit_; ++nn_; @@ -61,25 +61,25 @@ public: ASSERT_EQ(exit_, 1); // Disable the entry hook globaly - debug_interface->SetNotification(PtThread::NONE, false, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); + debugInterface->SetNotification(PtThread::NONE, false, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); } else if (nn_ == 2) { ASSERT_EQ(entry_, 1); ASSERT_EQ(exit_, 2); // Enable the entry hook locally - debug_interface->SetNotification(thread, true, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); + debugInterface->SetNotification(thread, true, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); } else if (nn_ == 3) { ASSERT_EQ(entry_, 2); ASSERT_EQ(exit_, 3); // Disable the entry hook locally - debug_interface->SetNotification(thread, false, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); + debugInterface->SetNotification(thread, false, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); } else if (nn_ == 4) { ASSERT_EQ(entry_, 2); ASSERT_EQ(exit_, 4); // Enable the entry hook globaly - debug_interface->SetNotification(PtThread::NONE, true, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); + debugInterface->SetNotification(PtThread::NONE, true, PtHookType::PT_HOOK_TYPE_METHOD_ENTRY); } else if (nn_ == 5) { ASSERT_EQ(entry_, 3); ASSERT_EQ(exit_, 5); diff --git a/tests/runtime/tooling/api_tests/js/js_set_variable_test.h b/tests/runtime/tooling/api_tests/js/js_set_variable_test.h index 5d2ad6dfbb99dda2b06d80dfd0da7eda049ed347..c0b925dfa5a050d38f052ba1ead5615f5d25f23c 100644 --- a/tests/runtime/tooling/api_tests/js/js_set_variable_test.h +++ b/tests/runtime/tooling/api_tests/js/js_set_variable_test.h @@ -30,14 +30,14 @@ class JsSetVariableTest : public ApiTest { public: JsSetVariableTest() { - vm_death = [this]() { + vmDeath = [this]() { ASSERT_TRUE(checked_); - ASSERT_EQ(breakpoint_count_, 4); + ASSERT_EQ(breakpointCount_, 4); return true; }; - load_module = [this](std::string_view module_name) { - if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { + loadModule = [this](std::string_view moduleName) { + if (moduleName.find(pandaFile_.c_str()) == std::string_view::npos) { return true; } // NOLINTNEXTLINE(readability-magic-numbers) @@ -53,36 +53,36 @@ public: // NOLINTBEGIN(readability-magic-numbers) breakpoint = [this](PtThread thread, Method *method, PtLocation location) { - breakpoint_count_ += 1; - auto method_name = method->GetFullName(); - int frame_depth = 0; - uint32_t curr_offset = location.GetBytecodeOffset(); - if (method_name == "_GLOBAL::func_setBoolean_1") { + breakpointCount_ += 1; + auto methodName = method->GetFullName(); + int frameDepth = 0; + uint32_t currOffset = location.GetBytecodeOffset(); + if (methodName == "_GLOBAL::func_setBoolean_1") { VRegValue value = ecmascript::PtEcmaScriptExtension::TaggedValueToVRegValue(JSTaggedValue(true)); - ASSERT_SUCCESS(debug_interface->SetVariable( - thread, frame_depth, TestUtil::GetValueRegister(method, "value", curr_offset), value)); - } else if (method_name == "_GLOBAL::func_setInt_2") { + ASSERT_SUCCESS(debugInterface->SetVariable( + thread, frameDepth, TestUtil::GetValueRegister(method, "value", currOffset), value)); + } else if (methodName == "_GLOBAL::func_setInt_2") { VRegValue value = ecmascript::PtEcmaScriptExtension::TaggedValueToVRegValue(JSTaggedValue(123456789)); // 123456789 - ASSERT_SUCCESS(debug_interface->SetVariable( - thread, frame_depth, TestUtil::GetValueRegister(method, "value", curr_offset), value)); - } else if (method_name == "_GLOBAL::func_setDouble_3") { + ASSERT_SUCCESS(debugInterface->SetVariable( + thread, frameDepth, TestUtil::GetValueRegister(method, "value", currOffset), value)); + } else if (methodName == "_GLOBAL::func_setDouble_3") { VRegValue value = ecmascript::PtEcmaScriptExtension::TaggedValueToVRegValue(JSTaggedValue(12345.6789)); // 12345.6789 - ASSERT_SUCCESS(debug_interface->SetVariable( - thread, frame_depth, TestUtil::GetValueRegister(method, "value", curr_offset), value)); - } else if (method_name == "_GLOBAL::func_setString_4") { + ASSERT_SUCCESS(debugInterface->SetVariable( + thread, frameDepth, TestUtil::GetValueRegister(method, "value", currOffset), value)); + } else if (methodName == "_GLOBAL::func_setString_4") { VRegValue value = ecmascript::JSTestApi::StringToVRegValue("x2348x"); - ASSERT_SUCCESS(debug_interface->SetVariable( - thread, frame_depth, TestUtil::GetValueRegister(method, "value", curr_offset), value)); + ASSERT_SUCCESS(debugInterface->SetVariable( + thread, frameDepth, TestUtil::GetValueRegister(method, "value", currOffset), value)); } return true; }; // NOLINTEND(readability-magic-numbers) - method_entry = [this](PtThread thread, Method *method) { - auto method_name = method->GetFullName(); - if (method_name == "_GLOBAL::func_checkData_5") { + methodEntry = [this](PtThread thread, Method *method) { + auto methodName = method->GetFullName(); + if (methodName == "_GLOBAL::func_checkData_5") { checked_ = CheckData(thread, method); } return true; @@ -91,28 +91,28 @@ public: std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: static bool GetGlobalVariable(const PandaString &name, VRegValue *out) { - JSThread *js_thread = JSThread::Cast(JSThread::GetCurrent()); - auto ecma_vm = js_thread->GetEcmaVM(); - panda::ecmascript::JSHandle global_env = ecma_vm->GetGlobalEnv(); - auto global_object = global_env->GetGlobalObject(); + JSThread *jsThread = JSThread::Cast(JSThread::GetCurrent()); + auto ecmaVm = jsThread->GetEcmaVM(); + panda::ecmascript::JSHandle globalEnv = ecmaVm->GetGlobalEnv(); + auto globalObject = globalEnv->GetGlobalObject(); - panda::ecmascript::ObjectFactory *factory = ecma_vm->GetFactory(); + panda::ecmascript::ObjectFactory *factory = ecmaVm->GetFactory(); // NOLINTBEGIN(readability-redundant-string-cstr) - panda::ecmascript::JSHandle exec_handle( + panda::ecmascript::JSHandle execHandle( factory->NewFromStdString(name.c_str())); // NOLINTEND(readability-redundant-string-cstr) - panda::ecmascript::JSHandle object_handle(js_thread, global_object); - if (!panda::ecmascript::JSObject::HasProperty(js_thread, object_handle, exec_handle)) { + panda::ecmascript::JSHandle objectHandle(jsThread, globalObject); + if (!panda::ecmascript::JSObject::HasProperty(jsThread, objectHandle, execHandle)) { return false; } - auto property = panda::ecmascript::JSObject::GetProperty(js_thread, object_handle, exec_handle); + auto property = panda::ecmascript::JSObject::GetProperty(jsThread, objectHandle, execHandle); *out = ecmascript::PtEcmaScriptExtension::TaggedValueToVRegValue(property.GetValue().GetTaggedValue()); return true; } @@ -120,48 +120,48 @@ private: bool CheckData(PtThread /*unused*/, Method * /*unused*/) { { - VRegValue pt_bool; - ASSERT_TRUE(GetGlobalVariable("boolData", &pt_bool)); - ASSERT_EQ(ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(pt_bool).GetRawData(), + VRegValue ptBool; + ASSERT_TRUE(GetGlobalVariable("boolData", &ptBool)); + ASSERT_EQ(ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(ptBool).GetRawData(), JSTaggedValue::VALUE_TRUE); } { - VRegValue pt_int; - const int expected_value = 123456789; - ASSERT_TRUE(GetGlobalVariable("intData", &pt_int)); - int int_value = ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(pt_int).GetInt(); - ASSERT_EQ(int_value, expected_value); + VRegValue ptInt; + const int expectedValue = 123456789; + ASSERT_TRUE(GetGlobalVariable("intData", &ptInt)); + int intValue = ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(ptInt).GetInt(); + ASSERT_EQ(intValue, expectedValue); } { - VRegValue pt_double; - const double expected_value = 12345.6789; - ASSERT_TRUE(GetGlobalVariable("doubleData", &pt_double)); - double double_value = ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(pt_double).GetDouble(); - ASSERT_EQ(double_value, expected_value); + VRegValue ptDouble; + const double expectedValue = 12345.6789; + ASSERT_TRUE(GetGlobalVariable("doubleData", &ptDouble)); + double doubleValue = ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(ptDouble).GetDouble(); + ASSERT_EQ(doubleValue, expectedValue); } { - VRegValue pt_string; - PandaString string_value; - const PandaString expected_value = "x2348x"; - ASSERT_TRUE(GetGlobalVariable("stringData", &pt_string)); - ASSERT_TRUE(ecmascript::JSTestApi::VRegValueToString(pt_string, &string_value)); + VRegValue ptString; + PandaString stringValue; + const PandaString expectedValue = "x2348x"; + ASSERT_TRUE(GetGlobalVariable("stringData", &ptString)); + ASSERT_TRUE(ecmascript::JSTestApi::VRegValueToString(ptString, &stringValue)); // NOLINTNEXTLINE(readability-string-compare) - ASSERT_TRUE(string_value.compare(expected_value) == 0); + ASSERT_TRUE(stringValue.compare(expectedValue) == 0); } return true; } void SetBreakpoint(uint32_t line) { - auto location = TestUtil::GetLocation("SetVariable.js", line, panda_file_.c_str()); + auto location = TestUtil::GetLocation("SetVariable.js", line, pandaFile_.c_str()); ASSERT_TRUE(location.GetMethodId().IsValid()); - ASSERT_SUCCESS(debug_interface->SetBreakpoint(location)); + ASSERT_SUCCESS(debugInterface->SetBreakpoint(location)); } bool checked_ = false; - uint32_t breakpoint_count_ = 0; - std::string panda_file_ = "js/SetVariable.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; + uint32_t breakpointCount_ = 0; + std::string pandaFile_ = "js/SetVariable.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; }; inline std::unique_ptr GetJsSetVariableTest() diff --git a/tests/runtime/tooling/api_tests/js/js_single_step_test.h b/tests/runtime/tooling/api_tests/js/js_single_step_test.h index 0226c89d610a8cd74b3968eeea6e413f5514fd82..60141e2023d6e2acc8eb3a1d2727aa3d2642d0ae 100644 --- a/tests/runtime/tooling/api_tests/js/js_single_step_test.h +++ b/tests/runtime/tooling/api_tests/js/js_single_step_test.h @@ -23,72 +23,72 @@ class JsSingleStepTest : public ApiTest { public: JsSingleStepTest() { - vm_start = [this] { + vmStart = [this] { // NOLINTNEXTLINE(readability-magic-numbers) - location_start_ = TestUtil::GetLocation("Sample.js", 19, panda_file_.c_str()); + locationStart_ = TestUtil::GetLocation("Sample.js", 19, pandaFile_.c_str()); // NOLINTNEXTLINE(readability-magic-numbers) - location_end_ = TestUtil::GetLocation("Sample.js", 22, panda_file_.c_str()); + locationEnd_ = TestUtil::GetLocation("Sample.js", 22, pandaFile_.c_str()); return true; }; - vm_death = [this]() { - ASSERT_NE(step_count_, 0); - ASSERT_EQ(breakpoint_count_, 2); + vmDeath = [this]() { + ASSERT_NE(stepCount_, 0); + ASSERT_EQ(breakpointCount_, 2); return true; }; - load_module = [this](std::string_view module_name) { - if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { + loadModule = [this](std::string_view moduleName) { + if (moduleName.find(pandaFile_.c_str()) == std::string_view::npos) { return true; } - ASSERT_SUCCESS(debug_interface->SetBreakpoint(location_end_)); + ASSERT_SUCCESS(debugInterface->SetBreakpoint(locationEnd_)); return true; }; breakpoint = [this](PtThread, Method *, const PtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); - ASSERT_LOCATION_EQ(location, location_end_); + ASSERT_LOCATION_EQ(location, locationEnd_); // Check's what step signalled before breakpoint - ASSERT_LOCATION_EQ(location, location_step_); - ASSERT_TRUE(collect_steps_); - breakpoint_count_++; + ASSERT_LOCATION_EQ(location, locationStep_); + ASSERT_TRUE(collectSteps_); + breakpointCount_++; // Disable collect steps - collect_steps_ = false; + collectSteps_ = false; return true; }; - single_step = [this](PtThread, Method *, const PtLocation &location) { + singleStep = [this](PtThread, Method *, const PtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); - if (!collect_steps_) { - if (location_start_ == location) { - collect_steps_ = true; + if (!collectSteps_) { + if (locationStart_ == location) { + collectSteps_ = true; } return true; } - ASSERT_NE(bytecode_offset_, location.GetBytecodeOffset()); - location_step_ = location; - step_count_++; - bytecode_offset_ = location.GetBytecodeOffset(); + ASSERT_NE(bytecodeOffset_, location.GetBytecodeOffset()); + locationStep_ = location; + stepCount_++; + bytecodeOffset_ = location.GetBytecodeOffset(); return true; }; } std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/Sample.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; - PtLocation location_start_ {nullptr, PtLocation::EntityId(0), 0}; - PtLocation location_end_ {nullptr, PtLocation::EntityId(0), 0}; - PtLocation location_step_ {nullptr, PtLocation::EntityId(0), 0}; - int step_count_ = 0; - int breakpoint_count_ = 0; - bool collect_steps_ = false; - uint32_t bytecode_offset_ = std::numeric_limits::max(); + std::string pandaFile_ = "js/Sample.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + PtLocation locationStart_ {nullptr, PtLocation::EntityId(0), 0}; + PtLocation locationEnd_ {nullptr, PtLocation::EntityId(0), 0}; + PtLocation locationStep_ {nullptr, PtLocation::EntityId(0), 0}; + int stepCount_ = 0; + int breakpointCount_ = 0; + bool collectSteps_ = false; + uint32_t bytecodeOffset_ = std::numeric_limits::max(); }; inline std::unique_ptr GetJsSingleStepTest() diff --git a/tests/runtime/tooling/api_tests/js/js_vm_event_test.h b/tests/runtime/tooling/api_tests/js/js_vm_event_test.h index 3691872df9c94655733b3ada671755116387a985..46acd025191de7e6946415285246c7976dd22d0f 100644 --- a/tests/runtime/tooling/api_tests/js/js_vm_event_test.h +++ b/tests/runtime/tooling/api_tests/js/js_vm_event_test.h @@ -23,38 +23,38 @@ class JsVmEventTest : public ApiTest { public: JsVmEventTest() { - vm_start = [this]() { - start_counter_++; + vmStart = [this]() { + startCounter_++; return true; }; - vm_init = [this](PtThread thread) { - init_thread_ = thread.GetId(); - init_counter_++; + vmInit = [this](PtThread thread) { + initThread_ = thread.GetId(); + initCounter_++; return true; }; - vm_death = [this]() { - death_counter_++; - ASSERT_NE(init_thread_, PtThread::NONE.GetId()); - ASSERT_EQ(start_counter_, 1U); - ASSERT_EQ(init_counter_, 1U); + vmDeath = [this]() { + deathCounter_++; + ASSERT_NE(initThread_, PtThread::NONE.GetId()); + ASSERT_EQ(startCounter_, 1U); + ASSERT_EQ(initCounter_, 1U); return true; }; } std::pair GetEntryPoint() override { - return {panda_file_.c_str(), entry_point_.c_str()}; + return {pandaFile_.c_str(), entryPoint_.c_str()}; } private: - std::string panda_file_ = "js/Sample.abc"; - std::string entry_point_ = "_GLOBAL::func_main_0"; - size_t start_counter_ = 0; - size_t init_counter_ = 0; - size_t death_counter_ = 0; - uint32_t init_thread_ = PtThread::NONE.GetId(); + std::string pandaFile_ = "js/Sample.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + size_t startCounter_ = 0; + size_t initCounter_ = 0; + size_t deathCounter_ = 0; + uint32_t initThread_ = PtThread::NONE.GetId(); }; inline std::unique_ptr GetJsVmEventTest() diff --git a/tests/runtime/tooling/js_test_api.h b/tests/runtime/tooling/js_test_api.h index 46e6a758eb3b72ffd344f9ec4e07557f8140c2f6..e248ff60e72aec8808cb40d4546fe0748382a2db 100644 --- a/tests/runtime/tooling/js_test_api.h +++ b/tests/runtime/tooling/js_test_api.h @@ -29,15 +29,15 @@ class JSTestApi { public: static VRegValue StringToVRegValue(const PandaString &value) { - JSThread *js_thread = JSThread::Cast(JSThread::GetCurrent()); - [[maybe_unused]] panda::ecmascript::EcmaHandleScope handle_scope(js_thread); - auto ecma_vm = js_thread->GetEcmaVM(); + JSThread *jsThread = JSThread::Cast(JSThread::GetCurrent()); + [[maybe_unused]] panda::ecmascript::EcmaHandleScope handleScope(jsThread); + auto ecmaVm = jsThread->GetEcmaVM(); - panda::ecmascript::ObjectFactory *factory = ecma_vm->GetFactory(); - panda::ecmascript::JSHandle str_handle( + panda::ecmascript::ObjectFactory *factory = ecmaVm->GetFactory(); + panda::ecmascript::JSHandle strHandle( factory->NewFromStdString(value.c_str())); - return PtEcmaScriptExtension::TaggedValueToVRegValue(str_handle.GetTaggedValue()); + return PtEcmaScriptExtension::TaggedValueToVRegValue(strHandle.GetTaggedValue()); } static bool VRegValueToString(VRegValue value, PandaString *out) { diff --git a/tests/runtime/tooling/launcher.cpp b/tests/runtime/tooling/launcher.cpp index aa1da27c769fcb413910abee1f5e7f009caae89b..ca7f098918c9d4712b751c58531fcb48c7800e11 100644 --- a/tests/runtime/tooling/launcher.cpp +++ b/tests/runtime/tooling/launcher.cpp @@ -21,7 +21,7 @@ #include "generated/base_options.h" namespace panda::tooling::test { -extern void SetExtractorFactoryForTest(TestExtractorFactory *test_extractor); +extern void SetExtractorFactoryForTest(TestExtractorFactory *testExtractor); class BaseDebugApiTest : public testing::TestWithParam { public: @@ -32,18 +32,18 @@ public: BaseDebugApiTest() = default; protected: - void RunTest(RuntimeOptions &options, const char *test_name) const + void RunTest(RuntimeOptions &options, const char *testName) const { - std::cout << "Running " << test_name << std::endl; - SetCurrentTestName(test_name); + std::cout << "Running " << testName << std::endl; + SetCurrentTestName(testName); auto *factory = new TestExtractorFactory(); SetExtractorFactoryForTest(factory); Logger::Initialize(base_options::Options("")); - auto [pandaFile, entryPoint] = GetTestEntryPoint(test_name); - auto boot_files = options.GetBootPandaFiles(); - boot_files.push_back(pandaFile); - options.SetBootPandaFiles(boot_files); - ASSERT_TRUE(Runtime::Create(options)) << test_name; + auto [pandaFile, entryPoint] = GetTestEntryPoint(testName); + auto bootFiles = options.GetBootPandaFiles(); + bootFiles.push_back(pandaFile); + options.SetBootPandaFiles(bootFiles); + ASSERT_TRUE(Runtime::Create(options)) << testName; auto res = Runtime::GetCurrent()->ExecutePandaFile(pandaFile, entryPoint, {}); ASSERT_TRUE(res.HasValue()); delete factory; @@ -53,21 +53,21 @@ protected: class EcmaScriptDebugApiTest : public BaseDebugApiTest { protected: - void RunEcmaScriptTest(const char *test_name) const + void RunEcmaScriptTest(const char *testName) const { RuntimeOptions options; options.SetDebuggerLibraryPath(DEBUG_LIBRARY_PATH); options.SetBootPandaFiles({PANDA_STD_LIB}); options.SetLoadRuntimes({"ecmascript"}); options.SetRunGcInPlace(true); - RunTest(options, test_name); + RunTest(options, testName); } }; TEST_P(EcmaScriptDebugApiTest, EcmaScriptSuite) { - const char *test_name = GetParam(); - RunEcmaScriptTest(test_name); + const char *testName = GetParam(); + RunEcmaScriptTest(testName); } INSTANTIATE_TEST_SUITE_P(DebugApiTests, EcmaScriptDebugApiTest, diff --git a/tests/runtime/tooling/test_list.cpp b/tests/runtime/tooling/test_list.cpp index 1ee1a60b9ea9b32f918275db27ed9a4347c1d04c..e519434fdc18835622f3907efba20c40b9134f76 100644 --- a/tests/runtime/tooling/test_list.cpp +++ b/tests/runtime/tooling/test_list.cpp @@ -19,7 +19,7 @@ #include "test_util.h" namespace panda::tooling::test { -static const char *G_CURRENT_TEST_NAME = nullptr; +static const char *g_gCurrentTestName = nullptr; static void RegisterTests() { @@ -44,29 +44,29 @@ std::vector GetTestList(panda_file::SourceLang language) RegisterTests(); std::vector res; auto &tests = TestUtil::GetTests(); - auto language_it = tests.find(language); - if (language_it == tests.end()) { + auto languageIt = tests.find(language); + if (languageIt == tests.end()) { return {}; } - for (const auto &entry : language_it->second) { + for (const auto &entry : languageIt->second) { res.push_back(entry.first); } return res; } -void SetCurrentTestName(const char *test_name) +void SetCurrentTestName(const char *testName) { - G_CURRENT_TEST_NAME = test_name; + g_gCurrentTestName = testName; } const char *GetCurrentTestName() { - return G_CURRENT_TEST_NAME; + return g_gCurrentTestName; } -std::pair GetTestEntryPoint(const char *test_name) +std::pair GetTestEntryPoint(const char *testName) { - return TestUtil::GetTest(test_name)->GetEntryPoint(); + return TestUtil::GetTest(testName)->GetEntryPoint(); } } // namespace panda::tooling::test diff --git a/tests/runtime/tooling/test_list.h b/tests/runtime/tooling/test_list.h index 3968c298bde3db5ffa5418104de8b971b43872d8..f4d6d88ed55d9ab4df06719e730eda65e7d39353 100644 --- a/tests/runtime/tooling/test_list.h +++ b/tests/runtime/tooling/test_list.h @@ -23,9 +23,9 @@ namespace panda::tooling::test { std::vector GetTestList(panda_file::SourceLang language); -void SetCurrentTestName(const char *test_name); +void SetCurrentTestName(const char *testName); -std::pair GetTestEntryPoint(const char *test_name); +std::pair GetTestEntryPoint(const char *testName); } // namespace panda::tooling::test #endif // PANDA_RUNTIME_DEBUG_TEST_TEST_LIST_H_