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_NumberObject_h 8 #define vm_NumberObject_h 9 10 #include "vm/NativeObject.h" 11 12 namespace js { 13 14 class NumberObject : public NativeObject { 15 /* Stores this Number 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 Number object boxing the given number. 27 * If proto is nullptr, then Number.prototype will be used instead. 28 */ 29 static inline NumberObject* create(JSContext* cx, double d, 30 HandleObject proto = nullptr); 31 unbox()32 double unbox() const { return getFixedSlot(PRIMITIVE_VALUE_SLOT).toNumber(); } 33 34 private: 35 static JSObject* createPrototype(JSContext* cx, JSProtoKey key); 36 setPrimitiveValue(double d)37 inline void setPrimitiveValue(double d) { 38 setFixedSlot(PRIMITIVE_VALUE_SLOT, NumberValue(d)); 39 } 40 }; 41 42 } // namespace js 43 44 #endif /* vm_NumberObject_h */ 45