18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org) 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is free software; you can redistribute it and/or 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modify it under the terms of the GNU Lesser General Public 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License as published by the Free Software Foundation; either 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * version 2 of the License, or (at your option) any later version. 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is distributed in the hope that it will be useful, 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Lesser General Public License for more details. 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * You should have received a copy of the GNU Lesser General Public 168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License along with this library; if not, write to the Free Software 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * USA 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */ 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h" 238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "NumberConstructor.h" 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "NumberObject.h" 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "NumberPrototype.h" 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace JSC { 298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectASSERT_CLASS_FITS_IN_CELL(NumberConstructor); 318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 325f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorNaNValue(ExecState*, const Identifier&, const PropertySlot&); 335f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorNegInfinity(ExecState*, const Identifier&, const PropertySlot&); 345f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorPosInfinity(ExecState*, const Identifier&, const PropertySlot&); 355f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorMaxValue(ExecState*, const Identifier&, const PropertySlot&); 365f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorMinValue(ExecState*, const Identifier&, const PropertySlot&); 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace JSC 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "NumberConstructor.lut.h" 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace JSC { 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectconst ClassInfo NumberConstructor::info = { "Function", &InternalFunction::info, 0, ExecState::numberTable }; 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* Source for NumberConstructor.lut.h 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project@begin numberTable 488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project NaN numberConstructorNaNValue DontEnum|DontDelete|ReadOnly 498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project NEGATIVE_INFINITY numberConstructorNegInfinity DontEnum|DontDelete|ReadOnly 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project POSITIVE_INFINITY numberConstructorPosInfinity DontEnum|DontDelete|ReadOnly 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project MAX_VALUE numberConstructorMaxValue DontEnum|DontDelete|ReadOnly 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project MIN_VALUE numberConstructorMinValue DontEnum|DontDelete|ReadOnly 538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project@end 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project*/ 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 56231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve BlockNumberConstructor::NumberConstructor(ExecState* exec, NonNullPassRefPtr<Structure> structure, NumberPrototype* numberPrototype) 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project : InternalFunction(&exec->globalData(), structure, Identifier(exec, numberPrototype->info.className)) 588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Number.Prototype 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project putDirectWithoutTransition(exec->propertyNames().prototype, numberPrototype, DontEnum | DontDelete | ReadOnly); 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // no. of arguments for constructor 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectbool NumberConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return getStaticValueSlot<NumberConstructor, InternalFunction>(exec, ExecState::numberTable(exec), this, propertyName, slot); 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 71231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockbool NumberConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) 72231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{ 73231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return getStaticValueDescriptor<NumberConstructor, InternalFunction>(exec, ExecState::numberTable(exec), this, propertyName, descriptor); 74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block} 75231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 765f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorNaNValue(ExecState* exec, const Identifier&, const PropertySlot&) 778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return jsNaN(exec); 798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 815f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorNegInfinity(ExecState* exec, const Identifier&, const PropertySlot&) 828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 83635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project return jsNumber(exec, -Inf); 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 865f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorPosInfinity(ExecState* exec, const Identifier&, const PropertySlot&) 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 88635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project return jsNumber(exec, Inf); 898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 915f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorMaxValue(ExecState* exec, const Identifier&, const PropertySlot&) 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 93635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project return jsNumber(exec, 1.7976931348623157E+308); 948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 965f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue numberConstructorMinValue(ExecState* exec, const Identifier&, const PropertySlot&) 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 98635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project return jsNumber(exec, 5E-324); 998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// ECMA 15.7.1 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstatic JSObject* constructWithNumberConstructor(ExecState* exec, JSObject*, const ArgList& args) 1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project NumberObject* object = new (exec) NumberObject(exec->lexicalGlobalObject()->numberObjectStructure()); 1055f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian double n = args.isEmpty() ? 0 : args.at(0).toNumber(exec); 1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project object->setInternalValue(jsNumber(exec, n)); 1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return object; 1088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectConstructType NumberConstructor::getConstructData(ConstructData& constructData) 1118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project constructData.native.function = constructWithNumberConstructor; 1138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return ConstructTypeHost; 1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// ECMA 15.7.2 1175f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic JSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) 1188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1195f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian return jsNumber(exec, args.isEmpty() ? 0 : args.at(0).toNumber(exec)); 1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectCallType NumberConstructor::getCallData(CallData& callData) 1238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project callData.native.function = callNumberConstructor; 1258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return CallTypeHost; 1268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace JSC 129