Bug 1885489 - Part 9: Add SnapshotIterator::readObject(). r=iain
[gecko.git] / js / public / shadow / Object.h
blob6f77de71bab0b168638dd290c56f0b64de73e8e0
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 /*
8 * Shadow definition of |JSObject| innards. (|js::NativeObject| is more
9 * accurate, but portions can sometimes be used in some non-native objects.) Do
10 * not use this directly!
13 #ifndef js_shadow_Object_h
14 #define js_shadow_Object_h
16 #include <stddef.h> // size_t
18 #include "js/shadow/Shape.h" // JS::shadow::Shape
19 #include "js/Value.h" // JS::Value
21 class JS_PUBLIC_API JSObject;
23 namespace JS {
25 class JS_PUBLIC_API Value;
27 namespace shadow {
29 /**
30 * This layout is shared by all native objects. For non-native objects, the
31 * shape may always be accessed safely, and other members may be as well,
32 * depending on the object's specific layout.
34 struct Object {
35 shadow::Shape* shape;
36 #ifndef JS_64BIT
37 uint32_t padding_;
38 #endif
39 Value* slots;
40 void* _1;
42 static constexpr size_t MAX_FIXED_SLOTS = 16;
44 size_t numFixedSlots() const {
45 return (shape->immutableFlags & shadow::Shape::FIXED_SLOTS_MASK) >>
46 shadow::Shape::FIXED_SLOTS_SHIFT;
49 Value* fixedSlots() const {
50 auto address = reinterpret_cast<uintptr_t>(this);
51 return reinterpret_cast<JS::Value*>(address + sizeof(shadow::Object));
54 Value& slotRef(size_t slot) const {
55 size_t nfixed = numFixedSlots();
56 if (slot < nfixed) {
57 return fixedSlots()[slot];
59 return slots[slot - nfixed];
63 } // namespace shadow
65 } // namespace JS
67 #endif // js_shadow_Object_h