• 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 #ifndef ECMASCRIPT_BUILTINS_BUILTINS_REFLECT_H
17 #define ECMASCRIPT_BUILTINS_BUILTINS_REFLECT_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/js_function.h"
21 #include "ecmascript/js_array.h"
22 
23 // List of functions in Reflect, excluding the '@@' properties.
24 // V(name, func, length, stubIndex)
25 // where BuiltinsRefject::func refers to the native implementation of Reflect[name].
26 //       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
27 #define BUILTIN_REFLECT_FUNCTIONS(V)                                                    \
28     /* Reflect.apply ( target, thisArgument, argumentsList ) */                         \
29     V("apply",                    ReflectApply,                    3, INVALID)          \
30     /* Reflect.construct ( target, argumentsList [ , newTarget ] ) */                   \
31     V("construct",                ReflectConstruct,                2, INVALID)          \
32     /* Reflect.defineProperty ( target, propertyKey, attributes ) */                    \
33     V("defineProperty",           ReflectDefineProperty,           3, INVALID)          \
34     /* Reflect.deleteProperty ( target, propertyKey ) */                                \
35     V("deleteProperty",           ReflectDeleteProperty,           2, INVALID)          \
36     /* Reflect.get ( target, propertyKey [ , receiver ] ) */                            \
37     V("get",                      ReflectGet,                      2, INVALID)          \
38     /* Reflect.getOwnPropertyDescriptor ( target, propertyKey ) */                      \
39     V("getOwnPropertyDescriptor", ReflectGetOwnPropertyDescriptor, 2, INVALID)          \
40     /* Reflect.getPrototypeOf ( target ) */                                             \
41     V("getPrototypeOf",           ReflectGetPrototypeOf,           1, INVALID)          \
42     /* Reflect.has ( target, propertyKey ) */                                           \
43     V("has",                      ReflectHas,                      2, INVALID)          \
44     /* Reflect.isExtensible ( target ) */                                               \
45     V("isExtensible",             ReflectIsExtensible,             1, INVALID)          \
46     /* Reflect.ownKeys ( target ) */                                                    \
47     V("ownKeys",                  ReflectOwnKeys,                  1, INVALID)          \
48     /* Reflect.preventExtensions ( target ) */                                          \
49     V("preventExtensions",        ReflectPreventExtensions,        1, INVALID)          \
50     /* Reflect.set ( target, propertyKey, V [ , receiver ] ) */                         \
51     V("set",                      ReflectSet,                      3, INVALID)          \
52     /* Reflect.setPrototypeOf ( target, proto ) */                                      \
53     V("setPrototypeOf",           ReflectSetPrototypeOf,           2, INVALID)
54 
55 namespace panda::ecmascript::builtins {
56 class BuiltinsReflect : public base::BuiltinsBase {
57 public:
58     // ecma 26.1.1
59     static JSTaggedValue ReflectApply(EcmaRuntimeCallInfo *argv);
60 
61     // ecma 26.1.2
62     static JSTaggedValue ReflectConstruct(EcmaRuntimeCallInfo *argv);
63 
64     // ecma 26.1.3
65     static JSTaggedValue ReflectDefineProperty(EcmaRuntimeCallInfo *argv);
66 
67     // ecma 26.1.4
68     static JSTaggedValue ReflectDeleteProperty(EcmaRuntimeCallInfo *argv);
69 
70     // ecma 26.1.5
71     static JSTaggedValue ReflectGet(EcmaRuntimeCallInfo *argv);
72 
73     // ecma 26.1.6
74     static JSTaggedValue ReflectGetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv);
75 
76     // ecma 26.1.7
77     static JSTaggedValue ReflectGetPrototypeOf(EcmaRuntimeCallInfo *argv);
78 
79     // ecma 26.1.8
80     static JSTaggedValue ReflectHas(EcmaRuntimeCallInfo *argv);
81 
82     // ecma 26.1.9
83     static JSTaggedValue ReflectIsExtensible(EcmaRuntimeCallInfo *argv);
84 
85     // ecma 26.1.10
86     static JSTaggedValue ReflectOwnKeys(EcmaRuntimeCallInfo *argv);
87 
88     // ecma 26.1.11
89     static JSTaggedValue ReflectPreventExtensions(EcmaRuntimeCallInfo *argv);
90 
91     // ecma 26.1.12
92     static JSTaggedValue ReflectSet(EcmaRuntimeCallInfo *argv);
93 
94     // ecma 26.1.13
95     static JSTaggedValue ReflectSetPrototypeOf(EcmaRuntimeCallInfo *argv);
96 
97     // Excluding the '@@' internal properties.
GetReflectFunctions()98     static Span<const base::BuiltinFunctionEntry> GetReflectFunctions()
99     {
100         return Span<const base::BuiltinFunctionEntry>(REFLECT_FUNCTIONS);
101     }
102 
103 private:
104 #define BUILTINS_REFLECT_FUNCTION_ENTRY(name, method, length, id) \
105     base::BuiltinFunctionEntry::Create(name, BuiltinsReflect::method, length, kungfu::BuiltinsStubCSigns::id),
106 
107     static constexpr std::array REFLECT_FUNCTIONS  = {
108         BUILTIN_REFLECT_FUNCTIONS(BUILTINS_REFLECT_FUNCTION_ENTRY)
109     };
110 #undef BUILTINS_REFLECT_FUNCTION_ENTRY
111 };
112 }  // namespace panda::ecmascript::builtins
113 #endif  // ECMASCRIPT_BUILTINS_BUILTINS_REFLECT_H
114