1/*
2 * Copyright (c) 2021-2024 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/ecma_vm.h"
19#include "ecmascript/global_env_constants.h"
20#include "ecmascript/global_env_constants-inl.h"
21#include "ecmascript/ic/ic_binary_op.h"
22#include "ecmascript/interpreter/slow_runtime_stub.h"
23#include "ecmascript/object_factory.h"
24#include "ecmascript/tests/test_helper.h"
25
26using namespace panda::ecmascript;
27namespace panda::test {
28class ICBinaryOPTest : public testing::Test {
29public:
30    static void SetUpTestCase()
31    {
32        GTEST_LOG_(INFO) << "SetUpTestCase";
33    }
34
35    static void TearDownTestCase()
36    {
37        GTEST_LOG_(INFO) << "TearDownCase";
38    }
39
40    void SetUp() override
41    {
42        TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope);
43    }
44
45    void TearDown() override
46    {
47        TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope);
48    }
49
50    EcmaHandleScope *scope {nullptr};
51    JSThread *thread {nullptr};
52    EcmaVM *ecmaVm = nullptr;
53};
54
55HWTEST_F_L0(ICBinaryOPTest, AddWithTSType)
56{
57    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
58
59    JSHandle<EcmaString> Str1 = factory->NewFromASCII("AddTest");
60    JSHandle<EcmaString> Str2 = factory->NewFromASCII("IC");
61    JSHandle<JSObject> arg4 = factory->NewEmptyJSObject();
62    JSTaggedValue arg1Value(static_cast<uint32_t>(2));
63    JSTaggedValue arg2Value(static_cast<uint32_t>(3));
64    JSTaggedValue arg3Value(static_cast<double>(9.5561));
65    JSHandle<JSTaggedValue> arg1(thread, arg1Value);
66    JSHandle<JSTaggedValue> arg2(thread, arg2Value);
67    JSHandle<JSTaggedValue> arg3(thread, arg3Value);
68
69    JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Add2(thread, arg1.GetTaggedValue(),
70                                                            arg2.GetTaggedValue());
71    JSHandle<JSTaggedValue> slowHandle1(thread, resInSlowPath1);
72    JSTaggedValue resInICPath1 = ICBinaryOP::AddWithTSType(thread,  arg1.GetTaggedValue(), arg2.GetTaggedValue(),
73                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
74    EXPECT_EQ(slowHandle1.GetTaggedValue(), resInICPath1);
75
76    JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Add2(thread, arg1.GetTaggedValue(),
77                                                            arg3.GetTaggedValue());
78    JSHandle<JSTaggedValue> slowHandle2(thread, resInSlowPath2);
79    JSTaggedValue resInICPath2 = ICBinaryOP::AddWithTSType(thread,  arg1.GetTaggedValue(), arg3.GetTaggedValue(),
80                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
81    EXPECT_EQ(slowHandle2.GetTaggedValue(), resInICPath2);
82
83    JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Add2(thread, Str1.GetTaggedValue(),
84                                                            Str2.GetTaggedValue());
85    JSHandle<EcmaString> slowHandle3(thread, reinterpret_cast<EcmaString *>(resInSlowPath3.GetRawData()));
86    JSTaggedValue resInICPath3 = ICBinaryOP::AddWithTSType(thread,  Str1.GetTaggedValue(), Str2.GetTaggedValue(),
87                                                           JSTaggedValue(static_cast<int>(BinaryType::STRING)));
88    ASSERT_TRUE(resInICPath3.IsString());
89    EXPECT_EQ(EcmaStringAccessor::Compare(ecmaVm, slowHandle3, JSHandle<EcmaString>(thread, resInICPath3)), 0);
90
91    JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Add2(thread, JSTaggedValue::Undefined(),
92                                                            arg2.GetTaggedValue());
93    JSHandle<JSTaggedValue> slowHandle4(thread, resInSlowPath4);
94    JSTaggedValue resInICPath4 = ICBinaryOP::AddWithTSType(thread,  JSTaggedValue::Undefined(),
95                                                           arg2.GetTaggedValue(),
96                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER_GEN)));
97    EXPECT_EQ(slowHandle4.GetTaggedValue(), resInICPath4);
98
99    JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Add2(thread, arg3.GetTaggedValue(),
100                                                            Str1.GetTaggedValue());
101    JSHandle<EcmaString> slowHandle5(thread, reinterpret_cast<EcmaString *>(resInSlowPath5.GetRawData()));
102    JSTaggedValue resInICPath5 = ICBinaryOP::AddWithTSType(thread,  arg3.GetTaggedValue(),
103                                                           Str1.GetTaggedValue(),
104                                                           JSTaggedValue(static_cast<int>(BinaryType::STRING_GEN)));
105    ASSERT_TRUE(resInICPath5.IsString());
106    EXPECT_EQ(EcmaStringAccessor::Compare(ecmaVm, slowHandle5, JSHandle<EcmaString>(thread, resInICPath5)), 0);
107
108    JSTaggedValue resInSlowPath6 = SlowRuntimeStub::Add2(thread, Str1.GetTaggedValue(),
109                                                            JSTaggedValue::Null());
110    JSHandle<EcmaString> slowHandle6(thread, reinterpret_cast<EcmaString *>(resInSlowPath6.GetRawData()));
111    JSTaggedValue resInICPath6 = ICBinaryOP::AddWithTSType(thread,  Str1.GetTaggedValue(), JSTaggedValue::Null(),
112                                                           JSTaggedValue(static_cast<int>(BinaryType::STRING_GEN)));
113    ASSERT_TRUE(resInICPath6.IsString());
114    EXPECT_EQ(EcmaStringAccessor::Compare(ecmaVm, slowHandle6, JSHandle<EcmaString>(thread, resInICPath6)), 0);
115
116    JSTaggedValue resInSlowPath7 = SlowRuntimeStub::Add2(thread, arg1.GetTaggedValue(),
117                                                            JSTaggedValue::True());
118    JSHandle<JSTaggedValue> slowHandle7(thread, resInSlowPath7);
119    JSTaggedValue resInICPath7 = ICBinaryOP::AddWithTSType(thread, arg1.GetTaggedValue(), JSTaggedValue::True(),
120                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER_GEN)));
121    EXPECT_EQ(slowHandle7.GetTaggedValue(), resInICPath7);
122
123    JSTaggedValue resInSlowPath8 = SlowRuntimeStub::Add2(thread, arg4.GetTaggedValue(),
124                                                            JSTaggedValue::Null());
125    JSHandle<EcmaString> slowHandle8(thread, reinterpret_cast<EcmaString *>(resInSlowPath8.GetRawData()));
126    JSTaggedValue resInICPath8 = ICBinaryOP::AddWithTSType(thread,  arg4.GetTaggedValue(), JSTaggedValue::Null(),
127                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
128    ASSERT_TRUE(resInICPath8.IsString());
129    EXPECT_EQ(EcmaStringAccessor::Compare(ecmaVm, slowHandle8, JSHandle<EcmaString>(thread, resInICPath8)), 0);
130};
131
132HWTEST_F_L0(ICBinaryOPTest, SubWithTSType)
133{
134    JSTaggedValue arg1Value(static_cast<uint32_t>(-2));
135    JSTaggedValue arg2Value(static_cast<uint32_t>(INT32_MAX-1));
136    JSTaggedValue arg3Value(static_cast<double>(9.5561));
137    JSHandle<JSTaggedValue> arg1(thread, arg1Value);
138    JSHandle<JSTaggedValue> arg2(thread, arg2Value);
139    JSHandle<JSTaggedValue> arg3(thread, arg3Value);
140
141    JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Sub2(thread, arg1.GetTaggedValue(), arg2.GetTaggedValue());
142    JSHandle<JSTaggedValue> slowHandle1(thread, resInSlowPath1);
143    JSTaggedValue resInICPath1 = ICBinaryOP::SubWithTSType(thread,  arg1.GetTaggedValue(), arg2.GetTaggedValue(),
144                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
145    EXPECT_EQ(slowHandle1.GetTaggedValue(), resInICPath1);
146
147    JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Sub2(thread, arg2.GetTaggedValue(), arg3.GetTaggedValue());
148    JSHandle<JSTaggedValue> slowHandle2(thread, resInSlowPath2);
149    JSTaggedValue resInICPath2 = ICBinaryOP::SubWithTSType(thread,  arg2.GetTaggedValue(), arg3.GetTaggedValue(),
150                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
151    EXPECT_EQ(slowHandle2.GetTaggedValue(), resInICPath2);
152
153    JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Sub2(thread, arg1.GetTaggedValue(), JSTaggedValue::True());
154    JSHandle<JSTaggedValue> slowHandle3(thread, resInSlowPath3);
155    JSTaggedValue resInICPath3 = ICBinaryOP::SubWithTSType(thread,  arg1.GetTaggedValue(), JSTaggedValue::True(),
156                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
157    EXPECT_EQ(slowHandle3.GetTaggedValue(), resInICPath3);
158};
159
160HWTEST_F_L0(ICBinaryOPTest, MulWithTSType)
161{
162    JSTaggedValue arg1Value(static_cast<double>(28.5));
163    JSTaggedValue arg2Value(static_cast<uint16_t>(354));
164    JSTaggedValue arg3Value(static_cast<double>(9.5561));
165    JSHandle<JSTaggedValue> arg1(thread, arg1Value);
166    JSHandle<JSTaggedValue> arg2(thread, arg2Value);
167    JSHandle<JSTaggedValue> arg3(thread, arg3Value);
168
169    JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Mul2(thread, arg1.GetTaggedValue(), arg2.GetTaggedValue());
170    JSHandle<JSTaggedValue> slowHandle1(thread, resInSlowPath1);
171    JSTaggedValue resInICPath1 = ICBinaryOP::MulWithTSType(thread,  arg1.GetTaggedValue(), arg2.GetTaggedValue(),
172                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
173    EXPECT_EQ(slowHandle1.GetTaggedValue(), resInICPath1);
174
175    JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Mul2(thread, arg2.GetTaggedValue(), arg3.GetTaggedValue());
176    JSHandle<JSTaggedValue> slowHandle2(thread, resInSlowPath2);
177    JSTaggedValue resInICPath2 = ICBinaryOP::MulWithTSType(thread,  arg2.GetTaggedValue(), arg3.GetTaggedValue(),
178                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
179    EXPECT_EQ(slowHandle2.GetTaggedValue(), resInICPath2);
180
181    JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Mul2(thread, arg1.GetTaggedValue(), JSTaggedValue::True());
182    JSHandle<JSTaggedValue> slowHandle3(thread, resInSlowPath3);
183    JSTaggedValue resInICPath3 = ICBinaryOP::MulWithTSType(thread,  arg1.GetTaggedValue(), JSTaggedValue::True(),
184                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
185    EXPECT_EQ(slowHandle3.GetTaggedValue(), resInICPath3);
186
187};
188
189HWTEST_F_L0(ICBinaryOPTest, DivWithTSType)
190{
191    JSTaggedValue arg1Value(static_cast<uint32_t>(2));
192    JSTaggedValue arg2Value(static_cast<uint32_t>(39884));
193    JSTaggedValue arg3Value(static_cast<uint32_t>(0));
194    JSTaggedValue arg4Value(static_cast<double>(934.5561));
195    JSHandle<JSTaggedValue> arg1(thread, arg1Value);
196    JSHandle<JSTaggedValue> arg2(thread, arg2Value);
197    JSHandle<JSTaggedValue> arg3(thread, arg3Value);
198    JSHandle<JSTaggedValue> arg4(thread, arg4Value);
199
200    JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Div2(thread, arg3.GetTaggedValue(), arg2.GetTaggedValue());
201    JSHandle<JSTaggedValue> slowHandle1(thread, resInSlowPath1);
202    JSTaggedValue resInICPath1 = ICBinaryOP::DivWithTSType(thread,  arg3.GetTaggedValue(), arg2.GetTaggedValue(),
203                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
204    EXPECT_EQ(slowHandle1.GetTaggedValue(), resInICPath1);
205
206    JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Div2(thread, arg2.GetTaggedValue(), arg3.GetTaggedValue());
207    JSHandle<JSTaggedValue> slowHandle2(thread, resInSlowPath2);
208    JSTaggedValue resInICPath2 = ICBinaryOP::DivWithTSType(thread,  arg2.GetTaggedValue(), arg3.GetTaggedValue(),
209                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
210    EXPECT_EQ(slowHandle2.GetTaggedValue(), resInICPath2);
211
212    JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Div2(thread, arg1.GetTaggedValue(), arg2.GetTaggedValue());
213    JSHandle<JSTaggedValue> slowHandle3(thread, resInSlowPath3);
214    JSTaggedValue resInICPath3 = ICBinaryOP::DivWithTSType(thread,  arg1.GetTaggedValue(), arg2.GetTaggedValue(),
215                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
216    EXPECT_EQ(slowHandle3.GetTaggedValue(), resInICPath3);
217
218    JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Div2(thread, arg2.GetTaggedValue(), JSTaggedValue::True());
219    JSHandle<JSTaggedValue> slowHandle4(thread, resInSlowPath4);
220    JSTaggedValue resInICPath4 = ICBinaryOP::DivWithTSType(thread,  arg2.GetTaggedValue(), JSTaggedValue::True(),
221                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
222    EXPECT_EQ(slowHandle4.GetTaggedValue(), resInICPath4);
223
224    JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Div2(thread, arg4.GetTaggedValue(), JSTaggedValue::False());
225    JSHandle<JSTaggedValue> slowHandle5(thread, resInSlowPath5);
226    JSTaggedValue resInICPath5 = ICBinaryOP::DivWithTSType(thread,  arg4.GetTaggedValue(),
227                                                           JSTaggedValue::False(),
228                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
229    EXPECT_EQ(slowHandle5.GetTaggedValue(), resInICPath5);
230};
231
232HWTEST_F_L0(ICBinaryOPTest, ModWithTSType)
233{
234    JSTaggedValue arg1Value(static_cast<uint32_t>(2));
235    JSTaggedValue arg2Value(static_cast<uint32_t>(39884));
236    JSTaggedValue arg3Value(static_cast<uint32_t>(0));
237    JSTaggedValue arg4Value(static_cast<double>(934.5561));
238    JSHandle<JSTaggedValue> arg1(thread, arg1Value);
239    JSHandle<JSTaggedValue> arg2(thread, arg2Value);
240    JSHandle<JSTaggedValue> arg3(thread, arg3Value);
241    JSHandle<JSTaggedValue> arg4(thread, arg4Value);
242
243    JSTaggedValue resInSlowPath1 = SlowRuntimeStub::Mod2(thread, arg3.GetTaggedValue(), arg2.GetTaggedValue());
244    JSHandle<JSTaggedValue> slowHandle1(thread, resInSlowPath1);
245    JSTaggedValue resInICPath1 = ICBinaryOP::ModWithTSType(thread,  arg3.GetTaggedValue(), arg2.GetTaggedValue(),
246                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
247    EXPECT_EQ(slowHandle1.GetTaggedValue(), resInICPath1);
248
249    JSTaggedValue resInSlowPath2 = SlowRuntimeStub::Mod2(thread, arg2.GetTaggedValue(), arg3.GetTaggedValue());
250    JSHandle<JSTaggedValue> slowHandle2(thread, resInSlowPath2);
251    JSTaggedValue resInICPath2 = ICBinaryOP::ModWithTSType(thread,  arg2.GetTaggedValue(), arg3.GetTaggedValue(),
252                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
253    EXPECT_EQ(slowHandle2.GetTaggedValue(), resInICPath2);
254
255    JSTaggedValue resInSlowPath3 = SlowRuntimeStub::Mod2(thread, arg1.GetTaggedValue(), arg2.GetTaggedValue());
256    JSHandle<JSTaggedValue> slowHandle3(thread, resInSlowPath3);
257    JSTaggedValue resInICPath3 = ICBinaryOP::ModWithTSType(thread,  arg1.GetTaggedValue(), arg2.GetTaggedValue(),
258                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
259    EXPECT_EQ(slowHandle3.GetTaggedValue(), resInICPath3);
260
261
262    JSTaggedValue resInSlowPath4 = SlowRuntimeStub::Mod2(thread, arg2.GetTaggedValue(), JSTaggedValue::True());
263    JSHandle<JSTaggedValue> slowHandle4(thread, resInSlowPath4);
264    JSTaggedValue resInICPath4 = ICBinaryOP::ModWithTSType(thread,  arg2.GetTaggedValue(), JSTaggedValue::True(),
265                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
266    EXPECT_EQ(slowHandle4.GetTaggedValue(), resInICPath4);
267
268
269    JSTaggedValue resInSlowPath5 = SlowRuntimeStub::Mod2(thread, arg4.GetTaggedValue(), JSTaggedValue::False());
270    JSHandle<JSTaggedValue> slowHandle5(thread, resInSlowPath5);
271    JSTaggedValue resInICPath5 = ICBinaryOP::ModWithTSType(thread,  arg4.GetTaggedValue(),
272                                                           JSTaggedValue::False(),
273                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
274    EXPECT_EQ(slowHandle5.GetTaggedValue(), resInICPath5);
275};
276
277HWTEST_F_L0(ICBinaryOPTest, ShlWithTSType)
278{
279    ObjectFactory *factory = ecmaVm->GetFactory();
280
281    JSHandle<EcmaString> Str1 = factory->NewFromASCII("225");
282    JSTaggedValue arg1(static_cast<uint32_t>(286));
283    JSTaggedValue arg3(static_cast<uint32_t>(5));
284
285    JSTaggedValue resInICPath1 = ICBinaryOP::ShlWithTSType(thread,  arg1, arg3,
286                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
287    EXPECT_EQ(JSTaggedValue(9152), resInICPath1);
288
289    JSTaggedValue resInICPath2 = ICBinaryOP::ShlWithTSType(thread,  Str1.GetTaggedValue(), arg3,
290                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
291    EXPECT_EQ(JSTaggedValue(7200), resInICPath2);
292};
293
294HWTEST_F_L0(ICBinaryOPTest, ShrWithTSType)
295{
296    ObjectFactory *factory = ecmaVm->GetFactory();
297
298    JSHandle<EcmaString> Str1 = factory->NewFromASCII("225");
299    JSTaggedValue arg1(static_cast<uint32_t>(286));
300    JSTaggedValue arg3(static_cast<uint32_t>(5));
301
302    JSTaggedValue resInICPath1 = ICBinaryOP::ShrWithTSType(thread,  arg1, arg3,
303                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
304    EXPECT_EQ(JSTaggedValue(8), resInICPath1);
305
306    JSTaggedValue resInICPath2 = ICBinaryOP::ShrWithTSType(thread,  Str1.GetTaggedValue(), arg3,
307                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
308    EXPECT_EQ(JSTaggedValue(7), resInICPath2);
309};
310
311HWTEST_F_L0(ICBinaryOPTest, AshrWithTSType)
312{
313    ObjectFactory *factory = ecmaVm->GetFactory();
314
315    JSHandle<EcmaString> Str1 = factory->NewFromASCII("225");
316    JSTaggedValue arg1(static_cast<uint32_t>(286));
317    JSTaggedValue arg2(static_cast<uint32_t>(-286));
318    JSTaggedValue arg3(static_cast<uint32_t>(5));
319
320    JSTaggedValue resInICPath1 = ICBinaryOP::AshrWithTSType(thread,  arg1, arg3,
321                                                            JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
322    EXPECT_EQ(JSTaggedValue(8), resInICPath1);
323
324    JSTaggedValue resInICPath3 = ICBinaryOP::AshrWithTSType(thread,  arg2, arg3,
325                                                            JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
326    EXPECT_EQ(JSTaggedValue(134217719), resInICPath3);
327
328    JSTaggedValue resInICPath2 = ICBinaryOP::AshrWithTSType(thread,  Str1.GetTaggedValue(), arg3,
329                                                            JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
330    EXPECT_EQ(JSTaggedValue(7), resInICPath2);
331
332};
333HWTEST_F_L0(ICBinaryOPTest, AndWithTSType)
334{
335    ObjectFactory *factory = ecmaVm->GetFactory();
336
337    JSHandle<EcmaString> Str1 = factory->NewFromASCII("225");
338    JSTaggedValue arg1(static_cast<uint32_t>(286));
339    JSTaggedValue arg3(static_cast<uint32_t>(541));
340
341    JSTaggedValue resInICPath1 = ICBinaryOP::AndWithTSType(thread,  arg1, arg3,
342                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
343    EXPECT_EQ(JSTaggedValue(28), resInICPath1);
344
345    JSTaggedValue resInICPath2 = ICBinaryOP::AndWithTSType(thread,  Str1.GetTaggedValue(), arg3,
346                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
347    EXPECT_EQ(JSTaggedValue(1), resInICPath2);
348};
349HWTEST_F_L0(ICBinaryOPTest, OrWithTSType)
350{
351    ObjectFactory *factory = ecmaVm->GetFactory();
352
353    JSHandle<EcmaString> Str1 = factory->NewFromASCII("225");
354    JSTaggedValue arg1(static_cast<uint32_t>(286));
355    JSTaggedValue arg3(static_cast<uint32_t>(523));
356
357    JSTaggedValue resInICPath1 = ICBinaryOP::OrWithTSType(thread,  arg1, arg3,
358                                                          JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
359    EXPECT_EQ(JSTaggedValue(799), resInICPath1);
360
361    JSTaggedValue resInICPath2 = ICBinaryOP::OrWithTSType(thread,  Str1.GetTaggedValue(), arg3,
362                                                          JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
363    EXPECT_EQ(JSTaggedValue(747), resInICPath2);
364};
365HWTEST_F_L0(ICBinaryOPTest, XorWithTSType)
366{
367    ObjectFactory *factory = ecmaVm->GetFactory();
368
369    JSHandle<EcmaString> Str1 = factory->NewFromASCII("1225");
370    JSTaggedValue arg1(static_cast<uint32_t>(286));
371    JSTaggedValue arg3(static_cast<uint32_t>(523));
372
373    JSTaggedValue resInICPath1 = ICBinaryOP::XorWithTSType(thread,  arg1, arg3,
374                                                           JSTaggedValue(static_cast<int>(BinaryType::NUMBER)));
375    EXPECT_EQ(JSTaggedValue(789), resInICPath1);
376
377    JSTaggedValue resInICPath2 = ICBinaryOP::XorWithTSType(thread,  Str1.GetTaggedValue(), arg3,
378                                                           JSTaggedValue(static_cast<int>(BinaryType::GENERIC)));
379    EXPECT_EQ(JSTaggedValue(1730), resInICPath2);
380};
381}  // namespace panda::test
382