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/. */
7 #ifndef vm_NumberObject_h
8 #define vm_NumberObject_h
10 #include "vm/NativeObject.h"
14 class NumberObject
: public NativeObject
{
15 /* Stores this Number object's [[PrimitiveValue]]. */
16 static const unsigned PRIMITIVE_VALUE_SLOT
= 0;
18 static const ClassSpec classSpec_
;
21 static const unsigned RESERVED_SLOTS
= 1;
23 static const JSClass class_
;
26 * Creates a new Number object boxing the given number.
27 * If proto is nullptr, then Number.prototype will be used instead.
29 static inline NumberObject
* create(JSContext
* cx
, double d
,
30 HandleObject proto
= nullptr);
32 double unbox() const { return getFixedSlot(PRIMITIVE_VALUE_SLOT
).toNumber(); }
35 static JSObject
* createPrototype(JSContext
* cx
, JSProtoKey key
);
37 inline void setPrimitiveValue(double d
) {
38 setFixedSlot(PRIMITIVE_VALUE_SLOT
, NumberValue(d
));
44 #endif /* vm_NumberObject_h */