2 * Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org)
3 * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
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.
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.
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
23 #include "NumberConstructor.h"
26 #include "NumberObject.h"
27 #include "NumberPrototype.h"
31 ASSERT_CLASS_FITS_IN_CELL(NumberConstructor
);
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
&);
41 #include "NumberConstructor.lut.h"
45 ASSERT_HAS_TRIVIAL_DESTRUCTOR(NumberConstructor
);
47 const ClassInfo
NumberConstructor::s_info
= { "Function", &InternalFunction::s_info
, 0, ExecState::numberConstructorTable
, CREATE_METHOD_TABLE(NumberConstructor
) };
49 /* Source for NumberConstructor.lut.h
50 @begin numberConstructorTable
51 NaN numberConstructorNaNValue DontEnum|DontDelete|ReadOnly
52 NEGATIVE_INFINITY numberConstructorNegInfinity DontEnum|DontDelete|ReadOnly
53 POSITIVE_INFINITY numberConstructorPosInfinity DontEnum|DontDelete|ReadOnly
54 MAX_VALUE numberConstructorMaxValue DontEnum|DontDelete|ReadOnly
55 MIN_VALUE numberConstructorMinValue DontEnum|DontDelete|ReadOnly
59 NumberConstructor::NumberConstructor(JSGlobalObject
* globalObject
, Structure
* structure
)
60 : InternalFunction(globalObject
, structure
)
64 void NumberConstructor::finishCreation(ExecState
* exec
, NumberPrototype
* numberPrototype
)
66 Base::finishCreation(exec
->globalData(), Identifier(exec
, numberPrototype
->s_info
.className
));
67 ASSERT(inherits(&s_info
));
70 putDirectWithoutTransition(exec
->globalData(), exec
->propertyNames().prototype
, numberPrototype
, DontEnum
| DontDelete
| ReadOnly
);
72 // no. of arguments for constructor
73 putDirectWithoutTransition(exec
->globalData(), exec
->propertyNames().length
, jsNumber(1), ReadOnly
| DontEnum
| DontDelete
);
76 bool NumberConstructor::getOwnPropertySlot(JSCell
* cell
, ExecState
* exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
78 return getStaticValueSlot
<NumberConstructor
, InternalFunction
>(exec
, ExecState::numberConstructorTable(exec
), jsCast
<NumberConstructor
*>(cell
), propertyName
, slot
);
81 bool NumberConstructor::getOwnPropertyDescriptor(JSObject
* object
, ExecState
* exec
, const Identifier
& propertyName
, PropertyDescriptor
& descriptor
)
83 return getStaticValueDescriptor
<NumberConstructor
, InternalFunction
>(exec
, ExecState::numberConstructorTable(exec
), jsCast
<NumberConstructor
*>(object
), propertyName
, descriptor
);
86 void NumberConstructor::put(JSCell
* cell
, ExecState
* exec
, const Identifier
& propertyName
, JSValue value
, PutPropertySlot
& slot
)
88 lookupPut
<NumberConstructor
, InternalFunction
>(exec
, propertyName
, value
, ExecState::numberConstructorTable(exec
), jsCast
<NumberConstructor
*>(cell
), slot
);
91 static JSValue
numberConstructorNaNValue(ExecState
*, JSValue
, const Identifier
&)
96 static JSValue
numberConstructorNegInfinity(ExecState
*, JSValue
, const Identifier
&)
98 return jsNumber(-std::numeric_limits
<double>::infinity());
101 static JSValue
numberConstructorPosInfinity(ExecState
*, JSValue
, const Identifier
&)
103 return jsNumber(std::numeric_limits
<double>::infinity());
106 static JSValue
numberConstructorMaxValue(ExecState
*, JSValue
, const Identifier
&)
108 return jsNumber(1.7976931348623157E+308);
111 static JSValue
numberConstructorMinValue(ExecState
*, JSValue
, const Identifier
&)
113 return jsNumber(5E-324);
117 static EncodedJSValue JSC_HOST_CALL
constructWithNumberConstructor(ExecState
* exec
)
119 NumberObject
* object
= NumberObject::create(exec
->globalData(), asInternalFunction(exec
->callee())->globalObject()->numberObjectStructure());
120 double n
= exec
->argumentCount() ? exec
->argument(0).toNumber(exec
) : 0;
121 object
->setInternalValue(exec
->globalData(), jsNumber(n
));
122 return JSValue::encode(object
);
125 ConstructType
NumberConstructor::getConstructData(JSCell
*, ConstructData
& constructData
)
127 constructData
.native
.function
= constructWithNumberConstructor
;
128 return ConstructTypeHost
;
132 static EncodedJSValue JSC_HOST_CALL
callNumberConstructor(ExecState
* exec
)
134 return JSValue::encode(jsNumber(!exec
->argumentCount() ? 0 : exec
->argument(0).toNumber(exec
)));
137 CallType
NumberConstructor::getCallData(JSCell
*, CallData
& callData
)
139 callData
.native
.function
= callNumberConstructor
;