1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef vm_PlainObject_h 8 #define vm_PlainObject_h 9 10 #include "gc/AllocKind.h" // js::gc::AllocKind 11 #include "js/Class.h" // JSClass 12 #include "js/Result.h" // JS::OOM, JS::Result 13 #include "js/RootingAPI.h" // JS::Handle 14 #include "vm/JSObject.h" // js::NewObjectKind 15 #include "vm/NativeObject.h" // js::NativeObject 16 17 struct JS_PUBLIC_API JSContext; 18 class JS_PUBLIC_API JSFunction; 19 class JS_PUBLIC_API JSObject; 20 21 namespace js { 22 23 struct IdValuePair; 24 25 // Object class for plain native objects created using '{}' object literals, 26 // 'new Object()', 'Object.create', etc. 27 class PlainObject : public NativeObject { 28 public: 29 static const JSClass class_; 30 31 private: 32 #ifdef DEBUG 33 void assertHasNoNonWritableOrAccessorPropExclProto() const; 34 #endif 35 36 static inline JS::Result<PlainObject*, JS::OOM> createWithShape( 37 JSContext* cx, JS::Handle<Shape*> shape); 38 39 public: 40 static inline JS::Result<PlainObject*, JS::OOM> createWithTemplate( 41 JSContext* cx, JS::Handle<PlainObject*> templateObject); 42 43 static JS::Result<PlainObject*, JS::OOM> createWithTemplateFromDifferentRealm( 44 JSContext* cx, JS::Handle<PlainObject*> templateObject); 45 46 /* Return the allocKind we would use if we were to tenure this object. */ 47 inline gc::AllocKind allocKindForTenure() const; 48 hasNonWritableOrAccessorPropExclProto()49 bool hasNonWritableOrAccessorPropExclProto() const { 50 if (hasFlag(ObjectFlag::HasNonWritableOrAccessorPropExclProto)) { 51 return true; 52 } 53 #ifdef DEBUG 54 assertHasNoNonWritableOrAccessorPropExclProto(); 55 #endif 56 return false; 57 } 58 }; 59 60 // Specializations of 7.3.23 CopyDataProperties(...) for NativeObjects. 61 extern bool CopyDataPropertiesNative(JSContext* cx, 62 JS::Handle<PlainObject*> target, 63 JS::Handle<NativeObject*> from, 64 JS::Handle<PlainObject*> excludedItems, 65 bool* optimized); 66 67 // Specialized call for constructing |this| with a known function callee. 68 extern PlainObject* CreateThisForFunction(JSContext* cx, 69 JS::Handle<JSFunction*> callee, 70 JS::Handle<JSObject*> newTarget, 71 NewObjectKind newKind); 72 73 extern PlainObject* NewPlainObjectWithProperties(JSContext* cx, 74 IdValuePair* properties, 75 size_t nproperties, 76 NewObjectKind newKind); 77 78 } // namespace js 79 80 #endif // vm_PlainObject_h 81