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