Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / vm / PlainObject.h
blobaa2a202fa07e06ee93f0e3e4df5685fc4b03f232
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/. */
7 #ifndef vm_PlainObject_h
8 #define vm_PlainObject_h
10 #include "ds/IdValuePair.h"
11 #include "gc/AllocKind.h" // js::gc::AllocKind
12 #include "js/Class.h" // JSClass
13 #include "js/RootingAPI.h" // JS::Handle
14 #include "vm/JSObject.h" // js::NewObjectKind
15 #include "vm/NativeObject.h" // js::NativeObject
17 struct JS_PUBLIC_API JSContext;
18 class JS_PUBLIC_API JSFunction;
19 class JS_PUBLIC_API JSObject;
21 namespace js {
23 struct IdValuePair;
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_;
31 private:
32 #ifdef DEBUG
33 void assertHasNoNonWritableOrAccessorPropExclProto() const;
34 #endif
36 public:
37 static inline js::PlainObject* createWithShape(JSContext* cx,
38 JS::Handle<SharedShape*> shape,
39 gc::AllocKind kind,
40 NewObjectKind newKind);
42 static inline js::PlainObject* createWithShape(
43 JSContext* cx, JS::Handle<SharedShape*> shape,
44 NewObjectKind newKind = GenericObject);
46 static inline PlainObject* createWithTemplate(
47 JSContext* cx, JS::Handle<PlainObject*> templateObject);
49 static js::PlainObject* createWithTemplateFromDifferentRealm(
50 JSContext* cx, JS::Handle<PlainObject*> templateObject);
52 /* Return the allocKind we would use if we were to tenure this object. */
53 inline gc::AllocKind allocKindForTenure() const;
55 bool hasNonWritableOrAccessorPropExclProto() const {
56 if (hasFlag(ObjectFlag::HasNonWritableOrAccessorPropExclProto)) {
57 return true;
59 #ifdef DEBUG
60 assertHasNoNonWritableOrAccessorPropExclProto();
61 #endif
62 return false;
66 // Specializations of 7.3.23 CopyDataProperties(...) for NativeObjects.
67 extern bool CopyDataPropertiesNative(JSContext* cx,
68 JS::Handle<PlainObject*> target,
69 JS::Handle<NativeObject*> from,
70 JS::Handle<PlainObject*> excludedItems,
71 bool* optimized);
73 // Specialized call to get the shape to use when creating |this| for a known
74 // function callee.
75 extern SharedShape* ThisShapeForFunction(JSContext* cx,
76 JS::Handle<JSFunction*> callee,
77 JS::Handle<JSObject*> newTarget);
79 // Create a new PlainObject with %Object.prototype% as prototype.
80 extern PlainObject* NewPlainObject(JSContext* cx,
81 NewObjectKind newKind = GenericObject);
83 // Like NewPlainObject, but uses the given AllocKind. This allows creating an
84 // object with fixed slots available for properties.
85 extern PlainObject* NewPlainObjectWithAllocKind(
86 JSContext* cx, gc::AllocKind allocKind,
87 NewObjectKind newKind = GenericObject);
89 // Create a new PlainObject with the given |proto| as prototype.
90 extern PlainObject* NewPlainObjectWithProto(
91 JSContext* cx, HandleObject proto, NewObjectKind newKind = GenericObject);
93 // Like NewPlainObjectWithProto, but uses the given AllocKind. This allows
94 // creating an object with fixed slots available for properties.
95 extern PlainObject* NewPlainObjectWithProtoAndAllocKind(
96 JSContext* cx, HandleObject proto, gc::AllocKind allocKind,
97 NewObjectKind newKind = GenericObject);
99 // Create a plain object with the given properties. The list must not contain
100 // duplicate keys or integer keys.
101 extern PlainObject* NewPlainObjectWithUniqueNames(
102 JSContext* cx, Handle<IdValueVector> properties,
103 NewObjectKind newKind = GenericObject);
105 // Create a plain object with the given properties. The list may contain integer
106 // keys or duplicate keys.
107 extern PlainObject* NewPlainObjectWithMaybeDuplicateKeys(
108 JSContext* cx, Handle<IdValueVector> properties,
109 NewObjectKind newKind = GenericObject);
111 } // namespace js
113 #endif // vm_PlainObject_h