| 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 "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 |
| 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 |
public: |
| 37 |
static inline js::PlainObject* createWithShape(JSContext* cx, |
| 38 |
JS::Handle<SharedShape*> shape, |
| 39 |
gc::AllocKind kind, |
| 40 |
NewObjectKind newKind); |
| 41 |
|
| 42 |
static inline js::PlainObject* createWithShape( |
| 43 |
JSContext* cx, JS::Handle<SharedShape*> shape, |
| 44 |
NewObjectKind newKind = GenericObject); |
| 45 |
|
| 46 |
static inline PlainObject* createWithTemplate( |
| 47 |
JSContext* cx, JS::Handle<PlainObject*> templateObject); |
| 48 |
|
| 49 |
static js::PlainObject* createWithTemplateFromDifferentRealm( |
| 50 |
JSContext* cx, JS::Handle<PlainObject*> templateObject); |
| 51 |
|
| 52 |
/* Return the allocKind we would use if we were to tenure this object. */ |
| 53 |
inline gc::AllocKind allocKindForTenure() const; |
| 54 |
|
| 55 |
bool hasNonWritableOrAccessorPropExclProto() const { |
| 56 |
if (hasFlag(ObjectFlag::HasNonWritableOrAccessorPropExclProto)) { |
| 57 |
return true; |
| 58 |
} |
| 59 |
#ifdef DEBUG |
| 60 |
assertHasNoNonWritableOrAccessorPropExclProto(); |
| 61 |
#endif |
| 62 |
return false; |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 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); |
| 72 |
|
| 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); |
| 78 |
|
| 79 |
// Create a new PlainObject with %Object.prototype% as prototype. |
| 80 |
extern PlainObject* NewPlainObject(JSContext* cx, |
| 81 |
NewObjectKind newKind = GenericObject); |
| 82 |
|
| 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); |
| 88 |
|
| 89 |
// Create a new PlainObject with the given |proto| as prototype. |
| 90 |
extern PlainObject* NewPlainObjectWithProto( |
| 91 |
JSContext* cx, HandleObject proto, NewObjectKind newKind = GenericObject); |
| 92 |
|
| 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); |
| 98 |
|
| 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); |
| 104 |
|
| 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); |
| 110 |
|
| 111 |
} // namespace js |
| 112 |
|
| 113 |
#endif // vm_PlainObject_h |