• 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/base/builtins_base.h"
17 #include "ecmascript/builtins/builtins.h"
18 #include "ecmascript/ecma_vm.h"
19 #include "ecmascript/global_env.h"
20 #include "ecmascript/global_env_constants-inl.h"
21 #include "ecmascript/js_handle.h"
22 #include "ecmascript/js_object-inl.h"
23 #include "ecmascript/js_thread.h"
24 #include "ecmascript/tests/test_helper.h"
25 
26 using namespace panda::ecmascript;
27 using namespace panda::ecmascript::base;
28 
29 namespace panda::test {
30 class GlueRegsTest :  public BaseTestWithScope<false> {
31 };
32 
HWTEST_F_L0(GlueRegsTest,ConstantClassTest)33 HWTEST_F_L0(GlueRegsTest, ConstantClassTest)
34 {
35     const GlobalEnvConstants *globalConst = thread->GlobalConstants();
36     ASSERT_NE(globalConst, nullptr);
37 
38     const JSTaggedValue *address = globalConst->BeginSlot();
39     size_t curIndex = static_cast<size_t>(ConstantIndex::CONSTANT_BEGIN);
40     size_t holeIndex = static_cast<size_t>(ConstantIndex::HOLE_INDEX);
41     while (address < globalConst->EndSlot()) {
42         if (curIndex != holeIndex) {
43         }
44         address += 1;
45         curIndex += 1;
46     }
47 }
48 
HWTEST_F_L0(GlueRegsTest,ConstantSpecialTest)49 HWTEST_F_L0(GlueRegsTest, ConstantSpecialTest)
50 {
51     const GlobalEnvConstants *globalConst = thread->GlobalConstants();
52     ASSERT_NE(globalConst, nullptr);
53 
54     EXPECT_TRUE(globalConst->GetUndefined().IsUndefined());
55     EXPECT_TRUE(globalConst->GetHandledUndefined()->IsUndefined());
56     EXPECT_TRUE(globalConst->GetNull().IsNull());
57     EXPECT_TRUE(globalConst->GetHandledNull()->IsNull());
58     EXPECT_TRUE(globalConst->GetEmptyString().IsString());
59     EXPECT_TRUE(globalConst->GetHandledEmptyString()->IsString());
60 }
61 
HWTEST_F_L0(GlueRegsTest,ConstantStringTest)62 HWTEST_F_L0(GlueRegsTest, ConstantStringTest)
63 {
64     const GlobalEnvConstants *globalConst = thread->GlobalConstants();
65     ASSERT_NE(globalConst, nullptr);
66 
67 #define CONSTANT_STRING_ITERATOR(Name, Index, Desc)                                     \
68     JSTaggedValue Name##value = globalConst->Get##Name();                               \
69     EXPECT_TRUE(Name##value.IsString());                                                \
70     Region *Name##region = Region::ObjectAddressToRange(Name##value.GetTaggedObject()); \
71     EXPECT_TRUE(Name##region->InSharedReadOnlySpace());
72     SHARED_GLOBAL_ENV_CONSTANT_STRING(CONSTANT_STRING_ITERATOR)
73 #undef CONSTANT_STRING_ITERATOR
74 }
75 
HWTEST_F_L0(GlueRegsTest,ConstantAccessorTest)76 HWTEST_F_L0(GlueRegsTest, ConstantAccessorTest)
77 {
78     const GlobalEnvConstants *globalConst = thread->GlobalConstants();
79     ASSERT_NE(globalConst, nullptr);
80 
81 #define CONSTANT_ACCESSOR_ITERATOR(Type, Name, Index, Desc)              \
82     Type Name##value = globalConst->Get##Name();                         \
83     EXPECT_TRUE(!Name##value.IsNull());                                  \
84     JSHandle<Type> Name##handledValue = globalConst->GetHandled##Name(); \
85     EXPECT_TRUE(!Name##handledValue->IsNull());
86     SHARED_GLOBAL_ENV_CONSTANT_ACCESSOR(CONSTANT_ACCESSOR_ITERATOR)
87 #undef CONSTANT_ACCESSOR_ITERATOR
88 }
89 }  // namespace panda::test