]>
Commit | Line | Data |
---|---|---|
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" | |
28 | ||
29 | namespace JSC { | |
30 | ||
31 | ASSERT_CLASS_FITS_IN_CELL(NumberConstructor); | |
32 | ||
4e4e5a6f A |
33 | static JSValue numberConstructorNaNValue(ExecState*, JSValue, const Identifier&); |
34 | static JSValue numberConstructorNegInfinity(ExecState*, JSValue, const Identifier&); | |
35 | static JSValue numberConstructorPosInfinity(ExecState*, JSValue, const Identifier&); | |
36 | static JSValue numberConstructorMaxValue(ExecState*, JSValue, const Identifier&); | |
37 | static JSValue numberConstructorMinValue(ExecState*, JSValue, const Identifier&); | |
9dae56ea A |
38 | |
39 | } // namespace JSC | |
40 | ||
41 | #include "NumberConstructor.lut.h" | |
42 | ||
43 | namespace JSC { | |
44 | ||
14957cd0 | 45 | const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::numberConstructorTable }; |
9dae56ea A |
46 | |
47 | /* Source for NumberConstructor.lut.h | |
14957cd0 | 48 | @begin numberConstructorTable |
9dae56ea A |
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 | ||
14957cd0 A |
57 | NumberConstructor::NumberConstructor(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, NumberPrototype* numberPrototype) |
58 | : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, numberPrototype->s_info.className)) | |
9dae56ea | 59 | { |
14957cd0 A |
60 | ASSERT(inherits(&s_info)); |
61 | ||
9dae56ea | 62 | // Number.Prototype |
14957cd0 | 63 | putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, numberPrototype, DontEnum | DontDelete | ReadOnly); |
9dae56ea A |
64 | |
65 | // no. of arguments for constructor | |
14957cd0 | 66 | putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete); |
9dae56ea A |
67 | } |
68 | ||
69 | bool NumberConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) | |
70 | { | |
14957cd0 | 71 | return getStaticValueSlot<NumberConstructor, InternalFunction>(exec, ExecState::numberConstructorTable(exec), this, propertyName, slot); |
9dae56ea A |
72 | } |
73 | ||
f9bf01c6 A |
74 | bool NumberConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) |
75 | { | |
14957cd0 | 76 | return getStaticValueDescriptor<NumberConstructor, InternalFunction>(exec, ExecState::numberConstructorTable(exec), this, propertyName, descriptor); |
f9bf01c6 A |
77 | } |
78 | ||
14957cd0 | 79 | static JSValue numberConstructorNaNValue(ExecState*, JSValue, const Identifier&) |
9dae56ea | 80 | { |
14957cd0 | 81 | return jsNaN(); |
9dae56ea A |
82 | } |
83 | ||
14957cd0 | 84 | static JSValue numberConstructorNegInfinity(ExecState*, JSValue, const Identifier&) |
9dae56ea | 85 | { |
14957cd0 | 86 | return jsNumber(-Inf); |
9dae56ea A |
87 | } |
88 | ||
14957cd0 | 89 | static JSValue numberConstructorPosInfinity(ExecState*, JSValue, const Identifier&) |
9dae56ea | 90 | { |
14957cd0 | 91 | return jsNumber(Inf); |
9dae56ea A |
92 | } |
93 | ||
14957cd0 | 94 | static JSValue numberConstructorMaxValue(ExecState*, JSValue, const Identifier&) |
9dae56ea | 95 | { |
14957cd0 | 96 | return jsNumber(1.7976931348623157E+308); |
9dae56ea A |
97 | } |
98 | ||
14957cd0 | 99 | static JSValue numberConstructorMinValue(ExecState*, JSValue, const Identifier&) |
9dae56ea | 100 | { |
14957cd0 | 101 | return jsNumber(5E-324); |
9dae56ea A |
102 | } |
103 | ||
104 | // ECMA 15.7.1 | |
14957cd0 | 105 | static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec) |
9dae56ea | 106 | { |
14957cd0 A |
107 | NumberObject* object = new (exec) NumberObject(exec->globalData(), asInternalFunction(exec->callee())->globalObject()->numberObjectStructure()); |
108 | double n = exec->argumentCount() ? exec->argument(0).toNumber(exec) : 0; | |
109 | object->setInternalValue(exec->globalData(), jsNumber(n)); | |
110 | return JSValue::encode(object); | |
9dae56ea A |
111 | } |
112 | ||
113 | ConstructType NumberConstructor::getConstructData(ConstructData& constructData) | |
114 | { | |
115 | constructData.native.function = constructWithNumberConstructor; | |
116 | return ConstructTypeHost; | |
117 | } | |
118 | ||
119 | // ECMA 15.7.2 | |
14957cd0 | 120 | static EncodedJSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec) |
9dae56ea | 121 | { |
14957cd0 | 122 | return JSValue::encode(jsNumber(!exec->argumentCount() ? 0 : exec->argument(0).toNumber(exec))); |
9dae56ea A |
123 | } |
124 | ||
125 | CallType NumberConstructor::getCallData(CallData& callData) | |
126 | { | |
127 | callData.native.function = callNumberConstructor; | |
128 | return CallTypeHost; | |
129 | } | |
130 | ||
131 | } // namespace JSC |