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_OBJECT_H 17 #define ECMASCRIPT_BUILTINS_BUILTINS_OBJECT_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 #include "ecmascript/js_handle.h" 22 #include "ecmascript/js_hclass.h" 23 24 namespace panda::ecmascript::builtins { 25 enum class KeyType : uint8_t { 26 STRING_TYPE = 0, 27 SYMBOL_TYPE, 28 }; 29 30 class BuiltinsObject : public base::BuiltinsBase { 31 public: 32 // 19.1.1.1Object ( [ value ] ) 33 static JSTaggedValue ObjectConstructor(EcmaRuntimeCallInfo *argv); 34 35 // 19.1.2.1Object.assign ( target, ...sources ) 36 static JSTaggedValue Assign(EcmaRuntimeCallInfo *argv); 37 // 19.1.2.2Object.create ( O [ , Properties ] ) 38 static JSTaggedValue Create(EcmaRuntimeCallInfo *argv); 39 // 19.1.2.3Object.defineProperties ( O, Properties ) 40 static JSTaggedValue DefineProperties(EcmaRuntimeCallInfo *argv); 41 // 19.1.2.4Object.defineProperty ( O, P, Attributes ) 42 static JSTaggedValue DefineProperty(EcmaRuntimeCallInfo *argv); 43 // 19.1.2.5Object.freeze ( O ) 44 static JSTaggedValue Freeze(EcmaRuntimeCallInfo *argv); 45 // 19.1.2.6Object.getOwnPropertyDescriptor ( O, P ) 46 static JSTaggedValue GetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv); 47 // 19.1.2.7Object.getOwnPropertyNames ( O ) 48 static JSTaggedValue GetOwnPropertyNames(EcmaRuntimeCallInfo *argv); 49 // 19.1.2.8Object.getOwnPropertySymbols ( O ) 50 static JSTaggedValue GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv); 51 // 19.1.2.9Object.getPrototypeOf ( O ) 52 static JSTaggedValue GetPrototypeOf(EcmaRuntimeCallInfo *argv); 53 // 19.1.2.10Object.is ( value1, value2 ) 54 static JSTaggedValue Is(EcmaRuntimeCallInfo *argv); 55 // 19.1.2.11Object.isExtensible ( O ) 56 static JSTaggedValue IsExtensible(EcmaRuntimeCallInfo *argv); 57 // 19.1.2.12Object.isFrozen ( O ) 58 static JSTaggedValue IsFrozen(EcmaRuntimeCallInfo *argv); 59 // 19.1.2.13Object.isSealed ( O ) 60 static JSTaggedValue IsSealed(EcmaRuntimeCallInfo *argv); 61 // 19.1.2.14 Object.keys(O) 62 static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); 63 // 20.1.2.22 Object.values(O) 64 static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); 65 // 19.1.2.15 Object.preventExtensions(O) 66 static JSTaggedValue PreventExtensions(EcmaRuntimeCallInfo *argv); 67 // 19.1.2.17 Object.seal(O) 68 static JSTaggedValue Seal(EcmaRuntimeCallInfo *argv); 69 // 19.1.2.18 Object.setPrototypeOf(O, proto) 70 static JSTaggedValue SetPrototypeOf(EcmaRuntimeCallInfo *argv); 71 72 // 19.1.3.2 Object.prototype.hasOwnProperty(V) 73 static JSTaggedValue HasOwnProperty(EcmaRuntimeCallInfo *argv); 74 // 19.1.3.3 Object.prototype.isPrototypeOf(V) 75 static JSTaggedValue IsPrototypeOf(EcmaRuntimeCallInfo *argv); 76 // 19.1.3.4 Object.prototype.propertyIsEnumerable(V) 77 static JSTaggedValue PropertyIsEnumerable(EcmaRuntimeCallInfo *argv); 78 // 19.1.3.5 Object.prototype.toLocaleString([reserved1[, reserved2]]) 79 static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv); 80 // 19.1.3.6 Object.prototype.toString() 81 static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); 82 // 19.1.3.7 Object.prototype.valueOf() 83 static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); 84 85 static JSTaggedValue CreateRealm(EcmaRuntimeCallInfo *argv); 86 // 20.1.2.5 Object.entries ( O ) 87 static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); 88 // 20.1.2.7 Object.fromEntries ( iterable ) 89 static JSTaggedValue FromEntries(EcmaRuntimeCallInfo *argv); 90 // B.2.2.1 Object.prototype.__proto__ 91 static JSTaggedValue ProtoGetter(EcmaRuntimeCallInfo *argv); 92 static JSTaggedValue ProtoSetter(EcmaRuntimeCallInfo *argv); 93 94 // 20.1.2.7.1 CreateDataPropertyOnObject Functions 95 static JSTaggedValue CreateDataPropertyOnObjectFunctions(EcmaRuntimeCallInfo *argv); 96 // 20.1.2.13 Object.hasOwn ( O, P ) 97 static JSTaggedValue HasOwn(EcmaRuntimeCallInfo *argv); 98 99 private: 100 static JSTaggedValue ObjectDefineProperties(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 101 const JSHandle<JSTaggedValue> &prop); 102 static JSTaggedValue GetOwnPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const KeyType &type); 103 static JSTaggedValue GetBuiltinTag(JSThread *thread, const JSHandle<JSObject> &object); 104 }; 105 } // namespace panda::ecmascript::builtins 106 #endif // ECMASCRIPT_BUILTINS_BUILTINS_OBJECT_H 107