2 * Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org)
3 * Copyright (C) 2007, 2008 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"
25 #include "NumberObject.h"
26 #include "NumberPrototype.h"
30 ASSERT_CLASS_FITS_IN_CELL(NumberConstructor
);
32 static JSValuePtr
numberConstructorNaNValue(ExecState
*, const Identifier
&, const PropertySlot
&);
33 static JSValuePtr
numberConstructorNegInfinity(ExecState
*, const Identifier
&, const PropertySlot
&);
34 static JSValuePtr
numberConstructorPosInfinity(ExecState
*, const Identifier
&, const PropertySlot
&);
35 static JSValuePtr
numberConstructorMaxValue(ExecState
*, const Identifier
&, const PropertySlot
&);
36 static JSValuePtr
numberConstructorMinValue(ExecState
*, const Identifier
&, const PropertySlot
&);
40 #include "NumberConstructor.lut.h"
44 const ClassInfo
NumberConstructor::info
= { "Function", &InternalFunction::info
, 0, ExecState::numberTable
};
46 /* Source for NumberConstructor.lut.h
48 NaN numberConstructorNaNValue DontEnum|DontDelete|ReadOnly
49 NEGATIVE_INFINITY numberConstructorNegInfinity DontEnum|DontDelete|ReadOnly
50 POSITIVE_INFINITY numberConstructorPosInfinity DontEnum|DontDelete|ReadOnly
51 MAX_VALUE numberConstructorMaxValue DontEnum|DontDelete|ReadOnly
52 MIN_VALUE numberConstructorMinValue DontEnum|DontDelete|ReadOnly
56 NumberConstructor::NumberConstructor(ExecState
* exec
, PassRefPtr
<Structure
> structure
, NumberPrototype
* numberPrototype
)
57 : InternalFunction(&exec
->globalData(), structure
, Identifier(exec
, numberPrototype
->info
.className
))
60 putDirectWithoutTransition(exec
->propertyNames().prototype
, numberPrototype
, DontEnum
| DontDelete
| ReadOnly
);
62 // no. of arguments for constructor
63 putDirectWithoutTransition(exec
->propertyNames().length
, jsNumber(exec
, 1), ReadOnly
| DontEnum
| DontDelete
);
66 bool NumberConstructor::getOwnPropertySlot(ExecState
* exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
68 return getStaticValueSlot
<NumberConstructor
, InternalFunction
>(exec
, ExecState::numberTable(exec
), this, propertyName
, slot
);
71 JSValuePtr
numberConstructorNaNValue(ExecState
* exec
, const Identifier
&, const PropertySlot
&)
76 JSValuePtr
numberConstructorNegInfinity(ExecState
* exec
, const Identifier
&, const PropertySlot
&)
78 return jsNumber(exec
, -Inf
);
81 JSValuePtr
numberConstructorPosInfinity(ExecState
* exec
, const Identifier
&, const PropertySlot
&)
83 return jsNumber(exec
, Inf
);
86 JSValuePtr
numberConstructorMaxValue(ExecState
* exec
, const Identifier
&, const PropertySlot
&)
88 return jsNumber(exec
, 1.7976931348623157E+308);
91 JSValuePtr
numberConstructorMinValue(ExecState
* exec
, const Identifier
&, const PropertySlot
&)
93 return jsNumber(exec
, 5E-324);
97 static JSObject
* constructWithNumberConstructor(ExecState
* exec
, JSObject
*, const ArgList
& args
)
99 NumberObject
* object
= new (exec
) NumberObject(exec
->lexicalGlobalObject()->numberObjectStructure());
100 double n
= args
.isEmpty() ? 0 : args
.at(exec
, 0).toNumber(exec
);
101 object
->setInternalValue(jsNumber(exec
, n
));
105 ConstructType
NumberConstructor::getConstructData(ConstructData
& constructData
)
107 constructData
.native
.function
= constructWithNumberConstructor
;
108 return ConstructTypeHost
;
112 static JSValuePtr
callNumberConstructor(ExecState
* exec
, JSObject
*, JSValuePtr
, const ArgList
& args
)
114 return jsNumber(exec
, args
.isEmpty() ? 0 : args
.at(exec
, 0).toNumber(exec
));
117 CallType
NumberConstructor::getCallData(CallData
& callData
)
119 callData
.native
.function
= callNumberConstructor
;