BooleanObject.h (1304B)
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_BooleanObject_h 8 #define vm_BooleanObject_h 9 10 #include "vm/NativeObject.h" 11 12 namespace js { 13 14 class BooleanObject : public NativeObject { 15 /* Stores this Boolean object's [[PrimitiveValue]]. */ 16 static const unsigned PRIMITIVE_VALUE_SLOT = 0; 17 18 static const ClassSpec classSpec_; 19 20 public: 21 static const unsigned RESERVED_SLOTS = 1; 22 23 static const JSClass class_; 24 25 /* 26 * Creates a new Boolean object boxing the given primitive bool. 27 * If proto is nullptr, the [[Prototype]] will default to Boolean.prototype. 28 */ 29 static inline BooleanObject* create(JSContext* cx, bool b, 30 HandleObject proto = nullptr); 31 32 bool unbox() const { return getFixedSlot(PRIMITIVE_VALUE_SLOT).toBoolean(); } 33 34 private: 35 static JSObject* createPrototype(JSContext* cx, JSProtoKey key); 36 37 inline void setPrimitiveValue(bool b) { 38 setFixedSlot(PRIMITIVE_VALUE_SLOT, BooleanValue(b)); 39 } 40 }; 41 42 } // namespace js 43 44 #endif /* vm_BooleanObject_h */