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