]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - runtime/NumberConstructor.cpp
JavaScriptCore-721.26.tar.gz
[apple/javascriptcore.git] / runtime / NumberConstructor.cpp
... / ...
CommitLineData
1/*
2 * Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org)
3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
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
25#include "Lookup.h"
26#include "NumberObject.h"
27#include "NumberPrototype.h"
28
29namespace JSC {
30
31ASSERT_CLASS_FITS_IN_CELL(NumberConstructor);
32
33static JSValue numberConstructorNaNValue(ExecState*, JSValue, const Identifier&);
34static JSValue numberConstructorNegInfinity(ExecState*, JSValue, const Identifier&);
35static JSValue numberConstructorPosInfinity(ExecState*, JSValue, const Identifier&);
36static JSValue numberConstructorMaxValue(ExecState*, JSValue, const Identifier&);
37static JSValue numberConstructorMinValue(ExecState*, JSValue, const Identifier&);
38
39} // namespace JSC
40
41#include "NumberConstructor.lut.h"
42
43namespace JSC {
44
45const ClassInfo NumberConstructor::info = { "Function", &InternalFunction::info, 0, ExecState::numberTable };
46
47/* Source for NumberConstructor.lut.h
48@begin numberTable
49 NaN numberConstructorNaNValue DontEnum|DontDelete|ReadOnly
50 NEGATIVE_INFINITY numberConstructorNegInfinity DontEnum|DontDelete|ReadOnly
51 POSITIVE_INFINITY numberConstructorPosInfinity DontEnum|DontDelete|ReadOnly
52 MAX_VALUE numberConstructorMaxValue DontEnum|DontDelete|ReadOnly
53 MIN_VALUE numberConstructorMinValue DontEnum|DontDelete|ReadOnly
54@end
55*/
56
57NumberConstructor::NumberConstructor(ExecState* exec, NonNullPassRefPtr<Structure> structure, NumberPrototype* numberPrototype)
58 : InternalFunction(&exec->globalData(), structure, Identifier(exec, numberPrototype->info.className))
59{
60 // Number.Prototype
61 putDirectWithoutTransition(exec->propertyNames().prototype, numberPrototype, DontEnum | DontDelete | ReadOnly);
62
63 // no. of arguments for constructor
64 putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
65}
66
67bool NumberConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
68{
69 return getStaticValueSlot<NumberConstructor, InternalFunction>(exec, ExecState::numberTable(exec), this, propertyName, slot);
70}
71
72bool NumberConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
73{
74 return getStaticValueDescriptor<NumberConstructor, InternalFunction>(exec, ExecState::numberTable(exec), this, propertyName, descriptor);
75}
76
77static JSValue numberConstructorNaNValue(ExecState* exec, JSValue, const Identifier&)
78{
79 return jsNaN(exec);
80}
81
82static JSValue numberConstructorNegInfinity(ExecState* exec, JSValue, const Identifier&)
83{
84 return jsNumber(exec, -Inf);
85}
86
87static JSValue numberConstructorPosInfinity(ExecState* exec, JSValue, const Identifier&)
88{
89 return jsNumber(exec, Inf);
90}
91
92static JSValue numberConstructorMaxValue(ExecState* exec, JSValue, const Identifier&)
93{
94 return jsNumber(exec, 1.7976931348623157E+308);
95}
96
97static JSValue numberConstructorMinValue(ExecState* exec, JSValue, const Identifier&)
98{
99 return jsNumber(exec, 5E-324);
100}
101
102// ECMA 15.7.1
103static JSObject* constructWithNumberConstructor(ExecState* exec, JSObject*, const ArgList& args)
104{
105 NumberObject* object = new (exec) NumberObject(exec->lexicalGlobalObject()->numberObjectStructure());
106 double n = args.isEmpty() ? 0 : args.at(0).toNumber(exec);
107 object->setInternalValue(jsNumber(exec, n));
108 return object;
109}
110
111ConstructType NumberConstructor::getConstructData(ConstructData& constructData)
112{
113 constructData.native.function = constructWithNumberConstructor;
114 return ConstructTypeHost;
115}
116
117// ECMA 15.7.2
118static JSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args)
119{
120 return jsNumber(exec, args.isEmpty() ? 0 : args.at(0).toNumber(exec));
121}
122
123CallType NumberConstructor::getCallData(CallData& callData)
124{
125 callData.native.function = callNumberConstructor;
126 return CallTypeHost;
127}
128
129} // namespace JSC