| 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 |
/* |
| 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! |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef js_shadow_Object_h |
| 14 |
#define js_shadow_Object_h |
| 15 |
|
| 16 |
#include <stddef.h> // size_t |
| 17 |
|
| 18 |
#include "js/shadow/Shape.h" // JS::shadow::Shape |
| 19 |
#include "js/Value.h" // JS::Value |
| 20 |
|
| 21 |
class JS_PUBLIC_API JSObject; |
| 22 |
|
| 23 |
namespace JS { |
| 24 |
|
| 25 |
class JS_PUBLIC_API Value; |
| 26 |
|
| 27 |
namespace shadow { |
| 28 |
|
| 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. |
| 33 |
*/ |
| 34 |
struct Object { |
| 35 |
shadow::Shape* shape; |
| 36 |
#ifndef JS_64BIT |
| 37 |
uint32_t padding_; |
| 38 |
#endif |
| 39 |
Value* slots; |
| 40 |
void* _1; |
| 41 |
|
| 42 |
static constexpr size_t MAX_FIXED_SLOTS = 16; |
| 43 |
|
| 44 |
size_t numFixedSlots() const { |
| 45 |
return (shape->immutableFlags & shadow::Shape::FIXED_SLOTS_MASK) >> |
| 46 |
shadow::Shape::FIXED_SLOTS_SHIFT; |
| 47 |
} |
| 48 |
|
| 49 |
Value* fixedSlots() const { |
| 50 |
auto address = reinterpret_cast<uintptr_t>(this); |
| 51 |
return reinterpret_cast<JS::Value*>(address + sizeof(shadow::Object)); |
| 52 |
} |
| 53 |
|
| 54 |
Value& slotRef(size_t slot) const { |
| 55 |
size_t nfixed = numFixedSlots(); |
| 56 |
if (slot < nfixed) { |
| 57 |
return fixedSlots()[slot]; |
| 58 |
} |
| 59 |
return slots[slot - nfixed]; |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
} // namespace shadow |
| 64 |
|
| 65 |
} // namespace JS |
| 66 |
|
| 67 |
#endif // js_shadow_Object_h |