14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#include <thread> 174514f5e3Sopenharmony_ci 184514f5e3Sopenharmony_ci#include "ecmascript/builtins/builtins_boolean.h" 194514f5e3Sopenharmony_ci#include "ecmascript/ecma_runtime_call_info.h" 204514f5e3Sopenharmony_ci#include "ecmascript/ecma_string.h" 214514f5e3Sopenharmony_ci#include "ecmascript/ecma_vm.h" 224514f5e3Sopenharmony_ci#include "ecmascript/global_env.h" 234514f5e3Sopenharmony_ci#include "ecmascript/global_env_constants.h" 244514f5e3Sopenharmony_ci#include "ecmascript/global_env_constants-inl.h" 254514f5e3Sopenharmony_ci#include "ecmascript/ic/ic_compare_op.cpp" 264514f5e3Sopenharmony_ci#include "ecmascript/ic/ic_compare_op.h" 274514f5e3Sopenharmony_ci#include "ecmascript/interpreter/slow_runtime_stub.h" 284514f5e3Sopenharmony_ci#include "ecmascript/js_primitive_ref.h" 294514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value-inl.h" 304514f5e3Sopenharmony_ci#include "ecmascript/object_factory.h" 314514f5e3Sopenharmony_ci#include "ecmascript/tests/test_helper.h" 324514f5e3Sopenharmony_ci 334514f5e3Sopenharmony_ciusing namespace panda::ecmascript; 344514f5e3Sopenharmony_cinamespace panda::test { 354514f5e3Sopenharmony_ciclass IcCompareOPTest : public testing::Test { 364514f5e3Sopenharmony_cipublic: 374514f5e3Sopenharmony_ci static void SetUpTestCase() 384514f5e3Sopenharmony_ci { 394514f5e3Sopenharmony_ci GTEST_LOG_(INFO) << "SetUpTestCase"; 404514f5e3Sopenharmony_ci } 414514f5e3Sopenharmony_ci 424514f5e3Sopenharmony_ci static void TearDownTestCase() 434514f5e3Sopenharmony_ci { 444514f5e3Sopenharmony_ci GTEST_LOG_(INFO) << "TearDownCase"; 454514f5e3Sopenharmony_ci } 464514f5e3Sopenharmony_ci 474514f5e3Sopenharmony_ci void SetUp() override 484514f5e3Sopenharmony_ci { 494514f5e3Sopenharmony_ci TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope); 504514f5e3Sopenharmony_ci } 514514f5e3Sopenharmony_ci 524514f5e3Sopenharmony_ci void TearDown() override 534514f5e3Sopenharmony_ci { 544514f5e3Sopenharmony_ci TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope); 554514f5e3Sopenharmony_ci } 564514f5e3Sopenharmony_ci 574514f5e3Sopenharmony_ci EcmaVM *ecmaVm {nullptr}; 584514f5e3Sopenharmony_ci EcmaHandleScope *scope {nullptr}; 594514f5e3Sopenharmony_ci JSThread *thread {nullptr}; 604514f5e3Sopenharmony_ci}; 614514f5e3Sopenharmony_ci 624514f5e3Sopenharmony_ciHWTEST_F_L0(IcCompareOPTest, EqualWithIC) 634514f5e3Sopenharmony_ci{ 644514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm->GetFactory(); 654514f5e3Sopenharmony_ci 664514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1")); 674514f5e3Sopenharmony_ci JSTaggedValue arg1(static_cast<uint32_t>(1)); 684514f5e3Sopenharmony_ci JSTaggedValue arg2(static_cast<double>(1.0)); 694514f5e3Sopenharmony_ci JSTaggedValue arg3(false); 704514f5e3Sopenharmony_ci JSTaggedValue arg4(true); 714514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg1Handle(thread, arg1); 724514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg2Handle(thread, arg2); 734514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg3Handle(thread, arg3); 744514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg4Handle(thread, arg4); 754514f5e3Sopenharmony_ci 764514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv(); 774514f5e3Sopenharmony_ci JSHandle<JSObject> globalObject(thread, env->GetGlobalObject()); 784514f5e3Sopenharmony_ci 794514f5e3Sopenharmony_ci JSHandle<JSFunction> boolean(env->GetBooleanFunction()); 804514f5e3Sopenharmony_ci auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6); 814514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); 824514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); 834514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(1))); 844514f5e3Sopenharmony_ci 854514f5e3Sopenharmony_ci JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); 864514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj); 874514f5e3Sopenharmony_ci 884514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Eq(thread, arg1Handle.GetTaggedValue(), 894514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue()); 904514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Eq(thread, Str1.GetTaggedValue(), arg1Handle.GetTaggedValue()); 914514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Eq(thread, Str1.GetTaggedValue(), arg3Handle.GetTaggedValue()); 924514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Eq(thread, Str1.GetTaggedValue(), arg4Handle.GetTaggedValue()); 934514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Eq(thread, booleanObjHandle.GetTaggedValue(), 944514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue()); 954514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath9 = SlowRuntimeStub::Eq(thread, JSTaggedValue::Undefined(), JSTaggedValue::Null()); 964514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath10 = SlowRuntimeStub::Eq(thread, JSTaggedValue::Undefined(), JSTaggedValue::True()); 974514f5e3Sopenharmony_ci 984514f5e3Sopenharmony_ci JSTaggedValue resInICPath1 = CompareOp::EqualWithIC(thread, arg1Handle.GetTaggedValue(), 994514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue(), CompareOpType::NUMBER_NUMBER); 1004514f5e3Sopenharmony_ci JSTaggedValue resInICPath2 = CompareOp::EqualWithIC(thread, Str1.GetTaggedValue(), 1014514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue(), CompareOpType::STRING_NUMBER); 1024514f5e3Sopenharmony_ci JSTaggedValue resInICPath3 = CompareOp::EqualWithIC(thread, Str1.GetTaggedValue(), 1034514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN); 1044514f5e3Sopenharmony_ci JSTaggedValue resInICPath4 = CompareOp::EqualWithIC(thread, Str1.GetTaggedValue(), 1054514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN); 1064514f5e3Sopenharmony_ci JSTaggedValue resInICPath5 = CompareOp::EqualWithIC(thread, booleanObjHandle.GetTaggedValue(), 1074514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue(), CompareOpType::OBJ_BOOLEAN); 1084514f5e3Sopenharmony_ci JSTaggedValue resInICPath9 = CompareOp::EqualWithIC(thread, JSTaggedValue::Undefined(), 1094514f5e3Sopenharmony_ci JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL); 1104514f5e3Sopenharmony_ci JSTaggedValue resInICPath10 = CompareOp::EqualWithIC(thread, JSTaggedValue::Undefined(), 1114514f5e3Sopenharmony_ci JSTaggedValue::True(), CompareOpType::OTHER); 1124514f5e3Sopenharmony_ci 1134514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath1, resInICPath1); 1144514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath2, resInICPath2); 1154514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath3, resInICPath3); 1164514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath4, resInICPath4); 1174514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath5, resInICPath5); 1184514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath9, resInICPath9); 1194514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath10, resInICPath10); 1204514f5e3Sopenharmony_ci}; 1214514f5e3Sopenharmony_ci 1224514f5e3Sopenharmony_ciHWTEST_F_L0(IcCompareOPTest, NotEqualWithIC) 1234514f5e3Sopenharmony_ci{ 1244514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm->GetFactory(); 1254514f5e3Sopenharmony_ci 1264514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1")); 1274514f5e3Sopenharmony_ci JSTaggedValue arg1(static_cast<uint32_t>(1)); 1284514f5e3Sopenharmony_ci JSTaggedValue arg2(static_cast<double>(2.0)); 1294514f5e3Sopenharmony_ci JSTaggedValue arg3(false); 1304514f5e3Sopenharmony_ci JSTaggedValue arg4(true); 1314514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg1Handle(thread, arg1); 1324514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg2Handle(thread, arg2); 1334514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg3Handle(thread, arg3); 1344514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg4Handle(thread, arg4); 1354514f5e3Sopenharmony_ci 1364514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv(); 1374514f5e3Sopenharmony_ci JSHandle<JSObject> globalObject(thread, env->GetGlobalObject()); 1384514f5e3Sopenharmony_ci 1394514f5e3Sopenharmony_ci JSHandle<JSFunction> boolean(env->GetBooleanFunction()); 1404514f5e3Sopenharmony_ci auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6); 1414514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); 1424514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); 1434514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(123))); 1444514f5e3Sopenharmony_ci 1454514f5e3Sopenharmony_ci JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); 1464514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj); 1474514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath1 = SlowRuntimeStub::NotEq(thread, arg1Handle.GetTaggedValue(), 1484514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue()); 1494514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath2 = SlowRuntimeStub::NotEq(thread, Str1.GetTaggedValue(), 1504514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue()); 1514514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath3 = SlowRuntimeStub::NotEq(thread, Str1.GetTaggedValue(), 1524514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue()); 1534514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath4 = SlowRuntimeStub::NotEq(thread, Str1.GetTaggedValue(), 1544514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue()); 1554514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath5 = SlowRuntimeStub::NotEq(thread, arg1Handle.GetTaggedValue(), 1564514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue()); 1574514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath9 = SlowRuntimeStub::NotEq(thread, JSTaggedValue::Undefined(), 1584514f5e3Sopenharmony_ci JSTaggedValue::Null()); 1594514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath10 = SlowRuntimeStub::NotEq(thread, JSTaggedValue::Undefined(), 1604514f5e3Sopenharmony_ci JSTaggedValue::True()); 1614514f5e3Sopenharmony_ci 1624514f5e3Sopenharmony_ci JSTaggedValue resInICPath1 = CompareOp::NotEqualWithIC(thread, arg1Handle.GetTaggedValue(), 1634514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue(), 1644514f5e3Sopenharmony_ci CompareOpType::NUMBER_NUMBER); 1654514f5e3Sopenharmony_ci JSTaggedValue resInICPath2 = CompareOp::NotEqualWithIC(thread, Str1.GetTaggedValue(), 1664514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue(), CompareOpType::STRING_NUMBER); 1674514f5e3Sopenharmony_ci JSTaggedValue resInICPath3 = CompareOp::NotEqualWithIC(thread, Str1.GetTaggedValue(), 1684514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN); 1694514f5e3Sopenharmony_ci JSTaggedValue resInICPath4 = CompareOp::NotEqualWithIC(thread, Str1.GetTaggedValue(), 1704514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN); 1714514f5e3Sopenharmony_ci JSTaggedValue resInICPath5 = CompareOp::NotEqualWithIC(thread, arg1Handle.GetTaggedValue(), 1724514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue(), 1734514f5e3Sopenharmony_ci CompareOpType::NUMBER_OBJ); 1744514f5e3Sopenharmony_ci JSTaggedValue resInICPath9 = CompareOp::NotEqualWithIC(thread, JSTaggedValue::Undefined(), 1754514f5e3Sopenharmony_ci JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL); 1764514f5e3Sopenharmony_ci JSTaggedValue resInICPath10 = CompareOp::NotEqualWithIC(thread, JSTaggedValue::Undefined(), 1774514f5e3Sopenharmony_ci JSTaggedValue::True(), CompareOpType::OTHER); 1784514f5e3Sopenharmony_ci 1794514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath1, resInICPath1); 1804514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath2, resInICPath2); 1814514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath3, resInICPath3); 1824514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath4, resInICPath4); 1834514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath5, resInICPath5); 1844514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath9, resInICPath9); 1854514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath10, resInICPath10); 1864514f5e3Sopenharmony_ci}; 1874514f5e3Sopenharmony_ci 1884514f5e3Sopenharmony_ci 1894514f5e3Sopenharmony_ciHWTEST_F_L0(IcCompareOPTest, LessWithIC) 1904514f5e3Sopenharmony_ci{ 1914514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm->GetFactory(); 1924514f5e3Sopenharmony_ci 1934514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("0")); 1944514f5e3Sopenharmony_ci JSTaggedValue arg1(static_cast<uint32_t>(1)); 1954514f5e3Sopenharmony_ci JSTaggedValue arg2(static_cast<double>(0.5)); 1964514f5e3Sopenharmony_ci JSTaggedValue arg3(false); 1974514f5e3Sopenharmony_ci JSTaggedValue arg4(true); 1984514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg1Handle(thread, arg1); 1994514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg2Handle(thread, arg2); 2004514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg3Handle(thread, arg3); 2014514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg4Handle(thread, arg4); 2024514f5e3Sopenharmony_ci 2034514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv(); 2044514f5e3Sopenharmony_ci JSHandle<JSObject> globalObject(thread, env->GetGlobalObject()); 2054514f5e3Sopenharmony_ci 2064514f5e3Sopenharmony_ci JSHandle<JSFunction> boolean(env->GetBooleanFunction()); 2074514f5e3Sopenharmony_ci auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6); 2084514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); 2094514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); 2104514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(123))); 2114514f5e3Sopenharmony_ci 2124514f5e3Sopenharmony_ci JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); 2134514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj); 2144514f5e3Sopenharmony_ci 2154514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Less(thread, arg1Handle.GetTaggedValue(), 2164514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue()); 2174514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Less(thread, Str1.GetTaggedValue(), 2184514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue()); 2194514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Less(thread, Str1.GetTaggedValue(), 2204514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue()); 2214514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Less(thread, Str1.GetTaggedValue(), 2224514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue()); 2234514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Less(thread, arg1Handle.GetTaggedValue(), 2244514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue()); 2254514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath9 = SlowRuntimeStub::Less(thread, 2264514f5e3Sopenharmony_ci JSTaggedValue::Undefined(), JSTaggedValue::Null()); 2274514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath10 = SlowRuntimeStub::Less(thread, 2284514f5e3Sopenharmony_ci JSTaggedValue::Undefined(), JSTaggedValue::True()); 2294514f5e3Sopenharmony_ci 2304514f5e3Sopenharmony_ci JSTaggedValue resInICPath1 = CompareOp::LessWithIC(thread, arg1Handle.GetTaggedValue(), 2314514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue(), CompareOpType::NUMBER_NUMBER); 2324514f5e3Sopenharmony_ci JSTaggedValue resInICPath2 = CompareOp::LessWithIC(thread, Str1.GetTaggedValue(), 2334514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue(), CompareOpType::STRING_NUMBER); 2344514f5e3Sopenharmony_ci JSTaggedValue resInICPath3 = CompareOp::LessWithIC(thread, Str1.GetTaggedValue(), 2354514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN); 2364514f5e3Sopenharmony_ci JSTaggedValue resInICPath4 = CompareOp::LessWithIC(thread, Str1.GetTaggedValue(), 2374514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN); 2384514f5e3Sopenharmony_ci JSTaggedValue resInICPath5 = CompareOp::LessWithIC(thread, arg1Handle.GetTaggedValue(), 2394514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue(), 2404514f5e3Sopenharmony_ci CompareOpType::NUMBER_OBJ); 2414514f5e3Sopenharmony_ci JSTaggedValue resInICPath9 = CompareOp::LessWithIC(thread, JSTaggedValue::Undefined(), 2424514f5e3Sopenharmony_ci JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL); 2434514f5e3Sopenharmony_ci JSTaggedValue resInICPath10 = CompareOp::LessWithIC(thread, JSTaggedValue::Undefined(), 2444514f5e3Sopenharmony_ci JSTaggedValue::True(), CompareOpType::OTHER); 2454514f5e3Sopenharmony_ci 2464514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath1, resInICPath1); 2474514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath2, resInICPath2); 2484514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath3, resInICPath3); 2494514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath4, resInICPath4); 2504514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath5, resInICPath5); 2514514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath9, resInICPath9); 2524514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath10, resInICPath10); 2534514f5e3Sopenharmony_ci}; 2544514f5e3Sopenharmony_ci 2554514f5e3Sopenharmony_ci 2564514f5e3Sopenharmony_ciHWTEST_F_L0(IcCompareOPTest, LessEqWithIC) 2574514f5e3Sopenharmony_ci{ 2584514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm->GetFactory(); 2594514f5e3Sopenharmony_ci 2604514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1")); 2614514f5e3Sopenharmony_ci JSTaggedValue arg1(static_cast<uint32_t>(1)); 2624514f5e3Sopenharmony_ci JSTaggedValue arg2(static_cast<double>(0.5)); 2634514f5e3Sopenharmony_ci JSTaggedValue arg3(false); 2644514f5e3Sopenharmony_ci JSTaggedValue arg4(true); 2654514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg1Handle(thread, arg1); 2664514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg2Handle(thread, arg2); 2674514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg3Handle(thread, arg3); 2684514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg4Handle(thread, arg4); 2694514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv(); 2704514f5e3Sopenharmony_ci JSHandle<JSObject> globalObject(thread, env->GetGlobalObject()); 2714514f5e3Sopenharmony_ci 2724514f5e3Sopenharmony_ci JSHandle<JSFunction> boolean(env->GetBooleanFunction()); 2734514f5e3Sopenharmony_ci auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6); 2744514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); 2754514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); 2764514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(123))); 2774514f5e3Sopenharmony_ci 2784514f5e3Sopenharmony_ci JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); 2794514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj); 2804514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath1 = SlowRuntimeStub::LessEq(thread, arg1Handle.GetTaggedValue(), 2814514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue()); 2824514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath2 = SlowRuntimeStub::LessEq(thread, Str1.GetTaggedValue(), 2834514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue()); 2844514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath3 = SlowRuntimeStub::LessEq(thread, Str1.GetTaggedValue(), 2854514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue()); 2864514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath4 = SlowRuntimeStub::LessEq(thread, Str1.GetTaggedValue(), 2874514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue()); 2884514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath5 = SlowRuntimeStub::LessEq(thread, arg1Handle.GetTaggedValue(), 2894514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue()); 2904514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath9 = SlowRuntimeStub::LessEq(thread, JSTaggedValue::Undefined(), 2914514f5e3Sopenharmony_ci JSTaggedValue::Null()); 2924514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath10 = SlowRuntimeStub::LessEq(thread, JSTaggedValue::Undefined(), 2934514f5e3Sopenharmony_ci JSTaggedValue::True()); 2944514f5e3Sopenharmony_ci JSTaggedValue resInICPath1 = CompareOp::LessEqWithIC(thread, arg1Handle.GetTaggedValue(), 2954514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue(), 2964514f5e3Sopenharmony_ci CompareOpType::NUMBER_NUMBER); 2974514f5e3Sopenharmony_ci JSTaggedValue resInICPath2 = CompareOp::LessEqWithIC(thread, Str1.GetTaggedValue(), 2984514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue(), 2994514f5e3Sopenharmony_ci CompareOpType::STRING_NUMBER); 3004514f5e3Sopenharmony_ci JSTaggedValue resInICPath3 = CompareOp::LessEqWithIC(thread, Str1.GetTaggedValue(), 3014514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue(), 3024514f5e3Sopenharmony_ci CompareOpType::STRING_BOOLEAN); 3034514f5e3Sopenharmony_ci JSTaggedValue resInICPath4 = CompareOp::LessEqWithIC(thread, Str1.GetTaggedValue(), 3044514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue(), 3054514f5e3Sopenharmony_ci CompareOpType::STRING_BOOLEAN); 3064514f5e3Sopenharmony_ci JSTaggedValue resInICPath5 = CompareOp::LessEqWithIC(thread, 3074514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue(), 3084514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue(), 3094514f5e3Sopenharmony_ci CompareOpType::NUMBER_OBJ); 3104514f5e3Sopenharmony_ci JSTaggedValue resInICPath9 = CompareOp::LessEqWithIC(thread, JSTaggedValue::Undefined(), 3114514f5e3Sopenharmony_ci JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL); 3124514f5e3Sopenharmony_ci JSTaggedValue resInICPath10 = CompareOp::LessEqWithIC(thread, JSTaggedValue::Undefined(), 3134514f5e3Sopenharmony_ci JSTaggedValue::True(), CompareOpType::OTHER); 3144514f5e3Sopenharmony_ci 3154514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath1, resInICPath1); 3164514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath2, resInICPath2); 3174514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath3, resInICPath3); 3184514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath4, resInICPath4); 3194514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath5, resInICPath5); 3204514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath9, resInICPath9); 3214514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath10, resInICPath10); 3224514f5e3Sopenharmony_ci}; 3234514f5e3Sopenharmony_ci 3244514f5e3Sopenharmony_ci 3254514f5e3Sopenharmony_ciHWTEST_F_L0(IcCompareOPTest, GreaterWithIC) 3264514f5e3Sopenharmony_ci{ 3274514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm->GetFactory(); 3284514f5e3Sopenharmony_ci 3294514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1")); 3304514f5e3Sopenharmony_ci JSTaggedValue arg1(static_cast<uint32_t>(1)); 3314514f5e3Sopenharmony_ci JSTaggedValue arg2(static_cast<double>(1.0)); 3324514f5e3Sopenharmony_ci JSTaggedValue arg3(false); 3334514f5e3Sopenharmony_ci JSTaggedValue arg4(true); 3344514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg1Handle(thread, arg1); 3354514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg2Handle(thread, arg2); 3364514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg3Handle(thread, arg3); 3374514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg4Handle(thread, arg4); 3384514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv(); 3394514f5e3Sopenharmony_ci JSHandle<JSObject> globalObject(thread, env->GetGlobalObject()); 3404514f5e3Sopenharmony_ci 3414514f5e3Sopenharmony_ci JSHandle<JSFunction> boolean(env->GetBooleanFunction()); 3424514f5e3Sopenharmony_ci auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6); 3434514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); 3444514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); 3454514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(1))); 3464514f5e3Sopenharmony_ci 3474514f5e3Sopenharmony_ci JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); 3484514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj); 3494514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Greater(thread, arg1Handle.GetTaggedValue(), 3504514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue()); 3514514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Greater(thread, Str1.GetTaggedValue(), 3524514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue()); 3534514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Greater(thread, Str1.GetTaggedValue(), 3544514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue()); 3554514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Greater(thread, Str1.GetTaggedValue(), 3564514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue()); 3574514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Greater(thread, arg1Handle.GetTaggedValue(), 3584514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue()); 3594514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath9 = SlowRuntimeStub::Greater(thread, JSTaggedValue::Undefined(), 3604514f5e3Sopenharmony_ci JSTaggedValue::Null()); 3614514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath10 = SlowRuntimeStub::Greater(thread, JSTaggedValue::Undefined(), 3624514f5e3Sopenharmony_ci JSTaggedValue::True()); 3634514f5e3Sopenharmony_ci 3644514f5e3Sopenharmony_ci JSTaggedValue resInICPath1 = CompareOp::GreaterWithIC(thread, arg1Handle.GetTaggedValue(), 3654514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue(), 3664514f5e3Sopenharmony_ci CompareOpType::NUMBER_NUMBER); 3674514f5e3Sopenharmony_ci JSTaggedValue resInICPath2 = CompareOp::GreaterWithIC(thread, Str1.GetTaggedValue(), 3684514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue(), 3694514f5e3Sopenharmony_ci CompareOpType::STRING_NUMBER); 3704514f5e3Sopenharmony_ci JSTaggedValue resInICPath3 = CompareOp::GreaterWithIC(thread, Str1.GetTaggedValue(), 3714514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue(), 3724514f5e3Sopenharmony_ci CompareOpType::STRING_BOOLEAN); 3734514f5e3Sopenharmony_ci JSTaggedValue resInICPath4 = CompareOp::GreaterWithIC(thread, Str1.GetTaggedValue(), 3744514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue(), 3754514f5e3Sopenharmony_ci CompareOpType::STRING_BOOLEAN); 3764514f5e3Sopenharmony_ci JSTaggedValue resInICPath5 = CompareOp::GreaterWithIC(thread, arg1Handle.GetTaggedValue(), 3774514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue(), 3784514f5e3Sopenharmony_ci CompareOpType::NUMBER_OBJ); 3794514f5e3Sopenharmony_ci JSTaggedValue resInICPath9 = CompareOp::GreaterWithIC(thread, JSTaggedValue::Undefined(), 3804514f5e3Sopenharmony_ci JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL); 3814514f5e3Sopenharmony_ci JSTaggedValue resInICPath10 = CompareOp::GreaterWithIC(thread, JSTaggedValue::Undefined(), 3824514f5e3Sopenharmony_ci JSTaggedValue::True(), CompareOpType::OTHER); 3834514f5e3Sopenharmony_ci 3844514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath1, resInICPath1); 3854514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath2, resInICPath2); 3864514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath3, resInICPath3); 3874514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath4, resInICPath4); 3884514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath5, resInICPath5); 3894514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath9, resInICPath9); 3904514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath10, resInICPath10); 3914514f5e3Sopenharmony_ci}; 3924514f5e3Sopenharmony_ci 3934514f5e3Sopenharmony_ci 3944514f5e3Sopenharmony_ciHWTEST_F_L0(IcCompareOPTest, GreaterEqWithIC) 3954514f5e3Sopenharmony_ci{ 3964514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm->GetFactory(); 3974514f5e3Sopenharmony_ci 3984514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1")); 3994514f5e3Sopenharmony_ci JSTaggedValue arg1(static_cast<uint32_t>(1)); 4004514f5e3Sopenharmony_ci JSTaggedValue arg2(static_cast<double>(1.0)); 4014514f5e3Sopenharmony_ci JSTaggedValue arg3(false); 4024514f5e3Sopenharmony_ci JSTaggedValue arg4(true); 4034514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg1Handle(thread, arg1); 4044514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg2Handle(thread, arg2); 4054514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg3Handle(thread, arg3); 4064514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arg4Handle(thread, arg4); 4074514f5e3Sopenharmony_ci 4084514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv(); 4094514f5e3Sopenharmony_ci JSHandle<JSObject> globalObject(thread, env->GetGlobalObject()); 4104514f5e3Sopenharmony_ci 4114514f5e3Sopenharmony_ci JSHandle<JSFunction> boolean(env->GetBooleanFunction()); 4124514f5e3Sopenharmony_ci auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6); 4134514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue()); 4144514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); 4154514f5e3Sopenharmony_ci ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(0))); 4164514f5e3Sopenharmony_ci 4174514f5e3Sopenharmony_ci JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); 4184514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj); 4194514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath1 = SlowRuntimeStub::GreaterEq(thread, arg1Handle.GetTaggedValue(), 4204514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue()); 4214514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath2 = SlowRuntimeStub::GreaterEq(thread, Str1.GetTaggedValue(), 4224514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue()); 4234514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath3 = SlowRuntimeStub::GreaterEq(thread, Str1.GetTaggedValue(), 4244514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue()); 4254514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath4 = SlowRuntimeStub::GreaterEq(thread, Str1.GetTaggedValue(), 4264514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue()); 4274514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath5 = SlowRuntimeStub::GreaterEq(thread, arg1Handle.GetTaggedValue(), 4284514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue()); 4294514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath9 = SlowRuntimeStub::GreaterEq(thread, JSTaggedValue::Undefined(), 4304514f5e3Sopenharmony_ci JSTaggedValue::Null()); 4314514f5e3Sopenharmony_ci JSTaggedValue resInSlowPath10 = SlowRuntimeStub::GreaterEq(thread, JSTaggedValue::Undefined(), 4324514f5e3Sopenharmony_ci JSTaggedValue::True()); 4334514f5e3Sopenharmony_ci 4344514f5e3Sopenharmony_ci JSTaggedValue resInICPath1 = CompareOp::GreaterEqWithIC(thread, arg1Handle.GetTaggedValue(), 4354514f5e3Sopenharmony_ci arg2Handle.GetTaggedValue(), 4364514f5e3Sopenharmony_ci CompareOpType::NUMBER_NUMBER); 4374514f5e3Sopenharmony_ci JSTaggedValue resInICPath2 = CompareOp::GreaterEqWithIC(thread, Str1.GetTaggedValue(), 4384514f5e3Sopenharmony_ci arg1Handle.GetTaggedValue(), 4394514f5e3Sopenharmony_ci CompareOpType::STRING_NUMBER); 4404514f5e3Sopenharmony_ci JSTaggedValue resInICPath3 = CompareOp::GreaterEqWithIC(thread, Str1.GetTaggedValue(), 4414514f5e3Sopenharmony_ci arg3Handle.GetTaggedValue(), 4424514f5e3Sopenharmony_ci CompareOpType::STRING_BOOLEAN); 4434514f5e3Sopenharmony_ci JSTaggedValue resInICPath4 = CompareOp::GreaterEqWithIC(thread, Str1.GetTaggedValue(), 4444514f5e3Sopenharmony_ci arg4Handle.GetTaggedValue(), 4454514f5e3Sopenharmony_ci CompareOpType::STRING_BOOLEAN); 4464514f5e3Sopenharmony_ci JSTaggedValue resInICPath5 = CompareOp::GreaterEqWithIC(thread, arg1Handle.GetTaggedValue(), 4474514f5e3Sopenharmony_ci booleanObjHandle.GetTaggedValue(), 4484514f5e3Sopenharmony_ci CompareOpType::NUMBER_OBJ); 4494514f5e3Sopenharmony_ci JSTaggedValue resInICPath9 = CompareOp::GreaterEqWithIC(thread, JSTaggedValue::Undefined(), 4504514f5e3Sopenharmony_ci JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL); 4514514f5e3Sopenharmony_ci JSTaggedValue resInICPath10 = CompareOp::GreaterEqWithIC(thread, JSTaggedValue::Undefined(), 4524514f5e3Sopenharmony_ci JSTaggedValue::True(), CompareOpType::OTHER); 4534514f5e3Sopenharmony_ci 4544514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath1, resInICPath1); 4554514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath2, resInICPath2); 4564514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath3, resInICPath3); 4574514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath4, resInICPath4); 4584514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath5, resInICPath5); 4594514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath9, resInICPath9); 4604514f5e3Sopenharmony_ci EXPECT_EQ(resInSlowPath10, resInICPath10); 4614514f5e3Sopenharmony_ci}; 4624514f5e3Sopenharmony_ci} // namespace panda::test 463