michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef vm_NumberObject_h michael@0: #define vm_NumberObject_h michael@0: michael@0: #include "jsnum.h" michael@0: michael@0: namespace js { michael@0: michael@0: class NumberObject : public JSObject michael@0: { michael@0: /* Stores this Number object's [[PrimitiveValue]]. */ michael@0: static const unsigned PRIMITIVE_VALUE_SLOT = 0; michael@0: michael@0: public: michael@0: static const unsigned RESERVED_SLOTS = 1; michael@0: michael@0: static const Class class_; michael@0: michael@0: /* michael@0: * Creates a new Number object boxing the given number. The object's michael@0: * [[Prototype]] is determined from context. michael@0: */ michael@0: static inline NumberObject *create(JSContext *cx, double d); michael@0: michael@0: double unbox() const { michael@0: return getFixedSlot(PRIMITIVE_VALUE_SLOT).toNumber(); michael@0: } michael@0: michael@0: private: michael@0: inline void setPrimitiveValue(double d) { michael@0: setFixedSlot(PRIMITIVE_VALUE_SLOT, NumberValue(d)); michael@0: } michael@0: michael@0: /* For access to init, as Number.prototype is special. */ michael@0: friend JSObject * michael@0: ::js_InitNumberClass(JSContext *cx, js::HandleObject global); michael@0: }; michael@0: michael@0: } // namespace js michael@0: michael@0: #endif /* vm_NumberObject_h */