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/tests/test_helper.h"
17
18#include "ecmascript/base/builtins_base.h"
19#include "ecmascript/builtins/builtins.h"
20#include "ecmascript/ecma_vm.h"
21#include "ecmascript/global_env.h"
22#include "ecmascript/js_handle.h"
23#include "ecmascript/js_object-inl.h"
24#include "ecmascript/js_thread.h"
25
26using namespace panda::ecmascript;
27using namespace panda::ecmascript::base;
28
29namespace panda::test {
30class BuiltinsTest : public BaseTestWithScope<false> {
31
32};
33
34HWTEST_F_L0(BuiltinsTest, ObjectInit)
35{
36    auto ecmaVM = thread->GetEcmaVM();
37    JSHandle<GlobalEnv> env = ecmaVM->GetGlobalEnv();
38
39    JSHandle<JSFunction> objectFunction(env->GetObjectFunction());
40    ASSERT_NE(*objectFunction, nullptr);
41}
42
43HWTEST_F_L0(BuiltinsTest, FunctionInit)
44{
45    auto ecmaVM = thread->GetEcmaVM();
46    JSHandle<GlobalEnv> env = ecmaVM->GetGlobalEnv();
47
48    JSHandle<JSFunction> functionFunction(env->GetFunctionFunction());
49    ASSERT_NE(*functionFunction, nullptr);
50
51    JSHandle<JSFunction> instanceFunction(env->GetHasInstanceFunction());
52    ASSERT_NE(*functionFunction, nullptr);
53    EXPECT_TRUE(!env->GetTaggedHasInstanceFunction().IsUndefined());
54}
55
56HWTEST_F_L0(BuiltinsTest, NumberInit)
57{
58    auto ecmaVM = thread->GetEcmaVM();
59    JSHandle<GlobalEnv> env = ecmaVM->GetGlobalEnv();
60
61    JSHandle<JSFunction> numberFunction(env->GetNumberFunction());
62    ASSERT_NE(*numberFunction, nullptr);
63}
64
65HWTEST_F_L0(BuiltinsTest, SetInit)
66{
67    auto ecmaVM = thread->GetEcmaVM();
68    JSHandle<GlobalEnv> env = ecmaVM->GetGlobalEnv();
69
70    JSHandle<JSFunction> setFunction(env->GetBuiltinsSetFunction());
71    ASSERT_NE(*setFunction, nullptr);
72}
73
74HWTEST_F_L0(BuiltinsTest, MapInit)
75{
76    auto ecmaVM = thread->GetEcmaVM();
77    JSHandle<GlobalEnv> env = ecmaVM->GetGlobalEnv();
78
79    JSHandle<JSFunction> mapFunction(env->GetBuiltinsMapFunction());
80    ASSERT_NE(*mapFunction, nullptr);
81}
82
83HWTEST_F_L0(BuiltinsTest, StrictModeForbiddenAccess)
84{
85    auto ecmaVM = thread->GetEcmaVM();
86    JSHandle<GlobalEnv> env = ecmaVM->GetGlobalEnv();
87
88    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
89
90    JSHandle<JSFunction> function = factory->NewJSFunction(env, static_cast<void *>(nullptr));
91
92    JSHandle<JSTaggedValue> callerKey(factory->NewFromASCII("caller"));
93    JSHandle<JSTaggedValue> argumentsKey(factory->NewFromASCII("arguments"));
94
95    JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(function), callerKey);
96    ASSERT_EQ(thread->HasPendingException(), true);
97
98    JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(function), argumentsKey);
99    ASSERT_EQ(thread->HasPendingException(), true);
100}
101}  // namespace panda::test
102