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"
28 #include "JSCInlines.h"
32 static EncodedJSValue
numberConstructorNaNValue(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
);
33 static EncodedJSValue
numberConstructorNegInfinity(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
);
34 static EncodedJSValue
numberConstructorPosInfinity(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
);
35 static EncodedJSValue
numberConstructorMaxValue(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
);
36 static EncodedJSValue
numberConstructorMinValue(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
);
40 #include "NumberConstructor.lut.h"
44 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NumberConstructor
);
46 const ClassInfo
NumberConstructor::s_info
= { "Function", &InternalFunction::s_info
, 0, ExecState::numberConstructorTable
, CREATE_METHOD_TABLE(NumberConstructor
) };
48 /* Source for NumberConstructor.lut.h
49 @begin numberConstructorTable
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
58 NumberConstructor::NumberConstructor(VM
& vm
, Structure
* structure
)
59 : InternalFunction(vm
, structure
)
63 void NumberConstructor::finishCreation(VM
& vm
, NumberPrototype
* numberPrototype
)
65 Base::finishCreation(vm
, NumberPrototype::info()->className
);
66 ASSERT(inherits(info()));
69 putDirectWithoutTransition(vm
, vm
.propertyNames
->prototype
, numberPrototype
, DontEnum
| DontDelete
| ReadOnly
);
71 // no. of arguments for constructor
72 putDirectWithoutTransition(vm
, vm
.propertyNames
->length
, jsNumber(1), ReadOnly
| DontEnum
| DontDelete
);
75 bool NumberConstructor::getOwnPropertySlot(JSObject
* object
, ExecState
* exec
, PropertyName propertyName
, PropertySlot
& slot
)
77 return getStaticValueSlot
<NumberConstructor
, InternalFunction
>(exec
, ExecState::numberConstructorTable(exec
->vm()), jsCast
<NumberConstructor
*>(object
), propertyName
, slot
);
80 static EncodedJSValue
numberConstructorNaNValue(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
)
82 return JSValue::encode(jsNaN());
85 static EncodedJSValue
numberConstructorNegInfinity(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
)
87 return JSValue::encode(jsNumber(-std::numeric_limits
<double>::infinity()));
90 static EncodedJSValue
numberConstructorPosInfinity(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
)
92 return JSValue::encode(jsNumber(std::numeric_limits
<double>::infinity()));
95 static EncodedJSValue
numberConstructorMaxValue(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
)
97 return JSValue::encode(jsNumber(1.7976931348623157E+308));
100 static EncodedJSValue
numberConstructorMinValue(ExecState
*, JSObject
*, EncodedJSValue
, PropertyName
)
102 return JSValue::encode(jsNumber(5E-324));
106 static EncodedJSValue JSC_HOST_CALL
constructWithNumberConstructor(ExecState
* exec
)
108 NumberObject
* object
= NumberObject::create(exec
->vm(), asInternalFunction(exec
->callee())->globalObject()->numberObjectStructure());
109 double n
= exec
->argumentCount() ? exec
->uncheckedArgument(0).toNumber(exec
) : 0;
110 object
->setInternalValue(exec
->vm(), jsNumber(n
));
111 return JSValue::encode(object
);
114 ConstructType
NumberConstructor::getConstructData(JSCell
*, ConstructData
& constructData
)
116 constructData
.native
.function
= constructWithNumberConstructor
;
117 return ConstructTypeHost
;
121 static EncodedJSValue JSC_HOST_CALL
callNumberConstructor(ExecState
* exec
)
123 return JSValue::encode(jsNumber(!exec
->argumentCount() ? 0 : exec
->uncheckedArgument(0).toNumber(exec
)));
126 CallType
NumberConstructor::getCallData(JSCell
*, CallData
& callData
)
128 callData
.native
.function
= callNumberConstructor
;