diff --git a/ecmascript/compiler/builtins/builtins_call_signature.h b/ecmascript/compiler/builtins/builtins_call_signature.h index b3f351c041078221b72e65ef059e9f7fb3055701..1843f9a18a6f8c27337a5c83776203e26ef785b8 100644 --- a/ecmascript/compiler/builtins/builtins_call_signature.h +++ b/ecmascript/compiler/builtins/builtins_call_signature.h @@ -327,6 +327,8 @@ public: switch (builtinId) { case BuiltinsStubCSigns::ID::StringFromCharCode: case BuiltinsStubCSigns::ID::MapGet: + case BuiltinsStubCSigns::ID::MapHas: + case BuiltinsStubCSigns::ID::SetHas: return true; default: return false; @@ -445,6 +447,10 @@ public: return ConstantIndex::MATH_IMUL_INDEX; case BuiltinsStubCSigns::ID::MapGet: return ConstantIndex::MAP_GET_INDEX; + case BuiltinsStubCSigns::ID::MapHas: + return ConstantIndex::MAP_HAS_INDEX; + case BuiltinsStubCSigns::ID::SetHas: + return ConstantIndex::SET_HAS_INDEX; case BuiltinsStubCSigns::ID::StringLocaleCompare: return ConstantIndex::LOCALE_COMPARE_FUNCTION_INDEX; case BuiltinsStubCSigns::ID::ArraySort: @@ -559,6 +565,8 @@ public: {GlobalIsFinite, "isFinite"}, {GlobalIsNan, "isNan"}, {MapGet, "Map.get"}, + {MapHas, "Map.has"}, + {SetHas, "Set.has"}, }; if (builtinId2Str.count(id) > 0) { return builtinId2Str.at(id); diff --git a/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp index e60f4eaf278145bbe3055b1530113952ad909bb8..3dacaefa7e8eb0f1d6489cdcb1977b53046c4b9d 100644 --- a/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp @@ -245,7 +245,7 @@ void BuiltinsCollectionStubBuilder::Has(Variable *result, Label LinkedHashTableStubBuilder linkedHashTableStubBuilder(this, glue_); res = linkedHashTableStubBuilder.Has(linkedTable, key); } - *result = res; + *result = BooleanToTaggedBooleanPtr(res); Jump(exit); } diff --git a/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp b/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp index ceeeca5befef4ea706e28152b3af9b4b158e1019..9c1725b416b34b00c21e25e78615a9d8e2569ada 100644 --- a/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp +++ b/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp @@ -579,26 +579,10 @@ GateRef LinkedHashTableStubBuilder:: auto env = GetEnvironment(); Label cfgEntry(env); env->SubCfgEntry(&cfgEntry); - Label exit(env); - Label nonEmpty(env); - DEFVARIABLE(res, VariableType::JS_ANY(), TaggedFalse()); - GateRef size = GetNumberOfElements(linkedTable); - BRANCH(Int32Equal(size, Int32(0)), &exit, &nonEmpty); - Bind(&nonEmpty); HashStubBuilder hashBuilder(this, glue_); GateRef hash = hashBuilder.GetHash(key); - GateRef entry = FindElement(linkedTable, key, hash); - Label findEntry(env); - BRANCH(Int32Equal(entry, Int32(-1)), &exit, &findEntry); - Bind(&findEntry); - { - res = TaggedTrue(); - Jump(&exit); - } - - Bind(&exit); - auto ret = *res; + GateRef ret = Int32NotEqual(entry, Int32(-1)); env->SubCfgExit(); return ret; } diff --git a/ecmascript/compiler/call_signature.cpp b/ecmascript/compiler/call_signature.cpp index 9dd224f78d4d956fa0a6bae7fd41b5ec53edbade..a6e536ab99530837db73685a30f0c1cc6cb66cec 100644 --- a/ecmascript/compiler/call_signature.cpp +++ b/ecmascript/compiler/call_signature.cpp @@ -2383,18 +2383,32 @@ DEF_CALL_SIGNATURE(CreateJSMapIterator) DEF_CALL_SIGNATURE(JSMapGet) { - // 3 : 3 input parameters - CallSignature signature("JSMapGet", 0, 3, - ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); - *callSign = signature; - // 3 : 3 input parameters - std::array params = { - VariableType::NATIVE_POINTER(), // glue - VariableType::JS_ANY(), // obj - VariableType::JS_ANY(), // key - }; - callSign->SetParameters(params.data()); - callSign->SetCallConv(CallSignature::CallConv::CCallConv); + *callSign = CallSignature("JSMapGet", 0, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY(), + { + VariableType::NATIVE_POINTER(), // glue + VariableType::JS_ANY(), // obj + VariableType::JS_ANY(), // key + }); +} + +DEF_CALL_SIGNATURE(JSMapHas) +{ + *callSign = CallSignature("JSMapHas", 0, ArgumentsOrder::DEFAULT_ORDER, VariableType::BOOL(), + { + VariableType::NATIVE_POINTER(), // glue + VariableType::JS_ANY(), // obj + VariableType::JS_ANY(), // key + }); +} + +DEF_CALL_SIGNATURE(JSSetHas) +{ + *callSign = CallSignature("JSSetHas", 0, ArgumentsOrder::DEFAULT_ORDER, VariableType::BOOL(), + { + VariableType::NATIVE_POINTER(), // glue + VariableType::JS_ANY(), // obj + VariableType::JS_ANY(), // key + }); } DEF_CALL_SIGNATURE(FastStringEqual) @@ -2410,7 +2424,6 @@ DEF_CALL_SIGNATURE(FastStringEqual) VariableType::JS_ANY(), // ecmaString2 }; callSign->SetParameters(params.data()); - callSign->SetCallConv(CallSignature::CallConv::CCallConv); } DEF_CALL_SIGNATURE(FastStringAdd) diff --git a/ecmascript/compiler/call_signature.h b/ecmascript/compiler/call_signature.h index 44e5a88fc900bbc190e4834846f9be87a8d10ef9..97a4b8e4f72a5248a964c181348cff8ed12c9265 100644 --- a/ecmascript/compiler/call_signature.h +++ b/ecmascript/compiler/call_signature.h @@ -81,6 +81,13 @@ public: SetVariadicArgs(flags); } + CallSignature(std::string name, int flags, ArgumentsOrder order, VariableType returnType, + std::initializer_list params) + : CallSignature(std::move(name), flags, params.size(), order, returnType) + { + paramsType_ = std::make_unique>(params); + } + CallSignature() = default; ~CallSignature() = default; @@ -505,6 +512,8 @@ private: V(CreateJSSetIterator) \ V(CreateJSMapIterator) \ V(JSMapGet) \ + V(JSMapHas) \ + V(JSSetHas) \ V(JSHClassFindProtoTransitions) \ V(NumberHelperStringToDouble) \ V(GetStringToListCacheArray) \ diff --git a/ecmascript/compiler/circuit_builder.h b/ecmascript/compiler/circuit_builder.h index d828213b3c262d40783b91f3c140d4e0f00dd612..ddef6ff1e5a4a312c0a3a4b3322a68b9ce90aba6 100644 --- a/ecmascript/compiler/circuit_builder.h +++ b/ecmascript/compiler/circuit_builder.h @@ -174,7 +174,8 @@ class PostSchedule; V(Int64LessThanOrEqual, Icmp, static_cast(ICmpCondition::SLE)) \ V(Int64GreaterThan, Icmp, static_cast(ICmpCondition::SGT)) \ V(Int64GreaterThanOrEqual, Icmp, static_cast(ICmpCondition::SGE)) \ - V(Int64UnsignedLessThanOrEqual, Icmp, static_cast(ICmpCondition::ULE)) + V(Int64UnsignedLessThanOrEqual, Icmp, static_cast(ICmpCondition::ULE)) \ + V(Int64UnsignedGreaterThanOrEqual, Icmp, static_cast(ICmpCondition::UGE)) class CircuitBuilder { public: diff --git a/ecmascript/compiler/common_stubs.cpp b/ecmascript/compiler/common_stubs.cpp index e7853b3786f828e696aa1d675224baeabe50846e..4c95cb30a66f925e1f854a13a4d3954657e2c4b2 100644 --- a/ecmascript/compiler/common_stubs.cpp +++ b/ecmascript/compiler/common_stubs.cpp @@ -1148,10 +1148,31 @@ void JSMapGetStubBuilder::GenerateCircuit() GateRef obj = TaggedArgument(1); GateRef key = TaggedArgument(2U); - LinkedHashTableStubBuilder linkedHashTableStubBuilder(this, glue); - GateRef linkedTable = linkedHashTableStubBuilder.GetLinked(obj); - GateRef result = linkedHashTableStubBuilder.Get(linkedTable, key); - Return(result); + LinkedHashTableStubBuilder builder(this, glue); + GateRef linkedTable = builder.GetLinked(obj); + Return(builder.Get(linkedTable, key)); +} + +void JSMapHasStubBuilder::GenerateCircuit() +{ + GateRef glue = PtrArgument(0); + GateRef obj = TaggedArgument(1); + GateRef key = TaggedArgument(2U); + + LinkedHashTableStubBuilder builder(this, glue); + GateRef linkedTable = builder.GetLinked(obj); + Return(builder.Has(linkedTable, key)); +} + +void JSSetHasStubBuilder::GenerateCircuit() +{ + GateRef glue = PtrArgument(0); + GateRef obj = TaggedArgument(1); + GateRef key = TaggedArgument(2U); + + LinkedHashTableStubBuilder builder(this, glue); + GateRef linkedTable = builder.GetLinked(obj); + Return(builder.Has(linkedTable, key)); } CallSignature CommonStubCSigns::callSigns_[CommonStubCSigns::NUM_OF_STUBS]; diff --git a/ecmascript/compiler/common_stubs.h b/ecmascript/compiler/common_stubs.h index 6a531b67b8372ab444d915278bdca0d50e23682d..ba41bad544b2fa27f392960d0faf8a98bdcff304 100644 --- a/ecmascript/compiler/common_stubs.h +++ b/ecmascript/compiler/common_stubs.h @@ -92,6 +92,8 @@ namespace panda::ecmascript::kungfu { V(CreateJSSetIterator) \ V(CreateJSMapIterator) \ V(JSMapGet) \ + V(JSMapHas) \ + V(JSSetHas) \ V(GetSingleCharCodeByIndex) \ V(FastStringEqual) \ V(FastStringAdd) \ diff --git a/ecmascript/compiler/mcr_opcodes.h b/ecmascript/compiler/mcr_opcodes.h index aac486bd6a7cad51cfcfa1c2bcc1e1054babad04..757e0c91b701604f6aba7d39bbff774498f6cb5a 100644 --- a/ecmascript/compiler/mcr_opcodes.h +++ b/ecmascript/compiler/mcr_opcodes.h @@ -118,6 +118,8 @@ namespace panda::ecmascript::kungfu { V(DataViewSet, DATA_VIEW_SET, GateFlags::NO_WRITE, 1, 1, 6) \ V(MapGet, MAP_GET, GateFlags::NO_WRITE, 1, 1, 2) \ V(DateGetTime, DATE_GET_TIME, GateFlags::NO_WRITE, 1, 1, 1) \ + V(MapHas, MAP_HAS, GateFlags::NO_WRITE, 1, 1, 2) \ + V(SetHas, SET_HAS, GateFlags::NO_WRITE, 1, 1, 2) \ MCR_BINARY_GATE_META_DATA_CACHE_LIST(V) #define MCR_GATE_META_DATA_LIST_WITH_PC_OFFSET(V) \ diff --git a/ecmascript/compiler/native_inline_lowering.cpp b/ecmascript/compiler/native_inline_lowering.cpp index 4417cdc2e0aaebf506d0b4b8afd83f68ca5f5b39..44d8a10088bfc7c9620cf57f656ba9d9cbf9927d 100644 --- a/ecmascript/compiler/native_inline_lowering.cpp +++ b/ecmascript/compiler/native_inline_lowering.cpp @@ -224,6 +224,12 @@ void NativeInlineLowering::RunNativeInlineLowering() case BuiltinsStubCSigns::ID::MapGet: InlineStubBuiltin(gate, 1U, argc, id, circuit_->MapGet(), skipThis); break; + case BuiltinsStubCSigns::ID::MapHas: + InlineStubBuiltin(gate, 1U, argc, id, circuit_->MapHas(), skipThis); + break; + case BuiltinsStubCSigns::ID::SetHas: + InlineStubBuiltin(gate, 1U, argc, id, circuit_->SetHas(), skipThis); + break; default: break; } diff --git a/ecmascript/compiler/number_speculative_retype.cpp b/ecmascript/compiler/number_speculative_retype.cpp index 861525b12a73c042565d97bfecd4e2c272554fac..931bf3c9dc291273e032039a1175def8ef2d036f 100644 --- a/ecmascript/compiler/number_speculative_retype.cpp +++ b/ecmascript/compiler/number_speculative_retype.cpp @@ -241,6 +241,9 @@ GateRef NumberSpeculativeRetype::VisitGate(GateRef gate) return VisitDataViewSet(gate); case OpCode::DATE_GET_TIME: return VisitDateGetTime(gate); + case OpCode::MAP_HAS: + case OpCode::SET_HAS: + return VisitOthers(gate, GateType::BooleanType()); case OpCode::JS_BYTECODE: case OpCode::RUNTIME_CALL: case OpCode::PRIMITIVE_TYPE_CHECK: @@ -795,10 +798,10 @@ GateRef NumberSpeculativeRetype::VisitFrameState(GateRef gate) return Circuit::NullGate(); } -GateRef NumberSpeculativeRetype::VisitOthers(GateRef gate) +GateRef NumberSpeculativeRetype::VisitOthers(GateRef gate, GateType outputType) { if (IsRetype()) { - return SetOutputType(gate, GateType::AnyType()); + return SetOutputType(gate, outputType); } if (IsConvert()) { size_t valueNum = acc_.GetNumValueIn(gate); diff --git a/ecmascript/compiler/number_speculative_retype.h b/ecmascript/compiler/number_speculative_retype.h index e616aaf952a991005db18fb829dc9debc0ea91fd..47f2364310ae08b02c14e4b8b69a1ad6aa09cf7e 100644 --- a/ecmascript/compiler/number_speculative_retype.h +++ b/ecmascript/compiler/number_speculative_retype.h @@ -109,10 +109,9 @@ private: GateRef VisitStoreProperty(GateRef gate); GateRef VisitLoadProperty(GateRef gate); GateRef VisitNumberRelated(GateRef gate, ParamType paramType); - GateRef VisitCallBuiltins(GateRef gate); GateRef VisitDataViewGet(GateRef gate); GateRef VisitDataViewSet(GateRef gate); - GateRef VisitOthers(GateRef gate); + GateRef VisitOthers(GateRef gate, GateType outputType = GateType::AnyType()); GateRef VisitTypeConvert(GateRef gate); GateRef VisitFrameState(GateRef gate); GateRef VisitIsTrueOrFalse(GateRef gate); diff --git a/ecmascript/compiler/stub_builder-inl.h b/ecmascript/compiler/stub_builder-inl.h index a7ebcdccf18113c2e8dc7e54da1ce7c20e8fa3cc..96e09e0f9f69649e84edda3b1b9bd26387d9d43a 100644 --- a/ecmascript/compiler/stub_builder-inl.h +++ b/ecmascript/compiler/stub_builder-inl.h @@ -829,6 +829,11 @@ inline GateRef StubBuilder::DoubleToTaggedDoublePtr(GateRef x) return env_->GetBuilder()->DoubleToTaggedDoublePtr(x); } +inline GateRef StubBuilder::BooleanToTaggedBooleanPtr(GateRef x) +{ + return env_->GetBuilder()->BooleanToTaggedBooleanPtr(x); +} + inline GateRef StubBuilder::TaggedPtrToTaggedDoublePtr(GateRef x) { return DoubleToTaggedDoublePtr(CastInt64ToFloat64(ChangeTaggedPointerToInt64(x))); @@ -995,6 +1000,11 @@ inline GateRef StubBuilder::Int64UnsignedLessThanOrEqual(GateRef x, GateRef y) return env_->GetBuilder()->Int64UnsignedLessThanOrEqual(x, y); } +inline GateRef StubBuilder::Int64UnsignedGreaterThanOrEqual(GateRef x, GateRef y) +{ + return env_->GetBuilder()->Int64UnsignedGreaterThanOrEqual(x, y); +} + inline GateRef StubBuilder::IntPtrGreaterThan(GateRef x, GateRef y) { return env_->GetBuilder()->IntPtrGreaterThan(x, y); diff --git a/ecmascript/compiler/stub_builder.cpp b/ecmascript/compiler/stub_builder.cpp index 2aa89422d836a6f96b1d10665f9b32218195879b..c3dcd54b1d4307b44e3bf5bfce4aaf78405f3a09 100644 --- a/ecmascript/compiler/stub_builder.cpp +++ b/ecmascript/compiler/stub_builder.cpp @@ -6776,7 +6776,6 @@ void StubBuilder::CalcHashcodeForDouble(GateRef x, Variable *res, Label *exit) GateRef xInt64 = Int64Sub(ChangeTaggedPointerToInt64(x), Int64(JSTaggedValue::DOUBLE_ENCODE_OFFSET)); GateRef fractionBits = Int64And(xInt64, Int64(base::DOUBLE_SIGNIFICAND_MASK)); GateRef expBits = Int64And(xInt64, Int64(base::DOUBLE_EXPONENT_MASK)); - GateRef signBit = Int64And(xInt64, Int64(base::DOUBLE_SIGN_MASK)); GateRef isZero = BoolAnd( Int64Equal(expBits, Int64(0)), Int64Equal(fractionBits, Int64(0))); @@ -6796,22 +6795,8 @@ void StubBuilder::CalcHashcodeForDouble(GateRef x, Variable *res, Label *exit) BRANCH(CanDoubleRepresentInt(exp, expBits, fractionBits), &calcHash, &convertToInt); Bind(&convertToInt); { - GateRef shift = Int64Sub(Int64(base::DOUBLE_SIGNIFICAND_SIZE), exp); - GateRef intVal = Int64Add( - Int64LSL(Int64(1), exp), - Int64LSR(fractionBits, shift)); - DEFVARIABLE(intVariable, VariableType::INT64(), intVal); - Label negate(env); - Label pass(env); - BRANCH(Int64NotEqual(signBit, Int64(0)), &negate, &pass); - Bind(&negate); - { - intVariable = Int64Sub(Int64(0), intVal); - Jump(&pass); - } - Bind(&pass); - value = IntToTaggedPtr(TruncInt64ToInt32(*intVariable)); - Jump(&calcHash); + *res = ChangeFloat64ToInt32(CastInt64ToFloat64(xInt64)); + Jump(exit); } Bind(&calcHash); { @@ -6821,7 +6806,7 @@ void StubBuilder::CalcHashcodeForDouble(GateRef x, Variable *res, Label *exit) } Bind(&zero); - *res = env_->GetBuilder()->CalcHashcodeForInt(IntToTaggedPtr(Int32(0))); + *res = Int32(0); Jump(exit); } diff --git a/ecmascript/compiler/stub_builder.h b/ecmascript/compiler/stub_builder.h index 33b62771337d9c10b74e47f1b278ac962c7d39ec..05389cdb9d9d5920f730a55c9a4412bd22c9a856 100644 --- a/ecmascript/compiler/stub_builder.h +++ b/ecmascript/compiler/stub_builder.h @@ -272,6 +272,7 @@ public: GateRef Int64ToTaggedInt(GateRef x); GateRef Int64ToTaggedIntPtr(GateRef x); GateRef DoubleToTaggedDoublePtr(GateRef x); + GateRef BooleanToTaggedBooleanPtr(GateRef x); GateRef TaggedPtrToTaggedDoublePtr(GateRef x); GateRef TaggedPtrToTaggedIntPtr(GateRef x); GateRef CastDoubleToInt64(GateRef x); @@ -306,6 +307,7 @@ public: GateRef Int64LessThanOrEqual(GateRef x, GateRef y); GateRef Int64GreaterThanOrEqual(GateRef x, GateRef y); GateRef Int64UnsignedLessThanOrEqual(GateRef x, GateRef y); + GateRef Int64UnsignedGreaterThanOrEqual(GateRef x, GateRef y); GateRef IntPtrGreaterThan(GateRef x, GateRef y); // cast operation GateRef ChangeInt64ToIntPtr(GateRef val); diff --git a/ecmascript/compiler/typed_native_inline_lowering.cpp b/ecmascript/compiler/typed_native_inline_lowering.cpp index 12c0755785eca1d30b6d62512b9200f199e2bdde..a423be5e5544c68c8764bd36b55ed77d88751f58 100644 --- a/ecmascript/compiler/typed_native_inline_lowering.cpp +++ b/ecmascript/compiler/typed_native_inline_lowering.cpp @@ -198,6 +198,12 @@ GateRef TypedNativeInlineLowering::VisitGate(GateRef gate) case OpCode::DATE_GET_TIME: LowerDateGetTime(gate); break; + case OpCode::MAP_HAS: + LowerToCommonStub(gate, CommonStubCSigns::JSMapHas); + break; + case OpCode::SET_HAS: + LowerToCommonStub(gate, CommonStubCSigns::JSSetHas); + break; default: break; } diff --git a/ecmascript/global_env_constants.h b/ecmascript/global_env_constants.h index 77ba09d941b8612ec23159f53d5ed28166648173..89ac2eddf05b097f6b5f44135554ac56193b06d6 100644 --- a/ecmascript/global_env_constants.h +++ b/ecmascript/global_env_constants.h @@ -195,6 +195,8 @@ class ObjectFactory; V(JSTaggedValue, GlobalIsFinite, GLOBAL_IS_FINITE_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, GlobalIsNan, GLOBAL_IS_NAN_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, MapGet, MAP_GET_INDEX, ecma_roots_builtins) \ + V(JSTaggedValue, MapHas, MAP_HAS_INDEX, ecma_roots_builtins) \ + V(JSTaggedValue, SetHas, SET_HAS_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, LocaleCompareFunction, LOCALE_COMPARE_FUNCTION_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, ArraySortFunction, ARRAY_SORT_FUNCTION_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, JsonStringifyFunction, JSON_STRINGIFY_FUNCTION_INDEX, ecma_roots_builtins) \ diff --git a/ecmascript/linked_hash_table.cpp b/ecmascript/linked_hash_table.cpp index de668f9567d5deca782af43c6b8fe01623e3bee4..68f1e816bfed95c0860c522601397df48e1b1b73 100644 --- a/ecmascript/linked_hash_table.cpp +++ b/ecmascript/linked_hash_table.cpp @@ -265,6 +265,9 @@ int LinkedHash::Hash(const JSThread *thread, JSTaggedValue key) // Int, Double, Special and HeapObject(except symbol and string) if (key.IsDouble()) { key = JSTaggedValue::TryCastDoubleToInt32(key.GetDouble()); + if (key.IsInt()) { + return key.GetInt(); + } } uint64_t keyValue = key.GetRawData(); return GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); diff --git a/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts b/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts index ba00c646d22b4e185782ae07d8451aba0f881924..751e28581fc8268a29a732ea75dd84de8409ccbd 100644 --- a/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts +++ b/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts @@ -36,31 +36,42 @@ function printHas(x: any) { let myMap = new Map([[0, 0], [0.0, 5], [-1, 1], [2.5, -2.5], [NaN, Infinity], [2000, -0.0], [56, "oops"], ["xyz", "12345"]]); // Check without params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has()); //: false // Check with adding element undefined myMap.set(undefined, 42); +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has()); //: true // Check with single param +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(0)); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(3)); //: false +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2.5)); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(NaN)); //: true // Check with 2 params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(0, 0)); //: true // Check with 3 params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(-21, 10.2, 15)); //: false // Check with 4 params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2.5, -800, 0.56, 0)); //: true // Check after inserting elements myMap.set(2000, 1e-98); myMap.set(133.33, -1); +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2000)); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(133.33)); //: true // Replace standard builtin @@ -71,11 +82,16 @@ myMap.has = replace print(myMap.has(2.5)); //: 2.5 myMap.has = true_has +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas(-1); //: true // Call standard builtin with non-number param +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("abc"); //: false +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("-1"); //: false +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas(56); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("xyz"); //: true if (ArkTools.isAOTCompiled(printHas)) { @@ -83,46 +99,52 @@ if (ArkTools.isAOTCompiled(printHas)) { myMap.has = replace } printHas(2.5); //pgo: true +//aot: [trace] Check Type: NotCallTarget1 //aot: 2.5 printHas("abc"); //pgo: false +//aot: [trace] Check Type: NotCallTarget1 //aot: abc myMap.has = true_has // Check IR correctness inside try-block try { + //aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas(2000); //: true + //aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("abc"); //: false } catch (e) { } let obj = {}; obj.valueOf = (() => { return 0; }) +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(obj)); //: false function Throwing() { - this.value = -1; -} -//aot: [trace] Check Type: InconsistentHClass6 -Throwing.prototype.valueOf = function() { - if (this.value > 0) { - throw new Error("already positive"); + this.value = 2.5; + this.valueOf = function() { + if (this.value > 0) { + throw new Error("already positive"); + } + return this.value; } - return this.value; } + let throwingObj = new Throwing(); try { - print(myMap.has(throwingObj)); //: false - throwingObj.value = 2.5; + //aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(throwingObj)); //: false } catch(e) { print(e); } finally { + //aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(obj)); //: false } // Check after clearing myMap.clear(); +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2000)); //: false diff --git a/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts b/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts index 239f5a8daffc0552349c888dd3926ddc640cfc1b..762711ce0ac0f8de442023b42be564f3e1cf7a38 100644 --- a/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts +++ b/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts @@ -36,31 +36,42 @@ function printHas(x: any) { let mySet = new Set([0, 0.0, -5, 2.5, 1e-78, NaN, "xyz", "12345"]); // Check without params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has()); //: false // Check with adding element undefined mySet.add(undefined); +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has()); //: true // Check with single param +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(0)); //: true +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(3)); //: false +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(2.5)); //: true +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(NaN)); //: true // Check with 2 params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(0, 0)); //: true // Check with 3 params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(-21, 10.2, 15)); //: false // Check with 4 params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(2.5, -800, 0.56, 0)); //: true // Check after inserting elements mySet.add(-5); mySet.add(133.33); +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(-5)); //: true +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(133.33)); //: true // Replace standard builtin @@ -71,10 +82,14 @@ mySet.has = replace print(mySet.has(2.5)); //: 2.5 mySet.has = true_has +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas(-5); //: true // Call standard builtin with non-number param +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("abc"); //: false +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("-5"); //: false +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("xyz"); //: true if (ArkTools.isAOTCompiled(printHas)) { @@ -82,46 +97,51 @@ if (ArkTools.isAOTCompiled(printHas)) { mySet.has = replace } printHas(2.5); //pgo: true +//aot: [trace] Check Type: NotCallTarget1 //aot: 2.5 printHas("abc"); //pgo: false +//aot: [trace] Check Type: NotCallTarget1 //aot: abc mySet.has = true_has // Check IR correctness inside try-block try { + //aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas(NaN); //: true + //aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("abc"); //: false } catch (e) { } let obj = {}; obj.valueOf = (() => { return 0; }) +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(obj)); //: false function Throwing() { - this.value = -1; -} -//aot: [trace] Check Type: InconsistentHClass6 -Throwing.prototype.valueOf = function() { - if (this.value > 0) { - throw new Error("already positive"); + this.value = 2.5; + this.valueOf = function() { + if (this.value > 0) { + throw new Error("already positive"); + } + return this.value; } - return this.value; } -let throwingObj = new Throwing(); +let throwingObj = new Throwing(); try { - print(mySet.has(throwingObj)); //: false - throwingObj.value = 2.5; + //aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(throwingObj)); //: false } catch(e) { print(e); } finally { + //aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(obj)); //: false } // Check after clearing mySet.clear(); +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(0)); //: false diff --git a/test/moduletest/mapget/mapget.js b/test/moduletest/mapget/mapget.js index 60b827f81489e5dce19efc6d1308ee949f12ce53..12e21a0ea2fd5dfa20ddd521b78af9ed80228383 100644 --- a/test/moduletest/mapget/mapget.js +++ b/test/moduletest/mapget/mapget.js @@ -48,8 +48,18 @@ function check(key) { } } +function checkIntAsDouble(intKey) { + intKey /= 2; + intKey += 0.5; + intKey *= 2; + intKey -= 1; + check(intKey); +} + check(0); check(1); +check(1 << 30); +check((1 << 30) - 1); check(-1); check(1.5); check(-1.5); @@ -66,6 +76,24 @@ check(Number.POSITIVE_INFINITY); check(Number.NEGATIVE_INFINITY); check(Number.parseFloat("+0.0")); check(Number.parseFloat("-0.0")); +check(true); +check(false); +check(undefined); +check(null); +check(""); +check("ab"); +check({}); +check(12n); +checkIntAsDouble(0); +checkIntAsDouble(1); +checkIntAsDouble(-1); +checkIntAsDouble(-1234); +checkIntAsDouble(1234); +checkIntAsDouble(1 << 29); +checkIntAsDouble(-(1 << 29)); +checkIntAsDouble(1 << 30); +checkIntAsDouble(-(1 << 30)); +check(Symbol.iterator); // regression test check(Number.parseFloat("1392210229"));