Shape.h (1551B)
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 |js::BaseShape| and |js::Shape| innards. Do not use 9 * this directly! 10 */ 11 12 #ifndef js_shadow_Shape_h 13 #define js_shadow_Shape_h 14 15 #include <stdint.h> // uint32_t 16 17 #include "jstypes.h" // JS_PUBLIC_API 18 19 #include "js/Id.h" // JS::PropertyKey 20 21 struct JSClass; 22 class JS_PUBLIC_API JSObject; 23 24 namespace JS { 25 26 namespace shadow { 27 28 struct BaseShape { 29 const JSClass* clasp; 30 JS::Realm* realm; 31 }; 32 33 class Shape { 34 public: 35 shadow::BaseShape* base; 36 uint32_t immutableFlags; 37 38 enum class Kind : uint8_t { 39 // SharedShape or DictionaryShape for NativeObject. 40 // (Only) these two kinds must have the low bit set, to allow for fast 41 // is-native checking. 42 Shared = 1, 43 Dictionary = 3, 44 // ProxyShape for ProxyObject. 45 Proxy = 0, 46 // WasmGCShape for WasmGCObject. 47 WasmGC = 2, 48 }; 49 50 static constexpr uint32_t KIND_SHIFT = 4; 51 static constexpr uint32_t KIND_MASK = 0b11; 52 53 static constexpr uint32_t FIXED_SLOTS_SHIFT = 6; 54 static constexpr uint32_t FIXED_SLOTS_MASK = 0x1f << FIXED_SLOTS_SHIFT; 55 56 bool isProxy() const { 57 return Kind((immutableFlags >> KIND_SHIFT) & KIND_MASK) == Kind::Proxy; 58 } 59 }; 60 61 } // namespace shadow 62 63 } // namespace JS 64 65 #endif // js_shadow_Shape_h