]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/NumberConstructor.cpp
JavaScriptCore-7600.1.4.15.12.tar.gz
[apple/javascriptcore.git] / runtime / NumberConstructor.cpp
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org)
14957cd0 3 * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
9dae56ea
A
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 *
20 */
21
22#include "config.h"
23#include "NumberConstructor.h"
24
4e4e5a6f 25#include "Lookup.h"
9dae56ea
A
26#include "NumberObject.h"
27#include "NumberPrototype.h"
81345200 28#include "JSCInlines.h"
9dae56ea
A
29
30namespace JSC {
31
81345200
A
32static EncodedJSValue numberConstructorNaNValue(ExecState*, JSObject*, EncodedJSValue, PropertyName);
33static EncodedJSValue numberConstructorNegInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName);
34static EncodedJSValue numberConstructorPosInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName);
35static EncodedJSValue numberConstructorMaxValue(ExecState*, JSObject*, EncodedJSValue, PropertyName);
36static EncodedJSValue numberConstructorMinValue(ExecState*, JSObject*, EncodedJSValue, PropertyName);
9dae56ea
A
37
38} // namespace JSC
39
40#include "NumberConstructor.lut.h"
41
42namespace JSC {
43
81345200 44STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NumberConstructor);
6fe7ccc8
A
45
46const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::numberConstructorTable, CREATE_METHOD_TABLE(NumberConstructor) };
9dae56ea
A
47
48/* Source for NumberConstructor.lut.h
14957cd0 49@begin numberConstructorTable
9dae56ea
A
50 NaN numberConstructorNaNValue DontEnum|DontDelete|ReadOnly
51 NEGATIVE_INFINITY numberConstructorNegInfinity DontEnum|DontDelete|ReadOnly
52 POSITIVE_INFINITY numberConstructorPosInfinity DontEnum|DontDelete|ReadOnly
53 MAX_VALUE numberConstructorMaxValue DontEnum|DontDelete|ReadOnly
54 MIN_VALUE numberConstructorMinValue DontEnum|DontDelete|ReadOnly
55@end
56*/
57
81345200
A
58NumberConstructor::NumberConstructor(VM& vm, Structure* structure)
59 : InternalFunction(vm, structure)
6fe7ccc8
A
60{
61}
62
81345200 63void NumberConstructor::finishCreation(VM& vm, NumberPrototype* numberPrototype)
9dae56ea 64{
81345200
A
65 Base::finishCreation(vm, NumberPrototype::info()->className);
66 ASSERT(inherits(info()));
14957cd0 67
9dae56ea 68 // Number.Prototype
81345200 69 putDirectWithoutTransition(vm, vm.propertyNames->prototype, numberPrototype, DontEnum | DontDelete | ReadOnly);
9dae56ea
A
70
71 // no. of arguments for constructor
81345200 72 putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
9dae56ea
A
73}
74
81345200 75bool NumberConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
6fe7ccc8 76{
81345200 77 return getStaticValueSlot<NumberConstructor, InternalFunction>(exec, ExecState::numberConstructorTable(exec->vm()), jsCast<NumberConstructor*>(object), propertyName, slot);
6fe7ccc8
A
78}
79
81345200 80static EncodedJSValue numberConstructorNaNValue(ExecState*, JSObject*, EncodedJSValue, PropertyName)
9dae56ea 81{
81345200 82 return JSValue::encode(jsNaN());
9dae56ea
A
83}
84
81345200 85static EncodedJSValue numberConstructorNegInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName)
f9bf01c6 86{
81345200 87 return JSValue::encode(jsNumber(-std::numeric_limits<double>::infinity()));
f9bf01c6
A
88}
89
81345200 90static EncodedJSValue numberConstructorPosInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName)
9dae56ea 91{
81345200 92 return JSValue::encode(jsNumber(std::numeric_limits<double>::infinity()));
9dae56ea
A
93}
94
81345200 95static EncodedJSValue numberConstructorMaxValue(ExecState*, JSObject*, EncodedJSValue, PropertyName)
9dae56ea 96{
81345200 97 return JSValue::encode(jsNumber(1.7976931348623157E+308));
9dae56ea
A
98}
99
81345200 100static EncodedJSValue numberConstructorMinValue(ExecState*, JSObject*, EncodedJSValue, PropertyName)
9dae56ea 101{
81345200 102 return JSValue::encode(jsNumber(5E-324));
9dae56ea
A
103}
104
105// ECMA 15.7.1
14957cd0 106static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec)
9dae56ea 107{
93a37866 108 NumberObject* object = NumberObject::create(exec->vm(), asInternalFunction(exec->callee())->globalObject()->numberObjectStructure());
81345200 109 double n = exec->argumentCount() ? exec->uncheckedArgument(0).toNumber(exec) : 0;
93a37866 110 object->setInternalValue(exec->vm(), jsNumber(n));
14957cd0 111 return JSValue::encode(object);
9dae56ea
A
112}
113
6fe7ccc8 114ConstructType NumberConstructor::getConstructData(JSCell*, ConstructData& constructData)
9dae56ea
A
115{
116 constructData.native.function = constructWithNumberConstructor;
117 return ConstructTypeHost;
118}
119
120// ECMA 15.7.2
14957cd0 121static EncodedJSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec)
9dae56ea 122{
81345200 123 return JSValue::encode(jsNumber(!exec->argumentCount() ? 0 : exec->uncheckedArgument(0).toNumber(exec)));
9dae56ea
A
124}
125
6fe7ccc8 126CallType NumberConstructor::getCallData(JSCell*, CallData& callData)
9dae56ea
A
127{
128 callData.native.function = callNumberConstructor;
129 return CallTypeHost;
130}
131
132} // namespace JSC