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