• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ecmascript/builtins/builtins_errors.h"
17 
18 #include "ecmascript/base/error_helper.h"
19 #include "ecmascript/ecma_string.h"
20 #include "ecmascript/ecma_vm.h"
21 #include "ecmascript/global_env.h"
22 
23 #include "ecmascript/js_handle.h"
24 #include "ecmascript/js_hclass.h"
25 #include "ecmascript/js_object-inl.h"
26 #include "ecmascript/js_tagged_value-inl.h"
27 
28 #include "ecmascript/js_thread.h"
29 #include "ecmascript/object_factory.h"
30 #include "ecmascript/tests/test_helper.h"
31 
32 using namespace panda::ecmascript;
33 using namespace panda::ecmascript::builtins;
34 
35 namespace panda::test {
36 using Error = ecmascript::builtins::BuiltinsError;
37 using RangeError = builtins::BuiltinsRangeError;
38 using ReferenceError = builtins::BuiltinsReferenceError;
39 using TypeError = builtins::BuiltinsTypeError;
40 using URIError = builtins::BuiltinsURIError;
41 using EvalError = builtins::BuiltinsEvalError;
42 using SyntaxError = builtins::BuiltinsSyntaxError;
43 using AggregateError = builtins::BuiltinsAggregateError;
44 using JSType = ecmascript::JSType;
45 
46 class BuiltinsErrorsTest : public testing::Test {
47 public:
SetUpTestCase()48     static void SetUpTestCase()
49     {
50         GTEST_LOG_(INFO) << "BuiltinsErrorsTest SetUpTestCase";
51     }
52 
TearDownTestCase()53     static void TearDownTestCase()
54     {
55         GTEST_LOG_(INFO) << "BuiltinsErrorsTest TearDownCase";
56     }
57 
SetUp()58     void SetUp() override
59     {
60         TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
61     }
62 
TearDown()63     void TearDown() override
64     {
65         TestHelper::DestroyEcmaVMWithScope(instance, scope);
66     }
67 
68     EcmaVM *instance {nullptr};
69     EcmaHandleScope *scope {nullptr};
70     JSThread *thread {nullptr};
71 };
72 
73 /*
74  * @tc.name: GetJSErrorObject
75  * @tc.desc: get JSError Object
76  * @tc.type: FUNC
77  */
HWTEST_F_L0(BuiltinsErrorsTest,GetJSErrorObject)78 HWTEST_F_L0(BuiltinsErrorsTest, GetJSErrorObject)
79 {
80     /**
81      * @tc.steps: step1. Create JSError object
82      */
83     ObjectFactory *factory = instance->GetFactory();
84 
85     JSHandle<JSObject> handleObj = factory->GetJSError(ErrorType::TYPE_ERROR);
86     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
87     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
88 
89     /**
90      * @tc.steps: step2. obtain JSError object prototype chain name property and message property
91      */
92     JSHandle<JSTaggedValue> msgValue(
93         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(handleObj), msgKey).GetValue());
94     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
95         JSHandle<EcmaString>(msgValue), factory->NewFromASCII("")), 0);
96     JSHandle<JSTaggedValue> nameValue(
97         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(handleObj), nameKey).GetValue());
98     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
99         factory->NewFromASCII("TypeError"), JSHandle<EcmaString>(nameValue)), 0);
100 }
101 
102 /*
103  * @tc.name: GetJSErrorWithMessage
104  * @tc.desc: Obtains the TypeError object.
105  * @tc.type: FUNC
106  */
HWTEST_F_L0(BuiltinsErrorsTest,GetJSErrorWithMessage)107 HWTEST_F_L0(BuiltinsErrorsTest, GetJSErrorWithMessage)
108 {
109     ObjectFactory *factory = instance->GetFactory();
110 
111     JSHandle<JSObject> handleObj = factory->GetJSError(ErrorType::TYPE_ERROR, "I am type error");
112     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
113     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
114     JSHandle<JSTaggedValue> msgValue(
115         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(handleObj), msgKey).GetValue());
116     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
117         factory->NewFromASCII("I am type error"), JSHandle<EcmaString>(msgValue)), 0);
118     JSHandle<JSTaggedValue> nameValue(
119         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(handleObj), nameKey).GetValue());
120     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
121         factory->NewFromASCII("TypeError"), JSHandle<EcmaString>(nameValue)), 0);
122 }
123 
124 /*
125  * @tc.name: ErrorNoParameterConstructor
126  * @tc.desc: new Error()
127  * @tc.type: FUNC
128  */
HWTEST_F_L0(BuiltinsErrorsTest,ErrorNoParameterConstructor)129 HWTEST_F_L0(BuiltinsErrorsTest, ErrorNoParameterConstructor)
130 {
131     ObjectFactory *factory = instance->GetFactory();
132     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
133 
134     JSHandle<JSFunction> error(env->GetErrorFunction());
135 
136     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 4);
137     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
138     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
139 
140     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
141     JSTaggedValue result = Error::ErrorConstructor(ecmaRuntimeCallInfo);
142 
143     EXPECT_TRUE(result.IsECMAObject());
144 
145     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
146     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
147     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
148 
149     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
150     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
151         factory->NewFromASCII(""), JSHandle<EcmaString>(msgValue)), 0);
152 
153     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
154     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
155         factory->NewFromASCII("Error"), JSHandle<EcmaString>(nameValue)), 0);
156 }
157 
158 /*
159  * @tc.name: ErrorParameterConstructor
160  * @tc.desc: new Error("Hello Error!")
161  * @tc.type: FUNC
162  */
HWTEST_F_L0(BuiltinsErrorsTest,ErrorParameterConstructor)163 HWTEST_F_L0(BuiltinsErrorsTest, ErrorParameterConstructor)
164 {
165     ObjectFactory *factory = instance->GetFactory();
166     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
167 
168     JSHandle<JSFunction> error(env->GetErrorFunction());
169     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello Error!"));
170 
171     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 6);
172     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
173     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
174     ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue());
175 
176     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
177     JSTaggedValue result = Error::ErrorConstructor(ecmaRuntimeCallInfo);
178 
179     EXPECT_TRUE(result.IsECMAObject());
180 
181     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
182     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
183     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
184     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
185 
186     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
187         factory->NewFromASCII("Hello Error!"), JSHandle<EcmaString>(msgValue)), 0);
188 
189     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
190     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
191         factory->NewFromASCII("Error"), JSHandle<EcmaString>(nameValue)), 0);
192 }
193 
194 /*
195  * @tc.name: ErrorNoParameterToString
196  * @tc.desc: new Error().toString()
197  * @tc.type: FUNC
198  */
HWTEST_F_L0(BuiltinsErrorsTest,ErrorNoParameterToString)199 HWTEST_F_L0(BuiltinsErrorsTest, ErrorNoParameterToString)
200 {
201     ObjectFactory *factory = instance->GetFactory();
202     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
203 
204     JSHandle<JSTaggedValue> errorObject = env->GetErrorFunction();
205     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
206 
207     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
208     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
209     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
210 
211     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
212     JSTaggedValue result = Error::ToString(ecmaRuntimeCallInfo);
213 
214     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
215     EXPECT_TRUE(result.IsString());
216     EXPECT_EQ(EcmaStringAccessor::Compare(instance, factory->NewFromASCII("Error"), resultHandle), 0);
217 }
218 
219 /*
220  * @tc.name: ErrorToString
221  * @tc.desc: new Error("This is Error!").toString()
222  * @tc.type: FUNC
223  */
HWTEST_F_L0(BuiltinsErrorsTest,ErrorToString)224 HWTEST_F_L0(BuiltinsErrorsTest, ErrorToString)
225 {
226     ObjectFactory *factory = instance->GetFactory();
227     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
228 
229     JSHandle<JSTaggedValue> errorObject = env->GetErrorFunction();
230     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
231 
232     JSHandle<JSTaggedValue> handleMsgKey(factory->NewFromASCII("message"));
233     JSObject::SetProperty(
234         thread, JSHandle<JSTaggedValue>(error), handleMsgKey,
235         JSHandle<JSTaggedValue>(thread, factory->NewFromASCII("This is Error!").GetTaggedValue()));
236 
237     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
238     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
239     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
240 
241     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
242     JSTaggedValue result = Error::ToString(ecmaRuntimeCallInfo);
243 
244     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
245     EXPECT_TRUE(result.IsString());
246     EXPECT_EQ(EcmaStringAccessor::Compare(instance, factory->NewFromASCII("Error: This is Error!"), resultHandle), 0);
247 }
248 
249 /*
250  * @tc.name: RangeErrorNoParameterConstructor
251  * @tc.desc: new RangeError()
252  * @tc.type: FUNC
253  */
HWTEST_F_L0(BuiltinsErrorsTest,RangeErrorNoParameterConstructor)254 HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorNoParameterConstructor)
255 {
256     ObjectFactory *factory = instance->GetFactory();
257     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
258 
259     JSHandle<JSFunction> error(env->GetRangeErrorFunction());
260 
261     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
262     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
263     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
264 
265     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
266     JSTaggedValue result = RangeError::RangeErrorConstructor(ecmaRuntimeCallInfo);
267 
268     EXPECT_TRUE(result.IsECMAObject());
269 
270     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
271     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
272     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
273 
274     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
275     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
276         factory->NewFromASCII(""), JSHandle<EcmaString>(msgValue)), 0);
277     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
278     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
279         factory->NewFromASCII("RangeError"), JSHandle<EcmaString>(nameValue)), 0);
280 }
281 
282 /*
283  * @tc.name: RangeErrorParameterConstructor
284  * @tc.desc: new RangeError("Hello RangeError!")
285  * @tc.type: FUNC
286  */
HWTEST_F_L0(BuiltinsErrorsTest,RangeErrorParameterConstructor)287 HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorParameterConstructor)
288 {
289     ObjectFactory *factory = instance->GetFactory();
290     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
291 
292     JSHandle<JSFunction> error(env->GetRangeErrorFunction());
293     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello RangeError!"));
294 
295     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 6);
296     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
297     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
298     ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue());
299 
300     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
301     JSTaggedValue result = RangeError::RangeErrorConstructor(ecmaRuntimeCallInfo);
302 
303     EXPECT_TRUE(result.IsECMAObject());
304 
305     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
306     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
307     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
308 
309     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
310     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
311         factory->NewFromASCII("Hello RangeError!"), JSHandle<EcmaString>(msgValue)), 0);
312 
313     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
314     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
315         factory->NewFromASCII("RangeError"), JSHandle<EcmaString>(nameValue)), 0);
316 }
317 
318 /*
319  * @tc.name: RangeErrorNoParameterToString
320  * @tc.desc: new RangeError().toString()
321  * @tc.type: FUNC
322  */
HWTEST_F_L0(BuiltinsErrorsTest,RangeErrorNoParameterToString)323 HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorNoParameterToString)
324 {
325     ObjectFactory *factory = instance->GetFactory();
326     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
327 
328     JSHandle<JSTaggedValue> errorObject = env->GetRangeErrorFunction();
329     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
330 
331     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
332     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
333     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
334 
335     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
336     JSTaggedValue result = RangeError::ToString(ecmaRuntimeCallInfo);
337     JSHandle<JSTaggedValue> resultHandle(thread, result);
338 
339     EXPECT_TRUE(result.IsString());
340 
341     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
342         factory->NewFromASCII("RangeError"), JSHandle<EcmaString>(resultHandle)), 0);
343 }
344 
345 /*
346  * @tc.name: RangeErrorToString
347  * @tc.desc: new RangeError("This is RangeError!").toString()
348  * @tc.type: FUNC
349  */
HWTEST_F_L0(BuiltinsErrorsTest,RangeErrorToString)350 HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorToString)
351 {
352     ObjectFactory *factory = instance->GetFactory();
353     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
354 
355     JSHandle<JSTaggedValue> errorObject = env->GetRangeErrorFunction();
356     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
357 
358     JSHandle<JSTaggedValue> handleMsgKey(factory->NewFromASCII("message"));
359     JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(error), handleMsgKey,
360                           JSHandle<JSTaggedValue>(factory->NewFromASCII("This is RangeError!")));
361 
362     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
363     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
364     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
365 
366     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
367     JSTaggedValue result = RangeError::ToString(ecmaRuntimeCallInfo);
368 
369     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
370     EXPECT_TRUE(result.IsString());
371     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
372         factory->NewFromASCII("RangeError: This is RangeError!"), resultHandle), 0);
373 }
374 
375 // new ReferenceError()
376 /*
377  * @tc.name: ReferenceErrorNoParameterConstructor
378  * @tc.desc: new ReferenceError()
379  * @tc.type: FUNC
380  */
HWTEST_F_L0(BuiltinsErrorsTest,ReferenceErrorNoParameterConstructor)381 HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorNoParameterConstructor)
382 {
383     ObjectFactory *factory = instance->GetFactory();
384     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
385 
386     JSHandle<JSFunction> error(env->GetReferenceErrorFunction());
387 
388     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 4);
389     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
390     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
391 
392     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
393     JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecmaRuntimeCallInfo);
394     EXPECT_TRUE(result.IsECMAObject());
395 
396     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
397     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
398     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
399 
400     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
401     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
402         factory->NewFromASCII(""), JSHandle<EcmaString>(msgValue)), 0);
403 
404     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
405     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
406         factory->NewFromASCII("ReferenceError"), JSHandle<EcmaString>(nameValue)), 0);
407 }
408 
409 /*
410  * @tc.name: ReferenceErrorParameterConstructor
411  * @tc.desc: new ReferenceError("Hello RangeError!")
412  * @tc.type: FUNC
413  */
HWTEST_F_L0(BuiltinsErrorsTest,ReferenceErrorParameterConstructor)414 HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorParameterConstructor)
415 {
416     ObjectFactory *factory = instance->GetFactory();
417     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
418 
419     JSHandle<JSFunction> error(env->GetReferenceErrorFunction());
420     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello ReferenceError!"));
421 
422     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 6);
423     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
424     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
425     ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue());
426 
427     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
428     JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecmaRuntimeCallInfo);
429     EXPECT_TRUE(result.IsECMAObject());
430 
431     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
432     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
433     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
434     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
435     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
436         factory->NewFromASCII("Hello ReferenceError!"), JSHandle<EcmaString>(msgValue)), 0);
437 
438     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
439     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
440         factory->NewFromASCII("ReferenceError"), JSHandle<EcmaString>(nameValue)), 0);
441 }
442 
443 /*
444  * @tc.name: ReferenceErrorNoParameterToString
445  * @tc.desc: new ReferenceError().toString()
446  * @tc.type: FUNC
447  */
HWTEST_F_L0(BuiltinsErrorsTest,ReferenceErrorNoParameterToString)448 HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorNoParameterToString)
449 {
450     ObjectFactory *factory = instance->GetFactory();
451     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
452 
453     JSHandle<JSTaggedValue> errorObject = env->GetReferenceErrorFunction();
454     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
455 
456     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
457     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
458     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
459 
460     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
461     JSTaggedValue result = ReferenceError::ToString(ecmaRuntimeCallInfo);
462     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
463     EXPECT_TRUE(result.IsString());
464     EXPECT_EQ(EcmaStringAccessor::Compare(instance, factory->NewFromASCII("ReferenceError"), resultHandle), 0);
465 }
466 
467 /*
468  * @tc.name: ReferenceErrorToString
469  * @tc.desc: new ReferenceError("This is ReferenceError!").toString()
470  * @tc.type: FUNC
471  */
HWTEST_F_L0(BuiltinsErrorsTest,ReferenceErrorToString)472 HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorToString)
473 {
474     ObjectFactory *factory = instance->GetFactory();
475     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
476 
477     JSHandle<JSTaggedValue> errorObject = env->GetReferenceErrorFunction();
478     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
479 
480     JSHandle<JSTaggedValue> handleMsgKey(factory->NewFromASCII("message"));
481     JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(error), handleMsgKey,
482                           JSHandle<JSTaggedValue>(factory->NewFromASCII("This is ReferenceError!")));
483 
484     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
485     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
486     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
487 
488     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
489     JSTaggedValue result = ReferenceError::ToString(ecmaRuntimeCallInfo);
490     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
491     EXPECT_TRUE(result.IsString());
492     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
493         factory->NewFromASCII("ReferenceError: This is ReferenceError!"), resultHandle), 0);
494 }
495 
496 /*
497  * @tc.name: TypeErrorNoParameterConstructor
498  * @tc.desc: new TypeError()
499  * @tc.type: FUNC
500  */
HWTEST_F_L0(BuiltinsErrorsTest,TypeErrorNoParameterConstructor)501 HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorNoParameterConstructor)
502 {
503     ObjectFactory *factory = instance->GetFactory();
504     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
505 
506     JSHandle<JSFunction> error(env->GetTypeErrorFunction());
507 
508     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 4);
509     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
510     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
511 
512     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
513     JSTaggedValue result = TypeError::TypeErrorConstructor(ecmaRuntimeCallInfo);
514     EXPECT_TRUE(result.IsECMAObject());
515 
516     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
517     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
518     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
519 
520     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
521     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
522         factory->NewFromASCII(""), JSHandle<EcmaString>(msgValue)), 0);
523 
524     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
525     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
526         JSHandle<EcmaString>(nameValue), JSHandle<EcmaString>(nameValue)), 0);
527 }
528 
529 /*
530  * @tc.name: TypeErrorParameterConstructor
531  * @tc.desc: new TypeError("Hello RangeError!")
532  * @tc.type: FUNC
533  */
HWTEST_F_L0(BuiltinsErrorsTest,TypeErrorParameterConstructor)534 HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorParameterConstructor)
535 {
536     ObjectFactory *factory = instance->GetFactory();
537     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
538 
539     JSHandle<JSFunction> error(env->GetTypeErrorFunction());
540     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello TypeError!"));
541 
542     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 6);
543     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
544     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
545     ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue());
546 
547     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
548     JSTaggedValue result = TypeError::TypeErrorConstructor(ecmaRuntimeCallInfo);
549     EXPECT_TRUE(result.IsECMAObject());
550 
551     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
552     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
553     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
554 
555     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
556     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
557         factory->NewFromASCII("Hello TypeError!"), JSHandle<EcmaString>(msgValue)), 0);
558 
559     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
560     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
561         factory->NewFromASCII("TypeError"), JSHandle<EcmaString>(nameValue)), 0);
562 }
563 
564 /*
565  * @tc.name: TypeErrorNoParameterToString
566  * @tc.desc: new TypeError().toString()
567  * @tc.type: FUNC
568  */
HWTEST_F_L0(BuiltinsErrorsTest,TypeErrorNoParameterToString)569 HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorNoParameterToString)
570 {
571     ObjectFactory *factory = instance->GetFactory();
572     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
573 
574     JSHandle<JSTaggedValue> errorObject = env->GetTypeErrorFunction();
575     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
576 
577     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
578     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
579     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
580 
581     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
582     JSTaggedValue result = TypeError::ToString(ecmaRuntimeCallInfo);
583     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
584     EXPECT_TRUE(result.IsString());
585     EXPECT_EQ(EcmaStringAccessor::Compare(instance, factory->NewFromASCII("TypeError"), resultHandle), 0);
586 }
587 
588 /*
589  * @tc.name: TypeErrorToString
590  * @tc.desc: new TypeError("This is TypeError!").toString()
591  * @tc.type: FUNC
592  */
HWTEST_F_L0(BuiltinsErrorsTest,TypeErrorToString)593 HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorToString)
594 {
595     ObjectFactory *factory = instance->GetFactory();
596     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
597 
598     JSHandle<JSTaggedValue> errorObject = env->GetTypeErrorFunction();
599     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
600 
601     JSHandle<JSTaggedValue> value(factory->NewFromASCII("This is TypeError!"));
602     JSHandle<JSTaggedValue> handleMsgKey(factory->NewFromASCII("message"));
603     JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(error), handleMsgKey, value);
604 
605     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
606     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
607     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
608 
609     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
610     JSTaggedValue result = TypeError::ToString(ecmaRuntimeCallInfo);
611     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
612     EXPECT_TRUE(result.IsString());
613     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
614         factory->NewFromASCII("TypeError: This is TypeError!"), resultHandle), 0);
615 }
616 
617 /*
618  * @tc.name: URIErrorNoParameterConstructor
619  * @tc.desc: new URIError()
620  * @tc.type: FUNC
621  */
HWTEST_F_L0(BuiltinsErrorsTest,URIErrorNoParameterConstructor)622 HWTEST_F_L0(BuiltinsErrorsTest, URIErrorNoParameterConstructor)
623 {
624     ObjectFactory *factory = instance->GetFactory();
625     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
626 
627     JSHandle<JSFunction> error(env->GetURIErrorFunction());
628 
629     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 4);
630     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
631     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
632 
633     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
634     JSTaggedValue result = URIError::URIErrorConstructor(ecmaRuntimeCallInfo);
635     EXPECT_TRUE(result.IsECMAObject());
636 
637     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
638     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
639     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
640 
641     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
642     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
643         factory->NewFromASCII(""), JSHandle<EcmaString>(msgValue)), 0);
644 
645     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
646     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
647         factory->NewFromASCII("URIError"), JSHandle<EcmaString>(nameValue)), 0);
648 }
649 
650 /*
651  * @tc.name: URIErrorParameterConstructor
652  * @tc.desc: new URIError("Hello RangeError!")
653  * @tc.type: FUNC
654  */
HWTEST_F_L0(BuiltinsErrorsTest,URIErrorParameterConstructor)655 HWTEST_F_L0(BuiltinsErrorsTest, URIErrorParameterConstructor)
656 {
657     ObjectFactory *factory = instance->GetFactory();
658     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
659 
660     JSHandle<JSFunction> error(env->GetURIErrorFunction());
661     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello URIError!"));
662 
663     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 6);
664     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
665     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
666     ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue());
667 
668     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
669     JSTaggedValue result = URIError::URIErrorConstructor(ecmaRuntimeCallInfo);
670     EXPECT_TRUE(result.IsECMAObject());
671 
672     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
673     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
674     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
675 
676     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
677     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
678         factory->NewFromASCII("Hello URIError!"), JSHandle<EcmaString>(msgValue)), 0);
679 
680     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
681     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
682         factory->NewFromASCII("URIError"), JSHandle<EcmaString>(nameValue)), 0);
683 }
684 
685 /*
686  * @tc.name: URIErrorNoParameterToString
687  * @tc.desc: new URIError().toString()
688  * @tc.type: FUNC
689  */
HWTEST_F_L0(BuiltinsErrorsTest,URIErrorNoParameterToString)690 HWTEST_F_L0(BuiltinsErrorsTest, URIErrorNoParameterToString)
691 {
692     ObjectFactory *factory = instance->GetFactory();
693     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
694 
695     JSHandle<JSTaggedValue> errorObject = env->GetURIErrorFunction();
696     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
697 
698     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
699     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
700     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
701 
702     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
703     JSTaggedValue result = URIError::ToString(ecmaRuntimeCallInfo);
704     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
705     EXPECT_TRUE(result.IsString());
706 
707     EXPECT_EQ(EcmaStringAccessor::Compare(instance, factory->NewFromASCII("URIError"), resultHandle), 0);
708 }
709 
710 /*
711  * @tc.name: URIErrorToString
712  * @tc.desc: new URIError("This is URIError!").toString()
713  * @tc.type: FUNC
714  */
HWTEST_F_L0(BuiltinsErrorsTest,URIErrorToString)715 HWTEST_F_L0(BuiltinsErrorsTest, URIErrorToString)
716 {
717     ObjectFactory *factory = instance->GetFactory();
718     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
719 
720     JSHandle<JSTaggedValue> errorObject = env->GetURIErrorFunction();
721     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
722 
723     JSHandle<JSTaggedValue> handleMsgKey(factory->NewFromASCII("message"));
724     JSObject::SetProperty(
725         thread, JSHandle<JSTaggedValue>(error), handleMsgKey,
726         JSHandle<JSTaggedValue>(thread, factory->NewFromASCII("This is URIError!").GetTaggedValue()));
727 
728     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
729     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
730     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
731 
732     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
733     JSTaggedValue result = URIError::ToString(ecmaRuntimeCallInfo);
734     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
735     EXPECT_TRUE(result.IsString());
736 
737     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
738         factory->NewFromASCII("URIError: This is URIError!"), resultHandle), 0);
739 }
740 
741 /*
742  * @tc.name: SyntaxErrorNoParameterConstructor
743  * @tc.desc: new SyntaxError()
744  * @tc.type: FUNC
745  */
HWTEST_F_L0(BuiltinsErrorsTest,SyntaxErrorNoParameterConstructor)746 HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorNoParameterConstructor)
747 {
748     ObjectFactory *factory = instance->GetFactory();
749     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
750 
751     JSHandle<JSFunction> error(env->GetSyntaxErrorFunction());
752 
753     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 4);
754     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
755     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
756 
757     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
758     JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecmaRuntimeCallInfo);
759     EXPECT_TRUE(result.IsECMAObject());
760 
761     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
762     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
763     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
764 
765     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
766     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
767         factory->NewFromASCII(""), JSHandle<EcmaString>(msgValue)), 0);
768 
769     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
770     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
771         factory->NewFromASCII("SyntaxError"), JSHandle<EcmaString>(nameValue)), 0);
772 }
773 
774 /*
775  * @tc.name: SyntaxErrorParameterConstructor
776  * @tc.desc: new SyntaxError("Hello RangeError!")
777  * @tc.type: FUNC
778  */
HWTEST_F_L0(BuiltinsErrorsTest,SyntaxErrorParameterConstructor)779 HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorParameterConstructor)
780 {
781     ObjectFactory *factory = instance->GetFactory();
782     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
783 
784     JSHandle<JSFunction> error(env->GetSyntaxErrorFunction());
785     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello SyntaxError!"));
786 
787     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 6);
788     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
789     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
790     ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue());
791 
792     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
793     JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecmaRuntimeCallInfo);
794     EXPECT_TRUE(result.IsECMAObject());
795 
796     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
797     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
798     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
799 
800     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
801     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
802         factory->NewFromASCII("Hello SyntaxError!"), JSHandle<EcmaString>(msgValue)), 0);
803 
804     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
805     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
806         factory->NewFromASCII("SyntaxError"), JSHandle<EcmaString>(nameValue)), 0);
807 }
808 
809 /*
810  * @tc.name: SyntaxErrorNoParameterToString
811  * @tc.desc: new SyntaxError().toString()
812  * @tc.type: FUNC
813  */
HWTEST_F_L0(BuiltinsErrorsTest,SyntaxErrorNoParameterToString)814 HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorNoParameterToString)
815 {
816     ObjectFactory *factory = instance->GetFactory();
817     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
818 
819     JSHandle<JSTaggedValue> errorObject = env->GetSyntaxErrorFunction();
820     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
821 
822     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
823     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
824     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
825 
826     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
827     JSTaggedValue result = SyntaxError::ToString(ecmaRuntimeCallInfo);
828     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
829     EXPECT_TRUE(result.IsString());
830 
831     EXPECT_EQ(EcmaStringAccessor::Compare(instance, factory->NewFromASCII("SyntaxError"), resultHandle), 0);
832 }
833 
834 /*
835  * @tc.name: SyntaxErrorToString
836  * @tc.desc: new SyntaxError("This is SyntaxError!").toString()
837  * @tc.type: FUNC
838  */
HWTEST_F_L0(BuiltinsErrorsTest,SyntaxErrorToString)839 HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorToString)
840 {
841     ObjectFactory *factory = instance->GetFactory();
842     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
843 
844     JSHandle<JSTaggedValue> errorObject = env->GetSyntaxErrorFunction();
845     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
846 
847     JSHandle<JSTaggedValue> handleMsgKey(factory->NewFromASCII("message"));
848     JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(error), handleMsgKey,
849                           JSHandle<JSTaggedValue>(factory->NewFromASCII("This is SyntaxError!")));
850 
851     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
852     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
853     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
854 
855     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
856     JSTaggedValue result = SyntaxError::ToString(ecmaRuntimeCallInfo);
857     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
858     EXPECT_TRUE(result.IsString());
859 
860     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
861         factory->NewFromASCII("SyntaxError: This is SyntaxError!"), resultHandle), 0);
862 }
863 
864 /*
865  * @tc.name: EvalErrorNoParameterConstructor
866  * @tc.desc: new EvalError()
867  * @tc.type: FUNC
868  */
HWTEST_F_L0(BuiltinsErrorsTest,EvalErrorNoParameterConstructor)869 HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorNoParameterConstructor)
870 {
871     ObjectFactory *factory = instance->GetFactory();
872     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
873 
874     JSHandle<JSFunction> error(env->GetEvalErrorFunction());
875 
876     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 4);
877     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
878     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
879 
880     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
881     JSTaggedValue result = EvalError::EvalErrorConstructor(ecmaRuntimeCallInfo);
882     EXPECT_TRUE(result.IsECMAObject());
883 
884     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
885     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
886     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
887 
888     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
889     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
890         factory->NewFromASCII(""), JSHandle<EcmaString>(msgValue)), 0);
891 
892     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
893     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
894         factory->NewFromASCII("EvalError"), JSHandle<EcmaString>(nameValue)), 0);
895 }
896 
897 /*
898  * @tc.name: EvalErrorParameterConstructor
899  * @tc.desc: new EvalError("Hello RangeError!")
900  * @tc.type: FUNC
901  */
HWTEST_F_L0(BuiltinsErrorsTest,EvalErrorParameterConstructor)902 HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorParameterConstructor)
903 {
904     ObjectFactory *factory = instance->GetFactory();
905     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
906 
907     JSHandle<JSFunction> error(env->GetEvalErrorFunction());
908     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello EvalError!"));
909 
910     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 6);
911     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
912     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
913     ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue());
914 
915     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
916     JSTaggedValue result = EvalError::EvalErrorConstructor(ecmaRuntimeCallInfo);
917     EXPECT_TRUE(result.IsECMAObject());
918 
919     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
920     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
921     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
922 
923     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
924     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
925         factory->NewFromASCII("Hello EvalError!"), JSHandle<EcmaString>(msgValue)), 0);
926 
927     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
928     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
929         factory->NewFromASCII("EvalError"), JSHandle<EcmaString>(nameValue)), 0);
930 }
931 
932 /*
933  * @tc.name: EvalErrorNoParameterToString
934  * @tc.desc: new EvalError().toString()
935  * @tc.type: FUNC
936  */
HWTEST_F_L0(BuiltinsErrorsTest,EvalErrorNoParameterToString)937 HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorNoParameterToString)
938 {
939     ObjectFactory *factory = instance->GetFactory();
940     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
941     JSHandle<JSTaggedValue> errorObject = env->GetEvalErrorFunction();
942     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
943 
944     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
945     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
946     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
947 
948     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
949     JSTaggedValue result = EvalError::ToString(ecmaRuntimeCallInfo);
950     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
951     EXPECT_TRUE(result.IsString());
952     EXPECT_EQ(EcmaStringAccessor::Compare(instance, factory->NewFromASCII("EvalError"), resultHandle), 0);
953 }
954 
955 /*
956  * @tc.name: EvalErrorToString
957  * @tc.desc: new EvalError("This is EvalError!").toString()
958  * @tc.type: FUNC
959  */
HWTEST_F_L0(BuiltinsErrorsTest,EvalErrorToString)960 HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorToString)
961 {
962     ObjectFactory *factory = instance->GetFactory();
963     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
964 
965     JSHandle<JSTaggedValue> errorObject = env->GetEvalErrorFunction();
966     JSHandle<JSObject> error = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errorObject), errorObject);
967 
968     JSHandle<JSTaggedValue> handleMsgKey(factory->NewFromASCII("message"));
969     JSObject::SetProperty(
970         thread, JSHandle<JSTaggedValue>(error), handleMsgKey,
971         JSHandle<JSTaggedValue>(thread, factory->NewFromASCII("This is EvalError!").GetTaggedValue()));
972 
973     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
974     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
975     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
976 
977     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
978     JSTaggedValue result = EvalError::ToString(ecmaRuntimeCallInfo);
979     JSHandle<EcmaString> resultHandle(thread, reinterpret_cast<EcmaString *>(result.GetRawData()));
980     EXPECT_TRUE(result.IsString());
981     EXPECT_EQ(EcmaStringAccessor::Compare(instance,
982         factory->NewFromASCII("EvalError: This is EvalError!"), resultHandle), 0);
983 }
984 
985 /*
986  * @tc.name: AggregateErrorParameterConstructor
987  * @tc.desc: new AggregateError([], "Hello AggregateError", {cause: "error cause"})
988  * @tc.type: FUNC
989  */
HWTEST_F_L0(BuiltinsErrorsTest,AggregateErrorParameterConstructor)990 HWTEST_F_L0(BuiltinsErrorsTest, AggregateErrorParameterConstructor)
991 {
992     ObjectFactory *factory = instance->GetFactory();
993     JSHandle<GlobalEnv> env = instance->GetGlobalEnv();
994 
995     JSHandle<JSFunction> error(env->GetAggregateErrorFunction());
996     JSHandle<JSTaggedValue> paramMsg(factory->NewFromASCII("Hello AggregateError!"));
997 
998     JSHandle<JSTaggedValue> errayFunc = env->GetArrayFunction();
999     JSHandle<JSObject> newArray = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(errayFunc), errayFunc);
1000 
1001     JSHandle<JSTaggedValue> causeKey = thread->GlobalConstants()->GetHandledCauseString();
1002     JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
1003     JSHandle<JSObject> optionsObj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
1004     JSHandle<JSTaggedValue> causeValue(factory->NewFromASCII("error cause")); // test error cause
1005     JSObject::SetProperty(thread, optionsObj, causeKey, causeValue);
1006 
1007     auto ecmaRuntimeCallInfo =
1008         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*error), 10); // 10 means 3 call args
1009     ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue());
1010     ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error));
1011     ecmaRuntimeCallInfo->SetCallArg(0, newArray.GetTaggedValue());
1012     ecmaRuntimeCallInfo->SetCallArg(1, paramMsg.GetTaggedValue());
1013     ecmaRuntimeCallInfo->SetCallArg(2, optionsObj.GetTaggedValue()); // 2 means the options arg
1014 
1015     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
1016     JSTaggedValue result = AggregateError::AggregateErrorConstructor(ecmaRuntimeCallInfo);
1017     EXPECT_TRUE(result.IsECMAObject());
1018 
1019     JSHandle<JSTaggedValue> errorObject(thread, reinterpret_cast<TaggedObject *>(result.GetRawData()));
1020     JSHandle<JSTaggedValue> msgKey(factory->NewFromASCII("message"));
1021     JSHandle<JSTaggedValue> nameKey = thread->GlobalConstants()->GetHandledNameString();
1022 
1023     JSHandle<JSTaggedValue> msgValue(JSObject::GetProperty(thread, errorObject, msgKey).GetValue());
1024     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
1025         factory->NewFromASCII("Hello AggregateError!"), JSHandle<EcmaString>(msgValue)), 0);
1026 
1027     JSHandle<JSTaggedValue> nameValue(JSObject::GetProperty(thread, errorObject, nameKey).GetValue());
1028     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
1029         factory->NewFromASCII("AggregateError"), JSHandle<EcmaString>(nameValue)), 0);
1030 
1031     JSHandle<JSTaggedValue> errCauseValue(JSObject::GetProperty(thread, errorObject, causeKey).GetValue());
1032     ASSERT_EQ(EcmaStringAccessor::Compare(instance,
1033         factory->NewFromASCII("error cause"), JSHandle<EcmaString>(errCauseValue)), 0);
1034 }
1035 }  // namespace panda::test
1036