1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <thread>
17 
18 #include "ecmascript/builtins/builtins_boolean.h"
19 #include "ecmascript/ecma_runtime_call_info.h"
20 #include "ecmascript/ecma_string.h"
21 #include "ecmascript/ecma_vm.h"
22 #include "ecmascript/global_env.h"
23 #include "ecmascript/global_env_constants.h"
24 #include "ecmascript/global_env_constants-inl.h"
25 #include "ecmascript/ic/ic_compare_op.cpp"
26 #include "ecmascript/ic/ic_compare_op.h"
27 #include "ecmascript/interpreter/slow_runtime_stub.h"
28 #include "ecmascript/js_primitive_ref.h"
29 #include "ecmascript/js_tagged_value-inl.h"
30 #include "ecmascript/object_factory.h"
31 #include "ecmascript/tests/test_helper.h"
32 
33 using namespace panda::ecmascript;
34 namespace panda::test {
35 class IcCompareOPTest : public testing::Test {
36 public:
SetUpTestCase()37     static void SetUpTestCase()
38     {
39         GTEST_LOG_(INFO) << "SetUpTestCase";
40     }
41 
TearDownTestCase()42     static void TearDownTestCase()
43     {
44         GTEST_LOG_(INFO) << "TearDownCase";
45     }
46 
47     void SetUp() override
48     {
49         TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope);
50     }
51 
52     void TearDown() override
53     {
54         TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope);
55     }
56 
57     EcmaVM *ecmaVm {nullptr};
58     EcmaHandleScope *scope {nullptr};
59     JSThread *thread {nullptr};
60 };
61 
HWTEST_F_L0(IcCompareOPTest, EqualWithIC)62 HWTEST_F_L0(IcCompareOPTest, EqualWithIC)
63 {
64     ObjectFactory *factory = ecmaVm->GetFactory();
65 
66     JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1"));
67     JSTaggedValue arg1(static_cast<uint32_t>(1));
68     JSTaggedValue arg2(static_cast<double>(1.0));
69     JSTaggedValue arg3(false);
70     JSTaggedValue arg4(true);
71     JSHandle<JSTaggedValue> arg1Handle(thread, arg1);
72     JSHandle<JSTaggedValue> arg2Handle(thread, arg2);
73     JSHandle<JSTaggedValue> arg3Handle(thread, arg3);
74     JSHandle<JSTaggedValue> arg4Handle(thread, arg4);
75 
76     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
77     JSHandle<JSObject> globalObject(thread, env->GetGlobalObject());
78 
79     JSHandle<JSFunction> boolean(env->GetBooleanFunction());
80     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6);
81     ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue());
82     ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue());
83     ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(1)));
84 
85     JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo);
86     JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj);
87 
88     JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Eq(thread, arg1Handle.GetTaggedValue(),
89                                                           arg2Handle.GetTaggedValue());
90     JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Eq(thread, Str1.GetTaggedValue(), arg1Handle.GetTaggedValue());
91     JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Eq(thread, Str1.GetTaggedValue(), arg3Handle.GetTaggedValue());
92     JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Eq(thread, Str1.GetTaggedValue(), arg4Handle.GetTaggedValue());
93     JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Eq(thread, booleanObjHandle.GetTaggedValue(),
94                                                           arg4Handle.GetTaggedValue());
95     JSTaggedValue resInSlowPath9 = SlowRuntimeStub::Eq(thread, JSTaggedValue::Undefined(), JSTaggedValue::Null());
96     JSTaggedValue resInSlowPath10 = SlowRuntimeStub::Eq(thread, JSTaggedValue::Undefined(), JSTaggedValue::True());
97 
98     JSTaggedValue resInICPath1 = CompareOp::EqualWithIC(thread, arg1Handle.GetTaggedValue(),
99                                                         arg2Handle.GetTaggedValue(), CompareOpType::NUMBER_NUMBER);
100     JSTaggedValue resInICPath2 = CompareOp::EqualWithIC(thread, Str1.GetTaggedValue(),
101                                                         arg1Handle.GetTaggedValue(), CompareOpType::STRING_NUMBER);
102     JSTaggedValue resInICPath3 = CompareOp::EqualWithIC(thread, Str1.GetTaggedValue(),
103                                                         arg3Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN);
104     JSTaggedValue resInICPath4 = CompareOp::EqualWithIC(thread, Str1.GetTaggedValue(),
105                                                         arg4Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN);
106     JSTaggedValue resInICPath5 = CompareOp::EqualWithIC(thread, booleanObjHandle.GetTaggedValue(),
107                                                         arg4Handle.GetTaggedValue(), CompareOpType::OBJ_BOOLEAN);
108     JSTaggedValue resInICPath9 = CompareOp::EqualWithIC(thread, JSTaggedValue::Undefined(),
109                                                         JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL);
110     JSTaggedValue resInICPath10 = CompareOp::EqualWithIC(thread, JSTaggedValue::Undefined(),
111                                                         JSTaggedValue::True(), CompareOpType::OTHER);
112 
113     EXPECT_EQ(resInSlowPath1, resInICPath1);
114     EXPECT_EQ(resInSlowPath2, resInICPath2);
115     EXPECT_EQ(resInSlowPath3, resInICPath3);
116     EXPECT_EQ(resInSlowPath4, resInICPath4);
117     EXPECT_EQ(resInSlowPath5, resInICPath5);
118     EXPECT_EQ(resInSlowPath9, resInICPath9);
119     EXPECT_EQ(resInSlowPath10, resInICPath10);
120 };
121 
HWTEST_F_L0(IcCompareOPTest, NotEqualWithIC)122 HWTEST_F_L0(IcCompareOPTest, NotEqualWithIC)
123 {
124     ObjectFactory *factory = ecmaVm->GetFactory();
125 
126     JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1"));
127     JSTaggedValue arg1(static_cast<uint32_t>(1));
128     JSTaggedValue arg2(static_cast<double>(2.0));
129     JSTaggedValue arg3(false);
130     JSTaggedValue arg4(true);
131     JSHandle<JSTaggedValue> arg1Handle(thread, arg1);
132     JSHandle<JSTaggedValue> arg2Handle(thread, arg2);
133     JSHandle<JSTaggedValue> arg3Handle(thread, arg3);
134     JSHandle<JSTaggedValue> arg4Handle(thread, arg4);
135 
136     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
137     JSHandle<JSObject> globalObject(thread, env->GetGlobalObject());
138 
139     JSHandle<JSFunction> boolean(env->GetBooleanFunction());
140     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6);
141     ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue());
142     ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue());
143     ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(123)));
144 
145     JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo);
146     JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj);
147     JSTaggedValue resInSlowPath1 = SlowRuntimeStub::NotEq(thread, arg1Handle.GetTaggedValue(),
148                                                              arg2Handle.GetTaggedValue());
149     JSTaggedValue resInSlowPath2 = SlowRuntimeStub::NotEq(thread, Str1.GetTaggedValue(),
150                                                              arg1Handle.GetTaggedValue());
151     JSTaggedValue resInSlowPath3 = SlowRuntimeStub::NotEq(thread, Str1.GetTaggedValue(),
152                                                              arg3Handle.GetTaggedValue());
153     JSTaggedValue resInSlowPath4 = SlowRuntimeStub::NotEq(thread, Str1.GetTaggedValue(),
154                                                              arg4Handle.GetTaggedValue());
155     JSTaggedValue resInSlowPath5 = SlowRuntimeStub::NotEq(thread, arg1Handle.GetTaggedValue(),
156                                                              booleanObjHandle.GetTaggedValue());
157     JSTaggedValue resInSlowPath9 = SlowRuntimeStub::NotEq(thread, JSTaggedValue::Undefined(),
158                                                              JSTaggedValue::Null());
159     JSTaggedValue resInSlowPath10 = SlowRuntimeStub::NotEq(thread, JSTaggedValue::Undefined(),
160                                                               JSTaggedValue::True());
161 
162     JSTaggedValue resInICPath1 = CompareOp::NotEqualWithIC(thread, arg1Handle.GetTaggedValue(),
163                                                            arg2Handle.GetTaggedValue(),
164                                                            CompareOpType::NUMBER_NUMBER);
165     JSTaggedValue resInICPath2 = CompareOp::NotEqualWithIC(thread, Str1.GetTaggedValue(),
166                                                            arg1Handle.GetTaggedValue(), CompareOpType::STRING_NUMBER);
167     JSTaggedValue resInICPath3 = CompareOp::NotEqualWithIC(thread, Str1.GetTaggedValue(),
168                                                            arg3Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN);
169     JSTaggedValue resInICPath4 = CompareOp::NotEqualWithIC(thread, Str1.GetTaggedValue(),
170                                                            arg4Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN);
171     JSTaggedValue resInICPath5 = CompareOp::NotEqualWithIC(thread, arg1Handle.GetTaggedValue(),
172                                                            booleanObjHandle.GetTaggedValue(),
173                                                            CompareOpType::NUMBER_OBJ);
174     JSTaggedValue resInICPath9 = CompareOp::NotEqualWithIC(thread, JSTaggedValue::Undefined(),
175                                                            JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL);
176     JSTaggedValue resInICPath10 = CompareOp::NotEqualWithIC(thread, JSTaggedValue::Undefined(),
177                                                             JSTaggedValue::True(), CompareOpType::OTHER);
178 
179     EXPECT_EQ(resInSlowPath1, resInICPath1);
180     EXPECT_EQ(resInSlowPath2, resInICPath2);
181     EXPECT_EQ(resInSlowPath3, resInICPath3);
182     EXPECT_EQ(resInSlowPath4, resInICPath4);
183     EXPECT_EQ(resInSlowPath5, resInICPath5);
184     EXPECT_EQ(resInSlowPath9, resInICPath9);
185     EXPECT_EQ(resInSlowPath10, resInICPath10);
186 };
187 
188 
HWTEST_F_L0(IcCompareOPTest, LessWithIC)189 HWTEST_F_L0(IcCompareOPTest, LessWithIC)
190 {
191     ObjectFactory *factory = ecmaVm->GetFactory();
192 
193     JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("0"));
194     JSTaggedValue arg1(static_cast<uint32_t>(1));
195     JSTaggedValue arg2(static_cast<double>(0.5));
196     JSTaggedValue arg3(false);
197     JSTaggedValue arg4(true);
198     JSHandle<JSTaggedValue> arg1Handle(thread, arg1);
199     JSHandle<JSTaggedValue> arg2Handle(thread, arg2);
200     JSHandle<JSTaggedValue> arg3Handle(thread, arg3);
201     JSHandle<JSTaggedValue> arg4Handle(thread, arg4);
202 
203     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
204     JSHandle<JSObject> globalObject(thread, env->GetGlobalObject());
205 
206     JSHandle<JSFunction> boolean(env->GetBooleanFunction());
207     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6);
208     ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue());
209     ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue());
210     ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(123)));
211 
212     JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo);
213     JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj);
214 
215     JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Less(thread, arg1Handle.GetTaggedValue(),
216                                                             arg2Handle.GetTaggedValue());
217     JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Less(thread, Str1.GetTaggedValue(),
218                                                             arg1Handle.GetTaggedValue());
219     JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Less(thread, Str1.GetTaggedValue(),
220                                                             arg3Handle.GetTaggedValue());
221     JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Less(thread, Str1.GetTaggedValue(),
222                                                             arg4Handle.GetTaggedValue());
223     JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Less(thread, arg1Handle.GetTaggedValue(),
224                                                             booleanObjHandle.GetTaggedValue());
225     JSTaggedValue resInSlowPath9 = SlowRuntimeStub::Less(thread,
226         JSTaggedValue::Undefined(), JSTaggedValue::Null());
227     JSTaggedValue resInSlowPath10 = SlowRuntimeStub::Less(thread,
228         JSTaggedValue::Undefined(), JSTaggedValue::True());
229 
230     JSTaggedValue resInICPath1 = CompareOp::LessWithIC(thread,  arg1Handle.GetTaggedValue(),
231                                                           arg2Handle.GetTaggedValue(), CompareOpType::NUMBER_NUMBER);
232     JSTaggedValue resInICPath2 = CompareOp::LessWithIC(thread, Str1.GetTaggedValue(),
233                                                            arg1Handle.GetTaggedValue(), CompareOpType::STRING_NUMBER);
234     JSTaggedValue resInICPath3 = CompareOp::LessWithIC(thread, Str1.GetTaggedValue(),
235                                                           arg3Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN);
236     JSTaggedValue resInICPath4 = CompareOp::LessWithIC(thread, Str1.GetTaggedValue(),
237                                                           arg4Handle.GetTaggedValue(), CompareOpType::STRING_BOOLEAN);
238     JSTaggedValue resInICPath5 = CompareOp::LessWithIC(thread,  arg1Handle.GetTaggedValue(),
239                                                           booleanObjHandle.GetTaggedValue(),
240                                                           CompareOpType::NUMBER_OBJ);
241     JSTaggedValue resInICPath9 = CompareOp::LessWithIC(thread, JSTaggedValue::Undefined(),
242                                                           JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL);
243     JSTaggedValue resInICPath10 = CompareOp::LessWithIC(thread, JSTaggedValue::Undefined(),
244                                                            JSTaggedValue::True(), CompareOpType::OTHER);
245 
246     EXPECT_EQ(resInSlowPath1, resInICPath1);
247     EXPECT_EQ(resInSlowPath2, resInICPath2);
248     EXPECT_EQ(resInSlowPath3, resInICPath3);
249     EXPECT_EQ(resInSlowPath4, resInICPath4);
250     EXPECT_EQ(resInSlowPath5, resInICPath5);
251     EXPECT_EQ(resInSlowPath9, resInICPath9);
252     EXPECT_EQ(resInSlowPath10, resInICPath10);
253 };
254 
255 
HWTEST_F_L0(IcCompareOPTest, LessEqWithIC)256 HWTEST_F_L0(IcCompareOPTest, LessEqWithIC)
257 {
258     ObjectFactory *factory = ecmaVm->GetFactory();
259 
260     JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1"));
261     JSTaggedValue arg1(static_cast<uint32_t>(1));
262     JSTaggedValue arg2(static_cast<double>(0.5));
263     JSTaggedValue arg3(false);
264     JSTaggedValue arg4(true);
265     JSHandle<JSTaggedValue> arg1Handle(thread, arg1);
266     JSHandle<JSTaggedValue> arg2Handle(thread, arg2);
267     JSHandle<JSTaggedValue> arg3Handle(thread, arg3);
268     JSHandle<JSTaggedValue> arg4Handle(thread, arg4);
269     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
270     JSHandle<JSObject> globalObject(thread, env->GetGlobalObject());
271 
272     JSHandle<JSFunction> boolean(env->GetBooleanFunction());
273     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6);
274     ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue());
275     ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue());
276     ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(123)));
277 
278     JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo);
279     JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj);
280     JSTaggedValue resInSlowPath1 = SlowRuntimeStub::LessEq(thread, arg1Handle.GetTaggedValue(),
281                                                               arg2Handle.GetTaggedValue());
282     JSTaggedValue resInSlowPath2 = SlowRuntimeStub::LessEq(thread, Str1.GetTaggedValue(),
283                                                               arg1Handle.GetTaggedValue());
284     JSTaggedValue resInSlowPath3 = SlowRuntimeStub::LessEq(thread, Str1.GetTaggedValue(),
285                                                               arg3Handle.GetTaggedValue());
286     JSTaggedValue resInSlowPath4 = SlowRuntimeStub::LessEq(thread, Str1.GetTaggedValue(),
287                                                               arg4Handle.GetTaggedValue());
288     JSTaggedValue resInSlowPath5 = SlowRuntimeStub::LessEq(thread, arg1Handle.GetTaggedValue(),
289                                                               booleanObjHandle.GetTaggedValue());
290     JSTaggedValue resInSlowPath9 = SlowRuntimeStub::LessEq(thread, JSTaggedValue::Undefined(),
291                                                               JSTaggedValue::Null());
292     JSTaggedValue resInSlowPath10 = SlowRuntimeStub::LessEq(thread, JSTaggedValue::Undefined(),
293                                                                JSTaggedValue::True());
294     JSTaggedValue resInICPath1 = CompareOp::LessEqWithIC(thread, arg1Handle.GetTaggedValue(),
295                                                             arg2Handle.GetTaggedValue(),
296                                                             CompareOpType::NUMBER_NUMBER);
297     JSTaggedValue resInICPath2 = CompareOp::LessEqWithIC(thread, Str1.GetTaggedValue(),
298                                                             arg1Handle.GetTaggedValue(),
299                                                             CompareOpType::STRING_NUMBER);
300     JSTaggedValue resInICPath3 = CompareOp::LessEqWithIC(thread, Str1.GetTaggedValue(),
301                                                             arg3Handle.GetTaggedValue(),
302                                                             CompareOpType::STRING_BOOLEAN);
303     JSTaggedValue resInICPath4 = CompareOp::LessEqWithIC(thread, Str1.GetTaggedValue(),
304                                                             arg4Handle.GetTaggedValue(),
305                                                             CompareOpType::STRING_BOOLEAN);
306     JSTaggedValue resInICPath5 = CompareOp::LessEqWithIC(thread,
307                                                             arg1Handle.GetTaggedValue(),
308                                                             booleanObjHandle.GetTaggedValue(),
309                                                             CompareOpType::NUMBER_OBJ);
310     JSTaggedValue resInICPath9 = CompareOp::LessEqWithIC(thread, JSTaggedValue::Undefined(),
311                                                             JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL);
312     JSTaggedValue resInICPath10 = CompareOp::LessEqWithIC(thread, JSTaggedValue::Undefined(),
313                                                             JSTaggedValue::True(), CompareOpType::OTHER);
314 
315     EXPECT_EQ(resInSlowPath1, resInICPath1);
316     EXPECT_EQ(resInSlowPath2, resInICPath2);
317     EXPECT_EQ(resInSlowPath3, resInICPath3);
318     EXPECT_EQ(resInSlowPath4, resInICPath4);
319     EXPECT_EQ(resInSlowPath5, resInICPath5);
320     EXPECT_EQ(resInSlowPath9, resInICPath9);
321     EXPECT_EQ(resInSlowPath10, resInICPath10);
322 };
323 
324 
HWTEST_F_L0(IcCompareOPTest, GreaterWithIC)325 HWTEST_F_L0(IcCompareOPTest, GreaterWithIC)
326 {
327     ObjectFactory *factory = ecmaVm->GetFactory();
328 
329     JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1"));
330     JSTaggedValue arg1(static_cast<uint32_t>(1));
331     JSTaggedValue arg2(static_cast<double>(1.0));
332     JSTaggedValue arg3(false);
333     JSTaggedValue arg4(true);
334     JSHandle<JSTaggedValue> arg1Handle(thread, arg1);
335     JSHandle<JSTaggedValue> arg2Handle(thread, arg2);
336     JSHandle<JSTaggedValue> arg3Handle(thread, arg3);
337     JSHandle<JSTaggedValue> arg4Handle(thread, arg4);
338     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
339     JSHandle<JSObject> globalObject(thread, env->GetGlobalObject());
340 
341     JSHandle<JSFunction> boolean(env->GetBooleanFunction());
342     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6);
343     ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue());
344     ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue());
345     ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(1)));
346 
347     JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo);
348     JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj);
349     JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Greater(thread, arg1Handle.GetTaggedValue(),
350                                                                arg2Handle.GetTaggedValue());
351     JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Greater(thread, Str1.GetTaggedValue(),
352                                                                arg1Handle.GetTaggedValue());
353     JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Greater(thread, Str1.GetTaggedValue(),
354                                                                arg3Handle.GetTaggedValue());
355     JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Greater(thread, Str1.GetTaggedValue(),
356                                                                arg4Handle.GetTaggedValue());
357     JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Greater(thread, arg1Handle.GetTaggedValue(),
358                                                                booleanObjHandle.GetTaggedValue());
359     JSTaggedValue resInSlowPath9 = SlowRuntimeStub::Greater(thread, JSTaggedValue::Undefined(),
360                                                                JSTaggedValue::Null());
361     JSTaggedValue resInSlowPath10 = SlowRuntimeStub::Greater(thread, JSTaggedValue::Undefined(),
362                                                                 JSTaggedValue::True());
363 
364     JSTaggedValue resInICPath1 = CompareOp::GreaterWithIC(thread, arg1Handle.GetTaggedValue(),
365                                                              arg2Handle.GetTaggedValue(),
366                                                              CompareOpType::NUMBER_NUMBER);
367     JSTaggedValue resInICPath2 = CompareOp::GreaterWithIC(thread, Str1.GetTaggedValue(),
368                                                              arg1Handle.GetTaggedValue(),
369                                                              CompareOpType::STRING_NUMBER);
370     JSTaggedValue resInICPath3 = CompareOp::GreaterWithIC(thread, Str1.GetTaggedValue(),
371                                                              arg3Handle.GetTaggedValue(),
372                                                              CompareOpType::STRING_BOOLEAN);
373     JSTaggedValue resInICPath4 = CompareOp::GreaterWithIC(thread, Str1.GetTaggedValue(),
374                                                              arg4Handle.GetTaggedValue(),
375                                                              CompareOpType::STRING_BOOLEAN);
376     JSTaggedValue resInICPath5 = CompareOp::GreaterWithIC(thread, arg1Handle.GetTaggedValue(),
377                                                              booleanObjHandle.GetTaggedValue(),
378                                                              CompareOpType::NUMBER_OBJ);
379     JSTaggedValue resInICPath9 = CompareOp::GreaterWithIC(thread, JSTaggedValue::Undefined(),
380                                                              JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL);
381     JSTaggedValue resInICPath10 = CompareOp::GreaterWithIC(thread, JSTaggedValue::Undefined(),
382                                                               JSTaggedValue::True(), CompareOpType::OTHER);
383 
384     EXPECT_EQ(resInSlowPath1, resInICPath1);
385     EXPECT_EQ(resInSlowPath2, resInICPath2);
386     EXPECT_EQ(resInSlowPath3, resInICPath3);
387     EXPECT_EQ(resInSlowPath4, resInICPath4);
388     EXPECT_EQ(resInSlowPath5, resInICPath5);
389     EXPECT_EQ(resInSlowPath9, resInICPath9);
390     EXPECT_EQ(resInSlowPath10, resInICPath10);
391 };
392 
393 
HWTEST_F_L0(IcCompareOPTest, GreaterEqWithIC)394 HWTEST_F_L0(IcCompareOPTest, GreaterEqWithIC)
395 {
396     ObjectFactory *factory = ecmaVm->GetFactory();
397 
398     JSHandle<JSTaggedValue> Str1 = JSHandle<JSTaggedValue>(factory->NewFromASCII("1"));
399     JSTaggedValue arg1(static_cast<uint32_t>(1));
400     JSTaggedValue arg2(static_cast<double>(1.0));
401     JSTaggedValue arg3(false);
402     JSTaggedValue arg4(true);
403     JSHandle<JSTaggedValue> arg1Handle(thread, arg1);
404     JSHandle<JSTaggedValue> arg2Handle(thread, arg2);
405     JSHandle<JSTaggedValue> arg3Handle(thread, arg3);
406     JSHandle<JSTaggedValue> arg4Handle(thread, arg4);
407 
408     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
409     JSHandle<JSObject> globalObject(thread, env->GetGlobalObject());
410 
411     JSHandle<JSFunction> boolean(env->GetBooleanFunction());
412     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*boolean), 6);
413     ecmaRuntimeCallInfo->SetFunction(boolean.GetTaggedValue());
414     ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue());
415     ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int32_t>(0)));
416 
417     JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo);
418     JSHandle<JSTaggedValue> booleanObjHandle(thread, booleanObj);
419     JSTaggedValue resInSlowPath1 = SlowRuntimeStub::GreaterEq(thread, arg1Handle.GetTaggedValue(),
420                                                                  arg2Handle.GetTaggedValue());
421     JSTaggedValue resInSlowPath2 = SlowRuntimeStub::GreaterEq(thread, Str1.GetTaggedValue(),
422                                                                  arg1Handle.GetTaggedValue());
423     JSTaggedValue resInSlowPath3 = SlowRuntimeStub::GreaterEq(thread, Str1.GetTaggedValue(),
424                                                                  arg3Handle.GetTaggedValue());
425     JSTaggedValue resInSlowPath4 = SlowRuntimeStub::GreaterEq(thread, Str1.GetTaggedValue(),
426                                                                  arg4Handle.GetTaggedValue());
427     JSTaggedValue resInSlowPath5 = SlowRuntimeStub::GreaterEq(thread, arg1Handle.GetTaggedValue(),
428                                                                  booleanObjHandle.GetTaggedValue());
429     JSTaggedValue resInSlowPath9 = SlowRuntimeStub::GreaterEq(thread, JSTaggedValue::Undefined(),
430                                                                  JSTaggedValue::Null());
431     JSTaggedValue resInSlowPath10 = SlowRuntimeStub::GreaterEq(thread, JSTaggedValue::Undefined(),
432                                                                   JSTaggedValue::True());
433 
434     JSTaggedValue resInICPath1 = CompareOp::GreaterEqWithIC(thread, arg1Handle.GetTaggedValue(),
435                                                                arg2Handle.GetTaggedValue(),
436                                                                CompareOpType::NUMBER_NUMBER);
437     JSTaggedValue resInICPath2 = CompareOp::GreaterEqWithIC(thread, Str1.GetTaggedValue(),
438                                                                arg1Handle.GetTaggedValue(),
439                                                                CompareOpType::STRING_NUMBER);
440     JSTaggedValue resInICPath3 = CompareOp::GreaterEqWithIC(thread, Str1.GetTaggedValue(),
441                                                                arg3Handle.GetTaggedValue(),
442                                                                CompareOpType::STRING_BOOLEAN);
443     JSTaggedValue resInICPath4 = CompareOp::GreaterEqWithIC(thread, Str1.GetTaggedValue(),
444                                                                arg4Handle.GetTaggedValue(),
445                                                                CompareOpType::STRING_BOOLEAN);
446     JSTaggedValue resInICPath5 = CompareOp::GreaterEqWithIC(thread, arg1Handle.GetTaggedValue(),
447                                                                booleanObjHandle.GetTaggedValue(),
448                                                                CompareOpType::NUMBER_OBJ);
449     JSTaggedValue resInICPath9 = CompareOp::GreaterEqWithIC(thread, JSTaggedValue::Undefined(),
450                                                                JSTaggedValue::Null(), CompareOpType::UNDEFINED_NULL);
451     JSTaggedValue resInICPath10 = CompareOp::GreaterEqWithIC(thread, JSTaggedValue::Undefined(),
452                                                                 JSTaggedValue::True(), CompareOpType::OTHER);
453 
454     EXPECT_EQ(resInSlowPath1, resInICPath1);
455     EXPECT_EQ(resInSlowPath2, resInICPath2);
456     EXPECT_EQ(resInSlowPath3, resInICPath3);
457     EXPECT_EQ(resInSlowPath4, resInICPath4);
458     EXPECT_EQ(resInSlowPath5, resInICPath5);
459     EXPECT_EQ(resInSlowPath9, resInICPath9);
460     EXPECT_EQ(resInSlowPath10, resInICPath10);
461 };
462 }  // namespace panda::test
463